mirror of
https://github.com/ae-utbm/sith.git
synced 2024-11-25 10:34:21 +00:00
Fix Weekmail article creation view's rights
This commit is contained in:
parent
23fe797a9e
commit
2f5bd7d2ef
19
com/views.py
19
com/views.py
@ -351,7 +351,7 @@ class WeekmailArticleEditView(ComTabsMixin, QuickNotifMixin, CanEditPropMixin, U
|
|||||||
quick_notif_url_arg = "qn_weekmail_article_edit"
|
quick_notif_url_arg = "qn_weekmail_article_edit"
|
||||||
current_tab = "weekmail"
|
current_tab = "weekmail"
|
||||||
|
|
||||||
class WeekmailArticleCreateView(QuickNotifMixin, CanViewMixin, CreateView): #XXX need to protect this view
|
class WeekmailArticleCreateView(QuickNotifMixin, CreateView):
|
||||||
"""Post an article"""
|
"""Post an article"""
|
||||||
model = WeekmailArticle
|
model = WeekmailArticle
|
||||||
fields = ['title', 'club', 'content']
|
fields = ['title', 'club', 'content']
|
||||||
@ -366,9 +366,22 @@ class WeekmailArticleCreateView(QuickNotifMixin, CanViewMixin, CreateView): #XXX
|
|||||||
except: pass
|
except: pass
|
||||||
return init
|
return init
|
||||||
|
|
||||||
|
def post(self, request, *args, **kwargs):
|
||||||
|
form = self.get_form()
|
||||||
|
self.object = form.instance
|
||||||
|
form.is_valid() # Valid a first time to populate club field
|
||||||
|
try:
|
||||||
|
m = form.instance.club.get_membership_for(request.user)
|
||||||
|
if m.role <= settings.SITH_MAXIMUM_FREE_ROLE:
|
||||||
|
raise
|
||||||
|
except:
|
||||||
|
form.add_error('club', ValidationError(_("You must be a board member of the selected club to post in the Weekmail.")))
|
||||||
|
if form.is_valid() and not 'preview' in request.POST.keys():
|
||||||
|
return self.form_valid(form)
|
||||||
|
else:
|
||||||
|
return self.form_invalid(form)
|
||||||
|
|
||||||
def form_valid(self, form):
|
def form_valid(self, form):
|
||||||
# club = get_object_or_404(Club, id=self.kwargs['club_id'])
|
|
||||||
# form.instance.club = club
|
|
||||||
form.instance.author = self.request.user
|
form.instance.author = self.request.user
|
||||||
return super(WeekmailArticleCreateView, self).form_valid(form)
|
return super(WeekmailArticleCreateView, self).form_valid(form)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user