diff --git a/judge/views/organization.py b/judge/views/organization.py index 53727ca..b3c23b8 100644 --- a/judge/views/organization.py +++ b/judge/views/organization.py @@ -1,4 +1,3 @@ -from itertools import chain from django import forms from django.conf import settings from django.contrib import messages @@ -1037,7 +1036,7 @@ class EditOrganizationBlog( MemberOrganizationMixin, UpdateView, ): - template_name = "organization/blog/add.html" + template_name = "organization/blog/edit.html" model = BlogPost def get_form_class(self): @@ -1063,6 +1062,10 @@ class EditOrganizationBlog( _("Not allowed to edit this blog"), ) + def delete_blog(self , request , *args , **kwargs): + self.blog_id = kwargs["blog_pk"] + BlogPost.objects.get(pk = self.blog_id).delete() + def get(self, request, *args, **kwargs): res = self.setup_blog(request, *args, **kwargs) if res: @@ -1073,7 +1076,13 @@ class EditOrganizationBlog( res = self.setup_blog(request, *args, **kwargs) if res: return res - return super().post(request, *args, **kwargs) + if request.POST['action'] == 'Delete': + self.create_notification("Delete blog") + self.delete_blog(request , *args , **kwargs) + cur_url = reverse("organization_pending_blogs", args=(self.organization_id,self.organization.slug) ) + return HttpResponseRedirect(cur_url) + else: + return super().post(request, *args, **kwargs) def get_object(self): return self.blog @@ -1081,32 +1090,36 @@ class EditOrganizationBlog( def get_title(self): return _("Edit blog %s") % self.object.title + def create_notification(self,action): + blog = BlogPost.objects.get(pk=self.blog_id) + link = reverse( + "edit_organization_blog", + args=[self.organization.id, self.organization.slug, self.blog_id], + ) + html = ( + f'{blog.title} - {self.organization.name}' + ) + post_authors = blog.authors.all() + posible_user = self.organization.admins.all() | post_authors + for user in posible_user: + if user.id == self.request.profile.id: + continue + notification = Notification( + owner=user, + author=self.request.profile, + category= action, + html_link=html, + ) + notification.save() + def form_valid(self, form): with transaction.atomic(), revisions.create_revision(): res = super(EditOrganizationBlog, self).form_valid(form) revisions.set_comment(_("Edited from site")) revisions.set_user(self.request.user) - - link = reverse( - "edit_organization_blog", - args=[self.organization.id, self.organization.slug, self.object.id], - ) - html = ( - f'{self.object.title} - {self.organization.name}' - ) - for user in self.organization.admins.all(): - if user.id == self.request.profile.id: - continue - notification = Notification( - owner=user, - author=self.request.profile, - category="Edit blog", - html_link=html, - ) - notification.save() + self.create_notification("Edit blog") return res - class PendingBlogs( LoginRequiredMixin, TitleMixin, diff --git a/resources/widgets.scss b/resources/widgets.scss index 6205be1..f99122e 100644 --- a/resources/widgets.scss +++ b/resources/widgets.scss @@ -100,6 +100,12 @@ background: darkblue; } } + + // class = "unselectable button full small" only appear in online-judge/templates/contest/list.html + // this attribute center buttons in contest list (including "Join", "Virutal Join", "Spectable") + &.unselectable.button.full.small { + margin: 0 auto + } } .button.full, input[type=submit].full, button.full { @@ -590,4 +596,4 @@ ul.select2-selection__rendered { .control-button:hover { background: gray; -} +} \ No newline at end of file diff --git a/templates/contest/ranking.html b/templates/contest/ranking.html index 5818c74..087a905 100644 --- a/templates/contest/ranking.html +++ b/templates/contest/ranking.html @@ -156,4 +156,4 @@ {{ _('Download as CSV') }} {% include "contest/ranking-table.html" %} -{% endblock %} +{% endblock %} \ No newline at end of file diff --git a/templates/organization/blog/edit.html b/templates/organization/blog/edit.html new file mode 100644 index 0000000..e2cca8e --- /dev/null +++ b/templates/organization/blog/edit.html @@ -0,0 +1,39 @@ +{% extends "organization/home-base.html" %} + +{% block three_col_js %} + {{ form.media.js }} + {% include "organization/home-js.html" %} +{% endblock %} + +{% block three_col_media %} + {{ form.media.css }} +{% endblock %} + +{% block middle_content %} +
+{% endblock %} \ No newline at end of file diff --git a/templates/organization/form.html b/templates/organization/form.html index f23df3c..227b59d 100644 --- a/templates/organization/form.html +++ b/templates/organization/form.html @@ -1,25 +1,25 @@ - \ No newline at end of file