Compare commits
1 commit
main
...
dependabot
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
877339a33d |
240 changed files with 2039 additions and 17106 deletions
|
|
@ -12,5 +12,3 @@ REDIS_URL=redis://redis:6379/0
|
||||||
# Flower
|
# Flower
|
||||||
CELERY_FLOWER_USER=debug
|
CELERY_FLOWER_USER=debug
|
||||||
CELERY_FLOWER_PASSWORD=debug
|
CELERY_FLOWER_PASSWORD=debug
|
||||||
|
|
||||||
SIGNING_KEY=ebd0c2f345ede5we3244t5r34a0dc1b994e33e729e
|
|
||||||
|
|
@ -5,12 +5,12 @@ DJANGO_SETTINGS_MODULE=config.settings.production
|
||||||
DJANGO_SECRET_KEY=CQHQz4M3wN1VL2TT53Gl8yupKOjQ5m01js4jPw6bQsUexzkdy9JGXhQg9h6H24M5
|
DJANGO_SECRET_KEY=CQHQz4M3wN1VL2TT53Gl8yupKOjQ5m01js4jPw6bQsUexzkdy9JGXhQg9h6H24M5
|
||||||
DJANGO_ADMIN_URL=6XfjlokEGlPf6SpVfGh7wBvs7t5ZFMDs/
|
DJANGO_ADMIN_URL=6XfjlokEGlPf6SpVfGh7wBvs7t5ZFMDs/
|
||||||
DJANGO_ALLOWED_HOSTS=.example.com
|
DJANGO_ALLOWED_HOSTS=.example.com
|
||||||
SIGNING_KEY=HQz4M3wN1ebd0c2f345ede5we324@#$%$#@#R$Q#Zaexsredg/*43/54333e729e
|
|
||||||
|
|
||||||
# Security
|
# Security
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
# TIP: better off using DNS, however, redirect is OK too
|
# TIP: better off using DNS, however, redirect is OK too
|
||||||
DJANGO_SECURE_SSL_REDIRECT=False
|
DJANGO_SECURE_SSL_REDIRECT=False
|
||||||
|
|
||||||
# Email
|
# Email
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
DJANGO_SERVER_EMAIL=
|
DJANGO_SERVER_EMAIL=
|
||||||
0
backend/.gitattributes → .gitattributes
vendored
0
backend/.gitattributes → .gitattributes
vendored
2
backend/.gitignore → .gitignore
vendored
2
backend/.gitignore → .gitignore
vendored
|
|
@ -277,5 +277,3 @@ lms/media/
|
||||||
.pytest_cache/
|
.pytest_cache/
|
||||||
.ipython/
|
.ipython/
|
||||||
.env
|
.env
|
||||||
|
|
||||||
# Ignore Django migrations
|
|
||||||
21
LICENSE
21
LICENSE
|
|
@ -1,21 +0,0 @@
|
||||||
MIT License
|
|
||||||
|
|
||||||
Copyright (c) 2025 Ahmed Nagi
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
SOFTWARE.
|
|
||||||
151
README.md
151
README.md
|
|
@ -1,8 +1,6 @@
|
||||||
# Learning Management System (LMS) API with Vue.js
|
# Learning Management System (LMS) API
|
||||||
|
|
||||||
Welcome to the Learning Management System (LMS) API! This project is a robust, scalable backend solution built with Django and Django Rest Framework (DRF), coupled with a modern and responsive frontend using Vue.js. It is designed to manage courses and their associated modules, providing a structured and secure platform for educational content delivery.
|
Welcome to the Learning Management System (LMS) API! This project is a robust and scalable backend solution built with Django and Django Rest Framework (DRF). It is designed to manage courses and their associated modules, providing a structured and secure platform for educational content delivery.
|
||||||
|
|
||||||

