Requires comments for non-abstain votes only
This commit is contained in:
		
							parent
							
								
									6e133970d9
								
							
						
					
					
						commit
						d305cd8c13
					
				
					 1 changed files with 14 additions and 1 deletions
				
			
		| 
						 | 
					@ -3,6 +3,8 @@ from __future__ import unicode_literals
 | 
				
			||||||
from datetime import datetime
 | 
					from datetime import datetime
 | 
				
			||||||
from decimal import Decimal
 | 
					from decimal import Decimal
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					from django.core.exceptions import ValidationError
 | 
				
			||||||
 | 
					
 | 
				
			||||||
from django.db import models
 | 
					from django.db import models
 | 
				
			||||||
from django.db.models import Q, F
 | 
					from django.db.models import Q, F
 | 
				
			||||||
from django.db.models import Case, When, Value
 | 
					from django.db.models import Case, When, Value
 | 
				
			||||||
| 
						 | 
					@ -126,10 +128,21 @@ class Review(models.Model):
 | 
				
			||||||
    # No way to encode "-0" vs. "+0" into an IntegerField, and I don't feel
 | 
					    # No way to encode "-0" vs. "+0" into an IntegerField, and I don't feel
 | 
				
			||||||
    # like some complicated encoding system.
 | 
					    # like some complicated encoding system.
 | 
				
			||||||
    vote = models.CharField(max_length=2, blank=True, choices=VOTES.CHOICES, verbose_name=_("Vote"))
 | 
					    vote = models.CharField(max_length=2, blank=True, choices=VOTES.CHOICES, verbose_name=_("Vote"))
 | 
				
			||||||
    comment = models.TextField(verbose_name=_("Comment"))
 | 
					    comment = models.TextField(
 | 
				
			||||||
 | 
					        blank=True,
 | 
				
			||||||
 | 
					        verbose_name=_("Comment")
 | 
				
			||||||
 | 
					    )
 | 
				
			||||||
    comment_html = models.TextField(blank=True)
 | 
					    comment_html = models.TextField(blank=True)
 | 
				
			||||||
    submitted_at = models.DateTimeField(default=datetime.now, editable=False, verbose_name=_("Submitted at"))
 | 
					    submitted_at = models.DateTimeField(default=datetime.now, editable=False, verbose_name=_("Submitted at"))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    def clean(self):
 | 
				
			||||||
 | 
					        err = {}
 | 
				
			||||||
 | 
					        if self.vote != VOTES.ABSTAIN and not self.comment.strip():
 | 
				
			||||||
 | 
					            err["comment"] = ValidationError(_("You must provide a comment"))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if err:
 | 
				
			||||||
 | 
					            raise ValidationError(err)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def save(self, **kwargs):
 | 
					    def save(self, **kwargs):
 | 
				
			||||||
        self.comment_html = parse(self.comment)
 | 
					        self.comment_html = parse(self.comment)
 | 
				
			||||||
        if self.vote:
 | 
					        if self.vote:
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		
		Reference in a new issue