Commit 54c3e1be7a6039e9092b23825209815468719910

Authored by filipecmedeiros
1 parent e71c793f

[Issue #361]

courses/templates/subject/replicate.html
... ... @@ -2,61 +2,51 @@
2 2  
3 3 {% load static i18n permission_tags widget_tweaks %}
4 4  
5   -{% block breadcrumbs %}
6   - <ol class="breadcrumb">
7   - <li><a href="{% url 'app:index' %}">{% trans 'Home' %}</a></li>
8   - <li class="active">{% trans 'Replicate Subject' %}</li>
9   - </ol>
10   -{% endblock %}
11   -
12 5 {% block content %}
13   -<div class="panel panel-default">
  6 +
  7 + <div class="panel panel-default">
14 8 <div class="panel-body">
15 9 <form class="form-group " method="post" action="">
16 10 {% csrf_token %}
17 11  
18 12 <div class="form-group {% if subject.name.errors %} has-error{% endif %}">
19   - <label for="{{ id_name }}" class="control-label label-static"> {% trans 'Name' %}</label>
20   - <input class="form-control" id="id_name" maxlength="100" name="name" type="text" required="True" value="{{subject.name}}">
21   - <span class="help-block">{% trans 'Subject name' %}</span>
  13 + <label for="id_name" class="control-label label-static"> {% trans 'Name'%}</label>
  14 + <textarea class="form-control" id="id_name" maxlength="100" rows="1" name="name" placeholder="Name" type="text" required >{{subject.name}}</textarea>
22 15  
  16 + <span class="help-block">{% trans 'Subject name'%}</span>
23 17 </div>
24 18  
25   - <div class="form-group {% if subject.name.errors %} has-error{% endif %}">
26   - <label for="{{ id_description }}" class="control-label label-static"> {% trans 'Description' %} </label>
27   - <textarea class="form-control" id="id_description" name="description" type="text" required="">{{subject.description}}</textarea>
28   - <span class="help-block">{% trans 'Subject Description' %}</span>
  19 + <div class="form-group">
  20 + <label for="id_description" class="control-label label-static"> {% trans 'Description'%}</label>
  21 + <textarea class="form-control" id="id_description" name="description" placeholder="Description" type="text" >{{subject.description}}</textarea>
29 22  
  23 + <span class="help-block">{% trans 'Subject description'%}</span>
30 24 </div>
31 25  
32   - <div class="form-group {% if subject.name.errors %} has-error{% endif %}">
33   - <label for="{{ id_init_date }}" class="control-label label-static"> {% trans 'Init date' %}</label>
34   - <input type="text" class="form-control date-picker" name="{{field.name}}" value="{{field.value|date:'SHORT_DA E_FORMAT'}}" min="{{now|date:'SHORT_DATE_FORMAT'}}">
35   - <span class="help-block">{% trans 'Subject init date' %}</span>
  26 + <div class="form-group">
  27 + <label for="id_init_date" class="control-label label-static"> {% trans 'Init date'%}</label>
  28 + <input type="text" class="form-control date-picker" name="init_date" value="{{field.value|date:'SHORT_DATE_FORMAT'}}" min="{{now|date:'SHORT_DATE_FORMAT'}}">
36 29  
  30 + <span class="help-block">{% trans 'Init date'%}</span>
37 31 </div>
38 32  
39   - <div class="form-group {% if subject.name.errors %} has-error{% endif %}">
40   - <label for="{{ id_end_date }}" class="control-label label-static"> {% trans 'End date' %}</label>
41   - <input type="text" class="form-control date-picker" name="{{field.name}}" value="{{field.value|date:'SHORT_DA E_FORMAT'}}" min="{{now|date:'SHORT_DATE_FORMAT'}}">
42   - <span class="help-block">{% trans 'Subject end date' %}</span>
43   -
44   - </div>
45   - <div class="form-group {% if subject.name.errors %} has-error{% endif %}">
46   - <label for="{{ id_visible }}" class="control-label label-static"> {% trans 'Visible?' %} </label>
47   - <input type="checkbox" class="form-control" id="id_visible" name="visible" required="true"/>
48   - <span class="help-block">{% trans 'Is it visible?' %}</span>
  33 + <div class="form-group">
  34 + <label for="id_end_date" class="control-label label-static"> {% trans 'End date'%}</label>
  35 + <input type="text" class="form-control date-picker" name="end_date" value="{{field.value|date:'SHORT_DATE_FORMAT'}}" min="{{now|date:'SHORT_DATE_FORMAT'}}">
49 36  
  37 + <span class="help-block">{% trans 'End date'%}</span>
50 38 </div>
51 39  
  40 + <div class="form-group">
  41 + <label for="id_visible" class="control-label label-static"> {% trans 'Visible'%}</label>
  42 + <input class="form-control" id="id_visible" name="visible" type="checkbox"/>
52 43  
  44 + <span class="help-block">{% trans 'Is it visible?'%}</span>
53 45 </div>
54   -
55 46 <div class="col-lg-offset-4 col-lg-4">
56   - <button type="submit" class="btn btn-raised btn-primary btn-lg btn-block">{% trans 'Replicate' %}</button>
  47 + <button type="submite" class="btn btn-raised btn-primary btn-lg btn-block">{% trans 'Replicate' %}</button>
57 48 </div>
58 49 </form>
59   -
60 50 </div>
61 51 </div>
62 52  
... ... @@ -70,4 +60,4 @@
70 60 $('#id_description').summernote({height: 300});
71 61 });
72 62 </script>
73   -{% endblock %}
74 63 \ No newline at end of file
  64 +{% endblock content %}