|
|
||||||
|
|
||||||
## Features
|
## Features
|
||||||
|
|
||||||
|
|
@ -11,38 +9,42 @@ Welcome to the Learning Management System (LMS) API! This project is a robust, s
|
||||||
- **Authentication & Permissions**: Secure access using Token Authentication and IsAuthenticated permissions.
|
- **Authentication & Permissions**: Secure access using Token Authentication and IsAuthenticated permissions.
|
||||||
- **RESTful API Design**: Follows REST principles with hyperlinked relationships for intuitive navigation.
|
- **RESTful API Design**: Follows REST principles with hyperlinked relationships for intuitive navigation.
|
||||||
- **Custom Query Logic**: Retrieve modules filtered by course ID for efficient data access.
|
- **Custom Query Logic**: Retrieve modules filtered by course ID for efficient data access.
|
||||||
- **Interactive Frontend**: A Vue.js-powered frontend for seamless interaction with the backend API, including real-time updates and dynamic views.
|
|
||||||
|
|
||||||
## Technologies Used
|
## Technologies Used
|
||||||
|
|
||||||
### Backend
|
- **Backend**: Django, Django Rest Framework (DRF)
|
||||||
- **Framework**: Django, Django Rest Framework (DRF)
|
|
||||||
- **Authentication**: dj-rest-auth & django-alluth
|
- **Authentication**: dj-rest-auth & django-alluth
|
||||||
- **Database**: PostgreSQL
|
- **Database**: PostgreSQL
|
||||||
- **API Documentation**: Auto-generated using drf-spectacular browsable API.
|
- **API Documentation**: Auto-generated using drf_yasg browsable API.
|
||||||
- **Project Scaffold**: Cookiecutter Django
|
|
||||||
|
|
||||||
### Frontend
|
## Getting Started
|
||||||
- **Framework**: Vue.js 3
|
|
||||||
- **Routing**: Vue Router
|
|
||||||
- **UI Framework**: Tailwind CSS, DaisyUI
|
|
||||||
|
|
||||||
|
|
||||||
### Integration
|
# Prerequisites
|
||||||
|
|
||||||
1. **API Consumption**: Use Axios or Fetch API in Vue.js to interact with the backend API endpoints.
|
- [Docker](https://docs.docker.com/docker-for-mac/install/)
|
||||||
2. **Authentication**: Implement login and token storage using Vuex/Pinia or localStorage.
|
|
||||||
3. **Components**: Create reusable Vue components for courses, modules, authentication, and navigation.
|
## Local Development
|
||||||
4. **Routing**: Use Vue Router to manage navigation between pages like course lists, module details, and user authentication.
|
|
||||||
|
Start the dev server for local development:
|
||||||
|
```bash
|
||||||
|
docker-compose up
|
||||||
|
```
|
||||||
|
|
||||||
|
Run a command inside the docker container:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
docker-compose run --rm web [command]
|
||||||
|
```
|
||||||
|
|
||||||
## API Endpoints
|
## API Endpoints
|
||||||
This project includes a fully interactive API documentation powered by drf-spectacular, a library for generating Swagger and ReDoc documentation for Django REST Framework (DRF).
|
|
||||||
|
|
||||||
### Features
|
This project includes a fully interactive API documentation powered by drf_yasg, a library for generating Swagger and ReDoc documentation for Django REST Framework (DRF).
|
||||||
|
Features
|
||||||
|
|
||||||
- **Interactive Swagger UI**: Test API endpoints directly within the browser.
|
* Interactive Swagger UI: Test API endpoints directly within the browser.
|
||||||
- **MkDocs Material Interface**: A clean and customizable documentation tool with a modern Material Design theme.
|
* ReDoc Interface: Professionally styled documentation for better readabi* lity.
|
||||||
- **Auto-generated**: No need to write documentation manually; drf-spectacularyasg extracts the information from DRF views and serializers.
|
* Auto-generated: No need to write documentation manually; drf_yasg extracts t* he information from DRF views and serializers.
|
||||||
|
|
||||||
## Contributing
|
## Contributing
|
||||||
|
|
||||||
|
|
@ -57,7 +59,106 @@ Contributions are welcome! If you’d like to contribute, please follow these st
|
||||||
|
|
||||||
This project is licensed under the MIT License. See the LICENSE file for details.
|
This project is licensed under the MIT License. See the LICENSE file for details.
|
||||||
|
|
||||||
---
|
## Acknowledgments
|
||||||
|
|
||||||
By combining the power of Django and Vue.js, this LMS API provides a full-stack solution for managing and delivering educational content effectively. Happy coding!
|
- Built with ❤️ using Django and Django Rest Framework.
|
||||||
|
- Inspired by the need for scalable and secure e-learning solutions.
|
||||||
|
|
||||||
|
Feel free to explore the API and contribute to its development. For any questions or feedback, please open an issue or contact the maintainers. Happy coding! 🚀
|
||||||
|
|
||||||
|
This README is clear, concise, and provides all the necessary information for users and contributors.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
[](https://github.com/cookiecutter/cookiecutter-django/)
|
||||||
|
[](https://github.com/astral-sh/ruff)
|
||||||
|
|
||||||
|
## Settings
|
||||||
|
|
||||||
|
Moved to [settings](https://cookiecutter-django.readthedocs.io/en/latest/1-getting-started/settings.html).
|
||||||
|
|
||||||
|
## Basic Commands
|
||||||
|
|
||||||
|
### Setting Up Your Users
|
||||||
|
|
||||||
|
- To create a **normal user account**, just go to Sign Up and fill out the form. Once you submit it, you'll see a "Verify Your E-mail Address" page. Go to your console to see a simulated email verification message. Copy the link into your browser. Now the user's email should be verified and ready to go.
|
||||||
|
|
||||||
|
- To create a **superuser account**, use this command:
|
||||||
|
|
||||||
|
$ python manage.py createsuperuser
|
||||||
|
|
||||||
|
For convenience, you can keep your normal user logged in on Chrome and your superuser logged in on Firefox (or similar), so that you can see how the site behaves for both kinds of users.
|
||||||
|
|
||||||
|
### Type checks
|
||||||
|
|
||||||
|
Running type checks with mypy:
|
||||||
|
|
||||||
|
$ mypy lms
|
||||||
|
|
||||||
|
### Test coverage
|
||||||
|
|
||||||
|
To run the tests, check your test coverage, and generate an HTML coverage report:
|
||||||
|
|
||||||
|
$ coverage run -m pytest
|
||||||
|
$ coverage html
|
||||||
|
$ open htmlcov/index.html
|
||||||
|
|
||||||
|
#### Running tests with pytest
|
||||||
|
|
||||||
|
$ pytest
|
||||||
|
|
||||||
|
### Live reloading and Sass CSS compilation
|
||||||
|
|
||||||
|
Moved to [Live reloading and SASS compilation](https://cookiecutter-django.readthedocs.io/en/latest/2-local-development/developing-locally.html#using-webpack-or-gulp).
|
||||||
|
|
||||||
|
### Celery
|
||||||
|
|
||||||
|
This app comes with Celery.
|
||||||
|
|
||||||
|
To run a celery worker:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
cd lms
|
||||||
|
celery -A config.celery_app worker -l info
|
||||||
|
```
|
||||||
|
|
||||||
|
Please note: For Celery's import magic to work, it is important _where_ the celery commands are run. If you are in the same folder with _manage.py_, you should be right.
|
||||||
|
|
||||||
|
To run [periodic tasks](https://docs.celeryq.dev/en/stable/userguide/periodic-tasks.html), you'll need to start the celery beat scheduler service. You can start it as a standalone process:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
cd lms
|
||||||
|
celery -A config.celery_app beat
|
||||||
|
```
|
||||||
|
|
||||||
|
or you can embed the beat service inside a worker with the `-B` option (not recommended for production use):
|
||||||
|
|
||||||
|
```bash
|
||||||
|
cd lms
|
||||||
|
celery -A config.celery_app worker -B -l info
|
||||||
|
```
|
||||||
|
|
||||||
|
### Email Server
|
||||||
|
|
||||||
|
In development, it is often nice to be able to see emails that are being sent from your application. For that reason local SMTP server [Mailpit](https://github.com/axllent/mailpit) with a web interface is available as docker container.
|
||||||
|
|
||||||
|
Container mailpit will start automatically when you will run all docker containers.
|
||||||
|
Please check [cookiecutter-django Docker documentation](https://cookiecutter-django.readthedocs.io/en/latest/2-local-development/developing-locally-docker.html) for more details how to start all containers.
|
||||||
|
|
||||||
|
With Mailpit running, to view messages that are sent by your application, open your browser and go to `http://127.0.0.1:8025`
|
||||||
|
|
||||||
|
### Sentry
|
||||||
|
|
||||||
|
Sentry is an error logging aggregator service. You can sign up for a free account at <https://sentry.io/signup/?code=cookiecutter> or download and host it yourself.
|
||||||
|
The system is set up with reasonable defaults, including 404 logging and integration with the WSGI application.
|
||||||
|
|
||||||
|
You must set the DSN url in production.
|
||||||
|
|
||||||
|
## Deployment
|
||||||
|
|
||||||
|
The following details how to deploy this application.
|
||||||
|
|
||||||
|
### Docker
|
||||||
|
|
||||||
|
See detailed [cookiecutter-django Docker documentation](https://cookiecutter-django.readthedocs.io/en/latest/3-deployment/deployment-with-docker.html).
|
||||||
|
|
|
||||||
|
|
@ -1,57 +0,0 @@
|
||||||
{ pkgs, ... }: {
|
|
||||||
# Which nixpkgs channel to use.
|
|
||||||
channel = "stable-24.05"; # or "unstable"
|
|
||||||
|
|
||||||
# Use https://search.nixos.org/packages to find packages
|
|
||||||
packages = [
|
|
||||||
pkgs.docker
|
|
||||||
pkgs.docker-compose
|
|
||||||
pkgs.sudo
|
|
||||||
];
|
|
||||||
|
|
||||||
# Sets environment variables in the workspace
|
|
||||||
env = {
|
|
||||||
PORT = "6000";
|
|
||||||
};
|
|
||||||
services.docker.enable = true;
|
|
||||||
|
|
||||||
|
|
||||||
idx = {
|
|
||||||
# Search for the extensions you want on https://open-vsx.org/ and use "publisher.id"
|
|
||||||
extensions = [
|
|
||||||
"ms-azuretools.vscode-docker"
|
|
||||||
];
|
|
||||||
|
|
||||||
workspace = {
|
|
||||||
# Runs when a workspace is first created with this `dev.nix` file
|
|
||||||
onCreate = {
|
|
||||||
setup-docker-compose = ''
|
|
||||||
# Ensure Docker Compose is built only once
|
|
||||||
docker-compose -f docker-compose.local.yml build
|
|
||||||
'';
|
|
||||||
# Open editors for the following files by default, if they exist:
|
|
||||||
default.openFiles = ["docker-compose.local.yml"];
|
|
||||||
};
|
|
||||||
# To run something each time the workspace is (re)started, use the `onStart` hook
|
|
||||||
onStart = {
|
|
||||||
start-docker-compose = ''
|
|
||||||
docker-compose -f docker-compose.local.yml up
|
|
||||||
'';
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
# Enable previews and customize configuration
|
|
||||||
previews = {
|
|
||||||
enable = true;
|
|
||||||
previews = {
|
|
||||||
web = {
|
|
||||||
command = ["docker-compose" "-f" "docker-compose.local.yml" "up"];
|
|
||||||
env = {
|
|
||||||
PORT = "$PORT";
|
|
||||||
};
|
|
||||||
manager = "web";
|
|
||||||
};
|
|
||||||
};
|
|
||||||
};
|
|
||||||
};
|
|
||||||
}
|
|
||||||
4
backend/.vscode/settings.json
vendored
4
backend/.vscode/settings.json
vendored
|
|
@ -1,4 +0,0 @@
|
||||||
{
|
|
||||||
"IDX.aI.enableInlineCompletion": true,
|
|
||||||
"IDX.aI.enableCodebaseIndexing": true
|
|
||||||
}
|
|
||||||
|
|
@ -1,91 +0,0 @@
|
||||||
[](https://github.com/cookiecutter/cookiecutter-django/)
|
|
||||||
[](https://github.com/astral-sh/ruff)
|
|
||||||
|
|
||||||
## Settings
|
|
||||||
|
|
||||||
Moved to [settings](https://cookiecutter-django.readthedocs.io/en/latest/1-getting-started/settings.html).
|
|
||||||
|
|
||||||
## Basic Commands
|
|
||||||
|
|
||||||
### Setting Up Your Users
|
|
||||||
|
|
||||||
- To create a **normal user account**, just go to Sign Up and fill out the form. Once you submit it, you'll see a "Verify Your E-mail Address" page. Go to your console to see a simulated email verification message. Copy the link into your browser. Now the user's email should be verified and ready to go.
|
|
||||||
|
|
||||||
- To create a **superuser account**, use this command:
|
|
||||||
|
|
||||||
$ python manage.py createsuperuser
|
|
||||||
|
|
||||||
For convenience, you can keep your normal user logged in on Chrome and your superuser logged in on Firefox (or similar), so that you can see how the site behaves for both kinds of users.
|
|
||||||
|
|
||||||
### Type checks
|
|
||||||
|
|
||||||
Running type checks with mypy:
|
|
||||||
|
|
||||||
$ mypy lms
|
|
||||||
|
|
||||||
### Test coverage
|
|
||||||
|
|
||||||
To run the tests, check your test coverage, and generate an HTML coverage report:
|
|
||||||
|
|
||||||
$ coverage run -m pytest
|
|
||||||
$ coverage html
|
|
||||||
$ open htmlcov/index.html
|
|
||||||
|
|
||||||
#### Running tests with pytest
|
|
||||||
|
|
||||||
$ pytest
|
|
||||||
|
|
||||||
### Live reloading and Sass CSS compilation
|
|
||||||
|
|
||||||
Moved to [Live reloading and SASS compilation](https://cookiecutter-django.readthedocs.io/en/latest/2-local-development/developing-locally.html#using-webpack-or-gulp).
|
|
||||||
|
|
||||||
### Celery
|
|
||||||
|
|
||||||
This app comes with Celery.
|
|
||||||
|
|
||||||
To run a celery worker:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
cd lms
|
|
||||||
celery -A config.celery_app worker -l info
|
|
||||||
```
|
|
||||||
|
|
||||||
Please note: For Celery's import magic to work, it is important _where_ the celery commands are run. If you are in the same folder with _manage.py_, you should be right.
|
|
||||||
|
|
||||||
To run [periodic tasks](https://docs.celeryq.dev/en/stable/userguide/periodic-tasks.html), you'll need to start the celery beat scheduler service. You can start it as a standalone process:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
cd lms
|
|
||||||
celery -A config.celery_app beat
|
|
||||||
```
|
|
||||||
|
|
||||||
or you can embed the beat service inside a worker with the `-B` option (not recommended for production use):
|
|
||||||
|
|
||||||
```bash
|
|
||||||
cd lms
|
|
||||||
celery -A config.celery_app worker -B -l info
|
|
||||||
```
|
|
||||||
|
|
||||||
### Email Server
|
|
||||||
|
|
||||||
In development, it is often nice to be able to see emails that are being sent from your application. For that reason local SMTP server [Mailpit](https://github.com/axllent/mailpit) with a web interface is available as docker container.
|
|
||||||
|
|
||||||
Container mailpit will start automatically when you will run all docker containers.
|
|
||||||
Please check [cookiecutter-django Docker documentation](https://cookiecutter-django.readthedocs.io/en/latest/2-local-development/developing-locally-docker.html) for more details how to start all containers.
|
|
||||||
|
|
||||||
With Mailpit running, to view messages that are sent by your application, open your browser and go to `http://127.0.0.1:8025`
|
|
||||||
|
|
||||||
### Sentry
|
|
||||||
|
|
||||||
Sentry is an error logging aggregator service. You can sign up for a free account at <https://sentry.io/signup/?code=cookiecutter> or download and host it yourself.
|
|
||||||
The system is set up with reasonable defaults, including 404 logging and integration with the WSGI application.
|
|
||||||
|
|
||||||
You must set the DSN url in production.
|
|
||||||
|
|
||||||
## Deployment
|
|
||||||
|
|
||||||
The following details how to deploy this application.
|
|
||||||
|
|
||||||
### Docker
|
|
||||||
|
|
||||||
See detailed [cookiecutter-django Docker documentation](https://cookiecutter-django.readthedocs.io/en/latest/3-deployment/deployment-with-docker.html).
|
|
||||||
|
|
@ -1,23 +0,0 @@
|
||||||
# Use a lightweight Python base image
|
|
||||||
FROM python:3.12.8-alpine AS python
|
|
||||||
|
|
||||||
# Python base stage
|
|
||||||
ENV PYTHONDONTWRITEBYTECODE=1
|
|
||||||
ENV PYTHONUNBUFFERED=1
|
|
||||||
|
|
||||||
# Install dependencies
|
|
||||||
RUN apk update && apk add --no-cache \
|
|
||||||
# Runtime dependencies
|
|
||||||
make \
|
|
||||||
gettext \
|
|
||||||
&& rm -rf /var/cache/apk/*
|
|
||||||
|
|
||||||
# Install MkDocs and required plugins
|
|
||||||
RUN pip install mkdocs==1.5.1 mkdocs-material==9.1.15 mkdocs-markdownextradata-plugin
|
|
||||||
|
|
||||||
# Copy the start script
|
|
||||||
COPY ./compose/local/docs/start /start-docs
|
|
||||||
RUN sed -i 's/\r$//g' /start-docs
|
|
||||||
RUN chmod +x /start-docs
|
|
||||||
|
|
||||||
WORKDIR /docs
|
|
||||||
|
|
@ -1,8 +0,0 @@
|
||||||
#!/bin/bash
|
|
||||||
|
|
||||||
set -o errexit
|
|
||||||
set -o pipefail
|
|
||||||
set -o nounset
|
|
||||||
|
|
||||||
# Start MkDocs live development server
|
|
||||||
exec mkdocs serve -a 0.0.0.0:6000
|
|
||||||
|
|
@ -1,13 +0,0 @@
|
||||||
# from django.conf import settings
|
|
||||||
# from rest_framework.routers import DefaultRouter
|
|
||||||
# from rest_framework.routers import SimpleRouter
|
|
||||||
|
|
||||||
# from lms.users.api.views import UserViewSet
|
|
||||||
|
|
||||||
# router = DefaultRouter() if settings.DEBUG else SimpleRouter()
|
|
||||||
|
|
||||||
# router.register("users", UserViewSet)
|
|
||||||
|
|
||||||
|
|
||||||
# app_name = "api"
|
|
||||||
# urlpatterns = router.urls
|
|
||||||
|
|
@ -1,67 +0,0 @@
|
||||||
# اسم الموقع
|
|
||||||
site_name: My Project
|
|
||||||
|
|
||||||
|
|
||||||
site_description: Learning Management System
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
theme:
|
|
||||||
name: material
|
|
||||||
custom_dir: overrides # تخصيص السمات (اختياري)
|
|
||||||
palette:
|
|
||||||
- scheme: default # الوضع الافتراضي
|
|
||||||
primary: indigo # اللون الأساسي
|
|
||||||
accent: pink # اللون الثانوي
|
|
||||||
- scheme: slate # وضع داكن
|
|
||||||
primary: deep purple
|
|
||||||
accent: amber
|
|
||||||
# features:
|
|
||||||
# - navigation.tabs # استخدام التبويبات للتنقل
|
|
||||||
# - navigation.expand # توسيع القوائم تلقائيًا
|
|
||||||
# - toc.integrate # دمج قائمة المحتويات (Table of Contents) مع التنقل
|
|
||||||
# logo: images/logo.png # شعار الموقع (اختياري)
|
|
||||||
# favicon: images/favicon.ico # أيقونة الموقع (اختياري)
|
|
||||||
|
|
||||||
# التنقل (Navigation)
|
|
||||||
nav:
|
|
||||||
- Home: index.md
|
|
||||||
- Getting Started:
|
|
||||||
- Introduction: getting-started/introduction.md
|
|
||||||
- Installation: getting-started/installation.md
|
|
||||||
- Reference:
|
|
||||||
- API Documentation: reference/api.md
|
|
||||||
- CLI: reference/cli.md
|
|
||||||
- About: about.md
|
|
||||||
|
|
||||||
# الإضافات (Plugins)
|
|
||||||
plugins:
|
|
||||||
- search # محرك البحث
|
|
||||||
- markdownextradata # إدراج البيانات الإضافية (اختياري)
|
|
||||||
|
|
||||||
# ملحقات Markdown
|
|
||||||
markdown_extensions:
|
|
||||||
- admonition # الملاحظات (تحذير، نصيحة، إلخ)
|
|
||||||
- codehilite # تمييز الأكواد
|
|
||||||
- toc # قائمة المحتويات
|
|
||||||
- tables # دعم الجداول
|
|
||||||
- pymdownx.arithmatex # دعم LaTeX (للمعادلات الرياضية)
|
|
||||||
- pymdownx.superfences # تحسين تداخل الأكواد والجداول
|
|
||||||
|
|
||||||
# إعدادات البحث
|
|
||||||
extra:
|
|
||||||
search:
|
|
||||||
lang: en # لغة البحث (يدعم الإنجليزية، الفرنسية، إلخ)
|
|
||||||
separator: "[\\s\\-]+" # الفاصل للبحث
|
|
||||||
|
|
||||||
# بيانات إضافية (اختيارية)
|
|
||||||
extra_css:
|
|
||||||
- styles/custom.css # ملف CSS مخصص
|
|
||||||
extra_javascript:
|
|
||||||
- scripts/custom.js # ملف JavaScript مخصص
|
|
||||||
|
|
||||||
# إعدادات مخرجات البناء
|
|
||||||
# site_dir: site # مسار مجلد الإخراج
|
|
||||||
docs_dir: docs # مسار مجلد الوثائق
|
|
||||||
|
|
||||||
dev_addr: 0.0.0.0:6000
|
|
||||||
|
|
@ -1,35 +0,0 @@
|
||||||
from django.contrib.auth import get_user_model
|
|
||||||
|
|
||||||
|
|
||||||
User = get_user_model()
|
|
||||||
|
|
||||||
class TransitionManager:
|
|
||||||
def __init__(self, get_response):
|
|
||||||
self.get_response = get_response
|
|
||||||
|
|
||||||
def __call__(self, request):
|
|
||||||
# هذه الخطوة تتم قبل وصول الطلب إلى الفيو
|
|
||||||
print("قبل معالجة الطلب")
|
|
||||||
|
|
||||||
# تمرير الطلب إلى الفيو والحصول على الاستجابة
|
|
||||||
response = self.get_response(request)
|
|
||||||
|
|
||||||
# التحقق من وجود المستخدم
|
|
||||||
try:
|
|
||||||
user = User.objects.get(email=request.user.email)
|
|
||||||
match user.role:
|
|
||||||
case "student":
|
|
||||||
print("طالب")
|
|
||||||
case "instructor":
|
|
||||||
print("instructor")
|
|
||||||
case "admin":
|
|
||||||
print("مشرف")
|
|
||||||
case _:
|
|
||||||
print("القيمة غير معروفة")
|
|
||||||
except User.DoesNotExist:
|
|
||||||
print("المستخدم غير موجود")
|
|
||||||
|
|
||||||
print("بعد معالجة الطلب")
|
|
||||||
|
|
||||||
return response
|
|
||||||
|
|
||||||
|
|
@ -1,39 +0,0 @@
|
||||||
# Generated by Django 5.0.10 on 2025-01-21 13:50
|
|
||||||
|
|
||||||
import django.utils.timezone
|
|
||||||
from django.db import migrations, models
|
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
|
||||||
|
|
||||||
initial = True
|
|
||||||
|
|
||||||
dependencies = [
|
|
||||||
('auth', '0012_alter_user_first_name_max_length'),
|
|
||||||
]
|
|
||||||
|
|
||||||
operations = [
|
|
||||||
migrations.CreateModel(
|
|
||||||
name='CustomUser',
|
|
||||||
fields=[
|
|
||||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
|
||||||
('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')),
|
|
||||||
('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(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')),
|
|
||||||
],
|
|
||||||
options={
|
|
||||||
'verbose_name': 'user',
|
|
||||||
'verbose_name_plural': 'users',
|
|
||||||
'abstract': False,
|
|
||||||
},
|
|
||||||
),
|
|
||||||
]
|
|
||||||
|
|
@ -1,43 +0,0 @@
|
||||||
from django.db import models
|
|
||||||
from django.contrib.auth.models import AbstractUser, BaseUserManager
|
|
||||||
|
|
||||||
|
|
||||||
class CustomUserManager(BaseUserManager):
|
|
||||||
def create_user(self, email, password=None, **extra_fields):
|
|
||||||
if not email:
|
|
||||||
raise ValueError('The Email field must be set')
|
|
||||||
email = self.normalize_email(email)
|
|
||||||
user = self.model(email=email, **extra_fields)
|
|
||||||
user.set_password(password)
|
|
||||||
user.save(using=self._db)
|
|
||||||
return user
|
|
||||||
|
|
||||||
def create_superuser(self, email, password=None, **extra_fields):
|
|
||||||
extra_fields.setdefault('is_staff', True)
|
|
||||||
extra_fields.setdefault('is_superuser', True)
|
|
||||||
return self.create_user(email, password, **extra_fields)
|
|
||||||
|
|
||||||
|
|
||||||
class CustomUser(AbstractUser):
|
|
||||||
ROLE_CHOICES = {
|
|
||||||
'student': 'Student',
|
|
||||||
'instructor': 'Instructor',
|
|
||||||
'admin': 'Admin',
|
|
||||||
}
|
|
||||||
username = None
|
|
||||||
first_name = None
|
|
||||||
last_name = None
|
|
||||||
|
|
||||||
email = models.EmailField(unique=True)
|
|
||||||
full_name = models.CharField(max_length=255, null=True, blank=True)
|
|
||||||
image = models.ImageField(upload_to="account/profile_image/", null=True, blank=True)
|
|
||||||
|
|
||||||
role = models.CharField(max_length=20, choices=ROLE_CHOICES, null=True, blank=True)
|
|
||||||
|
|
||||||
objects = CustomUserManager()
|
|
||||||
|
|
||||||
USERNAME_FIELD = 'email'
|
|
||||||
REQUIRED_FIELDS = []
|
|
||||||
|
|
||||||
def __str__(self):
|
|
||||||
return self.email
|
|
||||||
|
|
@ -1,116 +0,0 @@
|
||||||
from rest_framework import serializers
|
|
||||||
from .models import *
|
|
||||||
from dj_rest_auth.serializers import LoginSerializer
|
|
||||||
from django.contrib.auth import authenticate
|
|
||||||
from django.utils.translation import gettext_lazy as _
|
|
||||||
from allauth.account.models import EmailAddress
|
|
||||||
from dj_rest_auth.registration.serializers import RegisterSerializer
|
|
||||||
from django.contrib.auth import get_user_model
|
|
||||||
from rest_framework.exceptions import ValidationError
|
|
||||||
from allauth.account.utils import send_email_confirmation
|
|
||||||
from rest_framework.response import Response
|
|
||||||
from lms.utils.exception_handler import CustomValidationError
|
|
||||||
|
|
||||||
|
|
||||||
User = get_user_model()
|
|
||||||
|
|
||||||
class UserSerializer(serializers.ModelSerializer):
|
|
||||||
class Meta:
|
|
||||||
model = User
|
|
||||||
fields = ['id', 'email', 'full_name']
|
|
||||||
|
|
||||||
|
|
||||||
class CustomLoginSerializer(LoginSerializer):
|
|
||||||
|
|
||||||
email = serializers.EmailField(required=True)
|
|
||||||
password = serializers.CharField(style={'input_type': 'password'}, write_only=True)
|
|
||||||
|
|
||||||
def validate(self, attrs):
|
|
||||||
email = attrs.get('email')
|
|
||||||
password = attrs.get('password')
|
|
||||||
|
|
||||||
if not email or not password:
|
|
||||||
raise CustomValidationError(_("Please enter both email and password."))
|
|
||||||
|
|
||||||
# البحث عن المستخدم بالبريد الإلكتروني
|
|
||||||
users = User.objects.filter(email=email)
|
|
||||||
email_address = EmailAddress.objects.filter(email=email).first()
|
|
||||||
|
|
||||||
if not users.exists():
|
|
||||||
raise CustomValidationError(_("No account found with this email."))
|
|
||||||
|
|
||||||
if not email_address.verified:
|
|
||||||
CustomValidationError(_("Email not verified. Please verify your email first."))
|
|
||||||
|
|
||||||
if users.count() > 1:
|
|
||||||
raise CustomValidationError(_("Multiple accounts found with this email. Please contact support."))
|
|
||||||
|
|
||||||
user = users.first()
|
|
||||||
|
|
||||||
if not user.check_password(password):
|
|
||||||
raise CustomValidationError(_("Incorrect password."))
|
|
||||||
|
|
||||||
if not self.is_email_verified(user):
|
|
||||||
raise CustomValidationError(_("Email not verified. Please verify your email first."))
|
|
||||||
|
|
||||||
# إضافة المستخدم إلى الـ attrs
|
|
||||||
attrs['user'] = user
|
|
||||||
return attrs
|
|
||||||
|
|
||||||
def is_email_verified(self, user):
|
|
||||||
"""
|
|
||||||
التحقق من حالة التحقق من البريد الإلكتروني.
|
|
||||||
"""
|
|
||||||
try:
|
|
||||||
# استخدام نموذج EmailAddress للتحقق
|
|
||||||
email_address = EmailAddress.objects.get(user=user, email=user.email)
|
|
||||||
return email_address.verified
|
|
||||||
except EmailAddress.DoesNotExist:
|
|
||||||
return False
|
|
||||||
|
|
||||||
|
|
||||||
class CustomRegisterSerializer(RegisterSerializer):
|
|
||||||
full_name = serializers.CharField(required=True)
|
|
||||||
|
|
||||||
def save(self, request):
|
|
||||||
email = self.data.get('email')
|
|
||||||
|
|
||||||
email_address = EmailAddress.objects.filter(email=email).first()
|
|
||||||
if email_address:
|
|
||||||
if email_address.verified:
|
|
||||||
raise CustomValidationError({'email': 'This email is already.'})
|
|
||||||
else:
|
|
||||||
send_email_confirmation(request, email_address.user)
|
|
||||||
raise CustomValidationError({'email': 'A confirmation email has been sent. Please confirm your email.'})
|
|
||||||
|
|
||||||
user = super().save(request)
|
|
||||||
user.full_name = self.data.get('full_name', '')
|
|
||||||
user.save()
|
|
||||||
|
|
||||||
send_email_confirmation(request, user)
|
|
||||||
return user
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class ChangeEmailSerializer(serializers.Serializer):
|
|
||||||
email = serializers.EmailField()
|
|
||||||
|
|
||||||
def validate_email(self, value):
|
|
||||||
if EmailAddress.objects.filter(email=value).exists() or User.objects.filter(email=value).exists():
|
|
||||||
raise CustomValidationError("This email is already in use.")
|
|
||||||
return value
|
|
||||||
|
|
||||||
def save(self, user):
|
|
||||||
email = self.validated_data["email"]
|
|
||||||
EmailAddress.objects.filter(user=user, verified=False).delete() # حذف الايميلات السابقة
|
|
||||||
|
|
||||||
email_address, created = EmailAddress.objects.get_or_create(
|
|
||||||
user=user,
|
|
||||||
email=email,
|
|
||||||
defaults={"primary": False, "verified": False}
|
|
||||||
)
|
|
||||||
|
|
||||||
if created:
|
|
||||||
send_email_confirmation(self.context["request"], user, email=email)
|
|
||||||
|
|
||||||
return email
|
|
||||||
|
|
@ -1,10 +0,0 @@
|
||||||
from allauth.account.signals import email_confirmed
|
|
||||||
from django.dispatch import receiver
|
|
||||||
from allauth.account.models import EmailAddress
|
|
||||||
|
|
||||||
@receiver(email_confirmed)
|
|
||||||
def set_primary_email(sender, request, email_address, **kwargs):
|
|
||||||
user = email_address.user
|
|
||||||
EmailAddress.objects.filter(user=user).update(primary=False)
|
|
||||||
email_address.primary = True
|
|
||||||
email_address.save()
|
|
||||||
|
|
@ -1,17 +0,0 @@
|
||||||
from django.urls import path, re_path, include
|
|
||||||
from dj_rest_auth.views import PasswordResetConfirmView
|
|
||||||
from . import views
|
|
||||||
|
|
||||||
|
|
||||||
urlpatterns = [
|
|
||||||
path('', include('dj_rest_auth.urls')),
|
|
||||||
path('registration/', include('dj_rest_auth.registration.urls')),
|
|
||||||
path("registration/account-confirm-email/", views.ConfirmEmailAPIView.as_view(),name="account_confirm_email",),
|
|
||||||
path(
|
|
||||||
'password/reset/confirm/<uidb64>/<token>/',
|
|
||||||
PasswordResetConfirmView.as_view(),
|
|
||||||
name='password_reset_confirm',
|
|
||||||
),
|
|
||||||
path('change-email/', views.ChangeEmailView.as_view(), name='change_email'),
|
|
||||||
path('user-info/', views.UserView.as_view()),
|
|
||||||
]
|
|
||||||
|
|
@ -1,82 +0,0 @@
|
||||||
from rest_framework.views import APIView
|
|
||||||
from rest_framework.response import Response
|
|
||||||
from rest_framework import status
|
|
||||||
from django.utils.translation import gettext as _
|
|
||||||
from allauth.account.models import EmailConfirmation, EmailConfirmationHMAC, EmailAddress
|
|
||||||
from rest_framework.permissions import AllowAny, IsAuthenticated
|
|
||||||
from .serializers import ChangeEmailSerializer
|
|
||||||
from asgiref.sync import sync_to_async
|
|
||||||
from django.contrib.auth import get_user_model
|
|
||||||
from lms.utils.exception_handler import CustomValidationError
|
|
||||||
User = get_user_model()
|
|
||||||
|
|
||||||
class UserView(APIView):
|
|
||||||
permission_classes = [IsAuthenticated]
|
|
||||||
|
|
||||||
def get(self, request):
|
|
||||||
user = request.user
|
|
||||||
image_url = request.build_absolute_uri(user.image.url) if user.image else None
|
|
||||||
return Response({
|
|
||||||
"name": user.full_name,
|
|
||||||
"image": image_url
|
|
||||||
})
|
|
||||||
|
|
||||||
def patch(self, request):
|
|
||||||
print(request.data)
|
|
||||||
user = request.user
|
|
||||||
full_name = request.data.get('full_name')
|
|
||||||
|
|
||||||
if full_name:
|
|
||||||
user.full_name = full_name
|
|
||||||
|
|
||||||
profile_image = request.FILES.get('profile_image')
|
|
||||||
if profile_image:
|
|
||||||
user.image = profile_image
|
|
||||||
print("Ok")
|
|
||||||
user.save()
|
|
||||||
|
|
||||||
return Response(
|
|
||||||
{"ok"},
|
|
||||||
status=status.HTTP_200_OK
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class ChangeEmailView(APIView):
|
|
||||||
|
|
||||||
def post(self, request, *args, **kwargs):
|
|
||||||
serializer = ChangeEmailSerializer(data=request.data, context={"request": request})
|
|
||||||
if serializer.is_valid():
|
|
||||||
serializer.save(user=request.user)
|
|
||||||
return Response({
|
|
||||||
"message": "Confirmation email has been sent to the new address.",
|
|
||||||
}, status=status.HTTP_200_OK)
|
|
||||||
|
|
||||||
raise CustomValidationError(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class ConfirmEmailAPIView(APIView):
|
|
||||||
permission_classes = [AllowAny]
|
|
||||||
|
|
||||||
def post(self, request, *args, **kwargs):
|
|
||||||
key = request.data.get("key")
|
|
||||||
if not key:
|
|
||||||
raise CustomValidationError({"detail": _("Key is required.")}, status=status.HTTP_400_BAD_REQUEST)
|
|
||||||
|
|
||||||
try:
|
|
||||||
# Attempt to retrieve the email confirmation using HMAC key
|
|
||||||
email_confirmation = EmailConfirmationHMAC.from_key(key)
|
|
||||||
if email_confirmation is None:
|
|
||||||
# If HMAC fails, fallback to database key
|
|
||||||
email_confirmation = EmailConfirmation.objects.get(key=key)
|
|
||||||
except EmailConfirmation.DoesNotExist:
|
|
||||||
raise CustomValidationError({"detail": _("Invalid or expired key.")}, status=status.HTTP_400_BAD_REQUEST)
|
|
||||||
|
|
||||||
if email_confirmation.email_address.verified:
|
|
||||||
return Response({"detail": _("Email is already verified.")}, status=status.HTTP_200_OK)
|
|
||||||
|
|
||||||
# Verify the email
|
|
||||||
email_confirmation.confirm(request)
|
|
||||||
email = email_confirmation.email_address.email
|
|
||||||
return Response({"detail": _("Email successfully verified."), "email": email}, status=status.HTTP_200_OK)
|
|
||||||
|
|
@ -1,86 +0,0 @@
|
||||||
# Generated by Django 5.0.10 on 2025-01-21 13:50
|
|
||||||
|
|
||||||
import django.db.models.deletion
|
|
||||||
import uuid
|
|
||||||
from django.conf import settings
|
|
||||||
from django.db import migrations, models
|
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
|
||||||
|
|
||||||
initial = True
|
|
||||||
|
|
||||||
dependencies = [
|
|
||||||
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
|
||||||
]
|
|
||||||
|
|
||||||
operations = [
|
|
||||||
migrations.CreateModel(
|
|
||||||
name='AD',
|
|
||||||
fields=[
|
|
||||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
|
||||||
('title', models.CharField(max_length=255)),
|
|
||||||
('description', models.TextField()),
|
|
||||||
('image', models.ImageField(blank=True, null=True, upload_to='ads_images/')),
|
|
||||||
('created_at', models.DateTimeField(auto_now_add=True)),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
migrations.CreateModel(
|
|
||||||
name='Course',
|
|
||||||
fields=[
|
|
||||||
('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
|
|
||||||
('title', models.CharField(max_length=255, verbose_name='Course Title')),
|
|
||||||
('description', models.TextField(verbose_name='Course Description')),
|
|
||||||
('image', models.ImageField(null=True, upload_to='courses/image')),
|
|
||||||
('is_paid', models.BooleanField(default=False)),
|
|
||||||
('price', models.DecimalField(blank=True, decimal_places=2, max_digits=10, null=True)),
|
|
||||||
('rating', models.PositiveSmallIntegerField(blank=True, null=True)),
|
|
||||||
('created_at', models.DateTimeField(auto_now_add=True, verbose_name='Created At')),
|
|
||||||
('updated_at', models.DateTimeField(auto_now=True, verbose_name='Updated At')),
|
|
||||||
('owner', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='owner', to=settings.AUTH_USER_MODEL, verbose_name='Owner')),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
migrations.CreateModel(
|
|
||||||
name='Certificate',
|
|
||||||
fields=[
|
|
||||||
('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
|
|
||||||
('issued_at', models.DateTimeField(auto_now_add=True, verbose_name='Issued At')),
|
|
||||||
('certificate_file', models.FileField(upload_to='certificates/', verbose_name='Certificate File')),
|
|
||||||
('student', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='certificates', to=settings.AUTH_USER_MODEL, verbose_name='Student')),
|
|
||||||
('course', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='certificates', to='app.course', verbose_name='Course')),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
migrations.CreateModel(
|
|
||||||
name='Enrollment',
|
|
||||||
fields=[
|
|
||||||
('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
|
|
||||||
('enrolled_at', models.DateTimeField(auto_now_add=True, verbose_name='Enrollment Date')),
|
|
||||||
('completed', models.BooleanField(default=False, verbose_name='Completed')),
|
|
||||||
('course', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='enrollments', to='app.course', verbose_name='Course')),
|
|
||||||
('student', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='students_enrollments', to=settings.AUTH_USER_MODEL, verbose_name='Student')),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
migrations.CreateModel(
|
|
||||||
name='Module',
|
|
||||||
fields=[
|
|
||||||
('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
|
|
||||||
('title', models.CharField(max_length=255, verbose_name='Module Title')),
|
|
||||||
('description', models.TextField(null=True, verbose_name='Module Description')),
|
|
||||||
('course', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='modules', to='app.course', verbose_name='Course')),
|
|
||||||
('created_by', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL, verbose_name='Created By')),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
migrations.CreateModel(
|
|
||||||
name='Lesson',
|
|
||||||
fields=[
|
|
||||||
('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
|
|
||||||
('title', models.CharField(max_length=255, verbose_name='Lesson Title')),
|
|
||||||
('description', models.TextField(null=True, verbose_name='Lesson Description')),
|
|
||||||
('content', models.TextField(verbose_name='Lesson Content')),
|
|
||||||
('file', models.FileField(blank=True, null=True, upload_to='lesson_files/', verbose_name='Attached File')),
|
|
||||||
('quiz', models.JSONField(null=True)),
|
|
||||||
('created_by', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL, verbose_name='Created By')),
|
|
||||||
('module', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='lessons', to='app.module', verbose_name='Module')),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
]
|
|
||||||
|
|
@ -1,37 +0,0 @@
|
||||||
from rest_framework.permissions import IsAuthenticated, BasePermission, SAFE_METHODS
|
|
||||||
import logging
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
|
||||||
|
|
||||||
class IsOwnerOrReadOnly(BasePermission):
|
|
||||||
|
|
||||||
def has_object_permission(self, request, view, obj):
|
|
||||||
|
|
||||||
if request.method in SAFE_METHODS:
|
|
||||||
return True
|
|
||||||
|
|
||||||
view_name = view.__class__.__name__
|
|
||||||
match view_name:
|
|
||||||
case "CourseViewSet":
|
|
||||||
return obj.owner == request.user
|
|
||||||
|
|
||||||
case "ModuleViewSet":
|
|
||||||
return obj.created_by == request.user
|
|
||||||
|
|
||||||
case "LessonViewSet":
|
|
||||||
return obj.created_by == request.user
|
|
||||||
|
|
||||||
case "EnrollmentViewSet":
|
|
||||||
return obj.student == request.user
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class IsAdmin(BasePermission):
|
|
||||||
"""
|
|
||||||
Custom permission to allow access only to users with role 'instructor'.
|
|
||||||
"""
|
|
||||||
|
|
||||||
def has_permission(self, request, view):
|
|
||||||
# Ensure the user is authenticated and has a role of 'instructor'
|
|
||||||
return request.user.is_authenticated and request.user.role == 'admin'
|
|
||||||
|
|
@ -1,89 +0,0 @@
|
||||||
from rest_framework import serializers
|
|
||||||
from .models import *
|
|
||||||
from dj_rest_auth.serializers import LoginSerializer
|
|
||||||
from django.contrib.auth import authenticate
|
|
||||||
from django.utils.translation import gettext_lazy as _
|
|
||||||
from allauth.account.models import EmailAddress
|
|
||||||
from dj_rest_auth.registration.serializers import RegisterSerializer
|
|
||||||
from lms.utils.exception_handler import CustomValidationError
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class CourseSerializer(serializers.ModelSerializer):
|
|
||||||
owner_name = serializers.CharField(source='owner.full_name', read_only=True)
|
|
||||||
owner_image = serializers.SerializerMethodField()
|
|
||||||
students_in_course = serializers.SerializerMethodField()
|
|
||||||
class Meta:
|
|
||||||
model = Course
|
|
||||||
fields = ['id', 'title', 'description', 'is_paid', 'price', 'image', 'owner_name', 'owner_image', 'students_in_course', 'created_at', 'updated_at']
|
|
||||||
read_only_fields = ['created_at', 'updated_at']
|
|
||||||
|
|
||||||
def get_owner_image(self, obj):
|
|
||||||
request = self.context.get('request')
|
|
||||||
if obj.owner.image:
|
|
||||||
return request.build_absolute_uri(obj.owner.image.url)
|
|
||||||
return None
|
|
||||||
|
|
||||||
def get_students_in_course(self, obj):
|
|
||||||
return Enrollment.objects.filter(course=obj).values('student').distinct().count()
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class LessonSerializer(serializers.ModelSerializer):
|
|
||||||
module = serializers.PrimaryKeyRelatedField(queryset=Module.objects.all())
|
|
||||||
|
|
||||||
class Meta:
|
|
||||||
model = Lesson
|
|
||||||
fields = ['id', 'title', 'description', 'content', 'module', 'file']
|
|
||||||
|
|
||||||
|
|
||||||
class ModuleSerializer(serializers.ModelSerializer):
|
|
||||||
lessons = serializers.SerializerMethodField()
|
|
||||||
class Meta:
|
|
||||||
model = Module
|
|
||||||
fields = ['id', 'title', 'description', 'lessons', 'course']
|
|
||||||
read_only_fields = ['course', 'lessons']
|
|
||||||
|
|
||||||
def get_lessons(self, obj):
|
|
||||||
return obj.lessons.values('id', 'title', 'description')
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class EnrollmentSerializer(serializers.ModelSerializer):
|
|
||||||
course_details = serializers.SerializerMethodField()
|
|
||||||
class Meta:
|
|
||||||
model = Enrollment
|
|
||||||
fields = ['id', 'course', 'course_details', 'enrolled_at', 'completed']
|
|
||||||
read_only_fields = ['enrolled_at']
|
|
||||||
|
|
||||||
def get_course_details(self, obj):
|
|
||||||
course = obj.course
|
|
||||||
request = self.context.get('request')
|
|
||||||
image_url = course.image.url if course.image else None
|
|
||||||
|
|
||||||
if image_url and request:
|
|
||||||
image_url = request.build_absolute_uri(image_url)
|
|
||||||
|
|
||||||
return {
|
|
||||||
"id": course.id,
|
|
||||||
"title": course.title,
|
|
||||||
"description": course.description,
|
|
||||||
"image": image_url,
|
|
||||||
"is_paid": course.is_paid,
|
|
||||||
"price": course.price,
|
|
||||||
"rating": course.rating,
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class CertificateSerializer(serializers.ModelSerializer):
|
|
||||||
class Meta:
|
|
||||||
model = Certificate
|
|
||||||
fields = ['student', 'course', 'issued_at', 'certificate_file']
|
|
||||||
|
|
||||||
|
|
||||||
class PrivateEnrollmentSerializer(serializers.ModelSerializer):
|
|
||||||
class Meta:
|
|
||||||
model = Enrollment
|
|
||||||
fields = ['id', 'course', 'student', 'enrolled_at']
|
|
||||||
read_only_fields = ['enrolled_at']
|
|
||||||
|
|
@ -1,3 +0,0 @@
|
||||||
from django.db.models.signals import pre_save
|
|
||||||
from django.dispatch import receiver
|
|
||||||
from .model import Module
|
|
||||||
|
|
@ -1,8 +0,0 @@
|
||||||
# tasks.py
|
|
||||||
|
|
||||||
from celery import shared_task
|
|
||||||
|
|
||||||
@shared_task
|
|
||||||
def print_message(message):
|
|
||||||
print(f"الرسالة هي: {message}")
|
|
||||||
return message
|
|
||||||
|
|
@ -1,107 +0,0 @@
|
||||||
from django.test import TestCase
|
|
||||||
from django.contrib.auth import get_user_model
|
|
||||||
from rest_framework.test import APIClient
|
|
||||||
from rest_framework.exceptions import ValidationError
|
|
||||||
from lms.app.models import Course, Module, Lesson, Enrollment, Certificate, AD
|
|
||||||
from uuid import uuid4
|
|
||||||
|
|
||||||
User = get_user_model()
|
|
||||||
|
|
||||||
|
|
||||||
class ModelsTestCase(TestCase):
|
|
||||||
|
|
||||||
def setUp(self):
|
|
||||||
# Create test user
|
|
||||||
self.user = User.objects.create_user(email='testuser@email.com', password='password')
|
|
||||||
self.client = APIClient()
|
|
||||||
self.client.force_authenticate(user=self.user)
|
|
||||||
|
|
||||||
# Create a test course
|
|
||||||
self.course = Course.objects.create(
|
|
||||||
title="Test Course",
|
|
||||||
description="A test course description",
|
|
||||||
is_paid=True,
|
|
||||||
price=100.00,
|
|
||||||
owner=self.user
|
|
||||||
)
|
|
||||||
|
|
||||||
def test_course_creation(self):
|
|
||||||
"""Test creating a course"""
|
|
||||||
self.assertEqual(Course.objects.count(), 1)
|
|
||||||
self.assertEqual(self.course.title, "Test Course")
|
|
||||||
self.assertTrue(self.course.is_paid)
|
|
||||||
self.assertEqual(self.course.price, 100.00)
|
|
||||||
|
|
||||||
def test_course_validation(self):
|
|
||||||
"""Test course validation logic"""
|
|
||||||
course = Course(
|
|
||||||
title="Invalid Course",
|
|
||||||
description="Should fail validation",
|
|
||||||
is_paid=True,
|
|
||||||
price=None, # Invalid case
|
|
||||||
owner=self.user
|
|
||||||
)
|
|
||||||
with self.assertRaises(ValidationError):
|
|
||||||
course.clean()
|
|
||||||
|
|
||||||
def test_module_creation(self):
|
|
||||||
"""Test creating a module"""
|
|
||||||
module = Module.objects.create(
|
|
||||||
title="Test Module",
|
|
||||||
description="A test module description",
|
|
||||||
course=self.course,
|
|
||||||
created_by=self.user
|
|
||||||
)
|
|
||||||
self.assertEqual(Module.objects.count(), 1)
|
|
||||||
self.assertEqual(module.title, "Test Module")
|
|
||||||
|
|
||||||
def test_lesson_creation(self):
|
|
||||||
"""Test creating a lesson"""
|
|
||||||
module = Module.objects.create(
|
|
||||||
title="Test Module",
|
|
||||||
course=self.course,
|
|
||||||
created_by=self.user
|
|
||||||
)
|
|
||||||
lesson = Lesson.objects.create(
|
|
||||||
title="Test Lesson",
|
|
||||||
description="A test lesson description",
|
|
||||||
content="Lesson content here",
|
|
||||||
module=module,
|
|
||||||
created_by=self.user
|
|
||||||
)
|
|
||||||
self.assertEqual(Lesson.objects.count(), 1)
|
|
||||||
self.assertEqual(lesson.title, "Test Lesson")
|
|
||||||
self.assertEqual(lesson.module, module)
|
|
||||||
|
|
||||||
def test_enrollment_creation(self):
|
|
||||||
"""Test creating an enrollment"""
|
|
||||||
enrollment = Enrollment.objects.create(
|
|
||||||
student=self.user,
|
|
||||||
course=self.course,
|
|
||||||
completed=False
|
|
||||||
)
|
|
||||||
self.assertEqual(Enrollment.objects.count(), 1)
|
|
||||||
self.assertEqual(enrollment.student, self.user)
|
|
||||||
self.assertEqual(enrollment.course, self.course)
|
|
||||||
|
|
||||||
def test_certificate_creation(self):
|
|
||||||
"""Test creating a certificate"""
|
|
||||||
certificate = Certificate.objects.create(
|
|
||||||
student=self.user,
|
|
||||||
course=self.course,
|
|
||||||
certificate_file='path/to/certificate.pdf'
|
|
||||||
)
|
|
||||||
self.assertEqual(Certificate.objects.count(), 1)
|
|
||||||
self.assertEqual(certificate.student, self.user)
|
|
||||||
self.assertEqual(certificate.course, self.course)
|
|
||||||
|
|
||||||
def test_ad_creation(self):
|
|
||||||
"""Test creating an ad"""
|
|
||||||
ad = AD.objects.create(
|
|
||||||
title="Test Ad",
|
|
||||||
description="This is a test ad",
|
|
||||||
image=None
|
|
||||||
)
|
|
||||||
self.assertEqual(AD.objects.count(), 1)
|
|
||||||
self.assertEqual(ad.title, "Test Ad")
|
|
||||||
self.assertEqual(ad.description, "This is a test ad")
|
|
||||||
|
|
@ -1,328 +0,0 @@
|
||||||
from django.shortcuts import render
|
|
||||||
from .serializers import *
|
|
||||||
from .models import *
|
|
||||||
from rest_framework.viewsets import ModelViewSet, ReadOnlyModelViewSet
|
|
||||||
from rest_framework.response import Response
|
|
||||||
from rest_framework import status
|
|
||||||
from rest_framework.views import APIView
|
|
||||||
from rest_framework.permissions import IsAuthenticated, BasePermission
|
|
||||||
from .permissions import IsOwnerOrReadOnly, IsAdmin
|
|
||||||
from rest_framework.decorators import action
|
|
||||||
from rest_framework.exceptions import PermissionDenied
|
|
||||||
from django.contrib.auth import get_user_model
|
|
||||||
from lms.utils.exception_handler import CustomValidationError
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
User = get_user_model()
|
|
||||||
|
|
||||||
class CourseViewSet(ModelViewSet):
|
|
||||||
"""
|
|
||||||
A ViewSet for viewing and editing Course instances.
|
|
||||||
"""
|
|
||||||
queryset = Course.objects.all()
|
|
||||||
permission_classes = [IsAuthenticated, IsOwnerOrReadOnly]
|
|
||||||
serializer_class = CourseSerializer
|
|
||||||
|
|
||||||
def perform_create(self, serializer):
|
|
||||||
"""
|
|
||||||
Save the post data when creating a new course.
|
|
||||||
"""
|
|
||||||
|
|
||||||
serializer.save(owner=self.request.user)
|
|
||||||
|
|
||||||
@action(detail=False, methods=['get'], url_path='my-courses', url_name='my_courses')
|
|
||||||
def get_my_course(self, request):
|
|
||||||
my_courses = Course.objects.filter(owner=request.user).prefetch_related('enrollments__student')
|
|
||||||
total_students = Enrollment.objects.filter(course__in=my_courses).values('student').distinct().count()
|
|
||||||
|
|
||||||
serializer = self.get_serializer(my_courses, many=True)
|
|
||||||
response_data = {
|
|
||||||
"total_students": total_students,
|
|
||||||
"courses": serializer.data
|
|
||||||
}
|
|
||||||
return Response(response_data)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class ModuleViewSet(ModelViewSet):
|
|
||||||
"""
|
|
||||||
ViewSet for managing modules.
|
|
||||||
"""
|
|
||||||
|
|
||||||
serializer_class = ModuleSerializer
|
|
||||||
permission_classes = [IsAuthenticated, IsOwnerOrReadOnly]
|
|
||||||
|
|
||||||
def get_queryset(self):
|
|
||||||
"""
|
|
||||||
Return modules only if the user is the course owner.
|
|
||||||
"""
|
|
||||||
course_id = self.request.query_params.get('pk')
|
|
||||||
if course_id:
|
|
||||||
course = Course.objects.filter(id=course_id).select_related('owner').first()
|
|
||||||
if course:
|
|
||||||
return Module.objects.filter(course=course).select_related('course')
|
|
||||||
return Module.objects.none()
|
|
||||||
|
|
||||||
|
|
||||||
def perform_create(self, serializer):
|
|
||||||
"""
|
|
||||||
Allow only the course owner to create a module.
|
|
||||||
"""
|
|
||||||
course_id = self.request.data.get('course')
|
|
||||||
course = Course.objects.filter(id=course_id, owner=self.request.user).first()
|
|
||||||
is_owner = course.owner == self.request.user
|
|
||||||
if not is_owner:
|
|
||||||
raise PermissionDenied("You do not have permission to create module.")
|
|
||||||
|
|
||||||
if not course:
|
|
||||||
raise CustomValidationError(
|
|
||||||
{"detail": "This course not found."},
|
|
||||||
status=status.HTTP_404_NOT_FOUND,
|
|
||||||
)
|
|
||||||
serializer.save(course=course, created_by=self.request.user)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class LessonViewSet(ModelViewSet):
|
|
||||||
"""
|
|
||||||
ViewSet for managing lessons.
|
|
||||||
"""
|
|
||||||
|
|
||||||
serializer_class = LessonSerializer
|
|
||||||
permission_classes = [IsAuthenticated, IsOwnerOrReadOnly]
|
|
||||||
|
|
||||||
def get_queryset(self):
|
|
||||||
"""
|
|
||||||
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
|
|
||||||
|
|
||||||
# Check if both lesson_id and module_id are provided
|
|
||||||
if not lesson_id or not module_id:
|
|
||||||
return Lesson.objects.none() # Return no results if either is missing
|
|
||||||
|
|
||||||
# Verify that the module exist
|
|
||||||
module = Module.objects.filter(id=module_id).first()
|
|
||||||
if not module:
|
|
||||||
return Lesson.objects.none() # Return no results if the module does not exist
|
|
||||||
|
|
||||||
# Verify that the lesson exists and is associated with the module
|
|
||||||
lesson = Lesson.objects.filter(id=lesson_id, module=module).select_related('module__course__owner').first()
|
|
||||||
if not lesson:
|
|
||||||
return Lesson.objects.none() # Return no results if the lesson does not exist or is not linked to the module
|
|
||||||
|
|
||||||
# Check if the user has access (owner of the course or enrolled in the course)
|
|
||||||
is_owner = module.course.owner == self.request.user
|
|
||||||
is_enrolled = Enrollment.objects.filter(course=module.course, student=self.request.user).exists()
|
|
||||||
|
|
||||||
if is_owner or is_enrolled:
|
|
||||||
|
|
||||||
return Lesson.objects.filter(id=lesson_id) # Return the lesson if the user is authorized
|
|
||||||
|
|
||||||
return Lesson.objects.none() # Deny access if the user is not authorized
|
|
||||||
|
|
||||||
def perform_create(self, serializer):
|
|
||||||
"""
|
|
||||||
Customize the creation of a lesson to include the module and the user who created it.
|
|
||||||
"""
|
|
||||||
module_id = self.request.data.get('module') # Get the module ID from the request
|
|
||||||
module = Module.objects.filter(id=module_id).first() # Fetch the module
|
|
||||||
is_owner = module.course.owner == self.request.user
|
|
||||||
if not is_owner:
|
|
||||||
raise PermissionDenied("You do not have permission to create lessons in this module.")
|
|
||||||
|
|
||||||
if not module:
|
|
||||||
raise serializers.ValidationError({"module": "Module does not exist."})
|
|
||||||
|
|
||||||
# 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 = self.request.query_params.get('lesson_id')
|
|
||||||
if not lesson_id:
|
|
||||||
raise CustomValidationError({"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:
|
|
||||||
raise CustomValidationError({"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)
|
|
||||||
|
|
||||||
raise CustomValidationError(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:
|
|
||||||
raise CustomValidationError(
|
|
||||||
{"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:
|
|
||||||
raise CustomValidationError(
|
|
||||||
{"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):
|
|
||||||
queryset = Enrollment.objects.all()
|
|
||||||
serializer_class = EnrollmentSerializer
|
|
||||||
permission_classes = [IsAuthenticated]
|
|
||||||
http_method_names = ['get', 'post', 'delete']
|
|
||||||
|
|
||||||
def list(self, request, *args, **kwargs):
|
|
||||||
instance = Enrollment.objects.filter(student=request.user).select_related('course__owner')
|
|
||||||
|
|
||||||
serializer = self.get_serializer(instance, many=True)
|
|
||||||
return Response(serializer.data)
|
|
||||||
|
|
||||||
|
|
||||||
def create(self, request, *args, **kwargs):
|
|
||||||
|
|
||||||
course_id = request.data.get('course_id')
|
|
||||||
|
|
||||||
# Check if the student and course exist
|
|
||||||
try:
|
|
||||||
course = Course.objects.get(id=course_id)
|
|
||||||
except Course.DoesNotExist:
|
|
||||||
raise CustomValidationError({"detail": "Course not found"}, status=status.HTTP_404_NOT_FOUND)
|
|
||||||
|
|
||||||
if course.is_paid:
|
|
||||||
raise CustomValidationError({"detail": "This is paid"}, status=status.HTTP_404_NOT_FOUND)
|
|
||||||
|
|
||||||
if Enrollment.objects.filter(student=request.user, course=course).exists():
|
|
||||||
raise CustomValidationError({"detail": "You are already subscribed to this course."}, status=status.HTTP_404_NOT_FOUND)
|
|
||||||
|
|
||||||
if course.owner == request.user:
|
|
||||||
raise CustomValidationError({"detail": "You can't enroll in your course"}, status=status.HTTP_404_NOT_FOUND)
|
|
||||||
|
|
||||||
# Create a new enrollment
|
|
||||||
enrollment = Enrollment.objects.create(student=request.user, course=course)
|
|
||||||
serializer = self.get_serializer(enrollment)
|
|
||||||
return Response(serializer.data, status=status.HTTP_201_CREATED)
|
|
||||||
|
|
||||||
|
|
||||||
@action(detail=False, methods=['post'], url_path='private-enrollment')
|
|
||||||
def private_enrollment( self, request):
|
|
||||||
"""
|
|
||||||
Handles the private enrollment of a student into a specific course.
|
|
||||||
|
|
||||||
This custom action allows the owner of a paid course to manually enroll a student
|
|
||||||
using their email address. The course ID is provided in the URL, and the student's
|
|
||||||
email is received in the request body.
|
|
||||||
"""
|
|
||||||
course_id = request.data.get('course')
|
|
||||||
student_email = request.data.get('student_email').strip()
|
|
||||||
|
|
||||||
# Check if the course & student exists
|
|
||||||
course = Course.objects.filter(id=course_id).select_related('owner').first()
|
|
||||||
student = User.objects.filter(email=student_email).first()
|
|
||||||
|
|
||||||
if not student:
|
|
||||||
raise CustomValidationError("User not found", status=status.HTTP_404_NOT_FOUND)
|
|
||||||
|
|
||||||
if student_email == request.user.email:
|
|
||||||
raise CustomValidationError("You can't add yourself", status=status.HTTP_400_BAD_REQUEST)
|
|
||||||
|
|
||||||
|
|
||||||
if Enrollment.objects.filter(student__email=student_email, course=course).exists():
|
|
||||||
raise CustomValidationError("This user already exists", status=status.HTTP_400_BAD_REQUEST)
|
|
||||||
|
|
||||||
if not course.is_paid:
|
|
||||||
raise CustomValidationError("Course is not paid", status=status.HTTP_400_BAD_REQUEST)
|
|
||||||
|
|
||||||
# Allow only the course owner to enroll students
|
|
||||||
if course.owner != request.user:
|
|
||||||
raise CustomValidationError("You do not have permission to enroll students in this course",
|
|
||||||
status=status.HTTP_403_FORBIDDEN)
|
|
||||||
|
|
||||||
# Validate the data before saving
|
|
||||||
enrollment_data = {
|
|
||||||
'course': course.id,
|
|
||||||
'student': student.id
|
|
||||||
}
|
|
||||||
serializer = PrivateEnrollmentSerializer(data=enrollment_data)
|
|
||||||
if serializer.is_valid():
|
|
||||||
serializer.save()
|
|
||||||
return Response(f"Student {student.full_name} has been added",
|
|
||||||
status=status.HTTP_201_CREATED)
|
|
||||||
|
|
||||||
raise CustomValidationError(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
|
|
||||||
|
|
||||||
@action(detail=False, methods=['get'], url_path='get-my-students')
|
|
||||||
def get_my_students(self, request):
|
|
||||||
"""
|
|
||||||
Fetch detailed information about my students in a specific course.
|
|
||||||
"""
|
|
||||||
course_id = request.query_params.get('course')
|
|
||||||
if not course_id:
|
|
||||||
raise CustomValidationError(
|
|
||||||
{"detail": "Course ID is required in the query parameters."},
|
|
||||||
status=status.HTTP_400_BAD_REQUEST
|
|
||||||
)
|
|
||||||
|
|
||||||
try:
|
|
||||||
course = Course.objects.get(id=course_id, owner=request.user)
|
|
||||||
except Course.DoesNotExist:
|
|
||||||
raise CustomValidationError(
|
|
||||||
{"detail": "Course not found or you do not have permission to access it."},
|
|
||||||
status=status.HTTP_404_NOT_FOUND
|
|
||||||
)
|
|
||||||
|
|
||||||
my_students = (
|
|
||||||
Enrollment.objects.filter(course=course)
|
|
||||||
.select_related('student')
|
|
||||||
.values('student__full_name', 'student__email')
|
|
||||||
.distinct()
|
|
||||||
)
|
|
||||||
|
|
||||||
return Response(list(my_students), status=status.HTTP_200_OK)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -1,14 +0,0 @@
|
||||||
# import pytest
|
|
||||||
|
|
||||||
# from lms.users.models import User
|
|
||||||
# from lms.users.tests.factories import UserFactory
|
|
||||||
|
|
||||||
|
|
||||||
# @pytest.fixture(autouse=True)
|
|
||||||
# def _media_storage(settings, tmpdir) -> None:
|
|
||||||
# settings.MEDIA_ROOT = tmpdir.strpath
|
|
||||||
|
|
||||||
|
|
||||||
# @pytest.fixture
|
|
||||||
# def user(db) -> User:
|
|
||||||
# return UserFactory()
|
|
||||||
|
|
@ -1,6 +0,0 @@
|
||||||
|
|
||||||
{% load i18n %}
|
|
||||||
|
|
||||||
{% block content %}{% autoescape off %}{% blocktrans %}You're receiving this em{% endblocktrans %}
|
|
||||||
|
|
||||||
{{ password_reset_url }}
|
|
||||||
|
|
@ -1,39 +0,0 @@
|
||||||
from rest_framework.exceptions import APIException
|
|
||||||
from rest_framework import status
|
|
||||||
from rest_framework.views import exception_handler
|
|
||||||
from rest_framework.response import Response
|
|
||||||
|
|
||||||
|
|
||||||
class CustomValidationError(APIException):
|
|
||||||
default_status = status.HTTP_400_BAD_REQUEST
|
|
||||||
default_detail = 'A validation error occurred.'
|
|
||||||
|
|
||||||
def __init__(self, detail=None, status=None):
|
|
||||||
self.detail = detail if detail is not None else self.default_detail
|
|
||||||
self.status = status if status is not None else self.default_status
|
|
||||||
|
|
||||||
def __str__(self):
|
|
||||||
return f"{self.detail} (Status: {self.status})"
|
|
||||||
|
|
||||||
@property
|
|
||||||
def status_code(self):
|
|
||||||
# Map `status` to `status_code` to ensure compatibility with DRF
|
|
||||||
return self.status
|
|
||||||
|
|
||||||
|
|
||||||
def custom_exception_handler(exc, context):
|
|
||||||
# Call REST framework's default exception handler first
|
|
||||||
response = exception_handler(exc, context)
|
|
||||||
|
|
||||||
# Handle CustomValidationError
|
|
||||||
if isinstance(exc, CustomValidationError):
|
|
||||||
return Response(
|
|
||||||
{
|
|
||||||
'error': exc.detail,
|
|
||||||
'status_code': exc.status,
|
|
||||||
},
|
|
||||||
status=exc.status,
|
|
||||||
)
|
|
||||||
|
|
||||||
# Return the default response for other exceptions
|
|
||||||
return response
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
# set -o errexit
|
set -o errexit
|
||||||
set -o pipefail
|
set -o pipefail
|
||||||
set -o nounset
|
set -o nounset
|
||||||
|
|
||||||
62
compose/local/docs/Dockerfile
Normal file
62
compose/local/docs/Dockerfile
Normal file
|
|
@ -0,0 +1,62 @@
|
||||||
|
# define an alias for the specific python version used in this file.
|
||||||
|
FROM docker.io/python:3.12.8-slim-bookworm AS python
|
||||||
|
|
||||||
|
|
||||||
|
# Python build stage
|
||||||
|
FROM python AS python-build-stage
|
||||||
|
|
||||||
|
ENV PYTHONDONTWRITEBYTECODE=1
|
||||||
|
|
||||||
|
RUN apt-get update && apt-get install --no-install-recommends -y \
|
||||||
|
# dependencies for building Python packages
|
||||||
|
build-essential \
|
||||||
|
# psycopg dependencies
|
||||||
|
libpq-dev \
|
||||||
|
# cleaning up unused files
|
||||||
|
&& apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false \
|
||||||
|
&& rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
|
# Requirements are installed here to ensure they will be cached.
|
||||||
|
COPY ./requirements /requirements
|
||||||
|
|
||||||
|
# create python dependency wheels
|
||||||
|
RUN pip wheel --no-cache-dir --wheel-dir /usr/src/app/wheels \
|
||||||
|
-r /requirements/local.txt -r /requirements/production.txt \
|
||||||
|
&& rm -rf /requirements
|
||||||
|
|
||||||
|
|
||||||
|
# Python 'run' stage
|
||||||
|
FROM python AS python-run-stage
|
||||||
|
|
||||||
|
ARG BUILD_ENVIRONMENT
|
||||||
|
ENV PYTHONUNBUFFERED=1
|
||||||
|
ENV PYTHONDONTWRITEBYTECODE=1
|
||||||
|
|
||||||
|
RUN apt-get update && apt-get install --no-install-recommends -y \
|
||||||
|
# To run the Makefile
|
||||||
|
make \
|
||||||
|
# psycopg dependencies
|
||||||
|
libpq-dev \
|
||||||
|
# Translations dependencies
|
||||||
|
gettext \
|
||||||
|
# Uncomment below lines to enable Sphinx output to latex and pdf
|
||||||
|
# texlive-latex-recommended \
|
||||||
|
# texlive-fonts-recommended \
|
||||||
|
# texlive-latex-extra \
|
||||||
|
# latexmk \
|
||||||
|
# cleaning up unused files
|
||||||
|
&& apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false \
|
||||||
|
&& rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
|
# copy python dependency wheels from python-build-stage
|
||||||
|
COPY --from=python-build-stage /usr/src/app/wheels /wheels
|
||||||
|
|
||||||
|
# use wheels to install python dependencies
|
||||||
|
RUN pip install --no-cache /wheels/* \
|
||||||
|
&& rm -rf /wheels
|
||||||
|
|
||||||
|
COPY ./compose/local/docs/start /start-docs
|
||||||
|
RUN sed -i 's/\r$//g' /start-docs
|
||||||
|
RUN chmod +x /start-docs
|
||||||
|
|
||||||
|
WORKDIR /docs
|
||||||
7
compose/local/docs/start
Normal file
7
compose/local/docs/start
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
set -o errexit
|
||||||
|
set -o pipefail
|
||||||
|
set -o nounset
|
||||||
|
|
||||||
|
exec make livehtml
|
||||||
13
config/api_router.py
Normal file
13
config/api_router.py
Normal file
|
|
@ -0,0 +1,13 @@
|
||||||
|
from django.conf import settings
|
||||||
|
from rest_framework.routers import DefaultRouter
|
||||||
|
from rest_framework.routers import SimpleRouter
|
||||||
|
|
||||||
|
from lms.users.api.views import UserViewSet
|
||||||
|
|
||||||
|
router = DefaultRouter() if settings.DEBUG else SimpleRouter()
|
||||||
|
|
||||||
|
router.register("users", UserViewSet)
|
||||||
|
|
||||||
|
|
||||||
|
app_name = "api"
|
||||||
|
urlpatterns = router.urls
|
||||||
|
|
@ -75,7 +75,6 @@ THIRD_PARTY_APPS = [
|
||||||
"crispy_forms",
|
"crispy_forms",
|
||||||
"crispy_bootstrap5",
|
"crispy_bootstrap5",
|
||||||
"allauth",
|
"allauth",
|
||||||
'allauth.headless',
|
|
||||||
"allauth.account",
|
"allauth.account",
|
||||||
"allauth.mfa",
|
"allauth.mfa",
|
||||||
"allauth.socialaccount",
|
"allauth.socialaccount",
|
||||||
|
|
@ -87,6 +86,7 @@ THIRD_PARTY_APPS = [
|
||||||
]
|
]
|
||||||
|
|
||||||
LOCAL_APPS = [
|
LOCAL_APPS = [
|
||||||
|
"lms.users",
|
||||||
"lms.accounts",
|
"lms.accounts",
|
||||||
"lms.app",
|
"lms.app",
|
||||||
# Your stuff: custom apps go here
|
# Your stuff: custom apps go here
|
||||||
|
|
@ -103,7 +103,7 @@ MIGRATION_MODULES = {"sites": "lms.contrib.sites.migrations"}
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
# https://docs.djangoproject.com/en/dev/ref/settings/#authentication-backends
|
# https://docs.djangoproject.com/en/dev/ref/settings/#authentication-backends
|
||||||
AUTHENTICATION_BACKENDS = [
|
AUTHENTICATION_BACKENDS = [
|
||||||
# "django.contrib.auth.backends.ModelBackend",
|
"django.contrib.auth.backends.ModelBackend",
|
||||||
"allauth.account.auth_backends.AuthenticationBackend",
|
"allauth.account.auth_backends.AuthenticationBackend",
|
||||||
]
|
]
|
||||||
# https://docs.djangoproject.com/en/dev/ref/settings/#auth-user-model
|
# https://docs.djangoproject.com/en/dev/ref/settings/#auth-user-model
|
||||||
|
|
@ -137,8 +137,8 @@ AUTH_PASSWORD_VALIDATORS = [
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
# https://docs.djangoproject.com/en/dev/ref/settings/#middleware
|
# https://docs.djangoproject.com/en/dev/ref/settings/#middleware
|
||||||
MIDDLEWARE = [
|
MIDDLEWARE = [
|
||||||
"corsheaders.middleware.CorsMiddleware",
|
|
||||||
"django.middleware.security.SecurityMiddleware",
|
"django.middleware.security.SecurityMiddleware",
|
||||||
|
"corsheaders.middleware.CorsMiddleware",
|
||||||
"whitenoise.middleware.WhiteNoiseMiddleware",
|
"whitenoise.middleware.WhiteNoiseMiddleware",
|
||||||
"django.contrib.sessions.middleware.SessionMiddleware",
|
"django.contrib.sessions.middleware.SessionMiddleware",
|
||||||
"django.middleware.locale.LocaleMiddleware",
|
"django.middleware.locale.LocaleMiddleware",
|
||||||
|
|
@ -193,6 +193,7 @@ TEMPLATES = [
|
||||||
"django.template.context_processors.static",
|
"django.template.context_processors.static",
|
||||||
"django.template.context_processors.tz",
|
"django.template.context_processors.tz",
|
||||||
"django.contrib.messages.context_processors.messages",
|
"django.contrib.messages.context_processors.messages",
|
||||||
|
"lms.users.context_processors.allauth_settings",
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
@ -234,7 +235,7 @@ EMAIL_TIMEOUT = 5
|
||||||
# Django Admin URL.
|
# Django Admin URL.
|
||||||
ADMIN_URL = "admin/"
|
ADMIN_URL = "admin/"
|
||||||
# https://docs.djangoproject.com/en/dev/ref/settings/#admins
|
# https://docs.djangoproject.com/en/dev/ref/settings/#admins
|
||||||
ADMINS = [("""ص""", "e@gmail.com")]
|
ADMINS = [("""Ahmed Nagi""", "ahmed10nagi@gmail.com")]
|
||||||
# https://docs.djangoproject.com/en/dev/ref/settings/#managers
|
# https://docs.djangoproject.com/en/dev/ref/settings/#managers
|
||||||
MANAGERS = ADMINS
|
MANAGERS = ADMINS
|
||||||
# https://cookiecutter-django.readthedocs.io/en/latest/settings.html#other-environment-settings
|
# https://cookiecutter-django.readthedocs.io/en/latest/settings.html#other-environment-settings
|
||||||
|
|
@ -320,37 +321,18 @@ ACCOUNT_USERNAME_REQUIRED = False
|
||||||
ACCOUNT_USER_MODEL_USERNAME_FIELD = None
|
ACCOUNT_USER_MODEL_USERNAME_FIELD = None
|
||||||
# https://docs.allauth.org/en/latest/account/configuration.html
|
# https://docs.allauth.org/en/latest/account/configuration.html
|
||||||
ACCOUNT_EMAIL_VERIFICATION = "mandatory"
|
ACCOUNT_EMAIL_VERIFICATION = "mandatory"
|
||||||
ACCOUNT_LOGIN_METHODS = {"email"}
|
|
||||||
ACCOUNT_LOGOUT_ON_GET = True
|
ACCOUNT_LOGOUT_ON_GET = True
|
||||||
ACCOUNT_LOGOUT_ON_PASSWORD_CHANGE = False
|
LOGOUT_ON_PASSWORD_CHANGE = False
|
||||||
ACCOUNT_CHANGE_EMAIL = True
|
ACCOUNT_CHANGE_EMAIL = True
|
||||||
# ACCOUNT_EMAIL_VERIFICATION_BY_CODE_ENABLED = True
|
|
||||||
HEADLESS_SERVE_SPECIFICATION = True
|
|
||||||
|
|
||||||
ACCOUNT_EMAIL_CONFIRMATION_HMAC = True
|
ACCOUNT_EMAIL_CONFIRMATION_HMAC = True
|
||||||
ACCOUNT_CONFIRM_EMAIL_ON_GET = True
|
ACCOUNT_CONFIRM_EMAIL_ON_GET = True
|
||||||
ACCOUNT_MAX_EMAIL_ADDRESSES = 2
|
|
||||||
|
|
||||||
ACCOUNT_EMAIL_CONFIRMATION_ANONYMOUS_REDIRECT_URL = None
|
ACCOUNT_EMAIL_CONFIRMATION_ANONYMOUS_REDIRECT_URL = None
|
||||||
ACCOUNT_EMAIL_CONFIRMATION_AUTHENTICATED_REDIRECT_URL = None
|
ACCOUNT_EMAIL_CONFIRMATION_AUTHENTICATED_REDIRECT_URL = None
|
||||||
# ACCOUNT_RATE_LIMITS = {
|
# ACCOUNT_RATE_LIMITS = {
|
||||||
# "confirm_email": "1/4m", # 1 confirmation email every 4 minutes
|
# "confirm_email": "1/4m", # 1 confirmation email every 4 minutes
|
||||||
# }
|
# }
|
||||||
HEADLESS_FRONTEND_URLS = {
|
|
||||||
"account_signup":"http://localhost:3000/account/signup",
|
|
||||||
"account_confirm_email": "http://127.0.0.1:3000/account/email-confirmation/{key}/",
|
|
||||||
|
|
||||||
# "https://app.project.org/account/email/verify-email?token={key}",
|
|
||||||
"account_reset_password": "https://app.project.org/account/password/reset",
|
|
||||||
"account_reset_password_from_key": "https://app.project.org/account/password/reset/key/{key}",
|
|
||||||
# "account_signup": "https://app.project.org/account/signup",
|
|
||||||
# Fallback in case the state containing the `next` URL is lost and the handshake
|
|
||||||
# with the third-party provider fails.
|
|
||||||
# "socialaccount_login_error": "https://app.project.org/account/provider/callback",
|
|
||||||
}
|
|
||||||
HEADLESS_ONLY = True
|
|
||||||
# https://docs.allauth.org/en/latest/account/configuration.html
|
# https://docs.allauth.org/en/latest/account/configuration.html
|
||||||
# ACCOUNT_ADAPTER = "lms.accounts.adapters.CustomAccountAdapter"
|
ACCOUNT_ADAPTER = "lms.accounts.adapters.CustomAccountAdapter"
|
||||||
# https://docs.allauth.org/en/latest/account/forms.html
|
# https://docs.allauth.org/en/latest/account/forms.html
|
||||||
# ACCOUNT_FORMS = {"signup": "lms.users.forms.UserSignupForm"}
|
# ACCOUNT_FORMS = {"signup": "lms.users.forms.UserSignupForm"}
|
||||||
# https://docs.allauth.org/en/latest/socialaccount/configuration.html
|
# https://docs.allauth.org/en/latest/socialaccount/configuration.html
|
||||||
|
|
@ -372,13 +354,10 @@ REST_FRAMEWORK = {
|
||||||
'dj_rest_auth.jwt_auth.JWTCookieAuthentic ation',
|
'dj_rest_auth.jwt_auth.JWTCookieAuthentic ation',
|
||||||
),
|
),
|
||||||
"DEFAULT_PERMISSION_CLASSES": (
|
"DEFAULT_PERMISSION_CLASSES": (
|
||||||
# 'rest_framework.permissions.AllowAny',
|
|
||||||
"rest_framework.permissions.IsAuthenticated",
|
"rest_framework.permissions.IsAuthenticated",
|
||||||
),
|
),
|
||||||
"DEFAULT_SCHEMA_CLASS": "drf_spectacular.openapi.AutoS chema",
|
"DEFAULT_SCHEMA_CLASS": "drf_spectacular.openapi.AutoS chema",
|
||||||
'EXCEPTION_HANDLER': 'utils.exception_handler.custom_exception_handler',
|
|
||||||
}
|
}
|
||||||
|
|
||||||
REST_AUTH = {
|
REST_AUTH = {
|
||||||
'LOGIN_SERIALIZER': 'lms.accounts.serializers.CustomLoginSerializer',
|
'LOGIN_SERIALIZER': 'lms.accounts.serializers.CustomLoginSerializer',
|
||||||
'REGISTER_SERIALIZER': 'lms.accounts.serializers.CustomRegisterSerializer',
|
'REGISTER_SERIALIZER': 'lms.accounts.serializers.CustomRegisterSerializer',
|
||||||
|
|
@ -390,11 +369,11 @@ REST_AUTH = {
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
SIMPLE_JWT = {
|
SIMPLE_JWT = {
|
||||||
'ACCESS_TOKEN_LIFETIME': timedelta(hours=5),
|
'ACCESS_TOKEN_LIFETIME': timedelta(hours=5),
|
||||||
'REFRESH_TOKEN_LIFETIME': timedelta(days=15),
|
'REFRESH_TOKEN_LIFETIME': timedelta(days=30),
|
||||||
'ROTATE_REFRESH_TOKENS': True,
|
'ROTATE_REFRESH_TOKENS': True,
|
||||||
'BLACKLIST_AFTER_ROTATION': True,
|
'BLACKLIST_AFTER_ROTATION': True,
|
||||||
'ALGORITHM': 'HS256',
|
'ALGORITHM': 'HS256',
|
||||||
'SIGNING_KEY': 'env("SIGNING_KEY")',
|
'SIGNING_KEY': SECRET_KEY,
|
||||||
}
|
}
|
||||||
|
|
||||||
# django-cors-headers - https://github.com/adamchainz/django-cors-headers#setup
|
# django-cors-headers - https://github.com/adamchainz/django-cors-headers#setup
|
||||||
|
|
@ -406,9 +385,8 @@ SPECTACULAR_SETTINGS = {
|
||||||
"TITLE": "Learning Management System API",
|
"TITLE": "Learning Management System API",
|
||||||
"DESCRIPTION": "Documentation of API endpoints of Learning Management System",
|
"DESCRIPTION": "Documentation of API endpoints of Learning Management System",
|
||||||
"VERSION": "1.0.0",
|
"VERSION": "1.0.0",
|
||||||
# "SERVE_PERMISSIONS": ["rest_framework.permissions.IsAdminUser"],
|
"SERVE_PERMISSIONS": ["rest_framework.permissions.IsAdminUser"],
|
||||||
"SCHEMA_PATH_PREFIX": "/api/",
|
"SCHEMA_PATH_PREFIX": "/api/",
|
||||||
'SERVE_INCLUDE_SCHEMA': False,
|
|
||||||
}
|
}
|
||||||
# Your stuff...
|
# Your stuff...
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
|
|
@ -8,46 +8,13 @@ from .base import env
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
# https://docs.djangoproject.com/en/dev/ref/settings/#debug
|
# https://docs.djangoproject.com/en/dev/ref/settings/#debug
|
||||||
DEBUG = True
|
DEBUG = True
|
||||||
DEBUG = True
|
|
||||||
# https://docs.djangoproject.com/en/dev/ref/settings/#secret-key
|
# https://docs.djangoproject.com/en/dev/ref/settings/#secret-key
|
||||||
SECRET_KEY = env(
|
SECRET_KEY = env(
|
||||||
"DJANGO_SECRET_KEY",
|
"DJANGO_SECRET_KEY",
|
||||||
default="DM837WrWz7KIfZM2eb4swzqGlIG0VhhAIFNXf9KgamMtT42DTkHIEXfpF4N9rh2Y",
|
default="DM837WrWz7KIfZM2eb4swzqGlIG0VhhAIFNXf9KgamMtT42DTkHIEXfpF4N9rh2Y",
|
||||||
)
|
)
|
||||||
# https://docs.djangoproject.com/en/dev/ref/settings/#allowed-hosts
|
# https://docs.djangoproject.com/en/dev/ref/settings/#allowed-hosts
|
||||||
ALLOWED_HOSTS = ["127.0.0.1", "localhost",
|
ALLOWED_HOSTS = ["localhost", "0.0.0.0", "127.0.0.1"] # noqa: S104
|
||||||
"8000-idx-learning-management-systemgit-1737467650700.cluster-y34ecccqenfhcuavp7vbnxv7zk.cloudworkstations.dev"
|
|
||||||
] # حدد المضيفين المسموح بهم
|
|
||||||
|
|
||||||
CSRF_TRUSTED_ORIGINS = [
|
|
||||||
'http://localhost:3000',
|
|
||||||
'http://127.0.0.1:3000',
|
|
||||||
'https://8000-idx-learning-management-systemgit-1737467650700.cluster-y34ecccqenfhcuavp7vbnxv7zk.cloudworkstations.dev'
|
|
||||||
]
|
|
||||||
CORS_ORIGIN_ALLOW_ALL = True
|
|
||||||
CORS_ALLOW_CREDENTIALS = False
|
|
||||||
|
|
||||||
|
|
||||||
CORS_ALLOW_METHODS = [
|
|
||||||
"GET",
|
|
||||||
"POST",
|
|
||||||
"PUT",
|
|
||||||
"PATCH",
|
|
||||||
"DELETE",
|
|
||||||
"OPTIONS",
|
|
||||||
]
|
|
||||||
|
|
||||||
CORS_ALLOW_HEADERS = [
|
|
||||||
"content-type",
|
|
||||||
"authorization",
|
|
||||||
"accept",
|
|
||||||
"origin",
|
|
||||||
"user-agent",
|
|
||||||
"x-csrftoken",
|
|
||||||
"x-requested-with",
|
|
||||||
"x-session-token",
|
|
||||||
]
|
|
||||||
|
|
||||||
|
|
||||||
# CACHES
|
# CACHES
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
|
|
@ -114,5 +81,3 @@ INSTALLED_APPS += ["django_extensions"]
|
||||||
CELERY_TASK_EAGER_PROPAGATES = True
|
CELERY_TASK_EAGER_PROPAGATES = True
|
||||||
# Your stuff...
|
# Your stuff...
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -204,5 +204,3 @@ SPECTACULAR_SETTINGS["SERVERS"] = [
|
||||||
]
|
]
|
||||||
# Your stuff...
|
# Your stuff...
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
|
|
||||||
SIMPLE_JWT["SIGNING_KEY"]=SECRET_KEY
|
|
||||||
|
|
@ -4,26 +4,21 @@ from django.conf.urls.static import static
|
||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
|
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
|
||||||
from django.urls import include
|
from django.urls import include
|
||||||
from django.urls import path, re_path
|
from django.urls import path
|
||||||
from django.views import defaults as default_views
|
from django.views import defaults as default_views
|
||||||
from django.views.generic import TemplateView
|
from django.views.generic import TemplateView
|
||||||
from drf_spectacular.views import SpectacularAPIView
|
from drf_spectacular.views import SpectacularAPIView
|
||||||
from drf_spectacular.views import SpectacularSwaggerView
|
from drf_spectacular.views import SpectacularSwaggerView
|
||||||
from rest_framework.authtoken.views import obtain_auth_token
|
from rest_framework.authtoken.views import obtain_auth_token
|
||||||
from lms.accounts.views import *
|
from dj_rest_auth.views import PasswordResetConfirmView
|
||||||
|
|
||||||
from rest_framework.views import APIView
|
|
||||||
from rest_framework.response import Response
|
|
||||||
from rest_framework.permissions import AllowAny
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path("", TemplateView.as_view(template_name="pages/home.html"), name="home"),
|
path("", TemplateView.as_view(template_name="pages/home.html"), name="home"),
|
||||||
# Django Admin, use {% url 'admin:index' %}
|
# Django Admin, use {% url 'admin:index' %}
|
||||||
path(settings.ADMIN_URL, admin.site.urls),
|
path(settings.ADMIN_URL, admin.site.urls),
|
||||||
|
# User management
|
||||||
path("authwed/", include("allauth.urls")),
|
path("users/", include("lms.users.urls", namespace="users")),
|
||||||
|
path("accounts/", include("allauth.urls")),
|
||||||
# Your stuff: custom urls includes go here
|
# Your stuff: custom urls includes go here
|
||||||
# ...
|
# ...
|
||||||
# Media files
|
# Media files
|
||||||
|
|
@ -35,12 +30,24 @@ if settings.DEBUG:
|
||||||
|
|
||||||
# API URLS
|
# API URLS
|
||||||
urlpatterns += [
|
urlpatterns += [
|
||||||
path("api/accounts/", include("allauth.urls")),
|
path(
|
||||||
|
'auth/password/reset/confirm/<uidb64>/<token>/',
|
||||||
|
PasswordResetConfirmView.as_view(),
|
||||||
|
name='password_reset_confirm',
|
||||||
|
),
|
||||||
|
path('auth/registration/', include('dj_rest_auth.registration.urls')),
|
||||||
|
path('auth/', include('dj_rest_auth.urls')),
|
||||||
|
path('api-auth/', include('rest_framework.urls', namespace='rest_framework')),
|
||||||
|
|
||||||
path('api/auth/', include('lms.accounts.urls')),
|
|
||||||
|
|
||||||
path('api/app/', include('lms.app.urls')),
|
path('auth/', include('lms.accounts.urls')),
|
||||||
|
path('app/', include('lms.app.urls')),
|
||||||
|
|
||||||
|
|
||||||
|
# API base url
|
||||||
|
path("api/", include("config.api_router")),
|
||||||
|
# DRF auth token
|
||||||
|
path("api/auth-token/", obtain_auth_token),
|
||||||
path("api/schema/", SpectacularAPIView.as_view(), name="api-schema"),
|
path("api/schema/", SpectacularAPIView.as_view(), name="api-schema"),
|
||||||
path(
|
path(
|
||||||
"api/docs/",
|
"api/docs/",
|
||||||
|
|
@ -12,5 +12,5 @@ services:
|
||||||
- ./config:/app/config:z
|
- ./config:/app/config:z
|
||||||
- ./lms:/app/lms:z
|
- ./lms:/app/lms:z
|
||||||
ports:
|
ports:
|
||||||
- '6000:6000'
|
- '9000:9000'
|
||||||
command: mkdocs serve
|
command: /start-docs
|
||||||
29
docs/Makefile
Normal file
29
docs/Makefile
Normal file
|
|
@ -0,0 +1,29 @@
|
||||||
|
# Minimal makefile for Sphinx documentation
|
||||||
|
#
|
||||||
|
|
||||||
|
# You can set these variables from the command line, and also
|
||||||
|
# from the environment for the first two.
|
||||||
|
SPHINXOPTS ?=
|
||||||
|
SPHINXBUILD ?= sphinx-build
|
||||||
|
SOURCEDIR = .
|
||||||
|
BUILDDIR = ./_build
|
||||||
|
APP = /app
|
||||||
|
|
||||||
|
.PHONY: html livehtml apidocs Makefile
|
||||||
|
|
||||||
|
# Put it first so that "make" without argument is like "make html".
|
||||||
|
html:
|
||||||
|
@$(SPHINXBUILD) -M html "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) -c .
|
||||||
|
|
||||||
|
# Build, watch and serve docs with live reload
|
||||||
|
livehtml:
|
||||||
|
sphinx-autobuild -b html --host 0.0.0.0 --port 9000 --watch $(APP) -c . $(SOURCEDIR) $(BUILDDIR)/html
|
||||||
|
|
||||||
|
# Outputs rst files from django application code
|
||||||
|
apidocs:
|
||||||
|
sphinx-apidoc -o $(SOURCEDIR)/api $(APP)
|
||||||
|
|
||||||
|
# Catch-all target: route all unknown targets to Sphinx using the new
|
||||||
|
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
|
||||||
|
%: Makefile
|
||||||
|
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) -c .
|
||||||
1
docs/__init__.py
Normal file
1
docs/__init__.py
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
# Included so that Django's startproject comment runs against the docs directory
|
||||||
63
docs/conf.py
Normal file
63
docs/conf.py
Normal file
|
|
@ -0,0 +1,63 @@
|
||||||
|
# ruff: noqa
|
||||||
|
# Configuration file for the Sphinx documentation builder.
|
||||||
|
#
|
||||||
|
# This file only contains a selection of the most common options. For a full
|
||||||
|
# list see the documentation:
|
||||||
|
# https://www.sphinx-doc.org/en/master/usage/configuration.html
|
||||||
|
|
||||||
|
# -- Path setup --------------------------------------------------------------
|
||||||
|
|
||||||
|
# If extensions (or modules to document with autodoc) are in another directory,
|
||||||
|
# add these directories to sys.path here. If the directory is relative to the
|
||||||
|
# documentation root, use os.path.abspath to make it absolute, like shown here.
|
||||||
|
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
import django
|
||||||
|
|
||||||
|
if os.getenv("READTHEDOCS", default=False) == "True":
|
||||||
|
sys.path.insert(0, os.path.abspath(".."))
|
||||||
|
os.environ["DJANGO_READ_DOT_ENV_FILE"] = "True"
|
||||||
|
os.environ["USE_DOCKER"] = "no"
|
||||||
|
else:
|
||||||
|
sys.path.insert(0, os.path.abspath("/app"))
|
||||||
|
os.environ["DATABASE_URL"] = "sqlite:///readthedocs.db"
|
||||||
|
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.settings.local")
|
||||||
|
django.setup()
|
||||||
|
|
||||||
|
# -- Project information -----------------------------------------------------
|
||||||
|
|
||||||
|
project = "Learning Management System"
|
||||||
|
copyright = """2025, Ahmed Nagi"""
|
||||||
|
author = "Ahmed Nagi"
|
||||||
|
|
||||||
|
|
||||||
|
# -- General configuration ---------------------------------------------------
|
||||||
|
|
||||||
|
# Add any Sphinx extension module names here, as strings. They can be
|
||||||
|
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
|
||||||
|
# ones.
|
||||||
|
extensions = [
|
||||||
|
"sphinx.ext.autodoc",
|
||||||
|
"sphinx.ext.napoleon",
|
||||||
|
]
|
||||||
|
|
||||||
|
# Add any paths that contain templates here, relative to this directory.
|
||||||
|
# templates_path = ["_templates"]
|
||||||
|
|
||||||
|
# List of patterns, relative to source directory, that match files and
|
||||||
|
# directories to ignore when looking for source files.
|
||||||
|
# This pattern also affects html_static_path and html_extra_path.
|
||||||
|
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"]
|
||||||
|
|
||||||
|
# -- Options for HTML output -------------------------------------------------
|
||||||
|
|
||||||
|
# The theme to use for HTML and HTML Help pages. See the documentation for
|
||||||
|
# a list of builtin themes.
|
||||||
|
#
|
||||||
|
html_theme = "alabaster"
|
||||||
|
|
||||||
|
# Add any paths that contain custom static files (such as style sheets) here,
|
||||||
|
# relative to this directory. They are copied after the builtin static files,
|
||||||
|
# so a file named "default.css" will overwrite the builtin "default.css".
|
||||||
|
# html_static_path = ["_static"]
|
||||||
38
docs/howto.rst
Normal file
38
docs/howto.rst
Normal file
|
|
@ -0,0 +1,38 @@
|
||||||
|
How To - Project Documentation
|
||||||
|
======================================================================
|
||||||
|
|
||||||
|
Get Started
|
||||||
|
----------------------------------------------------------------------
|
||||||
|
|
||||||
|
Documentation can be written as rst files in `lms/docs`.
|
||||||
|
|
||||||
|
|
||||||
|
To build and serve docs, use the commands::
|
||||||
|
|
||||||
|
docker compose -f docker-compose.local.yml up docs
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Changes to files in `docs/_source` will be picked up and reloaded automatically.
|
||||||
|
|
||||||
|
`Sphinx <https://www.sphinx-doc.org/>`_ is the tool used to build documentation.
|
||||||
|
|
||||||
|
Docstrings to Documentation
|
||||||
|
----------------------------------------------------------------------
|
||||||
|
|
||||||
|
The sphinx extension `apidoc <https://www.sphinx-doc.org/en/master/man/sphinx-apidoc.html>`_ is used to automatically document code using signatures and docstrings.
|
||||||
|
|
||||||
|
Numpy or Google style docstrings will be picked up from project files and available for documentation. See the `Napoleon <https://sphinxcontrib-napoleon.readthedocs.io/en/latest/>`_ extension for details.
|
||||||
|
|
||||||
|
For an in-use example, see the `page source <_sources/users.rst.txt>`_ for :ref:`users`.
|
||||||
|
|
||||||
|
To compile all docstrings automatically into documentation source files, use the command:
|
||||||
|
::
|
||||||
|
|
||||||
|
make apidocs
|
||||||
|
|
||||||
|
|
||||||
|
This can be done in the docker container:
|
||||||
|
::
|
||||||
|
|
||||||
|
docker run --rm docs make apidocs
|
||||||
23
docs/index.rst
Normal file
23
docs/index.rst
Normal file
|
|
@ -0,0 +1,23 @@
|
||||||
|
.. Learning Management System documentation master file, created by
|
||||||
|
sphinx-quickstart.
|
||||||
|
You can adapt this file completely to your liking, but it should at least
|
||||||
|
contain the root `toctree` directive.
|
||||||
|
|
||||||
|
Welcome to Learning Management System's documentation!
|
||||||
|
======================================================================
|
||||||
|
|
||||||
|
.. toctree::
|
||||||
|
:maxdepth: 2
|
||||||
|
:caption: Contents:
|
||||||
|
|
||||||
|
howto
|
||||||
|
users
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Indices and tables
|
||||||
|
==================
|
||||||
|
|
||||||
|
* :ref:`genindex`
|
||||||
|
* :ref:`modindex`
|
||||||
|
* :ref:`search`
|
||||||
46
docs/make.bat
Normal file
46
docs/make.bat
Normal file
|
|
@ -0,0 +1,46 @@
|
||||||
|
@ECHO OFF
|
||||||
|
|
||||||
|
pushd %~dp0
|
||||||
|
|
||||||
|
REM Command file for Sphinx documentation
|
||||||
|
|
||||||
|
|
||||||
|
if "%SPHINXBUILD%" == "" (
|
||||||
|
set SPHINXBUILD=sphinx-build -c .
|
||||||
|
)
|
||||||
|
set SOURCEDIR=_source
|
||||||
|
set BUILDDIR=_build
|
||||||
|
set APP=..\lms
|
||||||
|
|
||||||
|
if "%1" == "" goto html
|
||||||
|
|
||||||
|
%SPHINXBUILD% >NUL 2>NUL
|
||||||
|
if errorlevel 9009 (
|
||||||
|
echo.
|
||||||
|
echo.The 'sphinx-build' command was not found. Make sure you have Sphinx
|
||||||
|
echo.installed, then set the SPHINXBUILD environment variable to point
|
||||||
|
echo.to the full path of the 'sphinx-build' executable. Alternatively you
|
||||||
|
echo.may add the Sphinx directory to PATH.
|
||||||
|
echo.
|
||||||
|
echo.Install sphinx-autobuild for live serving.
|
||||||
|
echo.If you don't have Sphinx installed, grab it from
|
||||||
|
echo.http://sphinx-doc.org/
|
||||||
|
exit /b 1
|
||||||
|
)
|
||||||
|
|
||||||
|
%SPHINXBUILD% -b %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
|
||||||
|
goto end
|
||||||
|
|
||||||
|
:livehtml
|
||||||
|
sphinx-autobuild -b html --open-browser -p 9000 --watch %APP% -c . %SOURCEDIR% %BUILDDIR%/html
|
||||||
|
GOTO :EOF
|
||||||
|
|
||||||
|
:apidocs
|
||||||
|
sphinx-apidoc -o %SOURCEDIR%/api %APP%
|
||||||
|
GOTO :EOF
|
||||||
|
|
||||||
|
:html
|
||||||
|
%SPHINXBUILD% -b html %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
|
||||||
|
|
||||||
|
:end
|
||||||
|
popd
|
||||||
15
docs/users.rst
Normal file
15
docs/users.rst
Normal file
|
|
@ -0,0 +1,15 @@
|
||||||
|
.. _users:
|
||||||
|
|
||||||
|
Users
|
||||||
|
======================================================================
|
||||||
|
|
||||||
|
Starting a new project, it’s highly recommended to set up a custom user model,
|
||||||
|
even if the default User model is sufficient for you.
|
||||||
|
|
||||||
|
This model behaves identically to the default user model,
|
||||||
|
but you’ll be able to customize it in the future if the need arises.
|
||||||
|
|
||||||
|
.. automodule:: lms.users.models
|
||||||
|
:members:
|
||||||
|
:noindex:
|
||||||
|
|
||||||
|
|
@ -1,12 +0,0 @@
|
||||||
# EditorConfig is awesome: https://EditorConfig.org
|
|
||||||
|
|
||||||
# top-most EditorConfig file
|
|
||||||
root = true
|
|
||||||
|
|
||||||
[*]
|
|
||||||
indent_style = space
|
|
||||||
indent_size = 4
|
|
||||||
end_of_line = crlf
|
|
||||||
charset = utf-8
|
|
||||||
trim_trailing_whitespace = false
|
|
||||||
insert_final_newline = false
|
|
||||||
30
frontend/.gitignore
vendored
30
frontend/.gitignore
vendored
|
|
@ -1,30 +0,0 @@
|
||||||
# Logs
|
|
||||||
logs
|
|
||||||
*.log
|
|
||||||
npm-debug.log*
|
|
||||||
yarn-debug.log*
|
|
||||||
yarn-error.log*
|
|
||||||
pnpm-debug.log*
|
|
||||||
lerna-debug.log*
|
|
||||||
|
|
||||||
node_modules
|
|
||||||
.DS_Store
|
|
||||||
dist
|
|
||||||
dist-ssr
|
|
||||||
coverage
|
|
||||||
*.local
|
|
||||||
|
|
||||||
/cypress/videos/
|
|
||||||
/cypress/screenshots/
|
|
||||||
|
|
||||||
# Editor directories and files
|
|
||||||
.vscode/*
|
|
||||||
!.vscode/extensions.json
|
|
||||||
.idea
|
|
||||||
*.suo
|
|
||||||
*.ntvs*
|
|
||||||
*.njsproj
|
|
||||||
*.sln
|
|
||||||
*.sw?
|
|
||||||
|
|
||||||
*.tsbuildinfo
|
|
||||||
6
frontend/.vscode/extensions.json
vendored
6
frontend/.vscode/extensions.json
vendored
|
|
@ -1,6 +0,0 @@
|
||||||
{
|
|
||||||
"recommendations": [
|
|
||||||
"Vue.volar",
|
|
||||||
"vitest.explorer"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
@ -1,38 +0,0 @@
|
||||||
# Add Domain link
|
|
||||||
Open the src/api.js file and add your domain link to the apiLink variable.
|
|
||||||
|
|
||||||
# vue-project
|
|
||||||
|
|
||||||
This template should help get you started developing with Vue 3 in Vite.
|
|
||||||
|
|
||||||
## Recommended IDE Setup
|
|
||||||
|
|
||||||
[VSCode](https://code.visualstudio.com/) + [Volar](https://marketplace.visualstudio.com/items?itemName=Vue.volar) (and disable Vetur).
|
|
||||||
|
|
||||||
## Customize configuration
|
|
||||||
|
|
||||||
See [Vite Configuration Reference](https://vite.dev/config/).
|
|
||||||
|
|
||||||
## Project Setup
|
|
||||||
|
|
||||||
```sh
|
|
||||||
pnpm install
|
|
||||||
```
|
|
||||||
|
|
||||||
### Compile and Hot-Reload for Development
|
|
||||||
|
|
||||||
```sh
|
|
||||||
pnpm dev
|
|
||||||
```
|
|
||||||
|
|
||||||
### Compile and Minify for Production
|
|
||||||
|
|
||||||
```sh
|
|
||||||
pnpm build
|
|
||||||
```
|
|
||||||
|
|
||||||
### Run Unit Tests with [Vitest](https://vitest.dev/)
|
|
||||||
|
|
||||||
```sh
|
|
||||||
pnpm test:unit
|
|
||||||
```
|
|
||||||
|
|
@ -1,13 +0,0 @@
|
||||||
<!DOCTYPE html>
|
|
||||||
<html lang="" data-theme="dracula">
|
|
||||||
<head>
|
|
||||||
<meta charset="UTF-8">
|
|
||||||
<link rel="icon" href="/favicon.ico">
|
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
||||||
<title>LMS</title>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<div id="app"></div>
|
|
||||||
<script type="module" src="/src/main.js"></script>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
|
|
@ -1,8 +0,0 @@
|
||||||
{
|
|
||||||
"compilerOptions": {
|
|
||||||
"paths": {
|
|
||||||
"@/*": ["./src/*"]
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"exclude": ["node_modules", "dist"]
|
|
||||||
}
|
|
||||||
|
|
@ -1,34 +0,0 @@
|
||||||
{
|
|
||||||
"name": "vue-project",
|
|
||||||
"version": "0.0.0",
|
|
||||||
"private": true,
|
|
||||||
"type": "module",
|
|
||||||
"scripts": {
|
|
||||||
"dev": "vite",
|
|
||||||
"build": "vite build",
|
|
||||||
"preview": "vite preview",
|
|
||||||
"test:unit": "vitest"
|
|
||||||
},
|
|
||||||
"dependencies": {
|
|
||||||
"axios": "^1.7.9",
|
|
||||||
"shaka-player": "^4.12.8",
|
|
||||||
"sweetalert2": "^11.15.10",
|
|
||||||
"vue": "^3.5.13",
|
|
||||||
"vue-easy-lightbox": "^1.19.0",
|
|
||||||
"vue-i18n": "^11.0.1",
|
|
||||||
"vue-router": "^4.5.0"
|
|
||||||
},
|
|
||||||
"devDependencies": {
|
|
||||||
"@vitejs/plugin-vue": "^5.2.1",
|
|
||||||
"@vue/cli-plugin-pwa": "^5.0.8",
|
|
||||||
"@vue/test-utils": "^2.4.6",
|
|
||||||
"autoprefixer": "^10.4.20",
|
|
||||||
"daisyui": "^4.12.23",
|
|
||||||
"jsdom": "^25.0.1",
|
|
||||||
"postcss": "^8.4.49",
|
|
||||||
"tailwindcss": "^3.4.17",
|
|
||||||
"vite": "^6.0.5",
|
|
||||||
"vite-plugin-vue-devtools": "^7.6.8",
|
|
||||||
"vitest": "^2.1.8"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
10678
frontend/pnpm-lock.yaml
generated
10678
frontend/pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load diff
|
|
@ -1,6 +0,0 @@
|
||||||
export default {
|
|
||||||
plugins: {
|
|
||||||
tailwindcss: {},
|
|
||||||
autoprefixer: {},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
Binary file not shown.
|
Before Width: | Height: | Size: 4.2 KiB |
|
|
@ -1,34 +0,0 @@
|
||||||
<script setup>
|
|
||||||
import { reactive, provide } from "vue";
|
|
||||||
import { setLoadingHandler } from "@/api";
|
|
||||||
import Loading from "./components/Loading.vue";
|
|
||||||
|
|
||||||
const state = reactive({
|
|
||||||
isLoading: false, // حالة شاشة الانتظار
|
|
||||||
});
|
|
||||||
|
|
||||||
// وظيفة لتغيير حالة شاشة الانتظار
|
|
||||||
const setLoading = (status) => {
|
|
||||||
state.isLoading = status;
|
|
||||||
};
|
|
||||||
|
|
||||||
// ربط شاشة الانتظار مع axios
|
|
||||||
setLoadingHandler(setLoading);
|
|
||||||
|
|
||||||
// توفير الحالة للمكونات الفرعية إذا لزم الأمر
|
|
||||||
provide("isLoading", state.isLoading);
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<template>
|
|
||||||
<div id="app">
|
|
||||||
<Loading v-if="state.isLoading" />
|
|
||||||
|
|
||||||
<header class="bg-white dark:bg-gray-800 shadow-md"></header>
|
|
||||||
<main>
|
|
||||||
<RouterView />
|
|
||||||
</main>
|
|
||||||
</div>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<style scoped>
|
|
||||||
</style>
|
|
||||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Reference in a new issue