Skip to content

Commit

Permalink
Merge pull request #2219 from FJNR-inc/develop
Browse files Browse the repository at this point in the history
Release
  • Loading branch information
MelanieFJNR authored Jan 8, 2024
2 parents 4730b20 + af32368 commit 0773538
Show file tree
Hide file tree
Showing 39 changed files with 484 additions and 108 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,5 @@ ve/

# miscellaneous
.idea/*
/static/
media/*
2 changes: 1 addition & 1 deletion blitz_api/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from django.contrib.auth.admin import UserAdmin
from django.contrib.auth.forms import UserChangeForm, UserCreationForm
from django.contrib.auth.models import AbstractUser, Permission
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _
from import_export.admin import ExportActionModelAdmin
from modeltranslation.admin import TranslationAdmin
from simple_history.admin import SimpleHistoryAdmin
Expand Down
2 changes: 1 addition & 1 deletion blitz_api/authentication.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from rest_framework.authentication import TokenAuthentication

from django.utils import timezone
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _
from django.conf import settings

from .models import TemporaryToken
Expand Down
2 changes: 1 addition & 1 deletion blitz_api/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from django.db.models import Sum
from django.utils import timezone
from django.contrib.auth.models import AbstractUser
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _

from dateutil.relativedelta import relativedelta
from jsonfield import JSONField
Expand Down
2 changes: 1 addition & 1 deletion blitz_api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from rest_framework.authtoken.serializers import AuthTokenSerializer
from django.contrib.auth import (get_user_model, password_validation,
authenticate, )
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _
from django.conf import settings
from django.core.exceptions import ValidationError

Expand Down
2 changes: 1 addition & 1 deletion blitz_api/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from django.conf import settings
from django.core.mail import EmailMessage
from django.http import HttpResponse
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _
from django.template.loader import render_to_string

from rest_framework.pagination import PageNumberPagination
Expand Down
6 changes: 3 additions & 3 deletions blitz_api/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import sys

from decouple import config, Csv
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _
from dj_database_url import parse as db_url

IS_GAE_ENV = config('GAE_INSTANCE', False)
Expand Down Expand Up @@ -152,7 +152,7 @@

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'ENGINE': 'django.db.backends.postgresql',
'HOST': config('DB_HOST', default="postgres"),
'USER': config('DB_USER', default='my_db_user'),
'PASSWORD': config('DB_PASSWORD', default='my_db_password'),
Expand Down Expand Up @@ -510,7 +510,7 @@
CELERY_RESULT_BACKEND = 'django-db'
CELERY_RESULT_BACKEND_DB = ''.join(
[
'postgresql+psycopg2://',
'postgresql://',
config("DB_USER", default='myprojectuser'),
":",
config("DB_PASSWORD", default='password'),
Expand Down
69 changes: 69 additions & 0 deletions blitz_api/tests/tests_view_Users.py
Original file line number Diff line number Diff line change
Expand Up @@ -851,3 +851,72 @@ def test_credit_ticket_negative_int(self):
response.status_code,
status.HTTP_400_BAD_REQUEST,
)

def test_member_filter(self):
"""
Ensure we can list members while filtering
"""
now = timezone.now()
str_now = now.strftime("%Y-%m-%d")
self.user.delete()
self.client.force_authenticate(user=self.admin)

new_membership = Membership.objects.create(
name="new_1",
available=True,
price=50,
duration=timedelta(days=365),
)

new_membership_2 = Membership.objects.create(
name="new_2",
available=True,
price=50,
duration=timedelta(days=365),
)

inactive_user = UserFactory()
inactive_user.is_active = False
inactive_user.save()

active_user = UserFactory()
active_user.is_active = True
active_user.save()

membership_ended_user = UserFactory()
membership_ended_user.is_active = True
membership_ended_user.membership = new_membership
membership_ended_user.membership_end = now - relativedelta(days=1)
membership_ended_user.save()

membership_1_user = UserFactory()
membership_1_user.is_active = True
membership_1_user.membership = new_membership
membership_1_user.membership_end = now + relativedelta(days=1)
membership_1_user.save()

membership_2_user = UserFactory()
membership_2_user.is_active = True
membership_2_user.membership = new_membership_2
membership_2_user.membership_end = now + relativedelta(days=1)
membership_2_user.save()

inactive_filter = f'?is_active=false'
active_filter = f'?is_active=true'
active_member = f'?is_active=true&membership_end_after={str_now}'
active_target_member = (f'?is_active=true'
f'&membership_end_after={str_now}'
f'&membership={new_membership.id}')

response = self.client.get(reverse('user-list') + inactive_filter)
self.assertEqual(json.loads(response.content)['count'], 1)

response = self.client.get(reverse('user-list') + active_filter)
# 5 including admin
self.assertEqual(json.loads(response.content)['count'], 5)

response = self.client.get(reverse('user-list') + active_member)
self.assertEqual(json.loads(response.content)['count'], 2)

response = self.client.get(reverse('user-list') + active_target_member)
self.assertEqual(json.loads(response.content)['count'], 1)
54 changes: 31 additions & 23 deletions blitz_api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,13 @@
from django.utils import timezone
from django.http import Http404
from django.core.exceptions import ValidationError
from django.utils.translation import ugettext_lazy as _

from django.utils.translation import gettext_lazy as _
from django_filters import (
FilterSet,
DateFilter,
NumberFilter,
BooleanFilter,
)
from rest_framework import status, viewsets, mixins, generics
from rest_framework.decorators import action
from rest_framework.parsers import MultiPartParser
Expand Down Expand Up @@ -36,6 +41,28 @@
LOCAL_TIMEZONE = pytz.timezone(settings.TIME_ZONE)


class UserFilter(FilterSet):
membership_end_after = DateFilter(
field_name='membership_end',
lookup_expr='gte',
)
university = NumberFilter(
field_name='university__id',
lookup_expr='exact',
)
membership = NumberFilter(
field_name='membership__id',
lookup_expr='exact',
)
is_active = BooleanFilter(
field_name='is_active'
)

class Meta:
model = User
fields = '__all__'


class UserViewSet(ExportMixin, viewsets.ModelViewSet):
"""
retrieve:
Expand All @@ -54,26 +81,7 @@ class UserViewSet(ExportMixin, viewsets.ModelViewSet):
Sets the user inactive.
"""
queryset = User.objects.all()
filterset_fields = {
'email',
'phone',
'other_phone',
'academic_field',
'university',
'academic_level',
'membership',
'last_login',
'first_name',
'last_name',
'is_active',
'date_joined',
'birthdate',
'gender',
'membership_end',
'tickets',
'groups',
'user_permissions',
}
filterset_class = UserFilter
search_fields = ('first_name', 'last_name', 'email')
ordering = ('email',)

Expand Down Expand Up @@ -646,7 +654,7 @@ class MailChimpView(generics.CreateAPIView):
class MagicLinkViewSet(viewsets.ModelViewSet):
serializer_class = serializers.MagicLinkSerializer
queryset = MagicLink.objects.all()
filter_fields = ('type',)
filterset_fields = ('type',)
permission_classes = []

def get_permissions(self):
Expand Down
2 changes: 1 addition & 1 deletion ckeditor_api/models.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from django.db import models
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _


class CKEditorPage(models.Model):
Expand Down
2 changes: 1 addition & 1 deletion cron_manager/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from django.contrib import admin

from . import models
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _
from django_admin_inline_paginator.admin import TabularInlinePaginated


Expand Down
2 changes: 1 addition & 1 deletion cron_manager/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from django.db import models
from django.utils import timezone

from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _


class Task(models.Model):
Expand Down
2 changes: 1 addition & 1 deletion log_management/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from django.conf import settings
from django.db import models
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _


class Log(models.Model):
Expand Down
7 changes: 1 addition & 6 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,4 @@ pycodestyle==2.8.0
coveralls==3.2.0
responses==0.15.0
awscli==1.21.7
six==1.16.0

# Please consider moving this line to the requirements.txt as soon as it will be fixed
# Hotfix to avoid installation problem if installed at the same time as django
# https://github.com/shinneider/django-admin-inline-paginator/issues/12
django-admin-inline-paginator==0.2.1
six==1.16.0
34 changes: 18 additions & 16 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,25 @@
mkdocs==1.2.3
mkdocs-material==7.3.6

Django==3.2.8
djangorestframework==3.12.4
django-cors-headers==3.10.0
django-filter==21.1
Django==4.2.5
djangorestframework==3.14.0
django-cors-headers==3.11.0
django-filter==23.4
coreapi==2.3.3
factory-boy==3.2.1
Pygments==2.10.0
Markdown==3.3.4
django-anymail==8.4
Pillow==8.4.0
django-anymail==10.2
Pillow==9.1.0
django-simple-history==3.0.0
python-decouple==3.5
django-storages==1.12.2
django-storages==1.14.2
dj_database_url==0.5.0
zappa==0.54.0
psycopg2-binary==2.9.1
django-safedelete==0.5.6
django-request-logging==0.7.3
psycopg-binary==3.1.12
psycopg==3.1.12
django-safedelete==1.3.3
django-request-logging==0.7.5
django-modeltranslation==0.17.3
django-import-export==2.6.1
jsonfield==3.1.0
Expand All @@ -31,13 +32,14 @@ mailchimp3==3.0.14
babel==2.9.1
troposphere==3.1.0

asgiref==3.4.1
django-admin-inline-paginator==0.4.0
asgiref==3.7.2

# Google cloud platform
google-cloud-storage==1.42.3
google-cloud-storage==2.8.0

# Celery
celery[pytest]==5.1.2
pytest==6.2.4
django-celery-results==2.2.0
django-celery-beat==2.2.1
celery[pytest]==5.2.7
pytest==7.2.2
django-celery-results==2.5.1
django-celery-beat==2.5.0
2 changes: 1 addition & 1 deletion retirement/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from django.contrib import admin
from django.contrib.auth import get_user_model
from django.http import HttpResponse
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _
from import_export.admin import ExportActionModelAdmin
from modeltranslation.admin import TranslationAdmin
from safedelete.admin import (
Expand Down
2 changes: 1 addition & 1 deletion retirement/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from rest_framework import serializers

from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _


class TimezoneField(serializers.CharField):
Expand Down
Loading

0 comments on commit 0773538

Please sign in to comment.