... ...
courses/urls.py
... ... @@ -6,7 +6,6 @@ urlpatterns = [
6 6 url(r'^all-courses/$', views.AllCoursesView.as_view(), name='all_courses'),
7 7 url(r'^create/$', views.CreateCourseView.as_view(), name='create'),
8 8 url(r'^replicate_course/(?P<slug>[\w_-]+)/$', views.ReplicateCourseView.as_view(), name='replicate_course'),
9   - url(r'^replicate_subject/(?P<slug>[\w_-]+)/$', views.ReplicateSubjectView.as_view(), name='replicate_subject'),
10 9 url(r'^edit/(?P<slug>[\w_-]+)/$', views.UpdateCourseView.as_view(), name='update'),
11 10 url(r'^delete/(?P<slug>[\w_-]+)/$', views.DeleteCourseView.as_view(), name='delete'),
12 11 url(r'^subscribe/(?P<slug>[\w_-]+)/$', views.subscribe_course, name='subscribe'),
... ... @@ -19,10 +18,11 @@ urlpatterns = [
19 18 url(r'^subjects/create/(?P<slug>[\w_-]+)/$', views.CreateSubjectView.as_view(), name='create_subject'),
20 19 url(r'^subjects/update/(?P<slug>[\w_-]+)/$', views.UpdateSubjectView.as_view(), name='update_subject'),
21 20 url(r'^subjects/delete/(?P<slug>[\w_-]+)/$', views.DeleteSubjectView.as_view(), name='delete_subject'),
  21 + url(r'^subjects/replicate/(?P<slug>[\w_-]+)/$', views.ReplicateSubjectView.as_view(), name='replicate_subject'),
22 22 url(r'^subjects/subscribe/(?P<slug>[\w_-]+)/$', views.subscribe_subject, name='subscribe_subject'),
23 23 url(r'^topics/create/(?P<slug>[\w_-]+)/$', views.CreateTopicView.as_view(), name='create_topic'),
24 24 url(r'^topics/update/(?P<slug>[\w_-]+)/$', views.UpdateTopicView.as_view(), name='update_topic'),
25   - url(r'^topics/update/(?P<slug>[\w_-]+)/$', views.DeleteTopic.as_view(), name='delete_topic'),
  25 + url(r'^topics/delete/(?P<slug>[\w_-]+)/$', views.DeleteTopic.as_view(), name='delete_topic'),
26 26 url(r'^topics/replicate/(?P<slug>[\w_-]+)/$', views.ReplicateTopicView.as_view(), name='replicate_topic'),
27 27 url(r'^topics/(?P<slug>[\w_-]+)/$', views.TopicsView.as_view(), name='view_topic'),
28 28 url(r'^subjects/categories$',views.IndexSubjectCategoryView.as_view(), name='subject_category_index'),
... ...
courses/views.py
... ... @@ -561,39 +561,6 @@ class SubjectsView(LoginRequiredMixin, LogMixin, generic.ListView):
561 561 context['files'] = TopicFile.objects.filter(students__name = self.request.user.name)
562 562 return context
563 563  
564   -class ReplicateSubjectView(LoginRequiredMixin, HasRoleMixin, LogMixin, NotificationMixin,generic.edit.CreateView):
565   -
566   - allowed_roles = ['professor', 'system_admin']
567   - login_url = reverse_lazy("core:home")
568   - redirect_field_name = 'next'
569   - template_name = 'subject/replicate.html'
570   - form_class = SubjectForm
571   - success_url = reverse_lazy('course:view')
572   -
573   - def get_context_data(self, **kwargs):
574   - context = super(ReplicateSubjectView, self).get_context_data(**kwargs)
575   - subject = get_object_or_404(Subject, slug=self.kwargs.get('slug'))
576   -
577   - if has_role(self.request.user,'system_admin'):
578   - subjects = Subject.objects.all()
579   - context['subjects'] = subjects
580   - elif has_role(self.request.user,'professor'):
581   - subject = self.request.user.professors_subjects.all()
582   - categorys_subjects = CategorySubject.objects.all()
583   -
584   - context['subject'] = subject
585   - context['categorys_subjects'] = categorys_subjects
586   - context['title'] = _("Replicate Subject")
587   - context['now'] = date.today()
588   - return context
589   -
590   - def form_valid(self, form):
591   - self.object = form.save()
592   -
593   - return super(ReplicateSubjectView, self).form_valid(form)
594   -
595   - def get_success_url(self):
596   - return reverse_lazy('course:view', kwargs={'slug' : self.object.slug})
597 564  
598 565 class UploadMaterialView(LoginRequiredMixin, generic.edit.CreateView):
599 566 login_url = reverse_lazy("core:home")
... ... @@ -1017,7 +984,7 @@ class TopicViewSet(viewsets.ModelViewSet):
1017 984 class ReplicateTopicView (LoginRequiredMixin, HasRoleMixin, LogMixin, NotificationMixin,generic.edit.CreateView):
1018 985 log_component = "course"
1019 986 log_resource = "topic"
1020   - log_action = "create"
  987 + log_action = "replicate"
1021 988 log_context = {}
1022 989  
1023 990 allowed_roles = ['professor', 'system_admin']
... ... @@ -1067,4 +1034,56 @@ class ReplicateTopicView (LoginRequiredMixin, HasRoleMixin, LogMixin, Notificati
1067 1034  
1068 1035 super(ReplicateTopicView, self).createLog(self.request.user, self.log_component, self.log_action, self.log_resource, self.log_context)
1069 1036  
1070   - return super(ReplicateTopicView, self).form_valid(form)
1071 1037 \ No newline at end of file
  1038 + return super(ReplicateTopicView, self).form_valid(form)
  1039 +
  1040 +class ReplicateSubjectView(LoginRequiredMixin, HasRoleMixin, LogMixin, NotificationMixin, generic.edit.CreateView):
  1041 + log_component = "course"
  1042 + log_resource = "subject"
  1043 + log_action = "replicate"
  1044 + log_context = {}
  1045 +
  1046 + allowed_roles = ['professor', 'system_admin']
  1047 + login_url = reverse_lazy("core:home")
  1048 + redirect_field_name = 'next'
  1049 + template_name = 'subject/replicate.html'
  1050 + form_class = SubjectForm
  1051 +
  1052 + def get_success_url(self):
  1053 + return reverse_lazy('course:view_subject', kwargs={'slug' : self.object.slug})
  1054 +
  1055 + def get_context_data(self, **kwargs):
  1056 + context = super(ReplicateSubjectView, self).get_context_data(**kwargs)
  1057 + subject = get_object_or_404(Subject, slug = self.kwargs.get('slug'))
  1058 + course = Course.objects.get(pk=subject.course_id)
  1059 + context['course'] = course
  1060 + context['subjects'] = course.subjects.filter(Q(visible=True) | Q(professors__in=[self.request.user]))
  1061 + context['subject'] = subject
  1062 + if (has_role(self.request.user,'system_admin')):
  1063 + context['subjects'] = course.subjects.all()
  1064 + return context
  1065 +
  1066 + def form_valid(self, form):
  1067 + subject = get_object_or_404(Subject, slug = self.kwargs.get('slug'))
  1068 + course = Course.objects.get(pk=subject.course_id)
  1069 +
  1070 + self.object = form.save(commit = False)
  1071 + self.object.course = course
  1072 + self.object.save()
  1073 + self.object.professors.add(self.request.user)
  1074 + if self.object.visible:
  1075 + super(ReplicateSubjectView, self).createNotification( " created subject " + self.object.name, resource_name=self.object.name,
  1076 + resource_slug = self.object.slug, actor=self.request.user, users= self.object.course.students.all(),
  1077 + resource_link = reverse('course:view_subject', args=[self.object.slug]))
  1078 +
  1079 + self.log_context['subject_id'] = self.object.id
  1080 + self.log_context['subject_name'] = self.object.name
  1081 + self.log_context['subject_slug'] = self.object.slug
  1082 + self.log_context['course_id'] = course.id
  1083 + self.log_context['course_name'] = course.name
  1084 + self.log_context['course_slug'] = course.slug
  1085 + self.log_context['course_category_id'] = course.category.id
  1086 + self.log_context['course_category_name'] = course.category.name
  1087 +
  1088 + super(ReplicateSubjectView, self).createLog(self.request.user, self.log_component, self.log_action, self.log_resource, self.log_context)
  1089 +
  1090 + return super(ReplicateSubjectView, self).form_valid(form)
... ...