mirror of
https://github.com/django-components/django-components.git
synced 2025-08-03 05:32:19 +00:00
59 lines
1.7 KiB
Python
59 lines
1.7 KiB
Python
from django_components import Component, register
|
|
|
|
|
|
@register("calendar")
|
|
class Calendar(Component):
|
|
# Templates inside `[your apps]/components` dir and `[project root]/components` dir
|
|
# will be automatically found.
|
|
#
|
|
# `template_name` can be relative to dir where `calendar.py` is, or relative to COMPONENTS.dirs
|
|
template_name = "calendar/calendar.html"
|
|
# Or
|
|
# def get_template_name(context):
|
|
# return f"template-{context['name']}.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):
|
|
return self.render_to_response(
|
|
kwargs={
|
|
"date": request.GET.get("date", ""),
|
|
},
|
|
)
|
|
|
|
class Media:
|
|
css = "calendar/calendar.css"
|
|
js = "calendar/calendar.js"
|
|
|
|
|
|
@register("calendar_relative")
|
|
class CalendarRelative(Component):
|
|
# Templates inside `[your apps]/components` dir and `[project root]/components` dir
|
|
# will be automatically found.
|
|
#
|
|
# `template_name` can be relative to dir where `calendar.py` is, or relative to COMPONENTS.dirs
|
|
template_name = "calendar.html"
|
|
# Or
|
|
# def get_template_name(context):
|
|
# return f"template-{context['name']}.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):
|
|
return self.render_to_response(
|
|
kwargs={
|
|
"date": request.GET.get("date", ""),
|
|
},
|
|
)
|
|
|
|
class Media:
|
|
css = "calendar.css"
|
|
js = "calendar.js"
|