Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

User model #929

Merged
merged 4 commits into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
imperosol marked this conversation as resolved.
Show resolved Hide resolved
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
26 changes: 11 additions & 15 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 @@ -108,17 +108,15 @@ def __str__(self):

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 @@ -336,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
6 changes: 2 additions & 4 deletions com/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

from club.models import Club, Membership
from com.models import News, Poster, Sith, Weekmail, WeekmailArticle
from core.models import AnonymousUser, RealGroup, User
from core.models import AnonymousUser, Group, User


@pytest.fixture()
Expand All @@ -49,9 +49,7 @@ class TestCom(TestCase):
@classmethod
def setUpTestData(cls):
cls.skia = User.objects.get(username="skia")
cls.com_group = RealGroup.objects.filter(
id=settings.SITH_GROUP_COM_ADMIN_ID
).first()
cls.com_group = Group.objects.get(id=settings.SITH_GROUP_COM_ADMIN_ID)
cls.skia.groups.set([cls.com_group])

def setUp(self):
Expand Down
52 changes: 24 additions & 28 deletions com/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
from django import forms
from django.conf import settings
from django.core.exceptions import PermissionDenied, ValidationError
from django.db.models import Max
from django.db.models import Exists, Max, OuterRef
from django.forms.models import modelform_factory
from django.http import HttpResponseRedirect
from django.shortcuts import get_object_or_404, redirect
Expand All @@ -42,7 +42,7 @@

from club.models import Club, Mailing
from com.models import News, NewsDate, Poster, Screen, Sith, Weekmail, WeekmailArticle
from core.models import Notification, RealGroup, User
from core.models import Notification, User
from core.views import (
CanCreateMixin,
CanEditMixin,
Expand Down Expand Up @@ -278,21 +278,18 @@ def form_valid(self, form):
else:
self.object.is_moderated = False
self.object.save()
for u in (
RealGroup.objects.filter(id=settings.SITH_GROUP_COM_ADMIN_ID)
.first()
.users.all()
unread_notif_subquery = Notification.objects.filter(
user=OuterRef("pk"), type="NEWS_MODERATION", viewed=False
)
for user in User.objects.filter(
~Exists(unread_notif_subquery),
groups__id__in=[settings.SITH_GROUP_COM_ADMIN_ID],
):
if not u.notifications.filter(
type="NEWS_MODERATION", viewed=False
).exists():
Notification(
user=u,
url=reverse(
"com:news_detail", kwargs={"news_id": self.object.id}
),
type="NEWS_MODERATION",
).save()
Notification.objects.create(
user=user,
url=self.object.get_absolute_url(),
type="NEWS_MODERATION",
)
return super().form_valid(form)


Expand Down Expand Up @@ -323,19 +320,18 @@ def form_valid(self, form):
self.object.is_moderated = True
self.object.save()
else:
for u in (
RealGroup.objects.filter(id=settings.SITH_GROUP_COM_ADMIN_ID)
.first()
.users.all()
unread_notif_subquery = Notification.objects.filter(
user=OuterRef("pk"), type="NEWS_MODERATION", viewed=False
)
for user in User.objects.filter(
~Exists(unread_notif_subquery),
groups__id__in=[settings.SITH_GROUP_COM_ADMIN_ID],
):
if not u.notifications.filter(
type="NEWS_MODERATION", viewed=False
).exists():
Notification(
user=u,
url=reverse("com:news_admin_list"),
type="NEWS_MODERATION",
).save()
Notification.objects.create(
user=user,
url=reverse("com:news_admin_list"),
type="NEWS_MODERATION",
)
return super().form_valid(form)


Expand Down
10 changes: 5 additions & 5 deletions core/management/commands/populate.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,19 +261,19 @@ def handle(self, *args, **options):
User.groups.through.objects.bulk_create(
[
User.groups.through(
realgroup_id=settings.SITH_GROUP_COUNTER_ADMIN_ID, user=counter
group_id=settings.SITH_GROUP_COUNTER_ADMIN_ID, user=counter
),
User.groups.through(
realgroup_id=settings.SITH_GROUP_ACCOUNTING_ADMIN_ID, user=comptable
group_id=settings.SITH_GROUP_ACCOUNTING_ADMIN_ID, user=comptable
),
User.groups.through(
realgroup_id=settings.SITH_GROUP_COM_ADMIN_ID, user=comunity
group_id=settings.SITH_GROUP_COM_ADMIN_ID, user=comunity
),
User.groups.through(
realgroup_id=settings.SITH_GROUP_PEDAGOGY_ADMIN_ID, user=tutu
group_id=settings.SITH_GROUP_PEDAGOGY_ADMIN_ID, user=tutu
),
User.groups.through(
realgroup_id=settings.SITH_GROUP_SAS_ADMIN_ID, user=skia
group_id=settings.SITH_GROUP_SAS_ADMIN_ID, user=skia
),
]
)
Expand Down
6 changes: 2 additions & 4 deletions core/management/commands/populate_more.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from faker import Faker

from club.models import Club, Membership
from core.models import RealGroup, User
from core.models import Group, User
from counter.models import (
Counter,
Customer,
Expand Down Expand Up @@ -225,9 +225,7 @@ def create_products(self):
ae = Club.objects.get(unix_name="ae")
other_clubs = random.sample(list(Club.objects.all()), k=3)
groups = list(
RealGroup.objects.filter(
name__in=["Subscribers", "Old subscribers", "Public"]
)
Group.objects.filter(name__in=["Subscribers", "Old subscribers", "Public"])
)
counters = list(
Counter.objects.filter(name__in=["Foyer", "MDE", "La Gommette", "Eboutic"])
Expand Down
Loading
Loading