Skip to content

Commit

Permalink
Merge pull request #960 from ae-utbm/taiste
Browse files Browse the repository at this point in the history
User model migration, better product types ordering and subscription page fix
  • Loading branch information
imperosol authored Dec 21, 2024
2 parents c1be55a + baebc0b commit b773a05
Show file tree
Hide file tree
Showing 56 changed files with 1,362 additions and 793 deletions.
13 changes: 6 additions & 7 deletions accounting/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ def test_new_operation_not_authorized(self):
self.journal.operations.filter(target_label="Le fantome du jour").exists()
)

def test__operation_simple_accounting(self):
def test_operation_simple_accounting(self):
sat = SimplifiedAccountingType.objects.all().first()
response = self.client.post(
reverse("accounting:op_new", args=[self.journal.id]),
Expand All @@ -237,15 +237,14 @@ def test__operation_simple_accounting(self):
"done": False,
},
)
self.assertFalse(response.status_code == 403)
self.assertTrue(self.journal.operations.filter(amount=23).exists())
assert response.status_code != 403
assert self.journal.operations.filter(amount=23).exists()
response_get = self.client.get(
reverse("accounting:journal_details", args=[self.journal.id])
)
self.assertTrue(
"<td>Le fantome de l&#39;aurore</td>" in str(response_get.content)
)
self.assertTrue(
assert "<td>Le fantome de l&#39;aurore</td>" in str(response_get.content)

assert (
self.journal.operations.filter(amount=23)
.values("accounting_type")
.first()["accounting_type"]
Expand Down
20 changes: 6 additions & 14 deletions accounting/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,47 +215,39 @@ def get_tabs_title(self):
return _("Journal")

def get_list_of_tabs(self):
tab_list = []
tab_list.append(
return [
{
"url": reverse(
"accounting:journal_details", kwargs={"j_id": self.object.id}
),
"slug": "journal",
"name": _("Journal"),
}
)
tab_list.append(
},
{
"url": reverse(
"accounting:journal_nature_statement",
kwargs={"j_id": self.object.id},
),
"slug": "nature_statement",
"name": _("Statement by nature"),
}
)
tab_list.append(
},
{
"url": reverse(
"accounting:journal_person_statement",
kwargs={"j_id": self.object.id},
),
"slug": "person_statement",
"name": _("Statement by person"),
}
)
tab_list.append(
},
{
"url": reverse(
"accounting:journal_accounting_statement",
kwargs={"j_id": self.object.id},
),
"slug": "accounting_statement",
"name": _("Accounting statement"),
}
)
return tab_list
},
]


class JournalCreateView(CanCreateMixin, CreateView):
Expand Down
20 changes: 0 additions & 20 deletions club/migrations/0010_auto_20170912_2028.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,6 @@
import django.db.models.deletion
from django.db import migrations, models

from club.models import Club
from core.operations import PsqlRunOnly


def generate_club_pages(apps, schema_editor):
def recursive_generate_club_page(club):
club.make_page()
for child in Club.objects.filter(parent=club).all():
recursive_generate_club_page(child)

for club in Club.objects.filter(parent=None).all():
recursive_generate_club_page(club)


class Migration(migrations.Migration):
dependencies = [("core", "0024_auto_20170906_1317"), ("club", "0010_club_logo")]
Expand Down Expand Up @@ -48,11 +35,4 @@ class Migration(migrations.Migration):
null=True,
),
),
PsqlRunOnly(
"SET CONSTRAINTS ALL IMMEDIATE", reverse_sql=migrations.RunSQL.noop
),
migrations.RunPython(generate_club_pages),
PsqlRunOnly(
migrations.RunSQL.noop, reverse_sql="SET CONSTRAINTS ALL IMMEDIATE"
),
]
27 changes: 13 additions & 14 deletions club/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@
from django.core.exceptions import ObjectDoesNotExist, ValidationError
from django.core.validators import RegexValidator, validate_email
from django.db import models, transaction
from django.db.models import Q
from django.db.models import Exists, OuterRef, Q
from django.urls import reverse
from django.utils import timezone
from django.utils.functional import cached_property
from django.utils.timezone import localdate
from django.utils.translation import gettext_lazy as _

from core.models import Group, MetaGroup, Notification, Page, RealGroup, SithFile, User
from core.models import Group, MetaGroup, Notification, Page, SithFile, User

# Create your models here.

Expand Down Expand Up @@ -438,19 +438,18 @@ def __str__(self):

