# HG changeset patch # User Ahsan Ali Shahid # Date 1376926219 -18000 # Node ID d534881629ff939949fab3f4de372788e2bfb77e # Parent 1f1e867cb37f6bd2232615491122c78902dbab3a Updated snippet's template and views files to fix rating code collision which prevented posting new snippets. Updated snippet's models file so that now secret id of each snippet will be unique. It also means that the no two or more than two snippets will have same secret id. diff -r 1f1e867cb37f -r d534881629ff apps/snippet/forms.py --- a/apps/snippet/forms.py Fri Jul 19 22:54:18 2013 +0500 +++ b/apps/snippet/forms.py Mon Aug 19 20:30:19 2013 +0500 @@ -35,8 +35,6 @@ ) - form_choices = ( (x,x) for x in range(1,6) ) - Rate = forms.ChoiceField(form_choices,widget=forms.RadioSelect(attrs={'onclick' :"document.getElementById('rate_form').submit();","class":"rate_radio"})) def __init__(self, *args, **kwargs): request = kwargs.pop('request') diff -r 1f1e867cb37f -r d534881629ff apps/snippet/models.py --- a/apps/snippet/models.py Fri Jul 19 22:54:18 2013 +0500 +++ b/apps/snippet/models.py Mon Aug 19 20:30:19 2013 +0500 @@ -12,7 +12,10 @@ t = 'abcdefghijkmnopqrstuvwwxyzABCDEFGHIJKLOMNOPQRSTUVWXYZ1234567890' def generate_secret_id(length=4): - return ''.join([random.choice(t) for i in range(length)]) + unique_id = ''.join([random.choice(t) for i in range(length)]) + while Snippet.objects.filter(secret_id = unique_id ).count()!= 0: + unique_id = ''.join([random.choice(t) for i in range(length)]) + return unique_id class SnippetManager(models.Manager): def public(self): diff -r 1f1e867cb37f -r d534881629ff apps/snippet/views.py --- a/apps/snippet/views.py Fri Jul 19 22:54:18 2013 +0500 +++ b/apps/snippet/views.py Mon Aug 19 20:30:19 2013 +0500 @@ -108,9 +108,11 @@ default_pygments_style = PygmentsStyle.objects.get(pk=1) + r = snippet.rating.votes + if snippet.rating.votes == 0: + r = 1 - score = (snippet.rating.score/snippet.rating.votes) - + score = snippet.rating.score/(r) context = { 'snippet_form': snippet_form, diff -r 1f1e867cb37f -r d534881629ff templates/snippet/snippet_details.djhtml --- a/templates/snippet/snippet_details.djhtml Fri Jul 19 22:54:18 2013 +0500 +++ b/templates/snippet/snippet_details.djhtml Mon Aug 19 20:30:19 2013 +0500 @@ -91,7 +91,13 @@
{% csrf_token%}

Rate this Snippet:

- {{ snippet_form.Rate }} +