From: Bryan Date: Sat, 22 Feb 2014 21:17:11 +0000 (-0500) Subject: removing school from course URL, using reverse for Course.get_absolute_url for #325 X-Git-Tag: release-20150131~163^2~10 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=dda166347b2e53e9e12e7204325f120765210c7b;p=oweals%2Fkarmaworld.git removing school from course URL, using reverse for Course.get_absolute_url for #325 --- diff --git a/karmaworld/apps/courses/models.py b/karmaworld/apps/courses/models.py index adbc3e2..6639180 100644 --- a/karmaworld/apps/courses/models.py +++ b/karmaworld/apps/courses/models.py @@ -13,6 +13,7 @@ import reversion from django.db import models from django.utils.text import slugify +from django.core.urlresolvers import reverse from karmaworld.settings.manual_unique_together import auto_add_check_unique_together @@ -247,8 +248,8 @@ class Course(models.Model): natural_key.dependencies = ['courses.department'] def get_absolute_url(self): - """ return url based on school slug and self slug """ - return u"/{0}/{1}".format(self.school.slug, self.slug) + """ return url based on urls.py definition. """ + return reverse('course_detail', kwargs={'slug':self.slug}) def save(self, *args, **kwargs): """ Save school and generate a slug if one doesn't exist """ diff --git a/karmaworld/apps/courses/views.py b/karmaworld/apps/courses/views.py index 42900f5..b88fe7b 100644 --- a/karmaworld/apps/courses/views.py +++ b/karmaworld/apps/courses/views.py @@ -52,10 +52,8 @@ class CourseListView(ListView, ModelFormMixin, ProcessFormView): return context def get_success_url(self): - """ On form submission success, redirect to what url """ - return u'/{school_slug}/{course_slug}'.format( - school_slug=self.object.school.slug, - course_slug=self.object.slug) + """ On success, return url based on urls.py definition. """ + return self.object.get_absolute_url() def form_invalid(self, form, **kwargs): """ override form_invalid to populate object_list on redirect """ diff --git a/karmaworld/urls.py b/karmaworld/urls.py index e6044b9..6777de8 100644 --- a/karmaworld/urls.py +++ b/karmaworld/urls.py @@ -84,7 +84,7 @@ urlpatterns = patterns('', url(r'^search/$', NoteSearchView.as_view(), name='note_search'), # VIEW for displaying a single Course - url(r'^' + SLUG.format('school_') + '/' + SLUG.format('') + '/$', + url(r'^course/' + SLUG.format('') + '/$', CourseDetailView.as_view(), name='course_detail'), ## NOTE MODEL