Commit b4415117d25c8c8dda84fd2bf116fc147c7a0602
Exists in
master
and in
5 other branches
Merge branch 'dev' of https://github.com/amadeusproject/amadeuslms into dev
Showing
6 changed files
with
142 additions
and
16 deletions
Show diff stats
amadeus/settings.py
core/forms.py
| ... | ... | @@ -37,7 +37,7 @@ class RegisterUserForm(forms.ModelForm): |
| 37 | 37 | def clean_cpf(self): |
| 38 | 38 | cpf = self.cleaned_data['cpf'] |
| 39 | 39 | if User.objects.filter(cpf = cpf).exists(): |
| 40 | - raise forms.ValidationError(_('There is already a registeres User with this CPF')) | |
| 40 | + raise forms.ValidationError(_('There is already a registered User with this CPF')) | |
| 41 | 41 | # if not self.validate_cpf(cpf): |
| 42 | 42 | # raise forms.ValidationError(_('Please enter a valid CPF')) |
| 43 | 43 | return cpf |
| ... | ... | @@ -76,4 +76,4 @@ class RegisterUserForm(forms.ModelForm): |
| 76 | 76 | model = User |
| 77 | 77 | # exclude = ['is_staff', 'is_active'] |
| 78 | 78 | fields = ['username', 'name', 'email', 'city', 'state', 'gender', 'cpf', 'birth_date', 'phone', 'image', 'titration', |
| 79 | - 'year_titration', 'institution', 'curriculum',] | |
| 80 | 79 | \ No newline at end of file |
| 80 | + 'year_titration', 'institution', 'curriculum',] | ... | ... |
courses/templates/subject/replicate.html
| ... | ... | @@ -14,20 +14,46 @@ |
| 14 | 14 | <div class="panel-body"> |
| 15 | 15 | <form class="form-group " method="post" action=""> |
| 16 | 16 | {% csrf_token %} |
| 17 | - {% for field in form %} | |
| 18 | - <div class="form-group {% if field.errors %} has-error{% endif %}"> | |
| 19 | - <label for="{{ field.auto_id }}" class="control-label label-static"> {{ field.label }}</label> | |
| 20 | - | |
| 21 | - {% if field.auto_id == 'id_init_date' or field.auto_id == 'id_end_date'%} | |
| 22 | - <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'}}"> | |
| 23 | - {% else %} | |
| 24 | - {% render_field field class='form-control' placeholder=field.label%} | |
| 25 | - {% endif %} | |
| 26 | - <span class="help-block">{{ field.help_text }}</span> | |
| 17 | + | |
| 18 | + <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> | |
| 22 | + | |
| 23 | + </div> | |
| 24 | + | |
| 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> | |
| 29 | + | |
| 30 | + </div> | |
| 31 | + | |
| 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> | |
| 36 | + | |
| 37 | + </div> | |
| 38 | + | |
| 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> | |
| 49 | + | |
| 27 | 50 | </div> |
| 28 | - {% endfor %} | |
| 51 | + | |
| 52 | + | |
| 53 | + </div> | |
| 54 | + | |
| 29 | 55 | <div class="col-lg-offset-4 col-lg-4"> |
| 30 | - <button type="submite" class="btn btn-raised btn-primary btn-lg btn-block">{% trans 'Update' %}</button> | |
| 56 | + <button type="submit" class="btn btn-raised btn-primary btn-lg btn-block">{% trans 'Replicate' %}</button> | |
| 31 | 57 | </div> |
| 32 | 58 | </form> |
| 33 | 59 | |
| ... | ... | @@ -40,5 +66,8 @@ |
| 40 | 66 | $('.date-picker').datepicker({ |
| 41 | 67 | language: locale, |
| 42 | 68 | }); |
| 69 | + $(document).ready(function() { | |
| 70 | + $('#id_description').summernote({height: 300}); | |
| 71 | + }); | |
| 43 | 72 | </script> |
| 44 | 73 | {% endblock %} |
| 45 | 74 | \ No newline at end of file | ... | ... |
| ... | ... | @@ -0,0 +1,38 @@ |
| 1 | +{% extends 'subject/index.html' %} | |
| 2 | + | |
| 3 | +{% load static i18n permission_tags widget_tweaks %} | |
| 4 | + | |
| 5 | +{% block content %} | |
| 6 | + | |
| 7 | + <div class="panel panel-default"> | |
| 8 | + <div class="panel-body"> | |
| 9 | + <form class="form-group " method="post" action=""> | |
| 10 | + {% csrf_token %} | |
| 11 | + | |
| 12 | + <div class="form-group {% if topic.name.errors %} has-error{% endif %}"> | |
| 13 | + <label for="id_name" class="control-label label-static"> {% trans 'Name'%}</label> | |
| 14 | + <input class="form-control" id="id_name" maxlength="100" name="name" placeholder="Name" type="text" value={{topic.name}} required /> | |
| 15 | + | |
| 16 | + <span class="help-block">{% trans 'Topic name'%}</span> | |
| 17 | + </div> | |
| 18 | + <div class="form-group {% if topic.description.errors %} has-error{% endif %}"> | |
| 19 | + <label for="id_description" class="control-label label-static"> {% trans 'Description'%}</label> | |
| 20 | + <textarea class="form-control" id="id_description" name="description" placeholder="Description" type="text"> {{topic.description}}</textarea> | |
| 21 | + | |
| 22 | + <span class="help-block">{% trans 'Topic description'%}</span> | |
| 23 | + </div> | |
| 24 | + | |
| 25 | + <div class="col-lg-offset-4 col-lg-4"> | |
| 26 | + <button type="submit" class="btn btn-raised btn-primary btn-lg btn-block">{% trans 'Create' %}</button> | |
| 27 | + | |
| 28 | + </div> | |
| 29 | + </form> | |
| 30 | + </div> | |
| 31 | + </div> | |
| 32 | + | |
| 33 | + <script type="text/javascript"> | |
| 34 | + $(document).ready(function() { | |
| 35 | + $('#id_description').summernote({height: 300}); | |
| 36 | + }); | |
| 37 | + </script> | |
| 38 | +{% endblock content %} | ... | ... |
courses/urls.py
| ... | ... | @@ -22,7 +22,8 @@ urlpatterns = [ |
| 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='update_topic'), | |
| 25 | + url(r'^topics/update/(?P<slug>[\w_-]+)/$', views.DeleteTopic.as_view(), name='delete_topic'), | |
| 26 | + url(r'^topics/replicate/(?P<slug>[\w_-]+)/$', views.ReplicateTopicView.as_view(), name='replicate_topic'), | |
| 26 | 27 | url(r'^topics/(?P<slug>[\w_-]+)/$', views.TopicsView.as_view(), name='view_topic'), |
| 27 | 28 | url(r'^subjects/categories$',views.IndexSubjectCategoryView.as_view(), name='subject_category_index'), |
| 28 | 29 | url(r'^forum/', include('forum.urls', namespace = 'forum')), | ... | ... |
courses/views.py
| ... | ... | @@ -587,6 +587,11 @@ class ReplicateSubjectView(LoginRequiredMixin, HasRoleMixin, LogMixin, Notificat |
| 587 | 587 | context['now'] = date.today() |
| 588 | 588 | return context |
| 589 | 589 | |
| 590 | + def form_valid(self, form): | |
| 591 | + self.object = form.save() | |
| 592 | + | |
| 593 | + return super(ReplicateSubjectView, self).form_valid(form) | |
| 594 | + | |
| 590 | 595 | def get_success_url(self): |
| 591 | 596 | return reverse_lazy('course:view', kwargs={'slug' : self.object.slug}) |
| 592 | 597 | |
| ... | ... | @@ -1008,3 +1013,56 @@ class TopicViewSet(viewsets.ModelViewSet): |
| 1008 | 1013 | queryset = Topic.objects.all() |
| 1009 | 1014 | serializer_class = TopicSerializer |
| 1010 | 1015 | permissions_class = (permissions.IsAuthenticatedOrReadOnly) |
| 1016 | + | |
| 1017 | +class ReplicateTopicView (LoginRequiredMixin, HasRoleMixin, LogMixin, NotificationMixin,generic.edit.CreateView): | |
| 1018 | + log_component = "course" | |
| 1019 | + log_resource = "topic" | |
| 1020 | + log_action = "create" | |
| 1021 | + log_context = {} | |
| 1022 | + | |
| 1023 | + allowed_roles = ['professor', 'system_admin'] | |
| 1024 | + login_url = reverse_lazy("core:home") | |
| 1025 | + model = Topic | |
| 1026 | + template_name = 'topic/replicate_topic.html' | |
| 1027 | + form_class = TopicForm | |
| 1028 | + | |
| 1029 | + def get_success_url(self): | |
| 1030 | + return reverse_lazy('course:view_subject', kwargs={'slug' : self.object.subject.slug}) | |
| 1031 | + | |
| 1032 | + def get_context_data(self, **kwargs): | |
| 1033 | + context = super(ReplicateTopicView, self).get_context_data(**kwargs) | |
| 1034 | + topic = get_object_or_404(Topic, slug = self.kwargs.get('slug')) | |
| 1035 | + subject = topic.subject | |
| 1036 | + context['course'] = subject.course | |
| 1037 | + context['subject'] = subject | |
| 1038 | + context['subjects'] = subject.course.subjects.all() | |
| 1039 | + context['topic'] = topic | |
| 1040 | + return context | |
| 1041 | + | |
| 1042 | + | |
| 1043 | + def form_valid(self, form): | |
| 1044 | + self.object.subject = self.object.subject.id | |
| 1045 | + self.object = form.save(commit = False) | |
| 1046 | + self.object.owner = self.request.user | |
| 1047 | + self.object.save() | |
| 1048 | + | |
| 1049 | + action = super(ReplicateTopicView, self).createorRetrieveAction("replicate Topic") | |
| 1050 | + super(ReplicateTopicView, self).createNotification("Topic "+ self.object.name + " was created", | |
| 1051 | + resource_name=self.object.name, resource_link= reverse('course:view_topic',args=[self.object.slug]), | |
| 1052 | + actor=self.request.user, users = self.object.subject.course.students.all() ) | |
| 1053 | + | |
| 1054 | + self.log_context['topic_id'] = self.object.id | |
| 1055 | + self.log_context['topic_name'] = self.object.name | |
| 1056 | + self.log_context['topic_slug'] = self.object.slug | |
| 1057 | + self.log_context['subject_id'] = self.object.subject.id | |
| 1058 | + self.log_context['subject_name'] = self.object.subject.name | |
| 1059 | + self.log_context['subject_slug'] = self.object.subject.slug | |
| 1060 | + self.log_context['course_id'] = self.object.subject.course.id | |
| 1061 | + self.log_context['course_name'] = self.object.subject.course.name | |
| 1062 | + self.log_context['course_slug'] = self.object.subject.course.slug | |
| 1063 | + self.log_context['course_category_id'] = self.object.subject.course.category.id | |
| 1064 | + self.log_context['course_category_name'] = self.object.subject.course.category.name | |
| 1065 | + | |
| 1066 | + super(ReplicateTopicView, self).createLog(self.request.user, self.log_component, self.log_action, self.log_resource, self.log_context) | |
| 1067 | + | |
| 1068 | + return super(ReplicateTopicView, self).form_valid(form) | |
| 1011 | 1069 | \ No newline at end of file | ... | ... |