django-components/sampleproject/components/nested/calendar/calendar.py
Juro Oravec e1382d3ccd
refactor: Remove safer_staticfiles, replace STATICFILES_DIRS with COMPONENTS.dirs, support [app]/components (#652)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2024-09-11 08:45:55 +02:00

30 lines
909 B
Python

from django_components import Component, register
@register("calendar_nested")
class CalendarNested(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"