FinalsClub/djKarma

Enforce Course uniqueness

Closed this issue · 2 comments

Currently, there's nothing preventing the existence of two courses at the same school with the same slug title. This can cause crashes when the server tries to get a course by slug/school (i.e: views.browse_one_course) expecting one result when in fact there are many.

We could remedy this by setting academic_year or semester on Courses and writing model-level validation to ensure a Course slug must be unique for a certain school at a given semester, year.

There is a unique_together function in django models (and in sql)
https://docs.djangoproject.com/en/1.4/ref/models/options/#unique-together

Then we can handle the create exception if adding fails.

Good catch

On Fri, Sep 28, 2012 at 4:05 PM, David Brodsky notifications@github.comwrote:

Currently, there's nothing preventing the existence of two courses at the
same school with the same slug title. This can cause crashes when the
server tries to get a course by slug/school (i.e: views.browse_one_course)

We could remedy this by setting academic_year or semester on Courses and
writing model-level validation to ensure a Course slug must be unique for a
certain school at a given semester, year.


Reply to this email directly or view it on GitHubhttps://github.com//issues/102.

fixed in 22e4cac. Thanks for the pointer! The current add course form shouldn't allow duplicates to be entered. The few I encountered must have been from way back.

python manage.py clean_courses will identify duplicate (school, slug) pairs in Course models, as well as populate required fields with default values (as fix_courses did before).