mirror of
https://github.com/ae-utbm/sith.git
synced 2025-07-11 04:19:25 +00:00
All: Apply Black coding rules
This commit is contained in:
112
trombi/models.py
112
trombi/models.py
@ -42,8 +42,11 @@ class TrombiManager(models.Manager):
|
||||
|
||||
class AvailableTrombiManager(models.Manager):
|
||||
def get_queryset(self):
|
||||
return super(AvailableTrombiManager,
|
||||
self).get_queryset().filter(subscription_deadline__gte=date.today())
|
||||
return (
|
||||
super(AvailableTrombiManager, self)
|
||||
.get_queryset()
|
||||
.filter(subscription_deadline__gte=date.today())
|
||||
)
|
||||
|
||||
|
||||
class Trombi(models.Model):
|
||||
@ -52,17 +55,32 @@ class Trombi(models.Model):
|
||||
It contains the deadlines for the users, and the link to the club that makes
|
||||
its Trombi.
|
||||
"""
|
||||
subscription_deadline = models.DateField(_('subscription deadline'),
|
||||
default=date.today, help_text=_("Before this date, users are "
|
||||
"allowed to subscribe to this Trombi. "
|
||||
"After this date, users subscribed will be allowed to comment on each other."))
|
||||
comments_deadline = models.DateField(_('comments deadline'),
|
||||
default=date.today, help_text=_("After this date, users won't be "
|
||||
"able to make comments anymore."))
|
||||
max_chars = models.IntegerField(_('maximum characters'), default=400,
|
||||
help_text=_('Maximum number of characters allowed in a comment.'))
|
||||
show_profiles = models.BooleanField(_("show users profiles to each other"), default=True)
|
||||
club = models.OneToOneField(Club, related_name='trombi')
|
||||
|
||||
subscription_deadline = models.DateField(
|
||||
_("subscription deadline"),
|
||||
default=date.today,
|
||||
help_text=_(
|
||||
"Before this date, users are "
|
||||
"allowed to subscribe to this Trombi. "
|
||||
"After this date, users subscribed will be allowed to comment on each other."
|
||||
),
|
||||
)
|
||||
comments_deadline = models.DateField(
|
||||
_("comments deadline"),
|
||||
default=date.today,
|
||||
help_text=_(
|
||||
"After this date, users won't be " "able to make comments anymore."
|
||||
),
|
||||
)
|
||||
max_chars = models.IntegerField(
|
||||
_("maximum characters"),
|
||||
default=400,
|
||||
help_text=_("Maximum number of characters allowed in a comment."),
|
||||
)
|
||||
show_profiles = models.BooleanField(
|
||||
_("show users profiles to each other"), default=True
|
||||
)
|
||||
club = models.OneToOneField(Club, related_name="trombi")
|
||||
|
||||
objects = TrombiManager()
|
||||
availables = AvailableTrombiManager()
|
||||
@ -72,11 +90,15 @@ class Trombi(models.Model):
|
||||
|
||||
def clean(self):
|
||||
if self.subscription_deadline > self.comments_deadline:
|
||||
raise ValidationError(_("Closing the subscriptions after the "
|
||||
"comments is definitively not a good idea."))
|
||||
raise ValidationError(
|
||||
_(
|
||||
"Closing the subscriptions after the "
|
||||
"comments is definitively not a good idea."
|
||||
)
|
||||
)
|
||||
|
||||
def get_absolute_url(self):
|
||||
return reverse('trombi:detail', kwargs={'trombi_id': self.id})
|
||||
return reverse("trombi:detail", kwargs={"trombi_id": self.id})
|
||||
|
||||
def is_owned_by(self, user):
|
||||
return user.can_edit(self.club)
|
||||
@ -93,12 +115,36 @@ class TrombiUser(models.Model):
|
||||
It also adds the pictures to the profile without needing all the security
|
||||
like the other SithFiles.
|
||||
"""
|
||||
user = models.OneToOneField(User, verbose_name=_("trombi user"), related_name='trombi_user')
|
||||
trombi = models.ForeignKey(Trombi, verbose_name=_("trombi"), related_name='users', blank=True, null=True, on_delete=models.SET_NULL)
|
||||
profile_pict = models.ImageField(upload_to='trombi', verbose_name=_("profile pict"), null=True, blank=True,
|
||||
help_text=_("The profile picture you want in the trombi (warning: this picture may be published)"))
|
||||
scrub_pict = models.ImageField(upload_to='trombi', verbose_name=_("scrub pict"), null=True, blank=True,
|
||||
help_text=_("The scrub picture you want in the trombi (warning: this picture may be published)"))
|
||||
|
||||
user = models.OneToOneField(
|
||||
User, verbose_name=_("trombi user"), related_name="trombi_user"
|
||||
)
|
||||
trombi = models.ForeignKey(
|
||||
Trombi,
|
||||
verbose_name=_("trombi"),
|
||||
related_name="users",
|
||||
blank=True,
|
||||
null=True,
|
||||
on_delete=models.SET_NULL,
|
||||
)
|
||||
profile_pict = models.ImageField(
|
||||
upload_to="trombi",
|
||||
verbose_name=_("profile pict"),
|
||||
null=True,
|
||||
blank=True,
|
||||
help_text=_(
|
||||
"The profile picture you want in the trombi (warning: this picture may be published)"
|
||||
),
|
||||
)
|
||||
scrub_pict = models.ImageField(
|
||||
upload_to="trombi",
|
||||
verbose_name=_("scrub pict"),
|
||||
null=True,
|
||||
blank=True,
|
||||
help_text=_(
|
||||
"The scrub picture you want in the trombi (warning: this picture may be published)"
|
||||
),
|
||||
)
|
||||
|
||||
def __str__(self):
|
||||
return str(self.user)
|
||||
@ -108,7 +154,9 @@ class TrombiUser(models.Model):
|
||||
|
||||
def make_memberships(self):
|
||||
self.memberships.all().delete()
|
||||
for m in self.user.memberships.filter(role__gt=settings.SITH_MAXIMUM_FREE_ROLE).order_by('end_date'):
|
||||
for m in self.user.memberships.filter(
|
||||
role__gt=settings.SITH_MAXIMUM_FREE_ROLE
|
||||
).order_by("end_date"):
|
||||
role = str(settings.SITH_CLUB_ROLES[m.role])
|
||||
if m.description:
|
||||
role += " (%s)" % m.description
|
||||
@ -130,8 +178,13 @@ class TrombiComment(models.Model):
|
||||
This represent a comment given by someone to someone else in the same Trombi
|
||||
instance.
|
||||
"""
|
||||
author = models.ForeignKey(TrombiUser, verbose_name=_("author"), related_name='given_comments')
|
||||
target = models.ForeignKey(TrombiUser, verbose_name=_("target"), related_name='received_comments')
|
||||
|
||||
author = models.ForeignKey(
|
||||
TrombiUser, verbose_name=_("author"), related_name="given_comments"
|
||||
)
|
||||
target = models.ForeignKey(
|
||||
TrombiUser, verbose_name=_("target"), related_name="received_comments"
|
||||
)
|
||||
content = models.TextField(_("content"), default="")
|
||||
is_moderated = models.BooleanField(_("is the comment moderated"), default=False)
|
||||
|
||||
@ -145,14 +198,17 @@ class TrombiClubMembership(models.Model):
|
||||
"""
|
||||
This represent a membership to a club
|
||||
"""
|
||||
user = models.ForeignKey(TrombiUser, verbose_name=_("user"), related_name='memberships')
|
||||
|
||||
user = models.ForeignKey(
|
||||
TrombiUser, verbose_name=_("user"), related_name="memberships"
|
||||
)
|
||||
club = models.CharField(_("club"), max_length=32, default="")
|
||||
role = models.CharField(_("role"), max_length=64, default="")
|
||||
start = models.CharField(_("start"), max_length=16, default="")
|
||||
end = models.CharField(_("end"), max_length=16, default="")
|
||||
|
||||
class Meta:
|
||||
ordering = ['id']
|
||||
ordering = ["id"]
|
||||
|
||||
def __str__(self):
|
||||
return "%s - %s - %s (%s)" % (self.user, self.club, self.role, self.start)
|
||||
@ -161,4 +217,4 @@ class TrombiClubMembership(models.Model):
|
||||
return user.id == self.user.user.id or user.can_edit(self.user.trombi)
|
||||
|
||||
def get_absolute_url(self):
|
||||
return reverse('trombi:profile')
|
||||
return reverse("trombi:profile")
|
||||
|
Reference in New Issue
Block a user