class PostAdminForm(forms.Form): change_type = forms.ChoiceField( label="Сменить тип поста", choices=Post.TYPES, required=False, ) new_label = forms.ChoiceField( label="Выдать лейбл", choices=[(None, "---")] + [(key, value.get("title")) for key, value in LABELS.items()], required=False, ) remove_label = forms.BooleanField(label="Удалить текуший лейбл", required=False) add_pin = forms.BooleanField(label="Запинить", required=False) pin_days = forms.IntegerField(label="На сколько дней пин?", initial=0, required=False) remove_pin = forms.BooleanField(label="Отпинить обратно", required=False) move_up = forms.BooleanField(label="Подбросить на главной", required=False) shadow_ban = forms.BooleanField( label="Шадоу бан (редко!)", required=False, ) hide_on_main = forms.BooleanField( label="Скрыть с главной", required=False, )
def do_post_admin_actions(request, post, data): # Labels if data["new_label"]: label = LABELS.get(data["new_label"]) if label: post.label = {"code": data["new_label"], **label} post.save() if data["remove_label"]: post.label = None post.save() # Pins if data["add_pin"]: post.is_pinned_until = datetime.utcnow() + timedelta( days=data["pin_days"]) post.save() if data["remove_pin"]: post.is_pinned_until = None post.save() # Moving up if data["move_up"]: post.last_activity_at = datetime.utcnow() post.save() # Shadow banning if data["shadow_ban"]: post.is_shadow_banned = True post.save() return redirect("show_post", post.type, post.slug)
def do_post_admin_actions(request, post, data): if not request.me.is_moderator: raise AccessDenied() # Change type if data["change_type"]: post.type = data["change_type"] post.save() # Labels if data["new_label"]: label = LABELS.get(data["new_label"]) if label: post.label = {"code": data["new_label"], **label} post.save() if data["remove_label"]: post.label = None post.save() # Pins if data["add_pin"]: post.is_pinned_until = datetime.utcnow() + timedelta( days=data["pin_days"]) post.save() if data["remove_pin"]: post.is_pinned_until = None post.save() # Moving up if data["move_up"]: post.last_activity_at = datetime.utcnow() post.save() # Shadow banning if data["shadow_ban"]: post.is_shadow_banned = True post.save() # Hide from main page if data["hide_on_main"]: post.is_visible_on_main_page = False post.save() # Close comments if data["close_comments"]: post.is_commentable = False post.save() # Transfer ownership to the given username if data["transfer_ownership"]: user = User.objects.filter( slug=data["transfer_ownership"].strip()).first() if user: post.author = user post.save() return redirect("show_post", post.type, post.slug)
def do_post_admin_actions(request, post, data): # Change type if data["change_type"]: post.type = data["change_type"] post.save() # Labels if data["new_label"]: label = LABELS.get(data["new_label"]) if label: post.label = {"code": data["new_label"], **label} post.save() if data["remove_label"]: post.label = None post.save() # Pins if data["add_pin"]: post.is_pinned_until = datetime.utcnow() + timedelta( days=data["pin_days"]) post.save() if data["remove_pin"]: post.is_pinned_until = None post.save() # Moving up if data["move_up"]: post.last_activity_at = datetime.utcnow() post.save() # Shadow banning if data["shadow_ban"]: post.is_shadow_banned = True post.save() # Hide from main page if data["hide_on_main"]: post.is_visible_on_main_page = False post.save() # Close comments if data["close_comments"]: post.is_commentable = False post.save() return redirect("show_post", post.type, post.slug)
def do_common_admin_and_curator_actions(request, post, data): # Change type if data["change_type"]: post.type = data["change_type"] post.save() # Labels if data["new_label"]: label = LABELS.get(data["new_label"]) if label: post.label_code = data["new_label"] post.save() if data["remove_label"]: post.label_code = None post.save() # Pins if data["add_pin"]: post.is_pinned_until = datetime.utcnow() + timedelta( days=data["pin_days"]) post.save() if data["remove_pin"]: post.is_pinned_until = None post.save() # Moving up if data["move_up"]: post.last_activity_at = datetime.utcnow() post.save() # Moving down if data["move_down"]: post.last_activity_at -= timedelta(days=3) post.save() # Shadow banning if data["shadow_ban"]: post.is_shadow_banned = True post.save() # Hide from feeds if data["hide_from_feeds"]: post.is_visible_in_feeds = False post.save()
def label(self): lbl = LABELS.get(self.label_code) if lbl is not None: lbl['code'] = self.label_code return lbl