def save(self, *args, **kwargs): """ Override model's saving function to do some checks """ # Call the "real" save() method. # http://docs.djangoproject.com/en/dev/topics/db/models/ #overriding-predefined-model-methods unique_slugify( self, '%s %s %s' % (self.name, self.course.code, self.course.year), 'slug') # happens if the slug is totally unicode characters if len(self.slug) == 0: raise ValidationError('QSet slug contains invalid characters') if self.min_num > self.max_num: raise ValidationError(('Minimum number of questions must be ' 'smaller or equal to maximum number.')) if self.min_total > self.max_total: raise ValidationError(('Minimum total must be ' 'smaller or equal than the maximum total.')) if self.min_difficulty > self.max_difficulty: raise ValidationError(('Minimum difficulty must be smaller ' 'or equal to the maximum difficulty.')) if self.ans_time_start > self.ans_time_final: raise ValidationError('Start time must be earlier than end time.') # Call the "real" save() method. super(QSet, self).save(*args, **kwargs)
def save(self, *args, **kwargs): """ Override the model's saving function to create the slug """ # http://docs.djangoproject.com/en/dev/topics/db/models/ #overriding-predefined-model-methods unique_slugify(self, self.user.username, 'slug') # Call the "real" save() method. super(UserProfile, self).save(*args, **kwargs)
def save(self, *args, **kwargs): """ http://docs.djangoproject.com/en/dev/topics/db/models/ overriding-predefined-model-methods """ self.first_name = self.first_name.strip() self.last_name = self.last_name.strip() unique_slugify(self, self.full_name, 'slug') super(Author, self).save(*args, **kwargs)
def save(self, force_insert=False, force_update=False, **kwargs): # Ensure this slug is unique amongst attachments attached to this object queryset = Attachment.objects.filter( content_type=self.content_type, object_id=self.object_id) if self.pk: queryset = queryset.exclude(pk=self.pk) unique_slugify(self, self.title, queryset=queryset) if not self.title: self.title = self.file_name() super(Attachment, self).save(force_insert, force_update)
def post(self): subject = self.request.get("subject") slug = utils.unique_slugify(" ".join(subject.split()[:10]), get_all_slugs()) content = self.request.get("content") draft = True if self.request.get("draft-checkbox") else False if subject: post = Post(subject=subject, slug=slug, content=content, draft=draft) post.put() memcache.delete("posts") self.redirect('/%s' % post.slug) else: error = "Your post needs title!" self.render_page(subject, content, draft, error)
def save(self, *args, **kwargs): slug_str = "%s" % self.name unique_slugify(self, slug_str) super(Brand, self).save(*args, **kwargs)
def save(self, *args, **kwargs): slug_str = "%s" % self.name unique_slugify(self, slug_str) self.cost_percent = (self.total_distance * self.gas_value) / self.transport.autonomy super(Map, self).save(*args, **kwargs)
def save(self, *args, **kwargs): slug_str = "%s" % self.name unique_slugify(self, slug_str) super(Vehicle, self).save(*args, **kwargs)
def save(self, force_update=False, force_insert=False): unique_slugify(self, self.name) super(Country, self).save(force_update=force_update, force_insert=force_insert)
def save(self, **kwargs): if self.pk is None: slug = '%s' % (self.name,) unique_slugify(self, slug) super(Content, self).save(**kwargs)
def save(self, **kwargs): if self.pk is None: slug = '%s %s' % (self.school.name,self.name) unique_slugify(self, slug) super(Class, self).save(**kwargs)
def save(self, *args, **kwargs): if not self.id: unique_slugify(self, self.name) super(Institution, self).save(*args, **kwargs)
def save(self, *args, **kwargs): if not self.id: unique_slugify(self, self.title) super(Lecture, self).save(*args, **kwargs)
def save(self, force_update=False, force_insert=False): unique_slugify(self, self.name) super(Subdivision, self).save(force_update=force_update, force_insert=force_insert)
def save(self, *args, **kwargs): self.title = self.title.strip() unique_slugify(self, self.title[0:255], 'slug') super(Item, self).save(*args, **kwargs)
def save(self, force_update=False, force_insert=False): unique_slugify(self, self.city) super(Location, self).save(force_update=force_update, force_insert=force_insert)