Commit eedf7a4e4df9edca975ff5e48dfa5f7cd31ecd77

Authored by filipecmedeiros
1 parent 37932331

[Issue #399]

amadeus/settings.py
... ... @@ -262,7 +262,7 @@ SUMMERNOTE_CONFIG = {
262 262  
263 263 # Change editor size
264 264 'width': '100%',
265   - 'height': '480',
  265 + 'height': '300',
266 266  
267 267 # Use proper language setting automatically (default)
268 268 'lang': None,
... ...
courses/templates/topic/replicate_topic.html 0 → 100644
... ... @@ -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
... ... @@ -599,6 +599,11 @@ class ReplicateSubjectView(LoginRequiredMixin, HasRoleMixin, LogMixin, Notificat
599 599 context['now'] = date.today()
600 600 return context
601 601  
  602 + def form_valid(self, form):
  603 + self.object = form.save()
  604 +
  605 + return super(ReplicateSubjectView, self).form_valid(form)
  606 +
602 607 def get_success_url(self):
603 608 return reverse_lazy('course:view', kwargs={'slug' : self.object.slug})
604 609  
... ... @@ -1020,3 +1025,56 @@ class TopicViewSet(viewsets.ModelViewSet):
1020 1025 queryset = Topic.objects.all()
1021 1026 serializer_class = TopicSerializer
1022 1027 permissions_class = (permissions.IsAuthenticatedOrReadOnly)
  1028 +
  1029 +class ReplicateTopicView (LoginRequiredMixin, HasRoleMixin, LogMixin, NotificationMixin,generic.edit.CreateView):
  1030 + log_component = "course"
  1031 + log_resource = "topic"
  1032 + log_action = "create"
  1033 + log_context = {}
  1034 +
  1035 + allowed_roles = ['professor', 'system_admin']
  1036 + login_url = reverse_lazy("core:home")
  1037 + model = Topic
  1038 + template_name = 'topic/replicate_topic.html'
  1039 + form_class = TopicForm
  1040 +
  1041 + def get_success_url(self):
  1042 + return reverse_lazy('course:view_subject', kwargs={'slug' : self.object.subject.slug})
  1043 +
  1044 + def get_context_data(self, **kwargs):
  1045 + context = super(ReplicateTopicView, self).get_context_data(**kwargs)
  1046 + topic = get_object_or_404(Topic, slug = self.kwargs.get('slug'))
  1047 + subject = topic.subject
  1048 + context['course'] = subject.course
  1049 + context['subject'] = subject
  1050 + context['subjects'] = subject.course.subjects.all()
  1051 + context['topic'] = topic
  1052 + return context
  1053 +
  1054 +
  1055 + def form_valid(self, form):
  1056 + self.object.subject = self.object.subject.id
  1057 + self.object = form.save(commit = False)
  1058 + self.object.owner = self.request.user
  1059 + self.object.save()
  1060 +
  1061 + action = super(ReplicateTopicView, self).createorRetrieveAction("replicate Topic")
  1062 + super(ReplicateTopicView, self).createNotification("Topic "+ self.object.name + " was created",
  1063 + resource_name=self.object.name, resource_link= reverse('course:view_topic',args=[self.object.slug]),
  1064 + actor=self.request.user, users = self.object.subject.course.students.all() )
  1065 +
  1066 + self.log_context['topic_id'] = self.object.id
  1067 + self.log_context['topic_name'] = self.object.name
  1068 + self.log_context['topic_slug'] = self.object.slug
  1069 + self.log_context['subject_id'] = self.object.subject.id
  1070 + self.log_context['subject_name'] = self.object.subject.name
  1071 + self.log_context['subject_slug'] = self.object.subject.slug
  1072 + self.log_context['course_id'] = self.object.subject.course.id
  1073 + self.log_context['course_name'] = self.object.subject.course.name
  1074 + self.log_context['course_slug'] = self.object.subject.course.slug
  1075 + self.log_context['course_category_id'] = self.object.subject.course.category.id
  1076 + self.log_context['course_category_name'] = self.object.subject.course.category.name
  1077 +
  1078 + super(ReplicateTopicView, self).createLog(self.request.user, self.log_component, self.log_action, self.log_resource, self.log_context)
  1079 +
  1080 + return super(ReplicateTopicView, self).form_valid(form)
1023 1081 \ No newline at end of file
... ...