def save(self, *args, **kwargs): created = self.pk is None self.content = smart_lower(self.content) if created: self.author.invalidate_entry_counts() super().save(*args, **kwargs) # Check if the user has written 10 entries, If so make them available for novice lookup if self.author.is_novice and self.author.application_status == "OH" and self.author.entry_count >= 10: self.author.application_status = "PN" self.author.application_date = timezone.now() self.author.save() Message.objects.compose( get_generic_superuser(), self.author, gettext( "as you entered your first 10 entries, you have been admitted to" " the novice list. you can see your queue number in your profile page." " if your entry count drops below 10, you will be kicked from the list." ), ) # assign topic creator (includes novices) if not self.is_draft and not self.topic.created_by: self.topic.created_by = self.author self.topic.save() self.topic.register_wishes(fulfiller_entry=self)
def mutate(_root, info, title, hint=""): sender = info.context.user if not sender.is_accessible: raise ValueError(_("sorry, the genie is now busy")) topic = Topic.objects.get_or_pseudo(unicode_string=title) hint = smart_lower(hint).strip() or None if hint: validate_user_text(hint, exctype=ValueError) if not topic.valid or (topic.exists and (topic.is_banned or topic.has_entries)): raise ValueError(_("we couldn't handle your request. try again later.")) if not topic.exists: topic = Topic.objects.create_topic(title=title) else: previous_wish = topic.wishes.filter(author=sender) deleted, _types = previous_wish.delete() if deleted: return WishTopic(feedback=_("your wish has been deleted")) Wish.objects.create(topic=topic, author=sender, hint=hint) return WishTopic( feedback=_("your wish is now enlisted. if someone starts a discussion, we will let you know."), hint=linebreaksbr(formatted(hint)), )
def mutate(_root, info, title, hint=""): sender = info.context.user topic = Topic.objects.get_or_pseudo(unicode_string=title) hint = smart_lower(hint).strip() or None if not topic.valid or (topic.exists and (topic.has_entries or topic.is_banned)): raise ValueError( _("we couldn't handle your request. try again later.")) wish = Wish(author=sender, hint=hint) try: wish.full_clean() except ValidationError as error: raise ValueError(", ".join(error.messages)) from error if not topic.exists: topic = Topic.objects.create_topic(title=title) else: previous_wish = topic.wishes.filter(author=sender) if previous_wish.exists(): previous_wish.delete() return WishTopic(feedback=_("your wish has been deleted")) if not sender.is_accessible: raise ValueError(_("sorry, the genie is now busy")) wish.save() topic.wishes.add(wish) return WishTopic( feedback= _("your wish is now enlisted. if someone starts a discussion, we will let you know." ), hint=linebreaksbr(formatted(hint)), )
def save(self, *args, **kwargs): self.content = smart_lower(self.content) super().save(*args, **kwargs)
def save(self, *args, **kwargs): self.body = smart_lower(self.body).strip() super().save(*args, **kwargs)