mirror of
https://github.com/ae-utbm/sith.git
synced 2024-11-22 14:13:21 +00:00
Add basic rights to weekmail
This commit is contained in:
parent
ae0b7699f3
commit
4954c610f8
@ -84,7 +84,6 @@ class Weekmail(models.Model):
|
|||||||
|
|
||||||
def send(self):
|
def send(self):
|
||||||
dest = [i[0] for i in Preferences.objects.filter(receive_weekmail=True).values_list('user__email')]
|
dest = [i[0] for i in Preferences.objects.filter(receive_weekmail=True).values_list('user__email')]
|
||||||
print(dest)
|
|
||||||
with transaction.atomic():
|
with transaction.atomic():
|
||||||
email = EmailMultiAlternatives(
|
email = EmailMultiAlternatives(
|
||||||
subject=self.title,
|
subject=self.title,
|
||||||
@ -112,6 +111,9 @@ class Weekmail(models.Model):
|
|||||||
def __str__(self):
|
def __str__(self):
|
||||||
return "Weekmail %s (sent: %s) - %s" % (self.id, self.sent, self.title)
|
return "Weekmail %s (sent: %s) - %s" % (self.id, self.sent, self.title)
|
||||||
|
|
||||||
|
def is_owned_by(self, user):
|
||||||
|
return user.is_in_group(settings.SITH_GROUP_COM_ADMIN_ID)
|
||||||
|
|
||||||
class WeekmailArticle(models.Model):
|
class WeekmailArticle(models.Model):
|
||||||
weekmail = models.ForeignKey(Weekmail, related_name="articles", verbose_name=_("weekmail"), null=True)
|
weekmail = models.ForeignKey(Weekmail, related_name="articles", verbose_name=_("weekmail"), null=True)
|
||||||
title = models.CharField(_("title"), max_length=64)
|
title = models.CharField(_("title"), max_length=64)
|
||||||
@ -120,3 +122,6 @@ class WeekmailArticle(models.Model):
|
|||||||
club = models.ForeignKey(Club, related_name="weekmail_articles", verbose_name=_("club"))
|
club = models.ForeignKey(Club, related_name="weekmail_articles", verbose_name=_("club"))
|
||||||
rank = models.IntegerField(_('rank'), default=-1)
|
rank = models.IntegerField(_('rank'), default=-1)
|
||||||
|
|
||||||
|
def is_owned_by(self, user):
|
||||||
|
return user.is_in_group(settings.SITH_GROUP_COM_ADMIN_ID)
|
||||||
|
|
||||||
|
12
com/views.py
12
com/views.py
@ -165,7 +165,7 @@ class NewsEditView(CanEditMixin, UpdateView):
|
|||||||
Notification(user=u, url=reverse("com:news_detail", kwargs={'news_id': self.object.id}), type="NEWS_MODERATION").save()
|
Notification(user=u, url=reverse("com:news_detail", kwargs={'news_id': self.object.id}), type="NEWS_MODERATION").save()
|
||||||
return super(NewsEditView, self).form_valid(form)
|
return super(NewsEditView, self).form_valid(form)
|
||||||
|
|
||||||
class NewsCreateView(CanCreateMixin, CreateView):
|
class NewsCreateView(CanCreateMixin, CreateView): #XXX no can_be_created_by function in News model
|
||||||
model = News
|
model = News
|
||||||
form_class = NewsForm
|
form_class = NewsForm
|
||||||
template_name = 'com/news_edit.jinja'
|
template_name = 'com/news_edit.jinja'
|
||||||
@ -232,7 +232,7 @@ class NewsDetailView(CanViewMixin, DetailView):
|
|||||||
|
|
||||||
# Weekmail
|
# Weekmail
|
||||||
|
|
||||||
class WeekmailPreviewView(ComTabsMixin, DetailView):
|
class WeekmailPreviewView(ComTabsMixin, CanEditPropMixin, DetailView):
|
||||||
model = Weekmail
|
model = Weekmail
|
||||||
template_name = 'com/weekmail_preview.jinja'
|
template_name = 'com/weekmail_preview.jinja'
|
||||||
success_url = reverse_lazy('com:weekmail')
|
success_url = reverse_lazy('com:weekmail')
|
||||||
@ -256,7 +256,7 @@ class WeekmailPreviewView(ComTabsMixin, DetailView):
|
|||||||
kwargs['weekmail_rendered'] = self.object.render_html()
|
kwargs['weekmail_rendered'] = self.object.render_html()
|
||||||
return kwargs
|
return kwargs
|
||||||
|
|
||||||
class WeekmailEditView(ComTabsMixin, QuickNotifMixin, UpdateView):
|
class WeekmailEditView(ComTabsMixin, QuickNotifMixin, CanEditPropMixin, UpdateView):
|
||||||
model = Weekmail
|
model = Weekmail
|
||||||
template_name = 'com/weekmail.jinja'
|
template_name = 'com/weekmail.jinja'
|
||||||
fields = ['title', 'intro', 'joke', 'protip', 'conclusion']
|
fields = ['title', 'intro', 'joke', 'protip', 'conclusion']
|
||||||
@ -310,7 +310,7 @@ class WeekmailEditView(ComTabsMixin, QuickNotifMixin, UpdateView):
|
|||||||
kwargs['orphans'] = WeekmailArticle.objects.filter(weekmail=None)
|
kwargs['orphans'] = WeekmailArticle.objects.filter(weekmail=None)
|
||||||
return kwargs
|
return kwargs
|
||||||
|
|
||||||
class WeekmailArticleEditView(ComTabsMixin, QuickNotifMixin, UpdateView):
|
class WeekmailArticleEditView(ComTabsMixin, QuickNotifMixin, CanEditPropMixin, UpdateView):
|
||||||
"""Edit an article"""
|
"""Edit an article"""
|
||||||
model = WeekmailArticle
|
model = WeekmailArticle
|
||||||
fields = ['title', 'content']
|
fields = ['title', 'content']
|
||||||
@ -320,7 +320,7 @@ class WeekmailArticleEditView(ComTabsMixin, QuickNotifMixin, UpdateView):
|
|||||||
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, CreateView):
|
class WeekmailArticleCreateView(QuickNotifMixin, CreateView): #XXX need to protect this view
|
||||||
"""Post an article"""
|
"""Post an article"""
|
||||||
model = WeekmailArticle
|
model = WeekmailArticle
|
||||||
fields = ['title', 'content']
|
fields = ['title', 'content']
|
||||||
@ -334,7 +334,7 @@ class WeekmailArticleCreateView(QuickNotifMixin, CreateView):
|
|||||||
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)
|
||||||
|
|
||||||
class WeekmailArticleDeleteView(DeleteView):
|
class WeekmailArticleDeleteView(CanEditPropMixin, DeleteView):
|
||||||
"""Delete an article"""
|
"""Delete an article"""
|
||||||
model = WeekmailArticle
|
model = WeekmailArticle
|
||||||
template_name = 'core/delete_confirm.jinja'
|
template_name = 'core/delete_confirm.jinja'
|
||||||
|
Loading…
Reference in New Issue
Block a user