removing school from course URL, using reverse for Course.get_absolute_url for #325
authorBryan <btbonval@gmail.com>
Sat, 22 Feb 2014 21:17:11 +0000 (16:17 -0500)
committerBryan <btbonval@gmail.com>
Sat, 22 Feb 2014 21:17:11 +0000 (16:17 -0500)
karmaworld/apps/courses/models.py
karmaworld/apps/courses/views.py
karmaworld/urls.py

index adbc3e2d3988e5ec28b4e6fd9de9ed5e2a48c39c..66391804b9b15e51baf5fbebcc07c4a00eae27bd 100644 (file)
@@ -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 """
index 42900f5ed9304a6e53f219cf6ced80e326705ccc..b88fe7b5a2be99601bac918a044ddb0a4c71114f 100644 (file)
@@ -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 """
index e6044b94b077accdcbf1021372413426d0e3e30b..6777de84baabba9a4a169642210b7da88d348119 100644 (file)
@@ -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