Commits

Fredrik Sjöblom  committed 636659e

For watchlist, use app_label for ContentType queries and urls to prevent conflicts with other apps.

  • Participants
  • Parent commits 1b0c10c
  • Tags 0.7rc

Comments (0)

Files changed (5)

File apps/watchlist/templatetags/watchlist_tags.py

 @register.simple_tag
 def unsubscribe_url(obj):
     ctype = ContentType.objects.get_for_model(obj)
-    return reverse('wl_unsubscribe', content_type=ctype.model, object_id=obj.pk)
+    return reverse('wl_unsubscribe', content_type='.'.join((ctype.app_label, ctype.model)), object_id=obj.pk)
+
+@register.simple_tag
+def unsubscribe_type_url(content_type):
+    return reverse('wl_unsubscribe_type', content_type='.'.join((content_type.app_label, content_type.model)))
 
 @register.simple_tag
 def subscribe_url(obj):
     ctype = ContentType.objects.get_for_model(obj)
-    return reverse('wl_subscribe', content_type=ctype.model, object_id=obj.pk)
+    return reverse('wl_subscribe', content_type='.'.join((ctype.app_label, ctype.model)), object_id=obj.pk)
 
 @register.filter
 def is_subscribed_to(user, obj):

File apps/watchlist/urls.py

 
 urlpatterns = patterns(
     '',
-    url(r'^subscribe/(?P<content_type>\w+)/(?P<object_id>\d+)/$', views.subscribe, name="wl_subscribe"),
-    url(r'^unsubscribe/(?P<content_type>\w+)/(?P<object_id>\d+)/$', views.unsubscribe, name="wl_unsubscribe"),
-    url(r'^unsubscribe-type/(?P<content_type>\w+)/$', views.unsubscribe_type, name="wl_unsubscribe_type"),
+    url(r'^subscribe/(?P<content_type>[\w]+\.[\w]+)/(?P<object_id>\d+)/$', views.subscribe, name="wl_subscribe"),
+    url(r'^unsubscribe/(?P<content_type>[\w]+\.[\w]+)/(?P<object_id>\d+)/$', views.unsubscribe, name="wl_unsubscribe"),
+    url(r'^unsubscribe-type/(?P<content_type>[\w]+\.[\w]+)/$', views.unsubscribe_type, name="wl_unsubscribe_type"),
     url(r'^list/$', views.list_subscriptions, name="wl_list"),
     )

File apps/watchlist/views.py

 @login_required
 @render_to('watchlist/subscribe.html')
 def subscribe(request, content_type, object_id):
-    ctype = get_object_or_404(ContentType, model=content_type)
+    app_label, app_model = content_type.split('.')
+    ctype = get_object_or_404(ContentType, app_label=app_label, model=app_model)
     obj = get_object_or_404(ctype.model_class(), pk=object_id)
     if request.method == 'POST' and 'Subscribe' in request.POST:
         Subscription.objects.subscribe(request.user, obj)
 @login_required
 @render_to('watchlist/unsubscribe.html')
 def unsubscribe(request, content_type, object_id):
-    ctype = get_object_or_404(ContentType, model=content_type)
+    app_label, app_model = content_type.split('.')
+    ctype = get_object_or_404(ContentType, app_label=app_label, model=app_model)
     obj = get_object_or_404(ctype.model_class(), pk=object_id)
     if request.method == 'POST' and 'Unsubscribe' in request.POST:
         Subscription.objects.unsubscribe(request.user, obj)
 @login_required
 @render_to('watchlist/unsubscribe.html')
 def unsubscribe_type(request, content_type):
-    ctype = get_object_or_404(ContentType, model=content_type)
+    app_label, app_model = content_type.split('.')
+    ctype = get_object_or_404(ContentType, app_label=app_label, model=app_model)
     if request.method == 'POST' and 'Unsubscribe' in request.POST:
         Subscription.objects.filter(user=request.user, content_type=ctype).delete()
         return HttpResponseRedirect(request.POST.get('next', '/'))

File templates/watchlist/list.html

 <ul>
   {% for subscription in object_list %}
   {% ifchanged subscription.content_type %}
-  <li><a href="{% url wl_unsubscribe_type subscription.content_type %}">
-      {% blocktrans with subscription.content_type as ctype %}Unsubscribe from all {{ ctype }}s.{% endblocktrans %}
+  <li><a href="{% unsubscribe_type_url subscription.content_type %}">
+    {% blocktrans with subscription.content_type.app_label as app and subscription.content_type.model as model %}Unsubscribe from all {{ app }} {{ model }}s.{% endblocktrans %}
   </li>
   {% endifchanged %}
   {% endfor %}

File templates/watchlist/unsubscribe.html

 
 {% load i18n %}
 
-{% block title %}{% trans "Unsubscribing from" %} {% if object %}{{ object }}{% else %}{{ ctype }}s{% endif %}{% endblock %}
+{% block title %}{% trans "Unsubscribing from" %} {% if object %}{{ object }}{% else %}{{ ctype.app_label }} {{ ctype.model }}s{% endif %}{% endblock %}
 
 {% block content %}
-<p>{% trans "Unsubscribing from" %} {% if object %}"{{ object }}"{% else %}{{ ctype }}s{% endif %}.
+<p>{% trans "Unsubscribing from" %} {% if object %}"{{ object }}"{% else %}{{ ctype.app_label }} {{ ctype.model }}s{% endif %}.
   {% blocktrans %}Are you sure you want to do that?{% endblocktrans %}</p>
 <form action="." method="post">
   <input type="hidden" value="{{ next }}" name="next" />