Commit 2aee4eaf7eb698123c6e2e525622f4e32d051e2f
1 parent
3f4e379a
Exists in
master
and in
3 other branches
when I create or update a subject, if the category is not visibile, the subject won't be
Showing
10 changed files
with
150 additions
and
6 deletions
Show diff stats
subjects/forms.py
... | ... | @@ -5,8 +5,7 @@ class CreateSubjectForm(forms.ModelForm): |
5 | 5 | class Meta: |
6 | 6 | model = Subject |
7 | 7 | |
8 | - fields = ('name', 'description_brief', 'description', 'tags', 'init_date', 'end_date', 'visible', 'professor', | |
9 | - 'students', ) | |
8 | + fields = ('name', 'description_brief', 'description', 'tags', 'init_date', 'end_date', 'visible', 'professor', 'students', ) | |
10 | 9 | |
11 | 10 | widgets = { |
12 | 11 | 'description_brief': forms.Textarea, | ... | ... |
... | ... | @@ -0,0 +1,27 @@ |
1 | +# -*- coding: utf-8 -*- | |
2 | +# Generated by Django 1.10.4 on 2017-01-10 02:04 | |
3 | +from __future__ import unicode_literals | |
4 | + | |
5 | +from django.db import migrations, models | |
6 | + | |
7 | + | |
8 | +class Migration(migrations.Migration): | |
9 | + | |
10 | + dependencies = [ | |
11 | + ('subjects', '0009_auto_20170105_1835'), | |
12 | + ] | |
13 | + | |
14 | + operations = [ | |
15 | + migrations.AddField( | |
16 | + model_name='subject', | |
17 | + name='subscribe_begin', | |
18 | + field=models.DateTimeField(default=1, verbose_name='Begin Subscribe'), | |
19 | + preserve_default=False, | |
20 | + ), | |
21 | + migrations.AddField( | |
22 | + model_name='subject', | |
23 | + name='subscribe_end', | |
24 | + field=models.DateTimeField(default=1, verbose_name='End Subscribe'), | |
25 | + preserve_default=False, | |
26 | + ), | |
27 | + ] | ... | ... |
... | ... | @@ -0,0 +1,26 @@ |
1 | +# -*- coding: utf-8 -*- | |
2 | +# Generated by Django 1.10.4 on 2017-01-10 02:08 | |
3 | +from __future__ import unicode_literals | |
4 | + | |
5 | +import datetime | |
6 | +from django.db import migrations, models | |
7 | + | |
8 | + | |
9 | +class Migration(migrations.Migration): | |
10 | + | |
11 | + dependencies = [ | |
12 | + ('subjects', '0010_auto_20170109_2304'), | |
13 | + ] | |
14 | + | |
15 | + operations = [ | |
16 | + migrations.AlterField( | |
17 | + model_name='subject', | |
18 | + name='subscribe_begin', | |
19 | + field=models.DateTimeField(default=datetime.datetime.now, verbose_name='Begin Subscribe'), | |
20 | + ), | |
21 | + migrations.AlterField( | |
22 | + model_name='subject', | |
23 | + name='subscribe_end', | |
24 | + field=models.DateTimeField(default=datetime.datetime.now, verbose_name='End Subscribe'), | |
25 | + ), | |
26 | + ] | ... | ... |
... | ... | @@ -0,0 +1,25 @@ |
1 | +# -*- coding: utf-8 -*- | |
2 | +# Generated by Django 1.10.4 on 2017-01-10 02:12 | |
3 | +from __future__ import unicode_literals | |
4 | + | |
5 | +from django.db import migrations, models | |
6 | + | |
7 | + | |
8 | +class Migration(migrations.Migration): | |
9 | + | |
10 | + dependencies = [ | |
11 | + ('subjects', '0011_auto_20170109_2308'), | |
12 | + ] | |
13 | + | |
14 | + operations = [ | |
15 | + migrations.AlterField( | |
16 | + model_name='subject', | |
17 | + name='subscribe_begin', | |
18 | + field=models.DateTimeField(verbose_name='Begin Subscribe'), | |
19 | + ), | |
20 | + migrations.AlterField( | |
21 | + model_name='subject', | |
22 | + name='subscribe_end', | |
23 | + field=models.DateTimeField(verbose_name='End Subscribe'), | |
24 | + ), | |
25 | + ] | ... | ... |
subjects/models.py
... | ... | @@ -7,7 +7,7 @@ from django.utils.translation import ugettext_lazy as _ |
7 | 7 | from users.models import User |
8 | 8 | |
9 | 9 | from categories.models import Category |
10 | - | |
10 | +import datetime | |
11 | 11 | class Tag(models.Model): |
12 | 12 | name = models.CharField( _("Name"), unique = True,max_length= 200) |
13 | 13 | def __str__(self): |
... | ... | @@ -30,6 +30,9 @@ class Subject(models.Model): |
30 | 30 | create_date = models.DateTimeField(_('Creation Date'), auto_now_add = True) |
31 | 31 | update_date = models.DateTimeField(_('Date of last update'), auto_now=True) |
32 | 32 | |
33 | + #subscribe_begin = models.DateTimeField(_('Begin Subscribe')) | |
34 | + #subscribe_end = models.DateTimeField(_('End Subscribe')) | |
35 | + | |
33 | 36 | professor = models.ManyToManyField(User, related_name="professors", blank=True) |
34 | 37 | students = models.ManyToManyField(User,verbose_name=_('Students'), related_name='subject_student', blank = True) |
35 | 38 | ... | ... |
... | ... | @@ -0,0 +1,19 @@ |
1 | +/* | |
2 | +Function to open modal for subscribing to subject | |
3 | +**/ | |
4 | + | |
5 | +var open_modal = { | |
6 | + get: function(url, id_modal, id_div_modal){ | |
7 | + $.get(url, function(data){ | |
8 | + if($(id_modal).exists()){ //So we check if does exist such modal | |
9 | + $(id_div_modal).empty(); | |
10 | + $(id_div_modal).append(data); | |
11 | + }else{ | |
12 | + $(id_div_modal).append(data); | |
13 | + } | |
14 | + $(id_modal).modal('show'); | |
15 | + }); | |
16 | + } | |
17 | +} | |
18 | + | |
19 | + | ... | ... |
subjects/templates/subjects/subject_card.html
1 | 1 | {% load static i18n permission_tags %} |
2 | 2 | {% if subject.visible %} |
3 | + | |
4 | + | |
5 | + | |
6 | + | |
7 | +<script type="text/javascript" src="{% static "subjects/js/subjects_card.js" %} "></script> | |
8 | + | |
3 | 9 | <div class="panel panel-info subject-panel"> |
4 | 10 | <div class="panel-heading"> |
5 | 11 | |
... | ... | @@ -56,7 +62,7 @@ |
56 | 62 | {% if request.user in subject.students.all or request.user in subject.professor.all or request.user.is_staff or request.user in category.coordinators.all %} |
57 | 63 | <a href="#"><button class="access-subject"> {% trans "Access Subject" %}</button></a> |
58 | 64 | {% else %} |
59 | - <a href="#"><button class="subscribe-subject"> {% trans "Subscribe to Subject" %}</button></a> | |
65 | + <a href=""><button class="subscribe-subject"> {% trans "Subscribe to Subject" %}</button></a> | |
60 | 66 | {% endif %} |
61 | 67 | </div> |
62 | 68 | </div> | ... | ... |
... | ... | @@ -0,0 +1,24 @@ |
1 | +{% load static i18n permission_tags %} | |
2 | + | |
3 | +<!-- Modal (remember to change the ids!!!) --> | |
4 | +<div class="modal fade" id="subscribe_modal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"> | |
5 | + <div class="modal-dialog" role="document"> | |
6 | + <div class="modal-content"> | |
7 | + <!-- Modal Body --> | |
8 | + <div class="modal-body"> | |
9 | + <!-- Put ONLY your content here!!! --> | |
10 | + <form id="modal_form" action="{% url 'subjects:subscribe' subject.slug %}" method="post"> | |
11 | + {% csrf_token %} | |
12 | + <p>{% trans 'Are you sure you want to subscribe to this subject' %} "{{subject.name}}"?</p> | |
13 | + </form> | |
14 | + </div> | |
15 | + <!-- Modal Footer --> | |
16 | + <div id="delete-category-footer"class="modal-footer"> | |
17 | + <!-- Don't remove that!!! --> | |
18 | + <button type="button" class="btn btn-default btn-raised" data-dismiss="modal">{% trans "Close" %}</button> | |
19 | + <button type="submit" id="button" form="delete_form" class="btn btn-primary btn-raised erase-button">{% trans "Subcribe" %}</button> | |
20 | + | |
21 | + </div> | |
22 | + </div> | |
23 | + </div> | |
24 | +</div> | |
0 | 25 | \ No newline at end of file | ... | ... |
subjects/urls.py
... | ... | @@ -8,4 +8,5 @@ urlpatterns = [ |
8 | 8 | url(r'^create/(?P<slug>[\w_-]+)/$', views.SubjectCreateView.as_view(), name='create'), |
9 | 9 | url(r'^replicate/(?P<subject_slug>[\w_-]+)/$', views.SubjectCreateView.as_view(), name='replicate'), |
10 | 10 | url(r'^update/(?P<slug>[\w_-]+)/$', views.SubjectUpdateView.as_view(), name='update'), |
11 | + #url(r'^modal/(?P<subject_slug>[\w_-]+)/$', views.subscribe_subject(), name='subscribe'), | |
11 | 12 | ] |
12 | 13 | \ No newline at end of file | ... | ... |
subjects/views.py
... | ... | @@ -169,7 +169,9 @@ class SubjectCreateView(CreateView): |
169 | 169 | return super(SubjectCreateView, self).form_valid(form) |
170 | 170 | |
171 | 171 | def get_success_url(self): |
172 | - | |
172 | + if not self.object.category.visible: | |
173 | + self.object.visible = False | |
174 | + self.object.save() | |
173 | 175 | |
174 | 176 | messages.success(self.request, _('Subject "%s" was registered on "%s" successfully!')%(self.object.name, self.object.category.name )) |
175 | 177 | return reverse_lazy('subjects:index') |
... | ... | @@ -193,8 +195,20 @@ class SubjectUpdateView(LogMixin, UpdateView): |
193 | 195 | return context |
194 | 196 | |
195 | 197 | def get_success_url(self): |
196 | - | |
198 | + if not self.object.category.visible: | |
199 | + self.object.visible = False | |
200 | + self.object.save() | |
197 | 201 | |
198 | 202 | messages.success(self.request, _('Subject "%s" was updated on "%s" successfully!')%(self.object.name, self.object.category.name )) |
199 | 203 | return reverse_lazy('subjects:index') |
200 | 204 | |
205 | + | |
206 | +def subscribe_subject(request, subject_slug): | |
207 | + subject = get_object_or_404(Subject, slug= subject_slug) | |
208 | + subject.students.add(request.user) | |
209 | + subject.save() | |
210 | + | |
211 | + messages.success(self.request, _('Subcribed "%s" was updated on "%s" successfully!')%(self.object.name, self.object.category.name )) | |
212 | + return reverse_lazy('subjects:index') | |
213 | + | |
214 | + | ... | ... |