mirror of
https://github.com/ae-utbm/sith.git
synced 2025-07-09 19:40:19 +00:00
All: Apply Black coding rules
This commit is contained in:
@ -21,4 +21,3 @@
|
||||
# Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
#
|
||||
#
|
||||
|
||||
|
@ -10,46 +10,134 @@ import django.db.models.deletion
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('club', '0007_auto_20170324_0917'),
|
||||
("club", "0007_auto_20170324_0917"),
|
||||
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='Trombi',
|
||||
name="Trombi",
|
||||
fields=[
|
||||
('id', models.AutoField(serialize=False, auto_created=True, verbose_name='ID', primary_key=True)),
|
||||
('subscription_deadline', models.DateField(default=datetime.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.', verbose_name='subscription deadline')),
|
||||
('comments_deadline', models.DateField(default=datetime.date.today, help_text="After this date, users won't be able to make comments anymore.", verbose_name='comments deadline')),
|
||||
('max_chars', models.IntegerField(default=400, help_text='Maximum number of characters allowed in a comment.', verbose_name='maximum characters')),
|
||||
('club', models.OneToOneField(to='club.Club', related_name='trombi')),
|
||||
(
|
||||
"id",
|
||||
models.AutoField(
|
||||
serialize=False,
|
||||
auto_created=True,
|
||||
verbose_name="ID",
|
||||
primary_key=True,
|
||||
),
|
||||
),
|
||||
(
|
||||
"subscription_deadline",
|
||||
models.DateField(
|
||||
default=datetime.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.",
|
||||
verbose_name="subscription deadline",
|
||||
),
|
||||
),
|
||||
(
|
||||
"comments_deadline",
|
||||
models.DateField(
|
||||
default=datetime.date.today,
|
||||
help_text="After this date, users won't be able to make comments anymore.",
|
||||
verbose_name="comments deadline",
|
||||
),
|
||||
),
|
||||
(
|
||||
"max_chars",
|
||||
models.IntegerField(
|
||||
default=400,
|
||||
help_text="Maximum number of characters allowed in a comment.",
|
||||
verbose_name="maximum characters",
|
||||
),
|
||||
),
|
||||
("club", models.OneToOneField(to="club.Club", related_name="trombi")),
|
||||
],
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='TrombiComment',
|
||||
name="TrombiComment",
|
||||
fields=[
|
||||
('id', models.AutoField(serialize=False, auto_created=True, verbose_name='ID', primary_key=True)),
|
||||
('content', models.TextField(default='', verbose_name='content')),
|
||||
(
|
||||
"id",
|
||||
models.AutoField(
|
||||
serialize=False,
|
||||
auto_created=True,
|
||||
verbose_name="ID",
|
||||
primary_key=True,
|
||||
),
|
||||
),
|
||||
("content", models.TextField(default="", verbose_name="content")),
|
||||
],
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='TrombiUser',
|
||||
name="TrombiUser",
|
||||
fields=[
|
||||
('id', models.AutoField(serialize=False, auto_created=True, verbose_name='ID', primary_key=True)),
|
||||
('profile_pict', models.ImageField(upload_to='trombi', blank=True, help_text='The profile picture you want in the trombi (warning: this picture may be published)', verbose_name='profile pict', null=True)),
|
||||
('scrub_pict', models.ImageField(upload_to='trombi', blank=True, help_text='The scrub picture you want in the trombi (warning: this picture may be published)', verbose_name='scrub pict', null=True)),
|
||||
('trombi', models.ForeignKey(to='trombi.Trombi', blank=True, verbose_name='trombi', related_name='users', on_delete=django.db.models.deletion.SET_NULL, null=True)),
|
||||
('user', models.OneToOneField(verbose_name='trombi user', to=settings.AUTH_USER_MODEL, related_name='trombi_user')),
|
||||
(
|
||||
"id",
|
||||
models.AutoField(
|
||||
serialize=False,
|
||||
auto_created=True,
|
||||
verbose_name="ID",
|
||||
primary_key=True,
|
||||
),
|
||||
),
|
||||
(
|
||||
"profile_pict",
|
||||
models.ImageField(
|
||||
upload_to="trombi",
|
||||
blank=True,
|
||||
help_text="The profile picture you want in the trombi (warning: this picture may be published)",
|
||||
verbose_name="profile pict",
|
||||
null=True,
|
||||
),
|
||||
),
|
||||
(
|
||||
"scrub_pict",
|
||||
models.ImageField(
|
||||
upload_to="trombi",
|
||||
blank=True,
|
||||
help_text="The scrub picture you want in the trombi (warning: this picture may be published)",
|
||||
verbose_name="scrub pict",
|
||||
null=True,
|
||||
),
|
||||
),
|
||||
(
|
||||
"trombi",
|
||||
models.ForeignKey(
|
||||
to="trombi.Trombi",
|
||||
blank=True,
|
||||
verbose_name="trombi",
|
||||
related_name="users",
|
||||
on_delete=django.db.models.deletion.SET_NULL,
|
||||
null=True,
|
||||
),
|
||||
),
|
||||
(
|
||||
"user",
|
||||
models.OneToOneField(
|
||||
verbose_name="trombi user",
|
||||
to=settings.AUTH_USER_MODEL,
|
||||
related_name="trombi_user",
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='trombicomment',
|
||||
name='author',
|
||||
field=models.ForeignKey(to='trombi.TrombiUser', verbose_name='author', related_name='given_comments'),
|
||||
model_name="trombicomment",
|
||||
name="author",
|
||||
field=models.ForeignKey(
|
||||
to="trombi.TrombiUser",
|
||||
verbose_name="author",
|
||||
related_name="given_comments",
|
||||
),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='trombicomment',
|
||||
name='target',
|
||||
field=models.ForeignKey(to='trombi.TrombiUser', verbose_name='target', related_name='received_comments'),
|
||||
model_name="trombicomment",
|
||||
name="target",
|
||||
field=models.ForeignKey(
|
||||
to="trombi.TrombiUser",
|
||||
verbose_name="target",
|
||||
related_name="received_comments",
|
||||
),
|
||||
),
|
||||
]
|
||||
|
@ -6,14 +6,14 @@ from django.db import migrations, models
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('trombi', '0001_initial'),
|
||||
]
|
||||
dependencies = [("trombi", "0001_initial")]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='trombi',
|
||||
name='show_profiles',
|
||||
field=models.BooleanField(default=True, verbose_name='show users profiles to each other'),
|
||||
),
|
||||
model_name="trombi",
|
||||
name="show_profiles",
|
||||
field=models.BooleanField(
|
||||
default=True, verbose_name="show users profiles to each other"
|
||||
),
|
||||
)
|
||||
]
|
||||
|
@ -6,14 +6,14 @@ from django.db import migrations, models
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('trombi', '0002_trombi_show_profiles'),
|
||||
]
|
||||
dependencies = [("trombi", "0002_trombi_show_profiles")]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='trombicomment',
|
||||
name='is_moderated',
|
||||
field=models.BooleanField(default=False, verbose_name='is the comment moderated'),
|
||||
),
|
||||
model_name="trombicomment",
|
||||
name="is_moderated",
|
||||
field=models.BooleanField(
|
||||
default=False, verbose_name="is the comment moderated"
|
||||
),
|
||||
)
|
||||
]
|
||||
|
@ -6,23 +6,46 @@ from django.db import migrations, models
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('trombi', '0003_trombicomment_is_moderated'),
|
||||
]
|
||||
dependencies = [("trombi", "0003_trombicomment_is_moderated")]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='TrombiClubMembership',
|
||||
name="TrombiClubMembership",
|
||||
fields=[
|
||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('club', models.CharField(default='', max_length=32, verbose_name='club')),
|
||||
('role', models.CharField(default='', max_length=64, verbose_name='role')),
|
||||
('start', models.CharField(default='', max_length=16, verbose_name='start')),
|
||||
('end', models.CharField(default='', max_length=16, verbose_name='end')),
|
||||
('user', models.ForeignKey(verbose_name='user', related_name='memberships', to='trombi.TrombiUser')),
|
||||
(
|
||||
"id",
|
||||
models.AutoField(
|
||||
auto_created=True,
|
||||
primary_key=True,
|
||||
serialize=False,
|
||||
verbose_name="ID",
|
||||
),
|
||||
),
|
||||
(
|
||||
"club",
|
||||
models.CharField(default="", max_length=32, verbose_name="club"),
|
||||
),
|
||||
(
|
||||
"role",
|
||||
models.CharField(default="", max_length=64, verbose_name="role"),
|
||||
),
|
||||
(
|
||||
"start",
|
||||
models.CharField(default="", max_length=16, verbose_name="start"),
|
||||
),
|
||||
(
|
||||
"end",
|
||||
models.CharField(default="", max_length=16, verbose_name="end"),
|
||||
),
|
||||
(
|
||||
"user",
|
||||
models.ForeignKey(
|
||||
verbose_name="user",
|
||||
related_name="memberships",
|
||||
to="trombi.TrombiUser",
|
||||
),
|
||||
),
|
||||
],
|
||||
options={
|
||||
'ordering': ['id'],
|
||||
},
|
||||
),
|
||||
options={"ordering": ["id"]},
|
||||
)
|
||||
]
|
||||
|
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")
|
||||
|
@ -27,20 +27,56 @@ from django.conf.urls import url
|
||||
from trombi.views import *
|
||||
|
||||
urlpatterns = [
|
||||
url(r'^(?P<club_id>[0-9]+)/new$', TrombiCreateView.as_view(), name='create'),
|
||||
url(r'^(?P<trombi_id>[0-9]+)/export$', TrombiExportView.as_view(), name='export'),
|
||||
url(r'^(?P<trombi_id>[0-9]+)/edit$', TrombiEditView.as_view(), name='edit'),
|
||||
url(r'^(?P<trombi_id>[0-9]+)/moderate_comments$', TrombiModerateCommentsView.as_view(), name='moderate_comments'),
|
||||
url(r'^(?P<comment_id>[0-9]+)/moderate$', TrombiModerateCommentView.as_view(), name='moderate_comment'),
|
||||
url(r'^user/(?P<user_id>[0-9]+)/delete$', TrombiDeleteUserView.as_view(), name='delete_user'),
|
||||
url(r'^(?P<trombi_id>[0-9]+)$', TrombiDetailView.as_view(), name='detail'),
|
||||
url(r'^(?P<user_id>[0-9]+)/new_comment$', TrombiCommentCreateView.as_view(), name='new_comment'),
|
||||
url(r'^(?P<user_id>[0-9]+)/profile$', UserTrombiProfileView.as_view(), name='user_profile'),
|
||||
url(r'^comment/(?P<comment_id>[0-9]+)/edit$', TrombiCommentEditView.as_view(), name='edit_comment'),
|
||||
url(r'^tools$', UserTrombiToolsView.as_view(), name='user_tools'),
|
||||
url(r'^profile$', UserTrombiEditProfileView.as_view(), name='profile'),
|
||||
url(r'^pictures$', UserTrombiEditPicturesView.as_view(), name='pictures'),
|
||||
url(r'^reset_memberships$', UserTrombiResetClubMembershipsView.as_view(), name='reset_memberships'),
|
||||
url(r'^membership/(?P<membership_id>[0-9]+)/edit$', UserTrombiEditMembershipView.as_view(), name='edit_membership'),
|
||||
url(r'^membership/(?P<membership_id>[0-9]+)/delete$', UserTrombiDeleteMembershipView.as_view(), name='delete_membership'),
|
||||
url(r"^(?P<club_id>[0-9]+)/new$", TrombiCreateView.as_view(), name="create"),
|
||||
url(r"^(?P<trombi_id>[0-9]+)/export$", TrombiExportView.as_view(), name="export"),
|
||||
url(r"^(?P<trombi_id>[0-9]+)/edit$", TrombiEditView.as_view(), name="edit"),
|
||||
url(
|
||||
r"^(?P<trombi_id>[0-9]+)/moderate_comments$",
|
||||
TrombiModerateCommentsView.as_view(),
|
||||
name="moderate_comments",
|
||||
),
|
||||
url(
|
||||
r"^(?P<comment_id>[0-9]+)/moderate$",
|
||||
TrombiModerateCommentView.as_view(),
|
||||
name="moderate_comment",
|
||||
),
|
||||
url(
|
||||
r"^user/(?P<user_id>[0-9]+)/delete$",
|
||||
TrombiDeleteUserView.as_view(),
|
||||
name="delete_user",
|
||||
),
|
||||
url(r"^(?P<trombi_id>[0-9]+)$", TrombiDetailView.as_view(), name="detail"),
|
||||
url(
|
||||
r"^(?P<user_id>[0-9]+)/new_comment$",
|
||||
TrombiCommentCreateView.as_view(),
|
||||
name="new_comment",
|
||||
),
|
||||
url(
|
||||
r"^(?P<user_id>[0-9]+)/profile$",
|
||||
UserTrombiProfileView.as_view(),
|
||||
name="user_profile",
|
||||
),
|
||||
url(
|
||||
r"^comment/(?P<comment_id>[0-9]+)/edit$",
|
||||
TrombiCommentEditView.as_view(),
|
||||
name="edit_comment",
|
||||
),
|
||||
url(r"^tools$", UserTrombiToolsView.as_view(), name="user_tools"),
|
||||
url(r"^profile$", UserTrombiEditProfileView.as_view(), name="profile"),
|
||||
url(r"^pictures$", UserTrombiEditPicturesView.as_view(), name="pictures"),
|
||||
url(
|
||||
r"^reset_memberships$",
|
||||
UserTrombiResetClubMembershipsView.as_view(),
|
||||
name="reset_memberships",
|
||||
),
|
||||
url(
|
||||
r"^membership/(?P<membership_id>[0-9]+)/edit$",
|
||||
UserTrombiEditMembershipView.as_view(),
|
||||
name="edit_membership",
|
||||
),
|
||||
url(
|
||||
r"^membership/(?P<membership_id>[0-9]+)/delete$",
|
||||
UserTrombiDeleteMembershipView.as_view(),
|
||||
name="delete_membership",
|
||||
),
|
||||
]
|
||||
|
313
trombi/views.py
313
trombi/views.py
@ -38,7 +38,14 @@ from datetime import date
|
||||
|
||||
from trombi.models import Trombi, TrombiUser, TrombiComment, TrombiClubMembership
|
||||
from core.views.forms import SelectDate
|
||||
from core.views import CanViewMixin, CanEditMixin, CanEditPropMixin, TabedViewMixin, CanCreateMixin, QuickNotifMixin
|
||||
from core.views import (
|
||||
CanViewMixin,
|
||||
CanEditMixin,
|
||||
CanEditPropMixin,
|
||||
TabedViewMixin,
|
||||
CanCreateMixin,
|
||||
QuickNotifMixin,
|
||||
)
|
||||
from core.models import User
|
||||
from club.models import Club
|
||||
|
||||
@ -49,29 +56,35 @@ class TrombiTabsMixin(TabedViewMixin):
|
||||
|
||||
def get_list_of_tabs(self):
|
||||
tab_list = []
|
||||
tab_list.append({
|
||||
'url': reverse('trombi:user_tools'),
|
||||
'slug': 'tools',
|
||||
'name': _("Tools"),
|
||||
})
|
||||
tab_list.append({
|
||||
'url': reverse('trombi:profile'),
|
||||
'slug': 'profile',
|
||||
'name': _("My profile"),
|
||||
})
|
||||
tab_list.append({
|
||||
'url': reverse('trombi:pictures'),
|
||||
'slug': 'pictures',
|
||||
'name': _("My pictures"),
|
||||
})
|
||||
tab_list.append(
|
||||
{"url": reverse("trombi:user_tools"), "slug": "tools", "name": _("Tools")}
|
||||
)
|
||||
tab_list.append(
|
||||
{
|
||||
"url": reverse("trombi:profile"),
|
||||
"slug": "profile",
|
||||
"name": _("My profile"),
|
||||
}
|
||||
)
|
||||
tab_list.append(
|
||||
{
|
||||
"url": reverse("trombi:pictures"),
|
||||
"slug": "pictures",
|
||||
"name": _("My pictures"),
|
||||
}
|
||||
)
|
||||
try:
|
||||
trombi = self.request.user.trombi_user.trombi
|
||||
if self.request.user.is_owner(trombi):
|
||||
tab_list.append({
|
||||
'url': reverse('trombi:detail', kwargs={'trombi_id': trombi.id}),
|
||||
'slug': 'admin_tools',
|
||||
'name': _("Admin tools"),
|
||||
})
|
||||
tab_list.append(
|
||||
{
|
||||
"url": reverse(
|
||||
"trombi:detail", kwargs={"trombi_id": trombi.id}
|
||||
),
|
||||
"slug": "admin_tools",
|
||||
"name": _("Admin tools"),
|
||||
}
|
||||
)
|
||||
except:
|
||||
pass
|
||||
return tab_list
|
||||
@ -80,20 +93,23 @@ class TrombiTabsMixin(TabedViewMixin):
|
||||
class TrombiForm(forms.ModelForm):
|
||||
class Meta:
|
||||
model = Trombi
|
||||
fields = ['subscription_deadline', 'comments_deadline', 'max_chars', 'show_profiles']
|
||||
widgets = {
|
||||
'subscription_deadline': SelectDate,
|
||||
'comments_deadline': SelectDate,
|
||||
}
|
||||
fields = [
|
||||
"subscription_deadline",
|
||||
"comments_deadline",
|
||||
"max_chars",
|
||||
"show_profiles",
|
||||
]
|
||||
widgets = {"subscription_deadline": SelectDate, "comments_deadline": SelectDate}
|
||||
|
||||
|
||||
class TrombiCreateView(CanCreateMixin, CreateView):
|
||||
"""
|
||||
Create a trombi for a club
|
||||
"""
|
||||
|
||||
model = Trombi
|
||||
form_class = TrombiForm
|
||||
template_name = 'core/create.jinja'
|
||||
template_name = "core/create.jinja"
|
||||
|
||||
def post(self, request, *args, **kwargs):
|
||||
"""
|
||||
@ -101,7 +117,7 @@ class TrombiCreateView(CanCreateMixin, CreateView):
|
||||
"""
|
||||
form = self.get_form()
|
||||
if form.is_valid():
|
||||
club = get_object_or_404(Club, id=self.kwargs['club_id'])
|
||||
club = get_object_or_404(Club, id=self.kwargs["club_id"])
|
||||
form.instance.club = club
|
||||
ret = self.form_valid(form)
|
||||
return ret
|
||||
@ -112,8 +128,8 @@ class TrombiCreateView(CanCreateMixin, CreateView):
|
||||
class TrombiEditView(CanEditPropMixin, TrombiTabsMixin, UpdateView):
|
||||
model = Trombi
|
||||
form_class = TrombiForm
|
||||
template_name = 'core/edit.jinja'
|
||||
pk_url_kwarg = 'trombi_id'
|
||||
template_name = "core/edit.jinja"
|
||||
pk_url_kwarg = "trombi_id"
|
||||
current_tab = "admin_tools"
|
||||
|
||||
def get_success_url(self):
|
||||
@ -121,12 +137,15 @@ class TrombiEditView(CanEditPropMixin, TrombiTabsMixin, UpdateView):
|
||||
|
||||
|
||||
class AddUserForm(forms.Form):
|
||||
user = AutoCompleteSelectField('users', required=True, label=_("Select user"), help_text=None)
|
||||
user = AutoCompleteSelectField(
|
||||
"users", required=True, label=_("Select user"), help_text=None
|
||||
)
|
||||
|
||||
|
||||
class TrombiDetailView(CanEditMixin, QuickNotifMixin, TrombiTabsMixin, DetailView):
|
||||
model = Trombi
|
||||
template_name = 'trombi/detail.jinja'
|
||||
pk_url_kwarg = 'trombi_id'
|
||||
template_name = "trombi/detail.jinja"
|
||||
pk_url_kwarg = "trombi_id"
|
||||
current_tab = "admin_tools"
|
||||
|
||||
def post(self, request, *args, **kwargs):
|
||||
@ -134,43 +153,51 @@ class TrombiDetailView(CanEditMixin, QuickNotifMixin, TrombiTabsMixin, DetailVie
|
||||
form = AddUserForm(request.POST)
|
||||
if form.is_valid():
|
||||
try:
|
||||
TrombiUser(user=form.cleaned_data['user'], trombi=self.object).save()
|
||||
TrombiUser(user=form.cleaned_data["user"], trombi=self.object).save()
|
||||
self.quick_notif_list.append("qn_success")
|
||||
except: # We don't care about duplicate keys
|
||||
except: # We don't care about duplicate keys
|
||||
self.quick_notif_list.append("qn_fail")
|
||||
return super(TrombiDetailView, self).get(request, *args, **kwargs)
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
kwargs = super(TrombiDetailView, self).get_context_data(**kwargs)
|
||||
kwargs['form'] = AddUserForm()
|
||||
kwargs["form"] = AddUserForm()
|
||||
return kwargs
|
||||
|
||||
|
||||
class TrombiExportView(CanEditMixin, TrombiTabsMixin, DetailView):
|
||||
model = Trombi
|
||||
template_name = 'trombi/export.jinja'
|
||||
pk_url_kwarg = 'trombi_id'
|
||||
template_name = "trombi/export.jinja"
|
||||
pk_url_kwarg = "trombi_id"
|
||||
current_tab = "admin_tools"
|
||||
|
||||
|
||||
class TrombiDeleteUserView(CanEditPropMixin, TrombiTabsMixin, DeleteView):
|
||||
model = TrombiUser
|
||||
pk_url_kwarg = 'user_id'
|
||||
template_name = 'core/delete_confirm.jinja'
|
||||
pk_url_kwarg = "user_id"
|
||||
template_name = "core/delete_confirm.jinja"
|
||||
current_tab = "admin_tools"
|
||||
|
||||
def get_success_url(self):
|
||||
return reverse('trombi:detail', kwargs={'trombi_id': self.object.trombi.id}) + "?qn_success"
|
||||
return (
|
||||
reverse("trombi:detail", kwargs={"trombi_id": self.object.trombi.id})
|
||||
+ "?qn_success"
|
||||
)
|
||||
|
||||
|
||||
class TrombiModerateCommentsView(CanEditPropMixin, QuickNotifMixin, TrombiTabsMixin, DetailView):
|
||||
class TrombiModerateCommentsView(
|
||||
CanEditPropMixin, QuickNotifMixin, TrombiTabsMixin, DetailView
|
||||
):
|
||||
model = Trombi
|
||||
template_name = 'trombi/comment_moderation.jinja'
|
||||
pk_url_kwarg = 'trombi_id'
|
||||
template_name = "trombi/comment_moderation.jinja"
|
||||
pk_url_kwarg = "trombi_id"
|
||||
current_tab = "admin_tools"
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
kwargs = super(TrombiModerateCommentsView, self).get_context_data(**kwargs)
|
||||
kwargs['comments'] = TrombiComment.objects.filter(is_moderated=False,
|
||||
author__trombi__id=self.object.id).exclude(target__user__id=self.request.user.id)
|
||||
kwargs["comments"] = TrombiComment.objects.filter(
|
||||
is_moderated=False, author__trombi__id=self.object.id
|
||||
).exclude(target__user__id=self.request.user.id)
|
||||
return kwargs
|
||||
|
||||
|
||||
@ -181,8 +208,8 @@ class TrombiModerateForm(forms.Form):
|
||||
|
||||
class TrombiModerateCommentView(DetailView):
|
||||
model = TrombiComment
|
||||
template_name = 'core/edit.jinja'
|
||||
pk_url_kwarg = 'comment_id'
|
||||
template_name = "core/edit.jinja"
|
||||
pk_url_kwarg = "comment_id"
|
||||
|
||||
def dispatch(self, request, *args, **kwargs):
|
||||
self.object = self.get_object()
|
||||
@ -192,79 +219,107 @@ class TrombiModerateCommentView(DetailView):
|
||||
|
||||
def post(self, request, *args, **kwargs):
|
||||
if "action" in request.POST:
|
||||
if request.POST['action'] == "accept":
|
||||
if request.POST["action"] == "accept":
|
||||
self.object.is_moderated = True
|
||||
self.object.save()
|
||||
return redirect(reverse('trombi:moderate_comments', kwargs={'trombi_id': self.object.author.trombi.id}) + "?qn_success")
|
||||
elif request.POST['action'] == "reject":
|
||||
return super(TrombiModerateCommentView, self).get(request, *args, **kwargs)
|
||||
elif request.POST['action'] == "delete" and "reason" in request.POST.keys():
|
||||
return redirect(
|
||||
reverse(
|
||||
"trombi:moderate_comments",
|
||||
kwargs={"trombi_id": self.object.author.trombi.id},
|
||||
)
|
||||
+ "?qn_success"
|
||||
)
|
||||
elif request.POST["action"] == "reject":
|
||||
return super(TrombiModerateCommentView, self).get(
|
||||
request, *args, **kwargs
|
||||
)
|
||||
elif request.POST["action"] == "delete" and "reason" in request.POST.keys():
|
||||
self.object.author.user.email_user(
|
||||
subject="[%s] %s" % (settings.SITH_NAME, _("Rejected comment")),
|
||||
message=_("Your comment to %(target)s on the Trombi \"%(trombi)s\" was rejected for the following "
|
||||
"reason: %(reason)s\n\n"
|
||||
"Your comment was:\n\n%(content)s"
|
||||
) % {
|
||||
'target': self.object.target.user.get_display_name(),
|
||||
'trombi': self.object.author.trombi,
|
||||
'reason': request.POST["reason"],
|
||||
'content': self.object.content,
|
||||
message=_(
|
||||
'Your comment to %(target)s on the Trombi "%(trombi)s" was rejected for the following '
|
||||
"reason: %(reason)s\n\n"
|
||||
"Your comment was:\n\n%(content)s"
|
||||
)
|
||||
% {
|
||||
"target": self.object.target.user.get_display_name(),
|
||||
"trombi": self.object.author.trombi,
|
||||
"reason": request.POST["reason"],
|
||||
"content": self.object.content,
|
||||
},
|
||||
)
|
||||
self.object.delete()
|
||||
return redirect(reverse('trombi:moderate_comments', kwargs={'trombi_id': self.object.author.trombi.id}) + "?qn_success")
|
||||
return redirect(
|
||||
reverse(
|
||||
"trombi:moderate_comments",
|
||||
kwargs={"trombi_id": self.object.author.trombi.id},
|
||||
)
|
||||
+ "?qn_success"
|
||||
)
|
||||
raise Http404
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
kwargs = super(TrombiModerateCommentView, self).get_context_data(**kwargs)
|
||||
kwargs['form'] = TrombiModerateForm()
|
||||
kwargs["form"] = TrombiModerateForm()
|
||||
return kwargs
|
||||
|
||||
|
||||
# User side
|
||||
|
||||
|
||||
class TrombiModelChoiceField(forms.ModelChoiceField):
|
||||
def label_from_instance(self, obj):
|
||||
return _("%(name)s (deadline: %(date)s)") % {'name': str(obj), 'date': str(obj.subscription_deadline)}
|
||||
return _("%(name)s (deadline: %(date)s)") % {
|
||||
"name": str(obj),
|
||||
"date": str(obj.subscription_deadline),
|
||||
}
|
||||
|
||||
|
||||
class UserTrombiForm(forms.Form):
|
||||
trombi = TrombiModelChoiceField(Trombi.availables.all(), required=False, label=_("Select trombi"),
|
||||
help_text=_("This allows you to subscribe to a Trombi. "
|
||||
"Be aware that you can subscribe only once, so don't play with that, "
|
||||
"or you will expose yourself to the admins' wrath!"))
|
||||
trombi = TrombiModelChoiceField(
|
||||
Trombi.availables.all(),
|
||||
required=False,
|
||||
label=_("Select trombi"),
|
||||
help_text=_(
|
||||
"This allows you to subscribe to a Trombi. "
|
||||
"Be aware that you can subscribe only once, so don't play with that, "
|
||||
"or you will expose yourself to the admins' wrath!"
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
class UserTrombiToolsView(QuickNotifMixin, TrombiTabsMixin, TemplateView):
|
||||
"""
|
||||
Display a user's trombi tools
|
||||
"""
|
||||
|
||||
template_name = "trombi/user_tools.jinja"
|
||||
current_tab = "tools"
|
||||
|
||||
def post(self, request, *args, **kwargs):
|
||||
self.form = UserTrombiForm(request.POST)
|
||||
if self.form.is_valid():
|
||||
trombi_user = TrombiUser(user=request.user,
|
||||
trombi=self.form.cleaned_data['trombi'])
|
||||
trombi_user = TrombiUser(
|
||||
user=request.user, trombi=self.form.cleaned_data["trombi"]
|
||||
)
|
||||
trombi_user.save()
|
||||
self.quick_notif_list += ['qn_success']
|
||||
self.quick_notif_list += ["qn_success"]
|
||||
return super(UserTrombiToolsView, self).get(request, *args, **kwargs)
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
kwargs = super(UserTrombiToolsView, self).get_context_data(**kwargs)
|
||||
kwargs['user'] = self.request.user
|
||||
if not hasattr(self.request.user, 'trombi_user'):
|
||||
kwargs['subscribe_form'] = UserTrombiForm()
|
||||
kwargs["user"] = self.request.user
|
||||
if not hasattr(self.request.user, "trombi_user"):
|
||||
kwargs["subscribe_form"] = UserTrombiForm()
|
||||
else:
|
||||
kwargs['trombi'] = self.request.user.trombi_user.trombi
|
||||
kwargs['date'] = date
|
||||
kwargs["trombi"] = self.request.user.trombi_user.trombi
|
||||
kwargs["date"] = date
|
||||
return kwargs
|
||||
|
||||
|
||||
class UserTrombiEditPicturesView(TrombiTabsMixin, UpdateView):
|
||||
model = TrombiUser
|
||||
fields = ['profile_pict', 'scrub_pict']
|
||||
fields = ["profile_pict", "scrub_pict"]
|
||||
template_name = "core/edit.jinja"
|
||||
current_tab = "pictures"
|
||||
|
||||
@ -272,19 +327,27 @@ class UserTrombiEditPicturesView(TrombiTabsMixin, UpdateView):
|
||||
return self.request.user.trombi_user
|
||||
|
||||
def get_success_url(self):
|
||||
return reverse('trombi:user_tools') + "?qn_success"
|
||||
return reverse("trombi:user_tools") + "?qn_success"
|
||||
|
||||
|
||||
class UserTrombiEditProfileView(QuickNotifMixin, TrombiTabsMixin, UpdateView):
|
||||
model = User
|
||||
form_class = modelform_factory(User,
|
||||
fields=['second_email', 'phone', 'department', 'dpt_option',
|
||||
'quote', 'parent_address'],
|
||||
labels={
|
||||
'second_email': _("Personal email (not UTBM)"),
|
||||
'phone': _("Phone"),
|
||||
'parent_address': _("Native town"),
|
||||
})
|
||||
form_class = modelform_factory(
|
||||
User,
|
||||
fields=[
|
||||
"second_email",
|
||||
"phone",
|
||||
"department",
|
||||
"dpt_option",
|
||||
"quote",
|
||||
"parent_address",
|
||||
],
|
||||
labels={
|
||||
"second_email": _("Personal email (not UTBM)"),
|
||||
"phone": _("Phone"),
|
||||
"parent_address": _("Native town"),
|
||||
},
|
||||
)
|
||||
template_name = "trombi/edit_profile.jinja"
|
||||
current_tab = "profile"
|
||||
|
||||
@ -292,7 +355,7 @@ class UserTrombiEditProfileView(QuickNotifMixin, TrombiTabsMixin, UpdateView):
|
||||
return self.request.user
|
||||
|
||||
def get_success_url(self):
|
||||
return reverse('trombi:user_tools') + "?qn_success"
|
||||
return reverse("trombi:user_tools") + "?qn_success"
|
||||
|
||||
|
||||
class UserTrombiResetClubMembershipsView(RedirectView):
|
||||
@ -304,29 +367,34 @@ class UserTrombiResetClubMembershipsView(RedirectView):
|
||||
return redirect(self.get_success_url())
|
||||
|
||||
def get_success_url(self):
|
||||
return reverse('trombi:profile') + "?qn_success"
|
||||
return reverse("trombi:profile") + "?qn_success"
|
||||
|
||||
|
||||
class UserTrombiDeleteMembershipView(TrombiTabsMixin, CanEditMixin, DeleteView):
|
||||
model = TrombiClubMembership
|
||||
pk_url_kwarg = "membership_id"
|
||||
template_name = "core/delete_confirm.jinja"
|
||||
success_url = reverse_lazy('trombi:profile')
|
||||
success_url = reverse_lazy("trombi:profile")
|
||||
current_tab = "profile"
|
||||
|
||||
def get_success_url(self):
|
||||
return super(UserTrombiDeleteMembershipView, self).get_success_url() + "?qn_success"
|
||||
return (
|
||||
super(UserTrombiDeleteMembershipView, self).get_success_url()
|
||||
+ "?qn_success"
|
||||
)
|
||||
|
||||
|
||||
class UserTrombiEditMembershipView(CanEditMixin, TrombiTabsMixin, UpdateView):
|
||||
model = TrombiClubMembership
|
||||
pk_url_kwarg = "membership_id"
|
||||
fields = ['role', 'start', 'end']
|
||||
fields = ["role", "start", "end"]
|
||||
template_name = "core/edit.jinja"
|
||||
current_tab = "profile"
|
||||
|
||||
def get_success_url(self):
|
||||
return super(UserTrombiEditMembershipView, self).get_success_url() + "?qn_success"
|
||||
return (
|
||||
super(UserTrombiEditMembershipView, self).get_success_url() + "?qn_success"
|
||||
)
|
||||
|
||||
|
||||
class UserTrombiProfileView(TrombiTabsMixin, DetailView):
|
||||
@ -338,52 +406,69 @@ class UserTrombiProfileView(TrombiTabsMixin, DetailView):
|
||||
|
||||
def get(self, request, *args, **kwargs):
|
||||
self.object = self.get_object()
|
||||
if (self.object.trombi.id != request.user.trombi_user.trombi.id or
|
||||
self.object.user.id == request.user.id or
|
||||
not self.object.trombi.show_profiles):
|
||||
if (
|
||||
self.object.trombi.id != request.user.trombi_user.trombi.id
|
||||
or self.object.user.id == request.user.id
|
||||
or not self.object.trombi.show_profiles
|
||||
):
|
||||
raise Http404()
|
||||
return super(UserTrombiProfileView, self).get(request, *args, **kwargs)
|
||||
|
||||
|
||||
class TrombiCommentFormView():
|
||||
class TrombiCommentFormView:
|
||||
"""
|
||||
Create/edit a trombi comment
|
||||
"""
|
||||
|
||||
model = TrombiComment
|
||||
fields = ['content']
|
||||
template_name = 'trombi/comment.jinja'
|
||||
fields = ["content"]
|
||||
template_name = "trombi/comment.jinja"
|
||||
|
||||
def get_form_class(self):
|
||||
self.trombi = self.request.user.trombi_user.trombi
|
||||
if date.today() <= self.trombi.subscription_deadline:
|
||||
raise Http404(_("You can not yet write comment, you must wait for "
|
||||
"the subscription deadline to be passed."))
|
||||
raise Http404(
|
||||
_(
|
||||
"You can not yet write comment, you must wait for "
|
||||
"the subscription deadline to be passed."
|
||||
)
|
||||
)
|
||||
if self.trombi.comments_deadline < date.today():
|
||||
raise Http404(_("You can not write comment anymore, the deadline is "
|
||||
"already passed."))
|
||||
return modelform_factory(self.model, fields=self.fields,
|
||||
widgets={
|
||||
'content': forms.widgets.Textarea(attrs={'maxlength': self.trombi.max_chars})
|
||||
},
|
||||
help_texts={
|
||||
'content': _("Maximum characters: %(max_length)s") % {'max_length': self.trombi.max_chars}
|
||||
})
|
||||
raise Http404(
|
||||
_(
|
||||
"You can not write comment anymore, the deadline is "
|
||||
"already passed."
|
||||
)
|
||||
)
|
||||
return modelform_factory(
|
||||
self.model,
|
||||
fields=self.fields,
|
||||
widgets={
|
||||
"content": forms.widgets.Textarea(
|
||||
attrs={"maxlength": self.trombi.max_chars}
|
||||
)
|
||||
},
|
||||
help_texts={
|
||||
"content": _("Maximum characters: %(max_length)s")
|
||||
% {"max_length": self.trombi.max_chars}
|
||||
},
|
||||
)
|
||||
|
||||
def get_success_url(self):
|
||||
return reverse('trombi:user_tools') + "?qn_success"
|
||||
return reverse("trombi:user_tools") + "?qn_success"
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
kwargs = super(TrombiCommentFormView, self).get_context_data(**kwargs)
|
||||
if 'user_id' in self.kwargs.keys():
|
||||
kwargs['target'] = get_object_or_404(TrombiUser, id=self.kwargs['user_id'])
|
||||
if "user_id" in self.kwargs.keys():
|
||||
kwargs["target"] = get_object_or_404(TrombiUser, id=self.kwargs["user_id"])
|
||||
else:
|
||||
kwargs['target'] = self.object.target
|
||||
kwargs["target"] = self.object.target
|
||||
return kwargs
|
||||
|
||||
|
||||
class TrombiCommentCreateView(TrombiCommentFormView, CreateView):
|
||||
def form_valid(self, form):
|
||||
target = get_object_or_404(TrombiUser, id=self.kwargs['user_id'])
|
||||
target = get_object_or_404(TrombiUser, id=self.kwargs["user_id"])
|
||||
author = self.request.user.trombi_user
|
||||
form.instance.author = author
|
||||
form.instance.target = target
|
||||
|
Reference in New Issue
Block a user