def save(self, *args, **kwargs):
if not self.is_moderated:
for user in (
RealGroup.objects.filter(id=settings.SITH_GROUP_COM_ADMIN_ID)
.first()
.users.all()
unread_notif_subquery = Notification.objects.filter(
user=OuterRef("pk"), type="MAILING_MODERATION", viewed=False
)
for user in User.objects.filter(
~Exists(unread_notif_subquery),
groups__id__in=[settings.SITH_GROUP_COM_ADMIN_ID],
):
if not user.notifications.filter(
type="MAILING_MODERATION", viewed=False
).exists():
Notification(
user=user,
url=reverse("com:mailing_admin"),
type="MAILING_MODERATION",
).save(*args, **kwargs)
Notification(
user=user,
url=reverse("com:mailing_admin"),
type="MAILING_MODERATION",
).save(*args, **kwargs)
super().save(*args, **kwargs)

def clean(self):
Expand Down
56 changes: 56 additions & 0 deletions com/migrations/0007_alter_news_club_alter_news_content_and_more.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Generated by Django 4.2.17 on 2024-12-16 14:51

import django.db.models.deletion
from django.conf import settings
from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("club", "0011_auto_20180426_2013"),
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
("com", "0006_remove_sith_index_page"),
]

operations = [
migrations.AlterField(
model_name="news",
name="club",
field=models.ForeignKey(
help_text="The club which organizes the event.",
on_delete=django.db.models.deletion.CASCADE,
related_name="news",
to="club.club",
verbose_name="club",
),
),
migrations.AlterField(
model_name="news",
name="content",
field=models.TextField(
blank=True,
default="",
help_text="A more detailed and exhaustive description of the event.",
verbose_name="content",
),
),
migrations.AlterField(
model_name="news",
name="moderator",
field=models.ForeignKey(
null=True,
on_delete=django.db.models.deletion.SET_NULL,
related_name="moderated_news",
to=settings.AUTH_USER_MODEL,
verbose_name="moderator",
),
),
migrations.AlterField(
model_name="news",
name="summary",
field=models.TextField(
help_text="A description of the event (what is the activity ? is there an associated clic ? is there a inscription form ?)",
verbose_name="summary",
),
),
]
51 changes: 31 additions & 20 deletions com/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
from django.utils.translation import gettext_lazy as _

from club.models import Club
from core.models import Notification, Preferences, RealGroup, User
from core.models import Notification, Preferences, User


class Sith(models.Model):
Expand Down Expand Up @@ -62,16 +62,31 @@ def is_owned_by(self, user):


class News(models.Model):
"""The news class."""
"""News about club events."""

title = models.CharField(_("title"), max_length=64)
summary = models.TextField(_("summary"))
content = models.TextField(_("content"))
summary = models.TextField(
_("summary"),
help_text=_(
"A description of the event (what is the activity ? "
"is there an associated clic ? is there a inscription form ?)"
),
)
content = models.TextField(
_("content"),
blank=True,
default="",
help_text=_("A more detailed and exhaustive description of the event."),
)
type = models.CharField(
_("type"), max_length=16, choices=NEWS_TYPES, default="EVENT"
)
club = models.ForeignKey(
Club, related_name="news", verbose_name=_("club"), on_delete=models.CASCADE
Club,
related_name="news",
verbose_name=_("club"),
on_delete=models.CASCADE,
help_text=_("The club which organizes the event."),
)
author = models.ForeignKey(
User,
Expand All @@ -85,25 +100,23 @@ class News(models.Model):
related_name="moderated_news",
verbose_name=_("moderator"),
null=True,
on_delete=models.CASCADE,
on_delete=models.SET_NULL,
)

def __str__(self):
return "%s: %s" % (self.type, self.title)

def save(self, *args, **kwargs):
super().save(*args, **kwargs)
for u in (
RealGroup.objects.filter(id=settings.SITH_GROUP_COM_ADMIN_ID)
.first()
.users.all()
for user in User.objects.filter(
groups__id__in=[settings.SITH_GROUP_COM_ADMIN_ID]
):
Notification(
user=u,
Notification.objects.create(
user=user,
url=reverse("com:news_admin_list"),
type="NEWS_MODERATION",
param="1",
).save()
)

def get_absolute_url(self):
return reverse("com:news_detail", kwargs={"news_id": self.id})
Expand Down Expand Up @@ -321,16 +334,14 @@ def __str__(self):

def save(self, *args, **kwargs):
if not self.is_moderated:
for u in (
RealGroup.objects.filter(id=settings.SITH_GROUP_COM_ADMIN_ID)
.first()
.users.all()
for user in User.objects.filter(
groups__id__in=[settings.SITH_GROUP_COM_ADMIN_ID]
):
Notification(
user=u,
Notification.objects.create(
user=user,
url=reverse("com:poster_moderate_list"),
type="POSTER_MODERATION",
).save()
)
return super().save(*args, **kwargs)

def clean(self, *args, **kwargs):
Expand Down
Loading

0 comments on commit b773a05

Please sign in to comment.