First commit
This commit is contained in:
commit
440f5a7df4
1563 changed files with 217996 additions and 0 deletions
0
courses/__init__.py
Normal file
0
courses/__init__.py
Normal file
16
courses/admin.py
Normal file
16
courses/admin.py
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
from django.contrib import admin
|
||||
from .models import *
|
||||
|
||||
# Register your models here.
|
||||
class CategoriesAdmin(admin.ModelAdmin):
|
||||
fieldsets = [
|
||||
('Nom', {'fields': ['name']}),
|
||||
('Description', {'fields': ['content']}),
|
||||
('Date de cr"ation', {'fields': ['created_at']}),
|
||||
]
|
||||
list_display = ('name', 'content', 'type')
|
||||
list_filter = ['type', 'name']
|
||||
search_fields = ['name', 'content']
|
||||
|
||||
admin.site.register(Course)
|
||||
admin.site.register(Lesson)
|
||||
6
courses/apps.py
Normal file
6
courses/apps.py
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class CoursesConfig(AppConfig):
|
||||
default_auto_field = 'django.db.models.BigAutoField'
|
||||
name = 'courses'
|
||||
5
courses/context_processors.py
Normal file
5
courses/context_processors.py
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
from .models import Course
|
||||
|
||||
def course_list(request):
|
||||
courses = Course.objects.all()
|
||||
return {'courses': courses}
|
||||
35
courses/migrations/0001_initial.py
Normal file
35
courses/migrations/0001_initial.py
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
# Generated by Django 5.0.6 on 2024-06-10 16:02
|
||||
|
||||
import django.db.models.deletion
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
initial = True
|
||||
|
||||
dependencies = [
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='Course',
|
||||
fields=[
|
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('name', models.CharField(max_length=200)),
|
||||
('content', models.TextField()),
|
||||
('created_at', models.DateTimeField(auto_now_add=True)),
|
||||
('updated_at', models.DateTimeField(auto_now=True)),
|
||||
],
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='Lesson',
|
||||
fields=[
|
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('name', models.CharField(max_length=200)),
|
||||
('content', models.TextField()),
|
||||
('order', models.PositiveIntegerField()),
|
||||
('course_id', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='lecons', to='courses.course')),
|
||||
],
|
||||
),
|
||||
]
|
||||
18
courses/migrations/0002_course_thumbnail.py
Normal file
18
courses/migrations/0002_course_thumbnail.py
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
# Generated by Django 5.0.6 on 2024-06-10 17:14
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('courses', '0001_initial'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='course',
|
||||
name='thumbnail',
|
||||
field=models.ImageField(default='default.jpg', upload_to='thumbnails/courses/'),
|
||||
),
|
||||
]
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
# Generated by Django 5.0.6 on 2024-06-11 07:51
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('courses', '0002_course_thumbnail'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='lesson',
|
||||
name='author',
|
||||
field=models.CharField(default=None, max_length=100),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='course',
|
||||
name='thumbnail',
|
||||
field=models.ImageField(default='default.jpg', upload_to='static/uploads/thumbnails/courses/'),
|
||||
),
|
||||
]
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
# Generated by Django 5.0.6 on 2024-06-11 08:26
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('courses', '0003_lesson_author_alter_course_thumbnail'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RemoveField(
|
||||
model_name='lesson',
|
||||
name='author',
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='course',
|
||||
name='author',
|
||||
field=models.CharField(default='Anthony Violet', max_length=100),
|
||||
),
|
||||
]
|
||||
18
courses/migrations/0005_rename_author_course_old_author.py
Normal file
18
courses/migrations/0005_rename_author_course_old_author.py
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
# Generated by Django 4.2.17 on 2024-12-14 10:12
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('courses', '0004_remove_lesson_author_course_author'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RenameField(
|
||||
model_name='course',
|
||||
old_name='author',
|
||||
new_name='old_author',
|
||||
),
|
||||
]
|
||||
21
courses/migrations/0006_course_author.py
Normal file
21
courses/migrations/0006_course_author.py
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
# Generated by Django 4.2.17 on 2024-12-14 10:13
|
||||
|
||||
from django.conf import settings
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
||||
('courses', '0005_rename_author_course_old_author'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='course',
|
||||
name='author',
|
||||
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL),
|
||||
),
|
||||
]
|
||||
21
courses/migrations/0007_convert_old_authors.py
Normal file
21
courses/migrations/0007_convert_old_authors.py
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
# Generated by Django 4.2.17 on 2024-12-14 10:13
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
def convert_old_authors(apps, schema_editor):
|
||||
Course = apps.get_model('courses', 'Course')
|
||||
User = apps.get_model('auth', 'User')
|
||||
default_user = User.objects.get(id=1)
|
||||
for course in Course.objects.all():
|
||||
course.author = default_user
|
||||
course.save()
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('courses', '0006_course_author'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RunPython(convert_old_authors),
|
||||
]
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
# Generated by Django 4.2.17 on 2024-12-14 10:16
|
||||
|
||||
from django.conf import settings
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
||||
('courses', '0007_convert_old_authors'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RemoveField(
|
||||
model_name='course',
|
||||
name='old_author',
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='course',
|
||||
name='author',
|
||||
field=models.ForeignKey(default=1, on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL),
|
||||
preserve_default=False,
|
||||
),
|
||||
]
|
||||
0
courses/migrations/__init__.py
Normal file
0
courses/migrations/__init__.py
Normal file
29
courses/models.py
Normal file
29
courses/models.py
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
from django.db import models
|
||||
from django.contrib.auth.models import User
|
||||
from django.utils.html import escape
|
||||
|
||||
class Course(models.Model):
|
||||
name = models.CharField(max_length=200)
|
||||
content = models.TextField()
|
||||
author = models.ForeignKey(User, on_delete=models.CASCADE)
|
||||
thumbnail = models.ImageField(upload_to='static/uploads/thumbnails/courses/', default='default.jpg')
|
||||
created_at = models.DateTimeField(auto_now_add=True)
|
||||
updated_at = models.DateTimeField(auto_now=True)
|
||||
|
||||
def __str__(self):
|
||||
return self.name
|
||||
|
||||
class Lesson(models.Model):
|
||||
course_id = models.ForeignKey(Course, on_delete=models.CASCADE, related_name='lecons')
|
||||
name = models.CharField(max_length=200)
|
||||
content = models.TextField()
|
||||
order = models.PositiveIntegerField()
|
||||
|
||||
def clean(self):
|
||||
# Remplacer les chevrons <?php et ?> par leurs équivalents HTML
|
||||
if self.content:
|
||||
self.content = self.content.replace('<?php', '<?php')
|
||||
self.content = self.content.replace('?>', '?>')
|
||||
|
||||
def __str__(self):
|
||||
return self.name
|
||||
3
courses/tests.py
Normal file
3
courses/tests.py
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
||||
8
courses/urls.py
Normal file
8
courses/urls.py
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
from django.urls import path
|
||||
from . import views
|
||||
|
||||
app_name = 'courses'
|
||||
urlpatterns = [
|
||||
path('', views.list, name='list'),
|
||||
path('<int:course_id>-<slug:course_name>/', views.show, name="show"),
|
||||
]
|
||||
12
courses/views.py
Normal file
12
courses/views.py
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
from django.shortcuts import render, get_object_or_404
|
||||
from django.views import generic
|
||||
from .models import Course, Lesson
|
||||
|
||||
def list(request):
|
||||
courses = Course.objects.all()
|
||||
return render(request, 'courses/list.html', {'courses': courses})
|
||||
|
||||
def show(request, course_name, course_id):
|
||||
course = get_object_or_404(Course, pk=course_id)
|
||||
lessons = Lesson.objects.filter(course_id=course_id)
|
||||
return render(request, 'courses/show.html', {'course' : course, 'lessons': lessons})
|
||||
Loading…
Add table
Add a link
Reference in a new issue