diff --git a/core/migrations/0002_auto_20160930_0124.py b/core/migrations/0002_auto_20160930_0124.py new file mode 100644 index 0000000..49d8270 --- /dev/null +++ b/core/migrations/0002_auto_20160930_0124.py @@ -0,0 +1,21 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10 on 2016-09-30 04:24 +from __future__ import unicode_literals + +import autoslug.fields +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('core', '0001_initial'), + ] + + operations = [ + migrations.AlterField( + model_name='resource', + name='slug', + field=autoslug.fields.AutoSlugField(editable=False, populate_from='name', unique=True, verbose_name='Slug'), + ), + ] diff --git a/courses/migrations/0002_auto_20160930_0124.py b/courses/migrations/0002_auto_20160930_0124.py new file mode 100644 index 0000000..4f0d660 --- /dev/null +++ b/courses/migrations/0002_auto_20160930_0124.py @@ -0,0 +1,56 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10 on 2016-09-30 04:24 +from __future__ import unicode_literals + +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', '0001_initial'), + ] + + operations = [ + migrations.RemoveField( + model_name='activity', + name='student', + ), + migrations.RemoveField( + model_name='material', + name='student', + ), + migrations.AddField( + model_name='activity', + name='all_students', + field=models.BooleanField(default=False, verbose_name='All Students'), + ), + migrations.AddField( + model_name='activity', + name='students', + field=models.ManyToManyField(related_name='activities', to=settings.AUTH_USER_MODEL, verbose_name='Students'), + ), + migrations.AddField( + model_name='material', + name='all_students', + field=models.BooleanField(default=False, verbose_name='All Students'), + ), + migrations.AddField( + model_name='material', + name='students', + field=models.ManyToManyField(related_name='materials', to=settings.AUTH_USER_MODEL, verbose_name='Students'), + ), + migrations.AlterField( + model_name='activity', + name='topic', + field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='activities', to='courses.Topic', verbose_name='Topic'), + ), + migrations.AlterField( + model_name='material', + name='topic', + field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='materials', to='courses.Topic', verbose_name='Topic'), + ), + ] diff --git a/courses/models.py b/courses/models.py index 3bce277..82e4c97 100644 --- a/courses/models.py +++ b/courses/models.py @@ -88,17 +88,19 @@ It is one kind of possible resources available inside a Topic. Activity is something that has a deadline and has to be delivered by the student """ class Activity(Resource): - topic = models.ForeignKey(Topic, verbose_name = _('Topic')) + topic = models.ForeignKey(Topic, verbose_name = _('Topic'), related_name='activities') limit_date = models.DateTimeField(_('Deliver Date')) - student = models.ForeignKey(User, verbose_name = _('student')) + students = models.ManyToManyField(User, verbose_name = _('Students'), related_name='activities') + all_students = models.BooleanField(_('All Students'), default=False) """ It represents any Material inside a topic, be it a file, a link, etc. """ class Material(Resource): - topic = models.ForeignKey(Topic, verbose_name = _('Topic')) - student = models.ForeignKey(User, verbose_name = _('student')) + topic = models.ForeignKey(Topic, verbose_name = _('Topic'), related_name='materials') + students = models.ManyToManyField(User, verbose_name = _('Students'), related_name='materials') + all_students = models.BooleanField(_('All Students'), default=False) """ It is a category for each subject. @@ -112,4 +114,3 @@ class SubjectCategory(models.Model): class Meta: verbose_name = _('subject category') verbose_name_plural = _('subject categories') - diff --git a/poll/forms.py b/poll/forms.py index 570d90d..3478cd4 100644 --- a/poll/forms.py +++ b/poll/forms.py @@ -5,18 +5,31 @@ from .models import Poll class PollForm(forms.ModelForm): - # password = forms.CharField(label=_('Password'), widget=forms.PasswordInput) - # password2 = forms.CharField(label = _('Password confirmation'), widget = forms.PasswordInput) - # birth_date = forms.DateField(widget=forms.SelectDateWidget()) - # MIN_LENGTH = 8 + def __init__(self, *args, **kwargs): + super(PollForm, self).__init__(*args, **kwargs) + self.fields["all_students"].required = False + self.fields["all_students"].initial = False + self.fields["students"].required = False + + def clean_all_students(self): + if('all_students' not in self.data): + if('students' in self.data): + return False + raise forms.ValidationError(_('It is required one these fields.')) + else: + all_students = self.data['all_students'] + if(not all_students): + raise forms.ValidationError(_('It is required one these fields.')) + return True + class Meta: model = Poll - # exclude = ['is_staff', 'is_active'] - fields = ['name','limit_date'] + fields = ['name','limit_date','students','all_students'] widgets = { 'name': forms.TextInput(attrs={'placeholder': 'Question?'}), - 'description': forms.DateTimeInput( + 'limit_date': forms.DateTimeInput( attrs={'placeholder': 'Maximum date permited to resolve the poll'}), + 'student': forms.Select(), } diff --git a/poll/migrations/0002_remove_poll_question.py b/poll/migrations/0002_remove_poll_question.py new file mode 100644 index 0000000..b4f9a20 --- /dev/null +++ b/poll/migrations/0002_remove_poll_question.py @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10 on 2016-09-30 04:24 +from __future__ import unicode_literals + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('poll', '0001_initial'), + ] + + operations = [ + migrations.RemoveField( + model_name='poll', + name='question', + ), + ] diff --git a/poll/models.py b/poll/models.py index 0a35b3a..b022aef 100644 --- a/poll/models.py +++ b/poll/models.py @@ -6,7 +6,6 @@ from core.models import Resource from courses.models import Activity class Poll(Activity): - question = models.CharField(_('Question'), max_length = 300) class Meta: #ordering = ('create_date','name') diff --git a/poll/templates/poll/create_update.html b/poll/templates/poll/create_update.html index 24ecfbe..e2a9e64 100644 --- a/poll/templates/poll/create_update.html +++ b/poll/templates/poll/create_update.html @@ -93,7 +93,9 @@