mirror of
https://github.com/ae-utbm/sith.git
synced 2025-07-09 19:40:19 +00:00
use google convention for docstrings
This commit is contained in:
@ -39,7 +39,7 @@ from core.models import Notification, Preferences, RealGroup, User
|
||||
|
||||
|
||||
class Sith(models.Model):
|
||||
"""A one instance class storing all the modifiable infos"""
|
||||
"""A one instance class storing all the modifiable infos."""
|
||||
|
||||
alert_msg = models.TextField(_("alert message"), default="", blank=True)
|
||||
info_msg = models.TextField(_("info message"), default="", blank=True)
|
||||
@ -64,7 +64,7 @@ NEWS_TYPES = [
|
||||
|
||||
|
||||
class News(models.Model):
|
||||
"""The news class"""
|
||||
"""The news class."""
|
||||
|
||||
title = models.CharField(_("title"), max_length=64)
|
||||
summary = models.TextField(_("summary"))
|
||||
@ -143,8 +143,7 @@ def news_notification_callback(notif):
|
||||
|
||||
|
||||
class NewsDate(models.Model):
|
||||
"""
|
||||
A date class, useful for weekly events, or for events that just have no date
|
||||
"""A date class, useful for weekly events, or for events that just have no date.
|
||||
|
||||
This class allows more flexibilty managing the dates related to a news, particularly when this news is weekly, since
|
||||
we don't have to make copies
|
||||
@ -164,8 +163,7 @@ class NewsDate(models.Model):
|
||||
|
||||
|
||||
class Weekmail(models.Model):
|
||||
"""
|
||||
The weekmail class
|
||||
"""The weekmail class.
|
||||
|
||||
:ivar title: Title of the weekmail
|
||||
:ivar intro: Introduction of the weekmail
|
||||
@ -189,8 +187,8 @@ class Weekmail(models.Model):
|
||||
return f"Weekmail {self.id} (sent: {self.sent}) - {self.title}"
|
||||
|
||||
def send(self):
|
||||
"""
|
||||
Send the weekmail to all users with the receive weekmail option opt-in.
|
||||
"""Send the weekmail to all users with the receive weekmail option opt-in.
|
||||
|
||||
Also send the weekmail to the mailing list in settings.SITH_COM_EMAIL.
|
||||
"""
|
||||
dest = [
|
||||
@ -214,33 +212,25 @@ class Weekmail(models.Model):
|
||||
Weekmail().save()
|
||||
|
||||
def render_text(self):
|
||||
"""
|
||||
Renders a pure text version of the mail for readers without HTML support.
|
||||
"""
|
||||
"""Renders a pure text version of the mail for readers without HTML support."""
|
||||
return render(
|
||||
None, "com/weekmail_renderer_text.jinja", context={"weekmail": self}
|
||||
).content.decode("utf-8")
|
||||
|
||||
def render_html(self):
|
||||
"""
|
||||
Renders an HTML version of the mail with images and fancy CSS.
|
||||
"""
|
||||
"""Renders an HTML version of the mail with images and fancy CSS."""
|
||||
return render(
|
||||
None, "com/weekmail_renderer_html.jinja", context={"weekmail": self}
|
||||
).content.decode("utf-8")
|
||||
|
||||
def get_banner(self):
|
||||
"""
|
||||
Return an absolute link to the banner.
|
||||
"""
|
||||
"""Return an absolute link to the banner."""
|
||||
return (
|
||||
"http://" + settings.SITH_URL + static("com/img/weekmail_bannerV2P22.png")
|
||||
)
|
||||
|
||||
def get_footer(self):
|
||||
"""
|
||||
Return an absolute link to the footer.
|
||||
"""
|
||||
"""Return an absolute link to the footer."""
|
||||
return "http://" + settings.SITH_URL + static("com/img/weekmail_footerP22.png")
|
||||
|
||||
def is_owned_by(self, user):
|
||||
|
28
com/tests.py
28
com/tests.py
@ -115,10 +115,7 @@ class ComTest(TestCase):
|
||||
|
||||
class SithTest(TestCase):
|
||||
def test_sith_owner(self):
|
||||
"""
|
||||
Test that the sith instance is owned by com admins
|
||||
and nobody else
|
||||
"""
|
||||
"""Test that the sith instance is owned by com admins and nobody else."""
|
||||
sith: Sith = Sith.objects.first()
|
||||
|
||||
com_admin = User.objects.get(username="comunity")
|
||||
@ -148,20 +145,17 @@ class NewsTest(TestCase):
|
||||
cls.anonymous = AnonymousUser()
|
||||
|
||||
def test_news_owner(self):
|
||||
"""Test that news are owned by com admins
|
||||
or by their author but nobody else.
|
||||
"""
|
||||
Test that news are owned by com admins
|
||||
or by their author but nobody else
|
||||
"""
|
||||
|
||||
assert self.new.is_owned_by(self.com_admin)
|
||||
assert self.new.is_owned_by(self.author)
|
||||
assert not self.new.is_owned_by(self.anonymous)
|
||||
assert not self.new.is_owned_by(self.sli)
|
||||
|
||||
def test_news_viewer(self):
|
||||
"""
|
||||
Test that moderated news can be viewed by anyone
|
||||
and not moderated news only by com admins
|
||||
"""Test that moderated news can be viewed by anyone
|
||||
and not moderated news only by com admins.
|
||||
"""
|
||||
# by default a news isn't moderated
|
||||
assert self.new.can_be_viewed_by(self.com_admin)
|
||||
@ -177,9 +171,7 @@ class NewsTest(TestCase):
|
||||
assert self.new.can_be_viewed_by(self.author)
|
||||
|
||||
def test_news_editor(self):
|
||||
"""
|
||||
Test that only com admins can edit news
|
||||
"""
|
||||
"""Test that only com admins can edit news."""
|
||||
assert self.new.can_be_edited_by(self.com_admin)
|
||||
assert not self.new.can_be_edited_by(self.sli)
|
||||
assert not self.new.can_be_edited_by(self.anonymous)
|
||||
@ -203,9 +195,7 @@ class WeekmailArticleTest(TestCase):
|
||||
cls.anonymous = AnonymousUser()
|
||||
|
||||
def test_weekmail_owner(self):
|
||||
"""
|
||||
Test that weekmails are owned only by com admins
|
||||
"""
|
||||
"""Test that weekmails are owned only by com admins."""
|
||||
assert self.article.is_owned_by(self.com_admin)
|
||||
assert not self.article.is_owned_by(self.author)
|
||||
assert not self.article.is_owned_by(self.anonymous)
|
||||
@ -229,9 +219,7 @@ class PosterTest(TestCase):
|
||||
cls.anonymous = AnonymousUser()
|
||||
|
||||
def test_poster_owner(self):
|
||||
"""
|
||||
Test that poster are owned by com admins and board members in clubs
|
||||
"""
|
||||
"""Test that poster are owned by com admins and board members in clubs."""
|
||||
assert self.poster.is_owned_by(self.com_admin)
|
||||
assert not self.poster.is_owned_by(self.anonymous)
|
||||
|
||||
|
40
com/views.py
40
com/views.py
@ -427,7 +427,7 @@ class WeekmailPreviewView(ComTabsMixin, QuickNotifMixin, CanEditPropMixin, Detai
|
||||
return self.model.objects.filter(sent=False).order_by("-id").first()
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
"""Add rendered weekmail"""
|
||||
"""Add rendered weekmail."""
|
||||
kwargs = super().get_context_data(**kwargs)
|
||||
kwargs["weekmail_rendered"] = self.object.render_html()
|
||||
kwargs["bad_recipients"] = self.bad_recipients
|
||||
@ -507,7 +507,7 @@ class WeekmailEditView(ComTabsMixin, QuickNotifMixin, CanEditPropMixin, UpdateVi
|
||||
return super().get(request, *args, **kwargs)
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
"""Add orphan articles"""
|
||||
"""Add orphan articles."""
|
||||
kwargs = super().get_context_data(**kwargs)
|
||||
kwargs["orphans"] = WeekmailArticle.objects.filter(weekmail=None)
|
||||
return kwargs
|
||||
@ -516,7 +516,7 @@ class WeekmailEditView(ComTabsMixin, QuickNotifMixin, CanEditPropMixin, UpdateVi
|
||||
class WeekmailArticleEditView(
|
||||
ComTabsMixin, QuickNotifMixin, CanEditPropMixin, UpdateView
|
||||
):
|
||||
"""Edit an article"""
|
||||
"""Edit an article."""
|
||||
|
||||
model = WeekmailArticle
|
||||
form_class = modelform_factory(
|
||||
@ -532,7 +532,7 @@ class WeekmailArticleEditView(
|
||||
|
||||
|
||||
class WeekmailArticleCreateView(QuickNotifMixin, CreateView):
|
||||
"""Post an article"""
|
||||
"""Post an article."""
|
||||
|
||||
model = WeekmailArticle
|
||||
form_class = modelform_factory(
|
||||
@ -574,7 +574,7 @@ class WeekmailArticleCreateView(QuickNotifMixin, CreateView):
|
||||
|
||||
|
||||
class WeekmailArticleDeleteView(CanEditPropMixin, DeleteView):
|
||||
"""Delete an article"""
|
||||
"""Delete an article."""
|
||||
|
||||
model = WeekmailArticle
|
||||
template_name = "core/delete_confirm.jinja"
|
||||
@ -614,7 +614,7 @@ class MailingModerateView(View):
|
||||
|
||||
|
||||
class PosterListBaseView(ListView):
|
||||
"""List communication posters"""
|
||||
"""List communication posters."""
|
||||
|
||||
current_tab = "posters"
|
||||
model = Poster
|
||||
@ -641,7 +641,7 @@ class PosterListBaseView(ListView):
|
||||
|
||||
|
||||
class PosterCreateBaseView(CreateView):
|
||||
"""Create communication poster"""
|
||||
"""Create communication poster."""
|
||||
|
||||
current_tab = "posters"
|
||||
form_class = PosterForm
|
||||
@ -673,7 +673,7 @@ class PosterCreateBaseView(CreateView):
|
||||
|
||||
|
||||
class PosterEditBaseView(UpdateView):
|
||||
"""Edit communication poster"""
|
||||
"""Edit communication poster."""
|
||||
|
||||
pk_url_kwarg = "poster_id"
|
||||
current_tab = "posters"
|
||||
@ -721,7 +721,7 @@ class PosterEditBaseView(UpdateView):
|
||||
|
||||
|
||||
class PosterDeleteBaseView(DeleteView):
|
||||
"""Edit communication poster"""
|
||||
"""Edit communication poster."""
|
||||
|
||||
pk_url_kwarg = "poster_id"
|
||||
current_tab = "posters"
|
||||
@ -738,7 +738,7 @@ class PosterDeleteBaseView(DeleteView):
|
||||
|
||||
|
||||
class PosterListView(IsComAdminMixin, ComTabsMixin, PosterListBaseView):
|
||||
"""List communication posters"""
|
||||
"""List communication posters."""
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
kwargs = super().get_context_data(**kwargs)
|
||||
@ -747,7 +747,7 @@ class PosterListView(IsComAdminMixin, ComTabsMixin, PosterListBaseView):
|
||||
|
||||
|
||||
class PosterCreateView(IsComAdminMixin, ComTabsMixin, PosterCreateBaseView):
|
||||
"""Create communication poster"""
|
||||
"""Create communication poster."""
|
||||
|
||||
success_url = reverse_lazy("com:poster_list")
|
||||
|
||||
@ -758,7 +758,7 @@ class PosterCreateView(IsComAdminMixin, ComTabsMixin, PosterCreateBaseView):
|
||||
|
||||
|
||||
class PosterEditView(IsComAdminMixin, ComTabsMixin, PosterEditBaseView):
|
||||
"""Edit communication poster"""
|
||||
"""Edit communication poster."""
|
||||
|
||||
success_url = reverse_lazy("com:poster_list")
|
||||
|
||||
@ -769,13 +769,13 @@ class PosterEditView(IsComAdminMixin, ComTabsMixin, PosterEditBaseView):
|
||||
|
||||
|
||||
class PosterDeleteView(IsComAdminMixin, ComTabsMixin, PosterDeleteBaseView):
|
||||
"""Delete communication poster"""
|
||||
"""Delete communication poster."""
|
||||
|
||||
success_url = reverse_lazy("com:poster_list")
|
||||
|
||||
|
||||
class PosterModerateListView(IsComAdminMixin, ComTabsMixin, ListView):
|
||||
"""Moderate list communication poster"""
|
||||
"""Moderate list communication poster."""
|
||||
|
||||
current_tab = "posters"
|
||||
model = Poster
|
||||
@ -789,7 +789,7 @@ class PosterModerateListView(IsComAdminMixin, ComTabsMixin, ListView):
|
||||
|
||||
|
||||
class PosterModerateView(IsComAdminMixin, ComTabsMixin, View):
|
||||
"""Moderate communication poster"""
|
||||
"""Moderate communication poster."""
|
||||
|
||||
def get(self, request, *args, **kwargs):
|
||||
obj = get_object_or_404(Poster, pk=kwargs["object_id"])
|
||||
@ -807,7 +807,7 @@ class PosterModerateView(IsComAdminMixin, ComTabsMixin, View):
|
||||
|
||||
|
||||
class ScreenListView(IsComAdminMixin, ComTabsMixin, ListView):
|
||||
"""List communication screens"""
|
||||
"""List communication screens."""
|
||||
|
||||
current_tab = "screens"
|
||||
model = Screen
|
||||
@ -815,7 +815,7 @@ class ScreenListView(IsComAdminMixin, ComTabsMixin, ListView):
|
||||
|
||||
|
||||
class ScreenSlideshowView(DetailView):
|
||||
"""Slideshow of actives posters"""
|
||||
"""Slideshow of actives posters."""
|
||||
|
||||
pk_url_kwarg = "screen_id"
|
||||
model = Screen
|
||||
@ -828,7 +828,7 @@ class ScreenSlideshowView(DetailView):
|
||||
|
||||
|
||||
class ScreenCreateView(IsComAdminMixin, ComTabsMixin, CreateView):
|
||||
"""Create communication screen"""
|
||||
"""Create communication screen."""
|
||||
|
||||
current_tab = "screens"
|
||||
model = Screen
|
||||
@ -838,7 +838,7 @@ class ScreenCreateView(IsComAdminMixin, ComTabsMixin, CreateView):
|
||||
|
||||
|
||||
class ScreenEditView(IsComAdminMixin, ComTabsMixin, UpdateView):
|
||||
"""Edit communication screen"""
|
||||
"""Edit communication screen."""
|
||||
|
||||
pk_url_kwarg = "screen_id"
|
||||
current_tab = "screens"
|
||||
@ -849,7 +849,7 @@ class ScreenEditView(IsComAdminMixin, ComTabsMixin, UpdateView):
|
||||
|
||||
|
||||
class ScreenDeleteView(IsComAdminMixin, ComTabsMixin, DeleteView):
|
||||
"""Delete communication screen"""
|
||||
"""Delete communication screen."""
|
||||
|
||||
pk_url_kwarg = "screen_id"
|
||||
current_tab = "screens"
|
||||
|
Reference in New Issue
Block a user