mirror of
https://github.com/django-components/django-components.git
synced 2025-12-16 00:23:56 +00:00
Resolve media and template files relative to component class dir (#395), thanks @JuroOravec
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Emil Stenström <emil@emilstenstrom.se>
This commit is contained in:
parent
1de859bd34
commit
37fd901908
21 changed files with 477 additions and 43 deletions
|
|
@ -23,3 +23,27 @@ class Calendar(component.Component):
|
|||
class Media:
|
||||
css = "calendar/calendar.css"
|
||||
js = "calendar/calendar.js"
|
||||
|
||||
|
||||
@component.register("calendar_relative")
|
||||
class CalendarRelative(component.Component):
|
||||
# Note that Django will look for templates inside `[your apps]/components` dir and
|
||||
# `[project root]/components` dir. To customize which template to use based on context
|
||||
# you can override def get_template_name() instead of specifying the below variable.
|
||||
template_name = "calendar.html"
|
||||
|
||||
# This component takes one parameter, a date string to show in the template
|
||||
def get_context_data(self, date):
|
||||
return {
|
||||
"date": date,
|
||||
}
|
||||
|
||||
def get(self, request, *args, **kwargs):
|
||||
context = {
|
||||
"date": request.GET.get("date", ""),
|
||||
}
|
||||
return self.render_to_response(context)
|
||||
|
||||
class Media:
|
||||
css = "calendar.css"
|
||||
js = "calendar.js"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue