Aller au contenu

Views

sith = Sith.objects.first module-attribute

Club

Bases: Model

The Club class, made as a tree to allow nice tidy organization.

check_loop()

Raise a validation error when a loop is found within the parent list.

Source code in club/models.py
def check_loop(self):
    """Raise a validation error when a loop is found within the parent list."""
    objs = []
    cur = self
    while cur.parent is not None:
        if cur in objs:
            raise ValidationError(_("You can not make loops in clubs"))
        objs.append(cur)
        cur = cur.parent

is_owned_by(user)

Method to see if that object can be super edited by the given user.

Source code in club/models.py
def is_owned_by(self, user):
    """Method to see if that object can be super edited by the given user."""
    if user.is_anonymous:
        return False
    return user.is_board_member

can_be_edited_by(user)

Method to see if that object can be edited by the given user.

Source code in club/models.py
def can_be_edited_by(self, user):
    """Method to see if that object can be edited by the given user."""
    return self.has_rights_in_club(user)

can_be_viewed_by(user)

Method to see if that object can be seen by the given user.

Source code in club/models.py
def can_be_viewed_by(self, user):
    """Method to see if that object can be seen by the given user."""
    sub = User.objects.filter(pk=user.pk).first()
    if sub is None:
        return False
    return sub.was_subscribed

get_membership_for(user)

Return the current membership the given user.

Note

The result is cached.

Source code in club/models.py
def get_membership_for(self, user: User) -> Membership | None:
    """Return the current membership the given user.

    Note:
        The result is cached.
    """
    if user.is_anonymous:
        return None
    membership = cache.get(f"membership_{self.id}_{user.id}")
    if membership == "not_member":
        return None
    if membership is None:
        membership = self.members.filter(user=user, end_date=None).first()
        if membership is None:
            cache.set(f"membership_{self.id}_{user.id}", "not_member")
        else:
            cache.set(f"membership_{self.id}_{user.id}", membership)
    return membership

Mailing

Bases: Model

A Mailing list for a club.

Warning

Remember that mailing lists should be validated by UTBM.

News

Bases: Model

The news class.

NewsDate

Bases: Model

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

Poster

Bases: Model

Screen

Bases: Model

Sith

Bases: Model

A one instance class storing all the modifiable infos.

Weekmail

Bases: Model

The weekmail class.

:ivar title: Title of the weekmail :ivar intro: Introduction of the weekmail :ivar joke: Joke of the week :ivar protip: Tip of the week :ivar conclusion: Conclusion of the weekmail :ivar sent: Track if the weekmail has been sent

send()

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.

Source code in com/models.py
def send(self):
    """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 = [
        i[0]
        for i in Preferences.objects.filter(receive_weekmail=True).values_list(
            "user__email"
        )
    ]
    with transaction.atomic():
        email = EmailMultiAlternatives(
            subject=self.title,
            body=self.render_text(),
            from_email=settings.SITH_COM_EMAIL,
            to=Sith.objects.first().weekmail_destinations.split(" "),
            bcc=dest,
        )
        email.attach_alternative(self.render_html(), "text/html")
        email.send()
        self.sent = True
        self.save()
        Weekmail().save()

render_text()

Renders a pure text version of the mail for readers without HTML support.

Source code in com/models.py
def render_text(self):
    """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")

render_html()

Renders an HTML version of the mail with images and fancy CSS.

Source code in com/models.py
def render_html(self):
    """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")

get_banner()

Return an absolute link to the banner.

Source code in com/models.py
def get_banner(self):
    """Return an absolute link to the banner."""
    return (
        "http://" + settings.SITH_URL + static("com/img/weekmail_bannerV2P22.png")
    )

Return an absolute link to the footer.

Source code in com/models.py
def get_footer(self):
    """Return an absolute link to the footer."""
    return "http://" + settings.SITH_URL + static("com/img/weekmail_footerP22.png")

WeekmailArticle

Bases: Model

PosterForm(*args, **kwargs)

Bases: ModelForm

Source code in com/views.py
def __init__(self, *args, **kwargs):
    self.user = kwargs.pop("user", None)
    super().__init__(*args, **kwargs)
    if self.user and not self.user.is_com_admin:
        self.fields["club"].queryset = Club.objects.filter(
            id__in=self.user.clubs_with_rights
        )
        self.fields.pop("display_time")

ComTabsMixin

Bases: TabedViewMixin

IsComAdminMixin

Bases: View

ComEditView

Bases: ComTabsMixin, CanEditPropMixin, UpdateView

AlertMsgEditView

Bases: ComEditView

InfoMsgEditView

Bases: ComEditView

WeekmailDestinationEditView

Bases: ComEditView

NewsForm

Bases: ModelForm

NewsEditView

Bases: CanEditMixin, UpdateView

NewsCreateView

Bases: CanCreateMixin, CreateView

NewsDeleteView

Bases: CanEditMixin, DeleteView

NewsModerateView

Bases: CanEditMixin, SingleObjectMixin

NewsAdminListView

Bases: CanEditMixin, ListView

NewsListView

Bases: CanViewMixin, ListView

NewsDetailView

Bases: CanViewMixin, DetailView

WeekmailPreviewView

Bases: ComTabsMixin, QuickNotifMixin, CanEditPropMixin, DetailView

get_context_data(**kwargs)

Add rendered weekmail.

Source code in com/views.py
def get_context_data(self, **kwargs):
    """Add rendered weekmail."""
    kwargs = super().get_context_data(**kwargs)
    kwargs["weekmail_rendered"] = self.object.render_html()
    kwargs["bad_recipients"] = self.bad_recipients
    return kwargs

WeekmailEditView

Bases: ComTabsMixin, QuickNotifMixin, CanEditPropMixin, UpdateView

get_context_data(**kwargs)

Add orphan articles.

Source code in com/views.py
def get_context_data(self, **kwargs):
    """Add orphan articles."""
    kwargs = super().get_context_data(**kwargs)
    kwargs["orphans"] = WeekmailArticle.objects.filter(weekmail=None)
    return kwargs

WeekmailArticleEditView

Bases: ComTabsMixin, QuickNotifMixin, CanEditPropMixin, UpdateView

Edit an article.

WeekmailArticleCreateView

Bases: QuickNotifMixin, CreateView

Post an article.

WeekmailArticleDeleteView

Bases: CanEditPropMixin, DeleteView

Delete an article.

MailingListAdminView

Bases: ComTabsMixin, ListView

MailingModerateView

Bases: View

PosterListBaseView

Bases: ListView

List communication posters.

PosterCreateBaseView

Bases: CreateView

Create communication poster.

PosterEditBaseView

Bases: UpdateView

Edit communication poster.

PosterDeleteBaseView

Bases: DeleteView

Edit communication poster.

PosterListView

Bases: IsComAdminMixin, ComTabsMixin, PosterListBaseView

List communication posters.

PosterCreateView

Bases: IsComAdminMixin, ComTabsMixin, PosterCreateBaseView

Create communication poster.

PosterEditView

Bases: IsComAdminMixin, ComTabsMixin, PosterEditBaseView

Edit communication poster.

PosterDeleteView

Bases: IsComAdminMixin, ComTabsMixin, PosterDeleteBaseView

Delete communication poster.

PosterModerateListView

Bases: IsComAdminMixin, ComTabsMixin, ListView

Moderate list communication poster.

PosterModerateView

Bases: IsComAdminMixin, ComTabsMixin, View

Moderate communication poster.

ScreenListView

Bases: IsComAdminMixin, ComTabsMixin, ListView

List communication screens.

ScreenSlideshowView

Bases: DetailView

Slideshow of actives posters.

ScreenCreateView

Bases: IsComAdminMixin, ComTabsMixin, CreateView

Create communication screen.

ScreenEditView

Bases: IsComAdminMixin, ComTabsMixin, UpdateView

Edit communication screen.

ScreenDeleteView

Bases: IsComAdminMixin, ComTabsMixin, DeleteView

Delete communication screen.