u
This commit is contained in:
parent
4855f8f66c
commit
573e911d01
24 changed files with 102 additions and 333 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -279,4 +279,3 @@ lms/media/
|
|||
.env
|
||||
|
||||
# Ignore Django migrations
|
||||
*/migrations/
|
||||
|
|
|
|||
|
|
@ -50,4 +50,4 @@
|
|||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
@ -245,23 +245,23 @@ DJANGO_ADMIN_FORCE_ALLAUTH = env.bool("DJANGO_ADMIN_FORCE_ALLAUTH", default=Fals
|
|||
# https://docs.djangoproject.com/en/dev/ref/settings/#logging
|
||||
# See https://docs.djangoproject.com/en/dev/topics/logging for
|
||||
# more details on how to customize your logging configuration.
|
||||
LOGGING = {
|
||||
"version": 1,
|
||||
"disable_existing_loggers": False,
|
||||
"formatters": {
|
||||
"verbose": {
|
||||
"format": "%(levelname)s %(asctime)s %(module)s %(process)d %(thread)d %(message)s",
|
||||
},
|
||||
},
|
||||
"handlers": {
|
||||
"console": {
|
||||
"level": "DEBUG",
|
||||
"class": "logging.StreamHandler",
|
||||
"formatter": "verbose",
|
||||
},
|
||||
},
|
||||
"root": {"level": "INFO", "handlers": ["console"]},
|
||||
}
|
||||
# LOGGING = {
|
||||
# "version": 1,
|
||||
# "disable_existing_loggers": False,
|
||||
# "formatters": {
|
||||
# "verbose": {
|
||||
# "format": "%(levelname)s %(asctime)s %(module)s %(process)d %(thread)d %(message)s",
|
||||
# },
|
||||
# },
|
||||
# "handlers": {
|
||||
# "console": {
|
||||
# "level": "DEBUG",
|
||||
# "class": "logging.StreamHandler",
|
||||
# "formatter": "verbose",
|
||||
# },
|
||||
# },
|
||||
# "root": {"level": "INFO", "handlers": ["console"]},
|
||||
# }
|
||||
|
||||
REDIS_URL = env("REDIS_URL", default="redis://redis:6379/0")
|
||||
REDIS_SSL = REDIS_URL.startswith("rediss://")
|
||||
|
|
|
|||
|
|
@ -8,18 +8,21 @@ from .base import env
|
|||
# ------------------------------------------------------------------------------
|
||||
# https://docs.djangoproject.com/en/dev/ref/settings/#debug
|
||||
DEBUG = True
|
||||
DEBUG = True
|
||||
# https://docs.djangoproject.com/en/dev/ref/settings/#secret-key
|
||||
SECRET_KEY = env(
|
||||
"DJANGO_SECRET_KEY",
|
||||
default="DM837WrWz7KIfZM2eb4swzqGlIG0VhhAIFNXf9KgamMtT42DTkHIEXfpF4N9rh2Y",
|
||||
)
|
||||
# https://docs.djangoproject.com/en/dev/ref/settings/#allowed-hosts
|
||||
ALLOWED_HOSTS = ["127.0.0.1", "localhost", "8000-idx-lms-1736949042591.cluster-qtqwjj3wgzff6uxtk26wj7fzq6.cloudworkstations.dev"] # حدد المضيفين المسموح بهم
|
||||
ALLOWED_HOSTS = ["127.0.0.1", "localhost",
|
||||
"8000-idx-lms-1736953337728.cluster-p6qcyjpiljdwusmrjxdspyb5m2.cloudworkstations.dev"
|
||||
] # حدد المضيفين المسموح بهم
|
||||
|
||||
CSRF_TRUSTED_ORIGINS = [
|
||||
'http://localhost:3000',
|
||||
'http://127.0.0.1:3000',
|
||||
'https://8000-idx-lms-1736949042591.cluster-qtqwjj3wgzff6uxtk26wj7fzq6.cloudworkstations.dev'
|
||||
'https://8000-idx-lms-1736953337728.cluster-p6qcyjpiljdwusmrjxdspyb5m2.cloudworkstations.dev'
|
||||
]
|
||||
CORS_ORIGIN_ALLOW_ALL = True
|
||||
CORS_ALLOW_CREDENTIALS = False
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ current_site = Site.objects.get_current()
|
|||
site_domain = current_site.domain
|
||||
|
||||
class CustomAccountAdapter(DefaultAccountAdapter):
|
||||
|
||||
|
||||
def get_email_confirmation_url(self, request, emailconfirmation):
|
||||
return f"http://{site_domain}/account/email-confirmation/{emailconfirmation.key}/"
|
||||
|
||||
|
|
@ -1,7 +1,5 @@
|
|||
# Generated by Django 5.0.10 on 2025-01-11 07:41
|
||||
# Generated by Django 5.0.10 on 2025-01-15 15:19
|
||||
|
||||
import django.contrib.auth.models
|
||||
import django.contrib.auth.validators
|
||||
import django.utils.timezone
|
||||
from django.db import migrations, models
|
||||
|
||||
|
|
@ -22,13 +20,13 @@ class Migration(migrations.Migration):
|
|||
('password', models.CharField(max_length=128, verbose_name='password')),
|
||||
('last_login', models.DateTimeField(blank=True, null=True, verbose_name='last login')),
|
||||
('is_superuser', models.BooleanField(default=False, help_text='Designates that this user has all permissions without explicitly assigning them.', verbose_name='superuser status')),
|
||||
('username', models.CharField(error_messages={'unique': 'A user with that username already exists.'}, help_text='Required. 150 characters or fewer. Letters, digits and @/./+/-/_ only.', max_length=150, unique=True, validators=[django.contrib.auth.validators.UnicodeUsernameValidator()], verbose_name='username')),
|
||||
('is_staff', models.BooleanField(default=False, help_text='Designates whether the user can log into this admin site.', verbose_name='staff status')),
|
||||
('is_active', models.BooleanField(default=True, help_text='Designates whether this user should be treated as active. Unselect this instead of deleting accounts.', verbose_name='active')),
|
||||
('date_joined', models.DateTimeField(default=django.utils.timezone.now, verbose_name='date joined')),
|
||||
('email', models.EmailField(max_length=254, unique=True)),
|
||||
('full_name', models.CharField(max_length=255, null=True)),
|
||||
('role', models.CharField(choices=[('admin', 'admin'), ('student', 'student'), ('instructor', 'instructor')], max_length=255, null=True)),
|
||||
('full_name', models.CharField(blank=True, max_length=255, null=True)),
|
||||
('image', models.ImageField(blank=True, null=True, upload_to='account/profile_image/')),
|
||||
('role', models.CharField(blank=True, choices=[('student', 'Student'), ('instructor', 'Instructor'), ('admin', 'Admin')], max_length=20, null=True)),
|
||||
('groups', models.ManyToManyField(blank=True, help_text='The groups this user belongs to. A user will get all permissions granted to each of their groups.', related_name='user_set', related_query_name='user', to='auth.group', verbose_name='groups')),
|
||||
('user_permissions', models.ManyToManyField(blank=True, help_text='Specific permissions for this user.', related_name='user_set', related_query_name='user', to='auth.permission', verbose_name='user permissions')),
|
||||
],
|
||||
|
|
@ -37,8 +35,5 @@ class Migration(migrations.Migration):
|
|||
'verbose_name_plural': 'users',
|
||||
'abstract': False,
|
||||
},
|
||||
managers=[
|
||||
('objects', django.contrib.auth.models.UserManager()),
|
||||
],
|
||||
),
|
||||
]
|
||||
|
|
|
|||
|
|
@ -1,18 +0,0 @@
|
|||
# Generated by Django 5.0.10 on 2025-01-11 07:47
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('accounts', '0001_initial'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='customuser',
|
||||
name='role',
|
||||
field=models.CharField(choices=[('instructor', 'instructor'), ('admin', 'admin'), ('student', 'student')], max_length=255, null=True),
|
||||
),
|
||||
]
|
||||
|
|
@ -1,18 +0,0 @@
|
|||
# Generated by Django 5.0.10 on 2025-01-11 07:47
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('accounts', '0002_alter_customuser_role'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='customuser',
|
||||
name='role',
|
||||
field=models.CharField(choices=[('student', 'student'), ('admin', 'admin'), ('instructor', 'instructor')], max_length=255, null=True),
|
||||
),
|
||||
]
|
||||
|
|
@ -1,18 +0,0 @@
|
|||
# Generated by Django 5.0.10 on 2025-01-11 07:50
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('accounts', '0003_alter_customuser_role'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='customuser',
|
||||
name='role',
|
||||
field=models.CharField(choices=[('student', 'student'), ('instructor', 'instructor'), ('admin', 'admin')], max_length=255, null=True),
|
||||
),
|
||||
]
|
||||
|
|
@ -1,18 +0,0 @@
|
|||
# Generated by Django 5.0.10 on 2025-01-11 10:05
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('accounts', '0004_alter_customuser_role'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='customuser',
|
||||
name='role',
|
||||
field=models.CharField(choices=[('student', 'student'), ('admin', 'admin'), ('instructor', 'instructor')], max_length=255, null=True),
|
||||
),
|
||||
]
|
||||
|
|
@ -1,23 +0,0 @@
|
|||
# Generated by Django 5.0.10 on 2025-01-11 10:07
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('accounts', '0005_alter_customuser_role'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterModelManagers(
|
||||
name='customuser',
|
||||
managers=[
|
||||
],
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='customuser',
|
||||
name='role',
|
||||
field=models.CharField(choices=[('instructor', 'instructor'), ('student', 'student'), ('admin', 'admin')], max_length=255, null=True),
|
||||
),
|
||||
]
|
||||
|
|
@ -1,27 +0,0 @@
|
|||
# Generated by Django 5.0.10 on 2025-01-11 10:11
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('accounts', '0006_alter_customuser_managers_alter_customuser_role'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RemoveField(
|
||||
model_name='customuser',
|
||||
name='username',
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='customuser',
|
||||
name='full_name',
|
||||
field=models.CharField(blank=True, max_length=255, null=True),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='customuser',
|
||||
name='role',
|
||||
field=models.CharField(blank=True, choices=[('student', 'Student'), ('instructor', 'Instructor'), ('admin', 'Admin')], max_length=20, null=True),
|
||||
),
|
||||
]
|
||||
|
|
@ -1,18 +0,0 @@
|
|||
# Generated by Django 5.0.10 on 2025-01-12 14:39
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('accounts', '0007_remove_customuser_username_and_more'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='customuser',
|
||||
name='image',
|
||||
field=models.ImageField(blank=True, null=True, upload_to='account/profile_image/'),
|
||||
),
|
||||
]
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
# Generated by Django 5.0.10 on 2025-01-15 14:43
|
||||
# Generated by Django 5.0.10 on 2025-01-15 15:19
|
||||
|
||||
import django.db.models.deletion
|
||||
import uuid
|
||||
|
|
|
|||
|
|
@ -1,18 +0,0 @@
|
|||
# Generated by Django 5.0.10 on 2025-01-15 14:47
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('app', '0001_initial'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='module',
|
||||
name='order',
|
||||
field=models.IntegerField(blank=True, null=True),
|
||||
),
|
||||
]
|
||||
|
|
@ -1,17 +0,0 @@
|
|||
# Generated by Django 5.0.10 on 2025-01-15 14:48
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('app', '0002_module_order'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RemoveField(
|
||||
model_name='module',
|
||||
name='order',
|
||||
),
|
||||
]
|
||||
|
|
@ -1,28 +0,0 @@
|
|||
# Generated by Django 5.0.10 on 2025-01-15 14:51
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('app', '0003_remove_module_order'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='enrollment',
|
||||
name='order',
|
||||
field=models.IntegerField(blank=True, null=True),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='lesson',
|
||||
name='order',
|
||||
field=models.IntegerField(blank=True, null=True),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='quiz',
|
||||
name='order',
|
||||
field=models.IntegerField(blank=True, null=True),
|
||||
),
|
||||
]
|
||||
|
|
@ -1,25 +0,0 @@
|
|||
# Generated by Django 5.0.10 on 2025-01-15 14:52
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('app', '0004_enrollment_order_lesson_order_quiz_order'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RemoveField(
|
||||
model_name='enrollment',
|
||||
name='order',
|
||||
),
|
||||
migrations.RemoveField(
|
||||
model_name='lesson',
|
||||
name='order',
|
||||
),
|
||||
migrations.RemoveField(
|
||||
model_name='quiz',
|
||||
name='order',
|
||||
),
|
||||
]
|
||||
|
|
@ -1,18 +0,0 @@
|
|||
# Generated by Django 5.0.10 on 2025-01-15 14:53
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('app', '0005_remove_enrollment_order_remove_lesson_order_and_more'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='enrollment',
|
||||
name='order',
|
||||
field=models.IntegerField(blank=True, null=True),
|
||||
),
|
||||
]
|
||||
|
|
@ -1,17 +0,0 @@
|
|||
# Generated by Django 5.0.10 on 2025-01-15 14:53
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('app', '0006_enrollment_order'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RemoveField(
|
||||
model_name='enrollment',
|
||||
name='order',
|
||||
),
|
||||
]
|
||||
|
|
@ -1,18 +0,0 @@
|
|||
# Generated by Django 5.0.10 on 2025-01-15 14:57
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('app', '0007_remove_enrollment_order'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='lesson',
|
||||
name='order',
|
||||
field=models.IntegerField(blank=True, null=True),
|
||||
),
|
||||
]
|
||||
|
|
@ -1,17 +0,0 @@
|
|||
# Generated by Django 5.0.10 on 2025-01-15 14:57
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('app', '0008_lesson_order'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RemoveField(
|
||||
model_name='lesson',
|
||||
name='order',
|
||||
),
|
||||
]
|
||||
|
|
@ -90,6 +90,7 @@ class LessonViewSet(ModelViewSet):
|
|||
"""
|
||||
Return a specific lesson within a specific module only if the user is authorized.
|
||||
"""
|
||||
|
||||
lesson_id = self.request.query_params.get('lesson_id') # Get lesson ID from the request
|
||||
module_id = self.request.query_params.get('module_id') # Get module ID from the request
|
||||
|
||||
|
|
@ -133,6 +134,74 @@ class LessonViewSet(ModelViewSet):
|
|||
# Save the lesson with the module and created_by user
|
||||
serializer.save(module=module, created_by=self.request.user)
|
||||
|
||||
@action(detail=False, methods=['patch'], url_path='update-lesson')
|
||||
def patch_lesson(self, request, *args, **kwargs):
|
||||
"""
|
||||
Custom PATCH method to update a lesson.
|
||||
"""
|
||||
# الحصول على معرف الكائن (lesson_id) من الـ URL
|
||||
lesson_id = self.request.query_params.get('lesson_id')
|
||||
if not lesson_id:
|
||||
return Response({"detail": "Lesson ID is required in the URL."}, status=status.HTTP_400_BAD_REQUEST)
|
||||
|
||||
# البحث عن الدرس
|
||||
lesson = Lesson.objects.filter(id=lesson_id).first()
|
||||
if not lesson:
|
||||
return Response({"detail": "Lesson not found."}, status=status.HTTP_404_NOT_FOUND)
|
||||
|
||||
# التحقق من الصلاحيات (مالك الكورس أو مسجل فيه)
|
||||
is_owner = lesson.module.course.owner == request.user
|
||||
|
||||
if not is_owner:
|
||||
raise PermissionDenied("You do not have permission to update this lesson.")
|
||||
|
||||
# تحديث الدرس باستخدام البيانات المرسلة في الطلب
|
||||
serializer = self.get_serializer(lesson, data=request.data, partial=True) # partial=True لتحديث الحقول المطلوبة فقط
|
||||
if serializer.is_valid():
|
||||
serializer.save()
|
||||
return Response(serializer.data, status=status.HTTP_200_OK)
|
||||
|
||||
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
|
||||
|
||||
|
||||
|
||||
|
||||
@action(detail=False, methods=['delete'], url_path='delete-lesson')
|
||||
def delete_lesson(self, request, *args, **kwargs):
|
||||
"""
|
||||
Custom DELETE method to delete a lesson.
|
||||
"""
|
||||
# الحصول على معرف الكائن (lesson_id) من الـ URL
|
||||
lesson_id = request.query_params.get('lesson_id')
|
||||
if not lesson_id:
|
||||
return Response(
|
||||
{"detail": "Lesson ID is required in the URL."},
|
||||
status=status.HTTP_400_BAD_REQUEST
|
||||
)
|
||||
|
||||
# البحث عن الدرس
|
||||
try:
|
||||
lesson = Lesson.objects.get(id=lesson_id)
|
||||
except Lesson.DoesNotExist:
|
||||
return Response(
|
||||
{"detail": "Lesson not found."},
|
||||
status=status.HTTP_404_NOT_FOUND
|
||||
)
|
||||
|
||||
# التحقق من الصلاحيات (مالك الكورس أو مسجل فيه)
|
||||
is_owner = lesson.module.course.owner == request.user
|
||||
|
||||
if not is_owner:
|
||||
raise PermissionDenied("You do not have permission to delete this lesson.")
|
||||
|
||||
# حذف الدرس
|
||||
lesson.delete()
|
||||
|
||||
return Response(
|
||||
{"detail": "Lesson deleted successfully."},
|
||||
status=status.HTTP_204_NO_CONTENT
|
||||
)
|
||||
|
||||
|
||||
|
||||
class EnrollmentViewSet(ModelViewSet):
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ http://cookiecutter-django.readthedocs.io/en/latest/faq.html#why-is-there-a-djan
|
|||
from django.conf import settings
|
||||
from django.db import migrations
|
||||
|
||||
domain_name = "example.com" # Front end domain
|
||||
|
||||
def _update_or_create_site_with_sequence(site_model, connection, domain, name):
|
||||
"""Update or create the site with default ID and keep the DB sequence in sync."""
|
||||
|
|
@ -40,7 +41,7 @@ def update_site_forward(apps, schema_editor):
|
|||
_update_or_create_site_with_sequence(
|
||||
Site,
|
||||
schema_editor.connection,
|
||||
"example.com",
|
||||
domain_name,
|
||||
"Learning Management System",
|
||||
)
|
||||
|
||||
|
|
@ -51,8 +52,8 @@ def update_site_backward(apps, schema_editor):
|
|||
_update_or_create_site_with_sequence(
|
||||
Site,
|
||||
schema_editor.connection,
|
||||
"example.com",
|
||||
"example.com",
|
||||
domain_name,
|
||||
domain_name,
|
||||
)
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue