Commit f002d8eb authored by Bruno Martin's avatar Bruno Martin
Browse files

initial version rewrite from timtec codebase

parent fa481e35
from course_material.models import CourseMaterial, File
from django.contrib import admin
class FileInline(admin.TabularInline):
model = File
extra = 1
class CourseMaterialAdmin(admin.ModelAdmin):
search_fields = ('text',)
list_display = ('course', 'text')
inlines = [
FileInline,
]
class FileAdmin(admin.ModelAdmin):
search_fields = ('file',)
list_display = ('file', 'course_material')
admin.site.register(CourseMaterial, CourseMaterialAdmin)
admin.site.register(File, FileAdmin)
from django.db import models
from django.utils.translation import ugettext_lazy as _
from django.utils.text import slugify
from courses.models import Course
class CourseMaterial(models.Model):
course = models.OneToOneField(
Course,
models.CASCADE,
related_name='course_material',
verbose_name=_('Course Materials'),
)
text = models.TextField(
_('Question'),
)
class Meta:
unique_together = ("id", "course")
def __unicode__(self):
return self.course.name
def get_upload_path(instance, filename):
filename, fileextension = filename.split(".", 2)
filename = slugify(filename.split("/", 2)[-1])
return '{0}/course_materials/{1}.{2}'.format(instance.course_material.course.slug, filename, fileextension)
class File(models.Model):
# title = models.CharField(_('Title'), max_length=255)
file = models.FileField(
upload_to=get_upload_path,
)
course_material = models.ForeignKey(
CourseMaterial, models.CASCADE,
related_name='files',
verbose_name=_('Files'),
)
# Generated by Django 2.1.7 on 2019-03-07 23:22
import autoslug.fields
import courses.course_material.models
import courses.utils
from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion
import django.utils.timezone
class Migration(migrations.Migration):
initial = True
dependencies = [
('contenttypes', '0002_remove_content_type_name'),
('auth', '0009_alter_user_last_name_max_length'),
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]
operations = [
migrations.CreateModel(
name='Class',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=255)),
('user_can_certificate', models.BooleanField(default=False, verbose_name='Certification Allowed')),
('user_can_certificate_even_without_progress', models.BooleanField(default=False, verbose_name='Certification Allowed Even Without Progress')),
('assistants', models.ManyToManyField(blank=True, related_name='professor_classes', to=settings.AUTH_USER_MODEL, verbose_name='Assistants')),
],
),
migrations.CreateModel(
name='Course',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('slug', models.SlugField(max_length=255, unique=True, verbose_name='Slug')),
('name', models.CharField(blank=True, max_length=255, verbose_name='Name')),
('application', models.TextField(blank=True, verbose_name='Application')),
('requirement', models.TextField(blank=True, verbose_name='Requirement')),
('abstract', models.TextField(blank=True, verbose_name='Abstract')),
('structure', models.TextField(blank=True, verbose_name='Structure')),
('workload', models.TextField(blank=True, verbose_name='Workload')),
('pronatec', models.TextField(blank=True, verbose_name='Pronatec')),
('status', models.CharField(choices=[('draft', 'Draft'), ('published', 'Published')], default='draft', max_length=64, verbose_name='Status')),
('thumbnail', models.ImageField(blank=True, null=True, upload_to=courses.utils.HashName('course_thumbnails', 'name'), verbose_name='Thumbnail')),
('home_thumbnail', models.ImageField(blank=True, null=True, upload_to=courses.utils.HashName('home_thumbnails', 'name'), verbose_name='Home thumbnail')),
('home_position', models.IntegerField(blank=True, null=True)),
('start_date', models.DateField(blank=True, default=None, null=True, verbose_name='Start date')),
('home_published', models.BooleanField(default=False)),
('min_percent_to_complete', models.IntegerField(blank=True, default=100, null=True)),
],
options={
'verbose_name': 'Course',
'verbose_name_plural': 'Courses',
},
),
migrations.CreateModel(
name='CourseAuthor',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('biography', models.TextField(blank=True, null=True, verbose_name='Biography')),
('picture', models.ImageField(blank=True, null=True, upload_to=courses.utils.HashName('bio-pictures', 'name'), verbose_name='Picture')),
('name', models.TextField(blank=True, max_length=30, null=True, verbose_name='Name')),
('position', models.IntegerField(blank=True, default=100, null=True)),
('course', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='course_authors', to='courses.Course', verbose_name='Course')),
('user', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='authoring_courses', to=settings.AUTH_USER_MODEL, verbose_name='Professor')),
],
options={
'verbose_name': 'Course Author',
'verbose_name_plural': 'Course Authors',
'ordering': ['position'],
},
),
migrations.CreateModel(
name='CourseMaterial',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('text', models.TextField(verbose_name='Question')),
('course', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, related_name='course_material', to='courses.Course', verbose_name='Course Materials')),
],
),
migrations.CreateModel(
name='CourseProfessor',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('biography', models.TextField(blank=True, null=True, verbose_name='Biography')),
('role', models.CharField(choices=[('instructor', 'Instructor'), ('assistant', 'Assistant'), ('coordinator', 'Professor Coordinator')], default='assistant', max_length=128, verbose_name='Role')),
('picture', models.ImageField(blank=True, null=True, upload_to=courses.utils.HashName('bio-pictures', 'name'), verbose_name='Picture')),
('name', models.TextField(blank=True, max_length=30, null=True, verbose_name='Name')),
('is_course_author', models.BooleanField(default=False)),
('course', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='course_professors', to='courses.Course', verbose_name='Course')),
('user', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='teaching_courses', to=settings.AUTH_USER_MODEL, verbose_name='Professor')),
],
options={
'verbose_name': 'Course Professor',
'verbose_name_plural': 'Course Professors',
},
),
migrations.CreateModel(
name='CourseStudent',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('start_date', models.DateTimeField(default=django.utils.timezone.now)),
('course', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='courses.Course', verbose_name='Course')),
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL, verbose_name='Student')),
],
options={
'ordering': ['course__start_date'],
},
),
migrations.CreateModel(
name='EmailTemplate',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=255)),
('subject', models.CharField(max_length=255)),
('template', models.TextField()),
],
),
migrations.CreateModel(
name='File',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('file', models.FileField(upload_to=courses.course_material.models.get_upload_path)),
('course_material', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='files', to='courses.CourseMaterial', verbose_name='Files')),
],
),
migrations.CreateModel(
name='Lesson',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('desc', models.TextField(verbose_name='Description')),
('name', models.CharField(max_length=255, verbose_name='Name')),
('notes', models.TextField(blank=True, default='', verbose_name='Notes')),
('position', models.IntegerField(default=0)),
('slug', autoslug.fields.AutoSlugField(editable=False, max_length=128, populate_from='name', unique=True, verbose_name='Slug')),
('status', models.CharField(choices=[('draft', 'Draft'), ('published', 'Published')], default='draft', max_length=64, verbose_name='Status')),
('course', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='lessons', to='courses.Course', verbose_name='Course')),
],
options={
'verbose_name': 'Lesson',
'verbose_name_plural': 'Lessons',
'ordering': ['position'],
},
),
migrations.CreateModel(
name='Note',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('text', models.TextField(verbose_name='Note')),
('create_timestamp', models.DateTimeField(auto_now_add=True)),
('last_edit_timestamp', models.DateTimeField(auto_now=True)),
('object_id', models.PositiveIntegerField()),
('content_type', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='contenttypes.ContentType')),
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL, verbose_name='User')),
],
),
migrations.CreateModel(
name='ProfessorMessage',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('subject', models.CharField(max_length=255, verbose_name='Subject')),
('message', models.TextField(verbose_name='Message')),
('date', models.DateTimeField(auto_now_add=True, verbose_name='Date')),
('course', models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='courses.Course', verbose_name='Course')),
('professor', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to=settings.AUTH_USER_MODEL, verbose_name='Professor')),
('users', models.ManyToManyField(related_name='messages', to=settings.AUTH_USER_MODEL)),
],
),
migrations.CreateModel(
name='ProfessorMessageRead',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('is_read', models.BooleanField(default=False)),
('message', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='read_status', to='courses.ProfessorMessage', verbose_name='ProfessorMessage')),
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL, verbose_name='Student')),
],
),
migrations.CreateModel(
name='StudentProgress',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('complete', models.DateTimeField(blank=True, null=True)),
('last_access', models.DateTimeField(auto_now=True)),
],
options={
'verbose_name': 'Student Progress',
},
),
migrations.CreateModel(
name='Unit',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('title', models.CharField(blank=True, max_length=128, verbose_name='Title')),
('side_notes', models.TextField(blank=True, verbose_name='Side notes')),
('position', models.IntegerField(default=0)),
('chat_room', models.CharField(blank=True, max_length=255, null=True, verbose_name='Chat Room')),
('lesson', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='units', to='courses.Lesson', verbose_name='Lesson')),
],
options={
'verbose_name': 'Unit',
'verbose_name_plural': 'Units',
'ordering': ['lesson', 'position'],
},
),
migrations.CreateModel(
name='Video',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=255)),
('youtube_id', models.CharField(max_length=100)),
],
options={
'verbose_name': 'Video',
'verbose_name_plural': 'Videos',
},
),
migrations.AddField(
model_name='unit',
name='video',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='unit', to='courses.Video', verbose_name='Video'),
),
migrations.AddField(
model_name='studentprogress',
name='unit',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='progress', to='courses.Unit', verbose_name='Unit'),
),
migrations.AddField(
model_name='studentprogress',
name='user',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL, verbose_name='Student'),
),
migrations.AddField(
model_name='course',
name='authors',
field=models.ManyToManyField(related_name='authorcourses', through='courses.CourseAuthor', to=settings.AUTH_USER_MODEL),
),
migrations.AddField(
model_name='course',
name='default_class',
field=models.OneToOneField(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='default_course', to='courses.Class', verbose_name='Default Class'),
),
migrations.AddField(
model_name='course',
name='groups',
field=models.ManyToManyField(blank=True, help_text='The Groups that can have access to this forum. If empty, there are no group restrictions.', related_name='courses', to='auth.Group', verbose_name='groups'),
),
migrations.AddField(
model_name='course',
name='intro_video',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='courses.Video', verbose_name='Intro video'),
),
migrations.AddField(
model_name='course',
name='professors',
field=models.ManyToManyField(related_name='professorcourse_set', through='courses.CourseProfessor', to=settings.AUTH_USER_MODEL),
),
migrations.AddField(
model_name='course',
name='students',
field=models.ManyToManyField(related_name='studentcourse_set', through='courses.CourseStudent', to=settings.AUTH_USER_MODEL),
),
migrations.AddField(
model_name='class',
name='course',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='courses.Course', verbose_name='Course'),
),
migrations.AddField(
model_name='class',
name='students',
field=models.ManyToManyField(blank=True, related_name='classes', to=settings.AUTH_USER_MODEL),
),
migrations.AlterUniqueTogether(
name='studentprogress',
unique_together={('user', 'unit')},
),
migrations.AlterUniqueTogether(
name='professormessageread',
unique_together={('user', 'message')},
),
migrations.AlterUniqueTogether(
name='coursestudent',
unique_together={('user', 'course')},
),
migrations.AlterUniqueTogether(
name='courseprofessor',
unique_together={('user', 'course')},
),
migrations.AlterUniqueTogether(
name='coursematerial',
unique_together={('id', 'course')},
),
migrations.AlterUniqueTogether(
name='courseauthor',
unique_together={('user', 'course')},
),
]
This diff is collapsed.
# -*- coding: utf-8 -*-
from django.contrib import admin
from notes.models import Note
class NoteAdmin(admin.ModelAdmin):
search_fields = ('text', 'user__username', 'user__first_name', 'user__last_name', 'user__email')
list_display = ('text', 'user', 'create_timestamp', 'last_edit_timestamp')
admin.site.register(Note, NoteAdmin)
from django.db import models
from django.contrib.contenttypes.models import ContentType
from django.contrib.contenttypes.fields import GenericForeignKey
from django.utils.translation import ugettext_lazy as _
from django.conf import settings
class Note(models.Model):
text = models.TextField(
_('Note'),
)
user = models.ForeignKey(
settings.AUTH_USER_MODEL,
models.CASCADE,
verbose_name=_('User'),
)
create_timestamp = models.DateTimeField(
auto_now_add=True,
editable=False,
)
last_edit_timestamp = models.DateTimeField(
auto_now=True,
editable=False,
)
content_type = models.ForeignKey(
ContentType,
models.CASCADE,
)
object_id = models.PositiveIntegerField()
content_object = GenericForeignKey(
'content_type',
'object_id',
)
{% comment %}
As the developer of this package, don't place anything here if you can help it
since this allows developers to have interoperability between your template
structure and their own.
Example: Developer melding the 2SoD pattern to fit inside with another pattern::
{% extends "base.html" %}
{% load static %}
<!-- Their site uses old school block layout -->
{% block extra_js %}
<!-- Your package using 2SoD block layout -->
{% block javascript %}
<script src="{% static 'js/ninja.js' %}" type="text/javascript"></script>
{% endblock javascript %}
{% endblock extra_js %}
{% endcomment %}
import os
import hashlib
from django.utils.deconstruct import deconstructible
@deconstructible
class HashName(object):
def __init__(self, path, attr):
self.path = path
self.attr = attr
def __call__(self, instance, filename):
root, ext = os.path.splitext(filename)
m = hashlib.md5()
m.update(root.encode('utf-8'))
name = getattr(instance, self.attr)
if name:
m.update(name.encode('utf-8'))
filename = m.hexdigest() + ext
# return the whole path to the file
return os.path.join(self.path, filename)
hash_name = HashName
from django.db import models
from django.utils.translation import ugettext_lazy as _
class Video(models.Model):
name = models.CharField(
max_length=255,
)
youtube_id = models.CharField(
max_length=100,
)
class Meta:
verbose_name = _('Video')
verbose_name_plural = _('Videos')
def __unicode__(self):
if self.unit.first():
unit = self.unit.first()
if unit.lesson:
return u'Aula: {0} | Unidade: {1} | id youtube: {2}'.format(
unit.lesson, unit, self.youtube_id)
return self.youtube_id
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment