プロジェクトに django-schedule を組み込もうとしています。Django-schedule のソースはこちらです。それらはすべてスラッグをキャプチャするため、URLは好きではありません。私のプロジェクトでは、ユーザーごとに 1 つのカレンダーしか許可されないため、スラッグをキャプチャしても意味がありません。そこで、django-schedule ビューを次のようにラップしました (現在のユーザーを使用してスラッグを検索し、それを django-schedule のビューに渡します)。
from schedule.views import calendar_by_periods
from schedule.models import Calendar
from schedule.periods import Month
def cal_by_periods_wrapper(view):
def new_view(request, *args, **kwargs):
kwargs['calendar_slug'] = Calendar.objects.get_calendars_for_object(obj=request.user, distinction="owner")[0].slug
return view(request, *args, **kwargs)
return new_view
urls.py の関連セクションは次のとおりです。
urlpatterns = patterns('',
url(r'^$',
cal_by_periods_wrapper(calendar_by_periods),
name = "month_calendar",
kwargs={'periods': [Month], 'template_name': 'schedule/calendar_month.html'}),
これは、django-schedule に含まれるテンプレート タグの 1 つ、prev_url に到達するまで問題なく動作します。
@register.simple_tag
def prev_url(target, slug, period):
return '%s%s' % (
reverse(target, kwargs=dict(calendar_slug=slug)),
querystring_for_date(period.prev().start))
この関数は以下を発生させます。
TemplateSyntaxError at /teacher/calendar/
Caught an exception while rendering: Reverse for 'month_calendar' with arguments
'()' and keyword arguments '{'calendar_slug': u'asdf'}' not found.
このビューをラップして、逆呼び出しを機能させるにはどうすればよいですか?