Spaces:
Sleeping
Sleeping
Commit
·
113d0af
1
Parent(s):
814d99a
track files 2
Browse filesThis view is limited to 50 files because it contains too many changes.
See raw diff
- .gitattributes +1 -0
- .gitignore +1 -0
- Dockerfile +37 -0
- authentication/__init__.py +0 -0
- authentication/__pycache__/__init__.cpython-310.pyc +0 -0
- authentication/__pycache__/admin.cpython-310.pyc +0 -0
- authentication/__pycache__/apps.cpython-310.pyc +0 -0
- authentication/__pycache__/models.cpython-310.pyc +0 -0
- authentication/__pycache__/serializers.cpython-310.pyc +0 -0
- authentication/__pycache__/urls.cpython-310.pyc +0 -0
- authentication/__pycache__/views.cpython-310.pyc +0 -0
- authentication/admin.py +12 -0
- authentication/apps.py +6 -0
- authentication/migrations/0001_initial.py +31 -0
- authentication/migrations/0002_useractivationcode.py +24 -0
- authentication/migrations/__init__.py +0 -0
- authentication/migrations/__pycache__/0001_initial.cpython-310.pyc +0 -0
- authentication/migrations/__pycache__/0002_useractivationcode.cpython-310.pyc +0 -0
- authentication/migrations/__pycache__/__init__.cpython-310.pyc +0 -0
- authentication/models.py +100 -0
- authentication/serializers.py +34 -0
- authentication/tests.py +3 -0
- authentication/urls.py +15 -0
- authentication/utils/__pycache__/account_send_email.cpython-310.pyc +0 -0
- authentication/utils/__pycache__/generate_password.cpython-310.pyc +0 -0
- authentication/utils/account_send_email.py +13 -0
- authentication/utils/generate_password.py +6 -0
- authentication/views.py +117 -0
- db.sqlite3 +0 -0
- formations/__init__.py +0 -0
- formations/__pycache__/__init__.cpython-310.pyc +0 -0
- formations/__pycache__/admin.cpython-310.pyc +0 -0
- formations/__pycache__/apps.cpython-310.pyc +0 -0
- formations/__pycache__/models.cpython-310.pyc +0 -0
- formations/__pycache__/serializers.cpython-310.pyc +0 -0
- formations/__pycache__/urls.cpython-310.pyc +0 -0
- formations/__pycache__/views.cpython-310.pyc +0 -0
- formations/admin.py +3 -0
- formations/apps.py +6 -0
- formations/migrations/0001_initial.py +125 -0
- formations/migrations/__init__.py +0 -0
- formations/migrations/__pycache__/0001_initial.cpython-310.pyc +0 -0
- formations/migrations/__pycache__/__init__.cpython-310.pyc +0 -0
- formations/models.py +88 -0
- formations/serializers.py +67 -0
- formations/tests.py +3 -0
- formations/urls.py +23 -0
- formations/views.py +135 -0
- lambdaAPI/__init__.py +0 -0
- lambdaAPI/__pycache__/__init__.cpython-310.pyc +0 -0
.gitattributes
CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
36 |
+
*.idx filter=lfs diff=lfs merge=lfs -text
|
.gitignore
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
venv/
|
Dockerfile
ADDED
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# read the doc: https://huggingface.co/docs/hub/spaces-sdks-docker
|
2 |
+
# you will also find guides on how best to write your Dockerfile
|
3 |
+
|
4 |
+
|
5 |
+
# Use an official Python runtime as a parent image
|
6 |
+
FROM python:3.9
|
7 |
+
|
8 |
+
# Set the working directory to /code
|
9 |
+
WORKDIR /code
|
10 |
+
|
11 |
+
# Copy the current directory contents into the container at /code
|
12 |
+
COPY . /code/
|
13 |
+
|
14 |
+
# Install any needed packages specified in requirements.txt
|
15 |
+
RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
|
16 |
+
|
17 |
+
# Expose port 8000 for Django development server
|
18 |
+
# EXPOSE 8000
|
19 |
+
|
20 |
+
# Collect static files
|
21 |
+
# RUN python manage.py collectstatic --noinput
|
22 |
+
|
23 |
+
# Run the Django development server
|
24 |
+
CMD ["python", "manage.py", "runserver", "0.0.0.0:7860"]
|
25 |
+
|
26 |
+
|
27 |
+
# FROM python:3.9
|
28 |
+
|
29 |
+
# WORKDIR /code
|
30 |
+
|
31 |
+
# COPY ./requirements.txt /code/requirements.txt
|
32 |
+
|
33 |
+
# RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
|
34 |
+
|
35 |
+
# COPY . .
|
36 |
+
|
37 |
+
# CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "7860"]
|
authentication/__init__.py
ADDED
File without changes
|
authentication/__pycache__/__init__.cpython-310.pyc
ADDED
Binary file (167 Bytes). View file
|
|
authentication/__pycache__/admin.cpython-310.pyc
ADDED
Binary file (622 Bytes). View file
|
|
authentication/__pycache__/apps.cpython-310.pyc
ADDED
Binary file (462 Bytes). View file
|
|
authentication/__pycache__/models.cpython-310.pyc
ADDED
Binary file (3.64 kB). View file
|
|
authentication/__pycache__/serializers.cpython-310.pyc
ADDED
Binary file (1.74 kB). View file
|
|
authentication/__pycache__/urls.cpython-310.pyc
ADDED
Binary file (751 Bytes). View file
|
|
authentication/__pycache__/views.cpython-310.pyc
ADDED
Binary file (4.1 kB). View file
|
|
authentication/admin.py
ADDED
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from django.contrib import admin
|
2 |
+
|
3 |
+
from authentication.models import User,UserActivationCode
|
4 |
+
|
5 |
+
# Register your models here.
|
6 |
+
@admin.register(User,)
|
7 |
+
class UserAdmin(admin.ModelAdmin):
|
8 |
+
pass
|
9 |
+
|
10 |
+
@admin.register(UserActivationCode)
|
11 |
+
class UserActivationCodeAdmin(admin.ModelAdmin):
|
12 |
+
pass
|
authentication/apps.py
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from django.apps import AppConfig
|
2 |
+
|
3 |
+
|
4 |
+
class AuthenticationConfig(AppConfig):
|
5 |
+
default_auto_field = 'django.db.models.BigAutoField'
|
6 |
+
name = 'authentication'
|
authentication/migrations/0001_initial.py
ADDED
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Generated by Django 4.2.5 on 2023-09-15 21:05
|
2 |
+
|
3 |
+
from django.db import migrations, models
|
4 |
+
|
5 |
+
|
6 |
+
class Migration(migrations.Migration):
|
7 |
+
|
8 |
+
initial = True
|
9 |
+
|
10 |
+
dependencies = [
|
11 |
+
]
|
12 |
+
|
13 |
+
operations = [
|
14 |
+
migrations.CreateModel(
|
15 |
+
name='User',
|
16 |
+
fields=[
|
17 |
+
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
18 |
+
('password', models.CharField(max_length=128, verbose_name='password')),
|
19 |
+
('last_login', models.DateTimeField(blank=True, null=True, verbose_name='last login')),
|
20 |
+
('email', models.EmailField(max_length=255, unique=True)),
|
21 |
+
('first_name', models.CharField(max_length=255, null=True)),
|
22 |
+
('last_name', models.CharField(max_length=255, null=True)),
|
23 |
+
('image', models.FileField(max_length=250, null=True, upload_to='')),
|
24 |
+
('is_active', models.BooleanField(default=True)),
|
25 |
+
('staff', models.BooleanField(default=False)),
|
26 |
+
],
|
27 |
+
options={
|
28 |
+
'abstract': False,
|
29 |
+
},
|
30 |
+
),
|
31 |
+
]
|
authentication/migrations/0002_useractivationcode.py
ADDED
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Generated by Django 4.2.5 on 2023-09-15 21:53
|
2 |
+
|
3 |
+
from django.conf import settings
|
4 |
+
from django.db import migrations, models
|
5 |
+
import django.db.models.deletion
|
6 |
+
|
7 |
+
|
8 |
+
class Migration(migrations.Migration):
|
9 |
+
|
10 |
+
dependencies = [
|
11 |
+
('authentication', '0001_initial'),
|
12 |
+
]
|
13 |
+
|
14 |
+
operations = [
|
15 |
+
migrations.CreateModel(
|
16 |
+
name='UserActivationCode',
|
17 |
+
fields=[
|
18 |
+
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
19 |
+
('activation_code', models.CharField(max_length=20, null=True)),
|
20 |
+
('usable', models.BooleanField(default=True)),
|
21 |
+
('user', models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
|
22 |
+
],
|
23 |
+
),
|
24 |
+
]
|
authentication/migrations/__init__.py
ADDED
File without changes
|
authentication/migrations/__pycache__/0001_initial.cpython-310.pyc
ADDED
Binary file (1.06 kB). View file
|
|
authentication/migrations/__pycache__/0002_useractivationcode.cpython-310.pyc
ADDED
Binary file (996 Bytes). View file
|
|
authentication/migrations/__pycache__/__init__.cpython-310.pyc
ADDED
Binary file (178 Bytes). View file
|
|
authentication/models.py
ADDED
@@ -0,0 +1,100 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from django.db import models
|
2 |
+
|
3 |
+
# Create your models here.
|
4 |
+
from django.db import models
|
5 |
+
from django.contrib.auth.models import BaseUserManager, AbstractBaseUser
|
6 |
+
|
7 |
+
|
8 |
+
DEFAULT_PROFILE_IMAGE_LINK = 'https://firebasestorage.googleapis.com/v0/b/deaf-traductor.appspot.com/o/profile_deaf.png?alt=media&token=d03df52d-7191-43a6-b6d2-1d6fc66c6845'
|
9 |
+
|
10 |
+
class UserManager(BaseUserManager):
|
11 |
+
def create_user(self,email, password):
|
12 |
+
"""
|
13 |
+
Creates and saves a User with the given email and password.
|
14 |
+
"""
|
15 |
+
|
16 |
+
if not email:
|
17 |
+
raise ValueError('Users must have email address')
|
18 |
+
|
19 |
+
user = self.model(
|
20 |
+
email=self.normalize_email(email),
|
21 |
+
)
|
22 |
+
|
23 |
+
user.set_password(password)
|
24 |
+
user.save(using=self._db)
|
25 |
+
return user
|
26 |
+
|
27 |
+
def create_staffuser(self, email, password):
|
28 |
+
"""user
|
29 |
+
Creates and saves a staff user with the given email and password.
|
30 |
+
"""
|
31 |
+
user = self.create_user(
|
32 |
+
email = email,
|
33 |
+
password=password,
|
34 |
+
)
|
35 |
+
user.staff = True
|
36 |
+
user.save(using=self._db)
|
37 |
+
return user
|
38 |
+
|
39 |
+
def create_superuser(self, email, password):
|
40 |
+
"""
|
41 |
+
Creates and saves a superuser with the given email and password.
|
42 |
+
"""
|
43 |
+
user = self.create_user(
|
44 |
+
email = email,
|
45 |
+
password=password,
|
46 |
+
)
|
47 |
+
user.staff = True
|
48 |
+
user.admin = True
|
49 |
+
user.is_active = True
|
50 |
+
user.save(using=self._db)
|
51 |
+
return user
|
52 |
+
|
53 |
+
class User(AbstractBaseUser):
|
54 |
+
email = models.EmailField(max_length=255, unique=True)
|
55 |
+
first_name = models.CharField(max_length=255, null=True)
|
56 |
+
last_name = models.CharField(max_length=255, null=True)
|
57 |
+
image = models.FileField(max_length=250, null=True)
|
58 |
+
is_active = models.BooleanField(default=True)
|
59 |
+
staff = models.BooleanField(default=False)
|
60 |
+
|
61 |
+
objects = UserManager()
|
62 |
+
|
63 |
+
USERNAME_FIELD = 'email'
|
64 |
+
|
65 |
+
def get_full_name(self):
|
66 |
+
return f"{self.email}"
|
67 |
+
|
68 |
+
def get_short_name(self):
|
69 |
+
return self.email
|
70 |
+
|
71 |
+
def __str__(self):
|
72 |
+
return self.email
|
73 |
+
|
74 |
+
def has_perm(self, perm, obj=None):
|
75 |
+
"Does the user have a specific permission?"
|
76 |
+
# Simplest possible answer: Yes, always
|
77 |
+
return True
|
78 |
+
|
79 |
+
def has_module_perms(self, app_label):
|
80 |
+
"Does the user have permissions to view the app `app_label`?"
|
81 |
+
# Simplest possible answer: Yes, always
|
82 |
+
return True
|
83 |
+
|
84 |
+
@property
|
85 |
+
def is_staff(self):
|
86 |
+
"Is the user a member of staff?"
|
87 |
+
return self.staff
|
88 |
+
|
89 |
+
@property
|
90 |
+
def is_admin(self):
|
91 |
+
"Is the user a admin member?"
|
92 |
+
return self.admin
|
93 |
+
|
94 |
+
class UserActivationCode(models.Model):
|
95 |
+
user = models.ForeignKey(User, on_delete=models.CASCADE, null=True)
|
96 |
+
activation_code = models.CharField(max_length=20, null=True)
|
97 |
+
usable = models.BooleanField(default=True)
|
98 |
+
|
99 |
+
def __str__(self) -> str:
|
100 |
+
return self.user.email + " : " + self.activation_code
|
authentication/serializers.py
ADDED
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from djoser.serializers import UserCreateSerializer
|
2 |
+
from django.contrib.auth import get_user_model
|
3 |
+
from rest_framework_simplejwt.tokens import RefreshToken, TokenError
|
4 |
+
from rest_framework import serializers
|
5 |
+
from .utils.account_send_email import send_email_to_user
|
6 |
+
from .utils.generate_password import random_pass_generator
|
7 |
+
|
8 |
+
|
9 |
+
User = get_user_model()
|
10 |
+
|
11 |
+
class UserSerializer(UserCreateSerializer):
|
12 |
+
class Meta(UserCreateSerializer.Meta):
|
13 |
+
model = User
|
14 |
+
fields = ('id', 'email', 'first_name','last_name', 'image', 'is_active', 'password',)
|
15 |
+
extra_kwargs = {'password': {'write_only': True}, 'is_active': {'read_only': True}}
|
16 |
+
depth = 1
|
17 |
+
|
18 |
+
class LogoutSerializer(serializers.Serializer):
|
19 |
+
refresh = serializers.CharField()
|
20 |
+
|
21 |
+
default_error_message = {
|
22 |
+
'bad_token': ('Token is expired or invalid')
|
23 |
+
}
|
24 |
+
|
25 |
+
def validate(self, attrs):
|
26 |
+
self.refresh_token = attrs['refresh']
|
27 |
+
return attrs
|
28 |
+
|
29 |
+
def save(self, **kwargs):
|
30 |
+
|
31 |
+
try:
|
32 |
+
RefreshToken(self.refresh_token).blacklist()
|
33 |
+
except TokenError:
|
34 |
+
self.fail('bad_token')
|
authentication/tests.py
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
from django.test import TestCase
|
2 |
+
|
3 |
+
# Create your tests here.
|
authentication/urls.py
ADDED
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from django.urls import path, include, re_path
|
2 |
+
from rest_framework.routers import DefaultRouter
|
3 |
+
from authentication.views import LogoutAPIView, UserActivationView, CustomUserViewset, AccountUserViewset
|
4 |
+
|
5 |
+
router = DefaultRouter()
|
6 |
+
router.register('auth', AccountUserViewset)
|
7 |
+
|
8 |
+
urlpatterns = [
|
9 |
+
# path('auth/', include('djoser.urls')),
|
10 |
+
path('', include(router.urls)),
|
11 |
+
path('auth/', include('djoser.urls.jwt')),
|
12 |
+
path('auth/logout/', LogoutAPIView.as_view(), name="logout"),
|
13 |
+
path('auth/user-me/update/', CustomUserViewset.as_view(), name='patch_user'),
|
14 |
+
path('auth/users/activation/<str:email>/<str:activation_code>/', UserActivationView.as_view()),
|
15 |
+
]
|
authentication/utils/__pycache__/account_send_email.cpython-310.pyc
ADDED
Binary file (544 Bytes). View file
|
|
authentication/utils/__pycache__/generate_password.cpython-310.pyc
ADDED
Binary file (580 Bytes). View file
|
|
authentication/utils/account_send_email.py
ADDED
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from django.core.mail import send_mail
|
2 |
+
|
3 |
+
def send_email_to_user(subject, message, email):
|
4 |
+
"""
|
5 |
+
Sert à envoyer de mails aux utilisateurs
|
6 |
+
"""
|
7 |
+
send_mail(
|
8 |
+
f'{subject} from Deaf Traductor',
|
9 |
+
f'{message}',
|
10 |
+
'[email protected]',
|
11 |
+
[email],
|
12 |
+
fail_silently=False,
|
13 |
+
)
|
authentication/utils/generate_password.py
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import random
|
2 |
+
import string
|
3 |
+
|
4 |
+
def random_pass_generator(length=4):
|
5 |
+
password = ''.join(random.choice(string.digits) for i in range(length))
|
6 |
+
return password
|
authentication/views.py
ADDED
@@ -0,0 +1,117 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from email import message
|
2 |
+
from django.shortcuts import render
|
3 |
+
from rest_framework import generics, status, permissions
|
4 |
+
from rest_framework.response import Response
|
5 |
+
from authentication.models import User, UserActivationCode
|
6 |
+
from rest_framework.views import APIView
|
7 |
+
from djoser.views import UserViewSet
|
8 |
+
from authentication.serializers import LogoutSerializer,UserSerializer
|
9 |
+
|
10 |
+
from .utils.account_send_email import send_email_to_user
|
11 |
+
from .utils.generate_password import random_pass_generator
|
12 |
+
from rest_framework_simplejwt.views import TokenObtainPairView
|
13 |
+
|
14 |
+
# Create your views here.
|
15 |
+
|
16 |
+
class AccountUserViewset(UserViewSet):
|
17 |
+
queryset = User.objects.all()
|
18 |
+
serializer_class = UserSerializer
|
19 |
+
|
20 |
+
def perform_create(self, serializer):
|
21 |
+
user = serializer.save()
|
22 |
+
activation_code = random_pass_generator()
|
23 |
+
|
24 |
+
user_activation_code = UserActivationCode.objects.create(user=user, activation_code=activation_code)
|
25 |
+
user_activation_code.save()
|
26 |
+
|
27 |
+
activation_message = f"Hello dear user.\n\nYou have just created your account on lambda elearning platform and you are asked to activate your account with the following password:\n\n{activation_code}"
|
28 |
+
send_email_to_user("Account activation code", activation_message, user.email)
|
29 |
+
|
30 |
+
# super(AccountUserViewset, self).perform_create(serializer)
|
31 |
+
# user = serializer.save()
|
32 |
+
# signals.user_registered.send(
|
33 |
+
# sender=self.__class__, user=user, request=self.request
|
34 |
+
# )
|
35 |
+
|
36 |
+
# context = {"user": user}
|
37 |
+
# to = [get_user_email(user)]
|
38 |
+
# if settings.SEND_ACTIVATION_EMAIL:
|
39 |
+
# settings.EMAIL.activation(self.request, context).send(to)
|
40 |
+
# elif settings.SEND_CONFIRMATION_EMAIL:
|
41 |
+
# settings.EMAIL.confirmation(self.request, context).send(to)
|
42 |
+
|
43 |
+
|
44 |
+
|
45 |
+
class CustomUserViewset(generics.UpdateAPIView):
|
46 |
+
queryset = User.objects.all()
|
47 |
+
serializer_class = UserSerializer
|
48 |
+
|
49 |
+
permission_classes = (permissions.IsAuthenticated,)
|
50 |
+
|
51 |
+
def get_serializer_context(self):
|
52 |
+
context = super(CustomUserViewset, self).get_serializer_context()
|
53 |
+
context.update({"request": self.request})
|
54 |
+
return context
|
55 |
+
|
56 |
+
def patch(self, request):
|
57 |
+
data = request.data
|
58 |
+
user = request.user
|
59 |
+
print(user)
|
60 |
+
print(data)
|
61 |
+
for key, value in data.items():
|
62 |
+
if key!='password':
|
63 |
+
setattr(user,key,value)
|
64 |
+
|
65 |
+
print(request)
|
66 |
+
user.save()
|
67 |
+
|
68 |
+
data = UserSerializer(user, context=self.get_serializer_context()).data
|
69 |
+
|
70 |
+
return Response(data, status=status.HTTP_200_OK)
|
71 |
+
|
72 |
+
class UserActivationView(APIView):
|
73 |
+
|
74 |
+
def get_permissions(self):
|
75 |
+
"""method = self.request.method
|
76 |
+
if method in ('POST', 'PUT', 'PATCH'):
|
77 |
+
return [IsAdminUser()]
|
78 |
+
else:
|
79 |
+
"""
|
80 |
+
return []
|
81 |
+
|
82 |
+
def get (self, request, email, activation_code):
|
83 |
+
print(email)
|
84 |
+
print(activation_code)
|
85 |
+
user = User.objects.filter(email=email).first()
|
86 |
+
if not user:
|
87 |
+
return Response({'message': "User not found"})
|
88 |
+
|
89 |
+
user_activation = UserActivationCode.objects.filter(user=user, usable=True).first()
|
90 |
+
if not user_activation:
|
91 |
+
return Response({'message': "User activation code not found"})
|
92 |
+
|
93 |
+
if user_activation.activation_code == activation_code:
|
94 |
+
user.is_active = True
|
95 |
+
user.save()
|
96 |
+
user_activation.usable=False
|
97 |
+
user_activation.save()
|
98 |
+
|
99 |
+
activation_message = f"Hello dear user.\n\nYour account has been activated succcessfully on the Deaf Traductor application."
|
100 |
+
send_email_to_user("Account Activated", activation_message, user.email)
|
101 |
+
return Response({'message': 'Account activted successfully'})
|
102 |
+
else:
|
103 |
+
return Response({'message':'Invalid activation code'})
|
104 |
+
|
105 |
+
|
106 |
+
class LogoutAPIView(generics.GenericAPIView):
|
107 |
+
serializer_class = LogoutSerializer
|
108 |
+
|
109 |
+
permission_classes = (permissions.IsAuthenticated,)
|
110 |
+
|
111 |
+
def post(self, request):
|
112 |
+
|
113 |
+
serializer = self.serializer_class(data=request.data)
|
114 |
+
serializer.is_valid(raise_exception=True)
|
115 |
+
serializer.save()
|
116 |
+
|
117 |
+
return Response(status=status.HTTP_204_NO_CONTENT)
|
db.sqlite3
ADDED
Binary file (246 kB). View file
|
|
formations/__init__.py
ADDED
File without changes
|
formations/__pycache__/__init__.cpython-310.pyc
ADDED
Binary file (166 Bytes). View file
|
|
formations/__pycache__/admin.cpython-310.pyc
ADDED
Binary file (207 Bytes). View file
|
|
formations/__pycache__/apps.cpython-310.pyc
ADDED
Binary file (453 Bytes). View file
|
|
formations/__pycache__/models.cpython-310.pyc
ADDED
Binary file (2.57 kB). View file
|
|
formations/__pycache__/serializers.cpython-310.pyc
ADDED
Binary file (3.33 kB). View file
|
|
formations/__pycache__/urls.cpython-310.pyc
ADDED
Binary file (887 Bytes). View file
|
|
formations/__pycache__/views.cpython-310.pyc
ADDED
Binary file (5.62 kB). View file
|
|
formations/admin.py
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
from django.contrib import admin
|
2 |
+
|
3 |
+
# Register your models here.
|
formations/apps.py
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from django.apps import AppConfig
|
2 |
+
|
3 |
+
|
4 |
+
class FormationsConfig(AppConfig):
|
5 |
+
default_auto_field = 'django.db.models.BigAutoField'
|
6 |
+
name = 'formations'
|
formations/migrations/0001_initial.py
ADDED
@@ -0,0 +1,125 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Generated by Django 4.2.5 on 2023-10-11 17:13
|
2 |
+
|
3 |
+
from django.conf import settings
|
4 |
+
from django.db import migrations, models
|
5 |
+
import django.db.models.deletion
|
6 |
+
|
7 |
+
|
8 |
+
class Migration(migrations.Migration):
|
9 |
+
|
10 |
+
initial = True
|
11 |
+
|
12 |
+
dependencies = [
|
13 |
+
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
14 |
+
]
|
15 |
+
|
16 |
+
operations = [
|
17 |
+
migrations.CreateModel(
|
18 |
+
name='CategorieFormation',
|
19 |
+
fields=[
|
20 |
+
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
21 |
+
('titre', models.CharField(max_length=255)),
|
22 |
+
('tag', models.CharField(max_length=255)),
|
23 |
+
('icone', models.CharField(max_length=255)),
|
24 |
+
('created_at', models.DateTimeField(auto_now_add=True)),
|
25 |
+
('updated_at', models.DateTimeField(auto_now=True)),
|
26 |
+
],
|
27 |
+
),
|
28 |
+
migrations.CreateModel(
|
29 |
+
name='Formation',
|
30 |
+
fields=[
|
31 |
+
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
32 |
+
('description', models.CharField(max_length=1024)),
|
33 |
+
('titre', models.CharField(max_length=255)),
|
34 |
+
('image', models.FileField(max_length=1024, upload_to='')),
|
35 |
+
('prerequis', models.CharField(max_length=1024)),
|
36 |
+
('montant', models.DecimalField(decimal_places=2, default=0, max_digits=16)),
|
37 |
+
('created_at', models.DateTimeField(auto_now_add=True)),
|
38 |
+
('updated_at', models.DateTimeField(auto_now=True)),
|
39 |
+
('author', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to=settings.AUTH_USER_MODEL)),
|
40 |
+
('categorie', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to='formations.categorieformation')),
|
41 |
+
],
|
42 |
+
),
|
43 |
+
migrations.CreateModel(
|
44 |
+
name='UserFormation',
|
45 |
+
fields=[
|
46 |
+
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
47 |
+
('created_at', models.DateTimeField(auto_now_add=True)),
|
48 |
+
('updated_at', models.DateTimeField(auto_now=True)),
|
49 |
+
('formation', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to='formations.formation')),
|
50 |
+
('user', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to=settings.AUTH_USER_MODEL)),
|
51 |
+
],
|
52 |
+
),
|
53 |
+
migrations.CreateModel(
|
54 |
+
name='PanierUser',
|
55 |
+
fields=[
|
56 |
+
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
57 |
+
('created_at', models.DateTimeField(auto_now_add=True)),
|
58 |
+
('updated_at', models.DateTimeField(auto_now=True)),
|
59 |
+
('formation', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to='formations.formation')),
|
60 |
+
('user', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to=settings.AUTH_USER_MODEL)),
|
61 |
+
],
|
62 |
+
),
|
63 |
+
migrations.CreateModel(
|
64 |
+
name='PaiementUser',
|
65 |
+
fields=[
|
66 |
+
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
67 |
+
('created_at', models.DateTimeField(auto_now_add=True)),
|
68 |
+
('updated_at', models.DateTimeField(auto_now=True)),
|
69 |
+
('formation', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to='formations.formation')),
|
70 |
+
('user', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to=settings.AUTH_USER_MODEL)),
|
71 |
+
],
|
72 |
+
),
|
73 |
+
migrations.CreateModel(
|
74 |
+
name='ListSouhaitFormation',
|
75 |
+
fields=[
|
76 |
+
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
77 |
+
('created_at', models.DateTimeField(auto_now_add=True)),
|
78 |
+
('updated_at', models.DateTimeField(auto_now=True)),
|
79 |
+
('formation', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to='formations.formation')),
|
80 |
+
('user', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to=settings.AUTH_USER_MODEL)),
|
81 |
+
],
|
82 |
+
),
|
83 |
+
migrations.CreateModel(
|
84 |
+
name='FavorisFormation',
|
85 |
+
fields=[
|
86 |
+
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
87 |
+
('created_at', models.DateTimeField(auto_now_add=True)),
|
88 |
+
('updated_at', models.DateTimeField(auto_now=True)),
|
89 |
+
('formation', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to='formations.formation')),
|
90 |
+
('user', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to=settings.AUTH_USER_MODEL)),
|
91 |
+
],
|
92 |
+
),
|
93 |
+
migrations.CreateModel(
|
94 |
+
name='Cours',
|
95 |
+
fields=[
|
96 |
+
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
97 |
+
('titre', models.CharField(max_length=255)),
|
98 |
+
('duree', models.IntegerField()),
|
99 |
+
('video', models.FileField(max_length=1024, upload_to='')),
|
100 |
+
('created_at', models.DateTimeField(auto_now_add=True)),
|
101 |
+
('updated_at', models.DateTimeField(auto_now=True)),
|
102 |
+
('formation', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to='formations.formation')),
|
103 |
+
],
|
104 |
+
),
|
105 |
+
migrations.CreateModel(
|
106 |
+
name='AvisFormation',
|
107 |
+
fields=[
|
108 |
+
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
109 |
+
('created_at', models.DateTimeField(auto_now_add=True)),
|
110 |
+
('updated_at', models.DateTimeField(auto_now=True)),
|
111 |
+
('formation', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to='formations.formation')),
|
112 |
+
('user', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to=settings.AUTH_USER_MODEL)),
|
113 |
+
],
|
114 |
+
),
|
115 |
+
migrations.CreateModel(
|
116 |
+
name='ArchiveFormation',
|
117 |
+
fields=[
|
118 |
+
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
119 |
+
('created_at', models.DateTimeField(auto_now_add=True)),
|
120 |
+
('updated_at', models.DateTimeField(auto_now=True)),
|
121 |
+
('formation', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to='formations.formation')),
|
122 |
+
('user', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to=settings.AUTH_USER_MODEL)),
|
123 |
+
],
|
124 |
+
),
|
125 |
+
]
|
formations/migrations/__init__.py
ADDED
File without changes
|
formations/migrations/__pycache__/0001_initial.cpython-310.pyc
ADDED
Binary file (2.72 kB). View file
|
|
formations/migrations/__pycache__/__init__.cpython-310.pyc
ADDED
Binary file (177 Bytes). View file
|
|
formations/models.py
ADDED
@@ -0,0 +1,88 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from django.db import models
|
2 |
+
|
3 |
+
# Create your models here.
|
4 |
+
from authentication.models import User
|
5 |
+
|
6 |
+
class CategorieFormation(models.Model):
|
7 |
+
titre = models.CharField(max_length=255)
|
8 |
+
tag = models.CharField(max_length=255)
|
9 |
+
icone = models.CharField(max_length=255)
|
10 |
+
created_at = models.DateTimeField(auto_now_add=True)
|
11 |
+
updated_at = models.DateTimeField(auto_now = True)
|
12 |
+
|
13 |
+
|
14 |
+
class Formation(models.Model):
|
15 |
+
|
16 |
+
description = models.CharField(max_length=1024)
|
17 |
+
titre = models.CharField(max_length=255)
|
18 |
+
image = models.FileField(max_length=1024)
|
19 |
+
prerequis = models.CharField(max_length=1024)
|
20 |
+
author = models.ForeignKey(User, on_delete=models.SET_NULL, null=True)
|
21 |
+
montant = models.DecimalField(default=0, max_digits=16, decimal_places= 2)
|
22 |
+
categorie = models.ForeignKey(CategorieFormation, on_delete=models.SET_NULL, null=True)
|
23 |
+
created_at = models.DateTimeField(auto_now_add=True)
|
24 |
+
updated_at = models.DateTimeField(auto_now = True)
|
25 |
+
|
26 |
+
|
27 |
+
class UserFormation(models.Model):
|
28 |
+
|
29 |
+
user = models.ForeignKey(User, on_delete=models.SET_NULL, null=True)
|
30 |
+
formation = models.ForeignKey(Formation, on_delete=models.SET_NULL, null=True)
|
31 |
+
created_at = models.DateTimeField(auto_now_add=True)
|
32 |
+
updated_at = models.DateTimeField(auto_now = True)
|
33 |
+
|
34 |
+
|
35 |
+
class Cours(models.Model):
|
36 |
+
|
37 |
+
titre = models.CharField(max_length=255)
|
38 |
+
duree = models.IntegerField()
|
39 |
+
video = models.FileField(max_length=1024)
|
40 |
+
formation = models.ForeignKey(Formation, on_delete=models.SET_NULL, null=True)
|
41 |
+
created_at = models.DateTimeField(auto_now_add=True)
|
42 |
+
updated_at = models.DateTimeField(auto_now = True)
|
43 |
+
|
44 |
+
# --------------------
|
45 |
+
|
46 |
+
class ArchiveFormation(models.Model):
|
47 |
+
|
48 |
+
user = models.ForeignKey(User, on_delete=models.SET_NULL, null=True)
|
49 |
+
formation = models.ForeignKey(Formation, on_delete=models.SET_NULL, null=True)
|
50 |
+
created_at = models.DateTimeField(auto_now_add=True)
|
51 |
+
updated_at = models.DateTimeField(auto_now = True)
|
52 |
+
|
53 |
+
|
54 |
+
class ListSouhaitFormation(models.Model):
|
55 |
+
|
56 |
+
user = models.ForeignKey(User, on_delete=models.SET_NULL, null=True)
|
57 |
+
formation = models.ForeignKey(Formation, on_delete=models.SET_NULL, null=True)
|
58 |
+
created_at = models.DateTimeField(auto_now_add=True)
|
59 |
+
updated_at = models.DateTimeField(auto_now = True)
|
60 |
+
|
61 |
+
class FavorisFormation(models.Model):
|
62 |
+
|
63 |
+
user = models.ForeignKey(User, on_delete=models.SET_NULL, null=True)
|
64 |
+
formation = models.ForeignKey(Formation, on_delete=models.SET_NULL, null=True)
|
65 |
+
created_at = models.DateTimeField(auto_now_add=True)
|
66 |
+
updated_at = models.DateTimeField(auto_now = True)
|
67 |
+
|
68 |
+
class PanierUser(models.Model):
|
69 |
+
|
70 |
+
user = models.ForeignKey(User, on_delete=models.SET_NULL, null=True)
|
71 |
+
formation = models.ForeignKey(Formation, on_delete=models.SET_NULL, null=True)
|
72 |
+
created_at = models.DateTimeField(auto_now_add=True)
|
73 |
+
updated_at = models.DateTimeField(auto_now = True)
|
74 |
+
|
75 |
+
class AvisFormation(models.Model):
|
76 |
+
|
77 |
+
user = models.ForeignKey(User, on_delete=models.SET_NULL, null=True)
|
78 |
+
formation = models.ForeignKey(Formation, on_delete=models.SET_NULL, null=True)
|
79 |
+
created_at = models.DateTimeField(auto_now_add=True)
|
80 |
+
updated_at = models.DateTimeField(auto_now = True)
|
81 |
+
|
82 |
+
class PaiementUser(models.Model):
|
83 |
+
|
84 |
+
user = models.ForeignKey(User, on_delete=models.SET_NULL, null=True)
|
85 |
+
formation = models.ForeignKey(Formation, on_delete=models.SET_NULL, null=True)
|
86 |
+
created_at = models.DateTimeField(auto_now_add=True)
|
87 |
+
updated_at = models.DateTimeField(auto_now = True)
|
88 |
+
|
formations/serializers.py
ADDED
@@ -0,0 +1,67 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
from rest_framework import serializers
|
3 |
+
from django.core.exceptions import ValidationError
|
4 |
+
from .models import CategorieFormation,Formation,UserFormation,Cours,ArchiveFormation,ListSouhaitFormation,FavorisFormation, PanierUser,AvisFormation,PaiementUser
|
5 |
+
|
6 |
+
class CategorieFormationSerializer(serializers.ModelSerializer):
|
7 |
+
|
8 |
+
class Meta:
|
9 |
+
model = CategorieFormation
|
10 |
+
fields = ('__all__')
|
11 |
+
|
12 |
+
|
13 |
+
class FormationSerializer(serializers.ModelSerializer):
|
14 |
+
|
15 |
+
class Meta:
|
16 |
+
model = Formation
|
17 |
+
fields = ('__all__')
|
18 |
+
|
19 |
+
|
20 |
+
class UserFormationSerializer(serializers.ModelSerializer):
|
21 |
+
|
22 |
+
class Meta:
|
23 |
+
model = UserFormation
|
24 |
+
fields = ('__all__')
|
25 |
+
|
26 |
+
class CoursSerializer(serializers.ModelSerializer):
|
27 |
+
|
28 |
+
class Meta:
|
29 |
+
model = Cours
|
30 |
+
fields = ('__all__')
|
31 |
+
|
32 |
+
|
33 |
+
class ListSouhaitFormationSerializer(serializers.ModelSerializer):
|
34 |
+
|
35 |
+
class Meta:
|
36 |
+
model = ListSouhaitFormation
|
37 |
+
fields = ('__all__')
|
38 |
+
|
39 |
+
class ArchiveFormationSerializer(serializers.ModelSerializer):
|
40 |
+
|
41 |
+
class Meta:
|
42 |
+
model = ArchiveFormation
|
43 |
+
fields = ('__all__')
|
44 |
+
|
45 |
+
class FavorisFormationSerializer(serializers.ModelSerializer):
|
46 |
+
|
47 |
+
class Meta:
|
48 |
+
model = FavorisFormation
|
49 |
+
fields = ('__all__')
|
50 |
+
|
51 |
+
class PanierUserSerializer(serializers.ModelSerializer):
|
52 |
+
|
53 |
+
class Meta:
|
54 |
+
model = PanierUser
|
55 |
+
fields = ('__all__')
|
56 |
+
|
57 |
+
class AvisFormationSerializer(serializers.ModelSerializer):
|
58 |
+
|
59 |
+
class Meta:
|
60 |
+
model = AvisFormation
|
61 |
+
fields = ('__all__')
|
62 |
+
|
63 |
+
class PaiementUserSerializer(serializers.ModelSerializer):
|
64 |
+
|
65 |
+
class Meta:
|
66 |
+
model = PaiementUser
|
67 |
+
fields = ('__all__')
|
formations/tests.py
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
from django.test import TestCase
|
2 |
+
|
3 |
+
# Create your tests here.
|
formations/urls.py
ADDED
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from django.urls import path, include
|
2 |
+
from .views import *
|
3 |
+
|
4 |
+
from rest_framework import routers
|
5 |
+
|
6 |
+
routes = routers.DefaultRouter()
|
7 |
+
|
8 |
+
routes.register(r'categorie_formations', CategorieFormationViews)
|
9 |
+
routes.register(r'formations',FormationViews)
|
10 |
+
routes.register(r'user_formations',UserFormationViews)
|
11 |
+
routes.register(r'cours',CoursViews)
|
12 |
+
routes.register(r'formations_archives',ArchiveFormationViews)
|
13 |
+
routes.register(r'list_souhait_formations',ListSouhaitFormationViews)
|
14 |
+
routes.register(r'favoris_formations',FavorisFormationViews)
|
15 |
+
routes.register(r'user_panier',PanierUserViews)
|
16 |
+
routes.register(r'avis_formation',AvisFormationViews)
|
17 |
+
routes.register(r'panier_user',PaiementUserViews)
|
18 |
+
|
19 |
+
|
20 |
+
# routes.register(r'type_roles',TypeRoleViews)
|
21 |
+
urlpatterns = [
|
22 |
+
path('',include(routes.urls)),
|
23 |
+
]
|
formations/views.py
ADDED
@@ -0,0 +1,135 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from rest_framework.response import Response
|
2 |
+
from rest_framework import viewsets
|
3 |
+
from rest_framework.permissions import IsAuthenticated,AllowAny
|
4 |
+
from .models import CategorieFormation,Formation,UserFormation,Cours,ArchiveFormation,ListSouhaitFormation,FavorisFormation, PanierUser,AvisFormation,PaiementUser
|
5 |
+
from .serializers import ArchiveFormationSerializer, AvisFormationSerializer, CategorieFormationSerializer, CoursSerializer, FavorisFormationSerializer, FormationSerializer, ListSouhaitFormationSerializer, PaiementUserSerializer, PanierUserSerializer , UserFormationSerializer
|
6 |
+
|
7 |
+
|
8 |
+
# Create your views here.
|
9 |
+
class CategorieFormationViews(viewsets.ModelViewSet):
|
10 |
+
serializer_class = CategorieFormationSerializer
|
11 |
+
queryset = CategorieFormation.objects.all().order_by('-id')
|
12 |
+
|
13 |
+
|
14 |
+
def get_permissions(self):
|
15 |
+
return [AllowAny()]
|
16 |
+
|
17 |
+
def get_serializer_context(self):
|
18 |
+
context = super(CategorieFormationViews, self).get_serializer_context()
|
19 |
+
context.update({"request": self.request})
|
20 |
+
return context
|
21 |
+
|
22 |
+
|
23 |
+
class FormationViews(viewsets.ModelViewSet):
|
24 |
+
serializer_class = FormationSerializer
|
25 |
+
queryset = Formation.objects.all().order_by('-id')
|
26 |
+
|
27 |
+
def get_permissions(self):
|
28 |
+
return [AllowAny()]
|
29 |
+
|
30 |
+
def get_serializer_context(self):
|
31 |
+
context = super(FormationViews, self).get_serializer_context()
|
32 |
+
context.update({"request": self.request})
|
33 |
+
return context
|
34 |
+
|
35 |
+
|
36 |
+
class UserFormationViews(viewsets.ModelViewSet):
|
37 |
+
serializer_class = UserFormationSerializer
|
38 |
+
queryset = UserFormation.objects.all().order_by('-id')
|
39 |
+
|
40 |
+
def get_permissions(self):
|
41 |
+
return [AllowAny()]
|
42 |
+
|
43 |
+
def get_serializer_context(self):
|
44 |
+
context = super(UserFormationViews, self).get_serializer_context()
|
45 |
+
context.update({"request": self.request})
|
46 |
+
return context
|
47 |
+
|
48 |
+
|
49 |
+
class CoursViews(viewsets.ModelViewSet):
|
50 |
+
serializer_class = CoursSerializer
|
51 |
+
queryset = Cours.objects.all().order_by('-id')
|
52 |
+
|
53 |
+
def get_permissions(self):
|
54 |
+
return [AllowAny()]
|
55 |
+
|
56 |
+
def get_serializer_context(self):
|
57 |
+
context = super(CoursViews, self).get_serializer_context()
|
58 |
+
context.update({"request": self.request})
|
59 |
+
return context
|
60 |
+
|
61 |
+
|
62 |
+
class ArchiveFormationViews(viewsets.ModelViewSet):
|
63 |
+
serializer_class = ArchiveFormationSerializer
|
64 |
+
queryset = ArchiveFormation.objects.all().order_by('-id')
|
65 |
+
|
66 |
+
def get_permissions(self):
|
67 |
+
return [AllowAny()]
|
68 |
+
|
69 |
+
def get_serializer_context(self):
|
70 |
+
context = super(ArchiveFormationViews, self).get_serializer_context()
|
71 |
+
context.update({"request": self.request})
|
72 |
+
return context
|
73 |
+
|
74 |
+
|
75 |
+
class ListSouhaitFormationViews(viewsets.ModelViewSet):
|
76 |
+
serializer_class = ListSouhaitFormationSerializer
|
77 |
+
queryset = ListSouhaitFormation.objects.all().order_by('-id')
|
78 |
+
|
79 |
+
def get_permissions(self):
|
80 |
+
return [AllowAny()]
|
81 |
+
|
82 |
+
def get_serializer_context(self):
|
83 |
+
context = super(ListSouhaitFormationViews, self).get_serializer_context()
|
84 |
+
context.update({"request": self.request})
|
85 |
+
return context
|
86 |
+
|
87 |
+
|
88 |
+
class FavorisFormationViews(viewsets.ModelViewSet):
|
89 |
+
serializer_class = FavorisFormationSerializer
|
90 |
+
queryset = FavorisFormation.objects.all().order_by('-id')
|
91 |
+
|
92 |
+
def get_permissions(self):
|
93 |
+
return [AllowAny()]
|
94 |
+
|
95 |
+
def get_serializer_context(self):
|
96 |
+
context = super(FavorisFormationViews, self).get_serializer_context()
|
97 |
+
context.update({"request": self.request})
|
98 |
+
return context
|
99 |
+
|
100 |
+
|
101 |
+
class PanierUserViews(viewsets.ModelViewSet):
|
102 |
+
serializer_class = PanierUserSerializer
|
103 |
+
queryset = PanierUser.objects.all().order_by('-id')
|
104 |
+
|
105 |
+
def get_permissions(self):
|
106 |
+
return [AllowAny()]
|
107 |
+
|
108 |
+
def get_serializer_context(self):
|
109 |
+
context = super(PanierUserViews, self).get_serializer_context()
|
110 |
+
context.update({"request": self.request})
|
111 |
+
return context
|
112 |
+
|
113 |
+
class AvisFormationViews(viewsets.ModelViewSet):
|
114 |
+
serializer_class = AvisFormationSerializer
|
115 |
+
queryset = AvisFormation.objects.all().order_by('-id')
|
116 |
+
|
117 |
+
def get_permissions(self):
|
118 |
+
return [AllowAny()]
|
119 |
+
|
120 |
+
def get_serializer_context(self):
|
121 |
+
context = super(AvisFormationViews, self).get_serializer_context()
|
122 |
+
context.update({"request": self.request})
|
123 |
+
return context
|
124 |
+
|
125 |
+
class PaiementUserViews(viewsets.ModelViewSet):
|
126 |
+
serializer_class = PaiementUserSerializer
|
127 |
+
queryset = PaiementUser.objects.all().order_by('-id')
|
128 |
+
|
129 |
+
def get_permissions(self):
|
130 |
+
return [AllowAny()]
|
131 |
+
|
132 |
+
def get_serializer_context(self):
|
133 |
+
context = super(PaiementUserViews, self).get_serializer_context()
|
134 |
+
context.update({"request": self.request})
|
135 |
+
return context
|
lambdaAPI/__init__.py
ADDED
File without changes
|
lambdaAPI/__pycache__/__init__.cpython-310.pyc
ADDED
Binary file (165 Bytes). View file
|
|