diff --git a/amadeus/settings.py b/amadeus/settings.py index 335b86f..79cef9f 100644 --- a/amadeus/settings.py +++ b/amadeus/settings.py @@ -262,7 +262,7 @@ SUMMERNOTE_CONFIG = { # Change editor size 'width': '100%', - 'height': '480', + 'height': '300', # Use proper language setting automatically (default) 'lang': None, diff --git a/courses/templates/topic/replicate_topic.html b/courses/templates/topic/replicate_topic.html new file mode 100644 index 0000000..ec591fa --- /dev/null +++ b/courses/templates/topic/replicate_topic.html @@ -0,0 +1,38 @@ +{% extends 'subject/index.html' %} + +{% load static i18n permission_tags widget_tweaks %} + +{% block content %} + +
+
+
+ {% csrf_token %} + +
+ + + + {% trans 'Topic name'%} +
+
+ + + + {% trans 'Topic description'%} +
+ +
+ + +
+
+
+
+ + +{% endblock content %} diff --git a/courses/urls.py b/courses/urls.py index 4cc446e..2b9bd3e 100644 --- a/courses/urls.py +++ b/courses/urls.py @@ -22,7 +22,8 @@ urlpatterns = [ url(r'^subjects/subscribe/(?P[\w_-]+)/$', views.subscribe_subject, name='subscribe_subject'), url(r'^topics/create/(?P[\w_-]+)/$', views.CreateTopicView.as_view(), name='create_topic'), url(r'^topics/update/(?P[\w_-]+)/$', views.UpdateTopicView.as_view(), name='update_topic'), - url(r'^topics/update/(?P[\w_-]+)/$', views.DeleteTopic.as_view(), name='update_topic'), + url(r'^topics/update/(?P[\w_-]+)/$', views.DeleteTopic.as_view(), name='delete_topic'), + url(r'^topics/replicate/(?P[\w_-]+)/$', views.ReplicateTopicView.as_view(), name='replicate_topic'), url(r'^topics/(?P[\w_-]+)/$', views.TopicsView.as_view(), name='view_topic'), url(r'^subjects/categories$',views.IndexSubjectCategoryView.as_view(), name='subject_category_index'), url(r'^forum/', include('forum.urls', namespace = 'forum')), diff --git a/courses/views.py b/courses/views.py index 4e3d5c7..5e8ef5a 100644 --- a/courses/views.py +++ b/courses/views.py @@ -599,6 +599,11 @@ class ReplicateSubjectView(LoginRequiredMixin, HasRoleMixin, LogMixin, Notificat context['now'] = date.today() return context + def form_valid(self, form): + self.object = form.save() + + return super(ReplicateSubjectView, self).form_valid(form) + def get_success_url(self): return reverse_lazy('course:view', kwargs={'slug' : self.object.slug}) @@ -1020,3 +1025,56 @@ class TopicViewSet(viewsets.ModelViewSet): queryset = Topic.objects.all() serializer_class = TopicSerializer permissions_class = (permissions.IsAuthenticatedOrReadOnly) + +class ReplicateTopicView (LoginRequiredMixin, HasRoleMixin, LogMixin, NotificationMixin,generic.edit.CreateView): + log_component = "course" + log_resource = "topic" + log_action = "create" + log_context = {} + + allowed_roles = ['professor', 'system_admin'] + login_url = reverse_lazy("core:home") + model = Topic + template_name = 'topic/replicate_topic.html' + form_class = TopicForm + + def get_success_url(self): + return reverse_lazy('course:view_subject', kwargs={'slug' : self.object.subject.slug}) + + def get_context_data(self, **kwargs): + context = super(ReplicateTopicView, self).get_context_data(**kwargs) + topic = get_object_or_404(Topic, slug = self.kwargs.get('slug')) + subject = topic.subject + context['course'] = subject.course + context['subject'] = subject + context['subjects'] = subject.course.subjects.all() + context['topic'] = topic + return context + + + def form_valid(self, form): + self.object.subject = self.object.subject.id + self.object = form.save(commit = False) + self.object.owner = self.request.user + self.object.save() + + action = super(ReplicateTopicView, self).createorRetrieveAction("replicate Topic") + super(ReplicateTopicView, self).createNotification("Topic "+ self.object.name + " was created", + resource_name=self.object.name, resource_link= reverse('course:view_topic',args=[self.object.slug]), + actor=self.request.user, users = self.object.subject.course.students.all() ) + + self.log_context['topic_id'] = self.object.id + self.log_context['topic_name'] = self.object.name + self.log_context['topic_slug'] = self.object.slug + self.log_context['subject_id'] = self.object.subject.id + self.log_context['subject_name'] = self.object.subject.name + self.log_context['subject_slug'] = self.object.subject.slug + self.log_context['course_id'] = self.object.subject.course.id + self.log_context['course_name'] = self.object.subject.course.name + self.log_context['course_slug'] = self.object.subject.course.slug + self.log_context['course_category_id'] = self.object.subject.course.category.id + self.log_context['course_category_name'] = self.object.subject.course.category.name + + super(ReplicateTopicView, self).createLog(self.request.user, self.log_component, self.log_action, self.log_resource, self.log_context) + + return super(ReplicateTopicView, self).form_valid(form) \ No newline at end of file -- libgit2 0.21.2