From 2eb4aceb927e55d244203aacd25985251dbe92d7 Mon Sep 17 00:00:00 2001 From: Zambom Date: Tue, 17 Jan 2017 17:28:08 -0200 Subject: [PATCH] Adding topic sort --- amadeus/static/css/base/amadeus.css | 4 ++-- amadeus/static/css/themes/green.css | 9 +++++++++ subjects/templates/subjects/view.html | 1 + topics/models.py | 1 + topics/templates/topics/list.html | 81 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ topics/urls.py | 1 + topics/views.py | 18 ++++++++++++++++++ 7 files changed, 113 insertions(+), 2 deletions(-) create mode 100644 topics/templates/topics/list.html diff --git a/amadeus/static/css/base/amadeus.css b/amadeus/static/css/base/amadeus.css index efbd19a..1aa6f72 100755 --- a/amadeus/static/css/base/amadeus.css +++ b/amadeus/static/css/base/amadeus.css @@ -73,11 +73,11 @@ a:focus { /* side bar menu ends*/ /* category app starts */ -.category-panel > .panel-heading, .subject-panel > .panel-heading, .special-panel > .panel-heading { +.category-panel > .panel-heading, .subject-panel > .panel-heading, .special-panel > .panel-heading, .topic-panel > .panel-heading { padding: 2px 0px; } -.subject-panel-invisible > .panel-heading{ +.subject-panel-invisible > .panel-heading, .topic-panel-invisible > .panel-heading { padding: 2px 0px; } diff --git a/amadeus/static/css/themes/green.css b/amadeus/static/css/themes/green.css index af8c641..9334f49 100644 --- a/amadeus/static/css/themes/green.css +++ b/amadeus/static/css/themes/green.css @@ -59,6 +59,15 @@ a, a:focus, a:hover { background-color: #039BE5 !important; } +.topic-panel > .panel-heading { + background-color: #7BA5B9 !important; +} + +.topic-panel-invisible > .panel-heading { + background-color: #BDBDBD !important; + color: #F5F5F5; +} + .category-header i { color: white; } diff --git a/subjects/templates/subjects/view.html b/subjects/templates/subjects/view.html index bac61a7..61d4a34 100644 --- a/subjects/templates/subjects/view.html +++ b/subjects/templates/subjects/view.html @@ -84,6 +84,7 @@ {% trans "Create new topic" %} {% endif %} + {% include 'topics/list.html' with subject=subject %} {% endblock content %} \ No newline at end of file diff --git a/topics/models.py b/topics/models.py index e13d1f6..7ea8447 100644 --- a/topics/models.py +++ b/topics/models.py @@ -18,6 +18,7 @@ class Topic(models.Model): class Meta: verbose_name = _('Topic') verbose_name_plural = _('Topics') + ordering = ['order'] def __str__(self): return self.name \ No newline at end of file diff --git a/topics/templates/topics/list.html b/topics/templates/topics/list.html new file mode 100644 index 0000000..ff55f77 --- /dev/null +++ b/topics/templates/topics/list.html @@ -0,0 +1,81 @@ +{% load static i18n pagination permissions_tags %} +{% load django_bootstrap_breadcrumbs %} + +{% subject_permissions request.user subject as has_subject_permissions %} + +
+ {% for topic in subject.topic_subject.all %} + {% if not topic.repository and topic.visible or has_subject_permissions %} +
+
+
+
+

+ + {{ topic }} + +

+ + {% if has_subject_permissions %} + + {% endif %} +
+
+
+
+ + +
+
+ {% endif %} + {% endfor %} +
+ + \ No newline at end of file diff --git a/topics/urls.py b/topics/urls.py index 67e6698..01ca0e5 100644 --- a/topics/urls.py +++ b/topics/urls.py @@ -5,4 +5,5 @@ from . import views urlpatterns = [ url(r'^create/(?P[\w_-]+)/$', views.CreateView.as_view(), name = 'create'), + url(r'^update_order/$', views.update_order, name = 'update_order'), ] diff --git a/topics/views.py b/topics/views.py index 39bc7c7..5488e2e 100644 --- a/topics/views.py +++ b/topics/views.py @@ -1,10 +1,13 @@ from django.shortcuts import get_object_or_404, redirect, render from django.views import generic from django.contrib import messages +from django.http import JsonResponse from django.core.urlresolvers import reverse, reverse_lazy from django.utils.translation import ugettext_lazy as _ from django.contrib.auth.mixins import LoginRequiredMixin +import json + from amadeus.permissions import has_subject_permissions from subjects.models import Subject @@ -66,3 +69,18 @@ class CreateView(LoginRequiredMixin, generic.edit.CreateView): messages.success(self.request, _('Topic "%s" was created on virtual enviroment "%s" successfully!')%(self.object.name, self.object.subject.name)) return reverse_lazy('subjects:view', kwargs = {'slug': self.object.subject.slug}) + +def update_order(request): + data = request.GET.get('data', None) + + if not data is None: + data = json.loads(data) + + for t_data in data: + topic = get_object_or_404(Topic, id = t_data['topic_id']) + topic.order = t_data['topic_order'] + topic.save() + + return JsonResponse({'message': 'ok'}) + + return JsonResponse({'message': 'No data received'}) \ No newline at end of file -- libgit2 0.21.2