From 056537b26c10fd51de6bb7c1293b41b84660d8d5 Mon Sep 17 00:00:00 2001 From: Zambom Date: Mon, 2 Jan 2017 19:57:20 -0200 Subject: [PATCH] Updating categories breadcrumbs and other adjusts --- categories/migrations/0006_auto_20170102_1856.py | 20 ++++++++++++++++++++ categories/models.py | 8 ++++---- categories/templates/categories/create.html | 2 +- categories/templates/categories/list.html | 10 ++++------ categories/templates/categories/update.html | 2 +- categories/views.py | 11 ++++++++++- 6 files changed, 40 insertions(+), 13 deletions(-) create mode 100644 categories/migrations/0006_auto_20170102_1856.py diff --git a/categories/migrations/0006_auto_20170102_1856.py b/categories/migrations/0006_auto_20170102_1856.py new file mode 100644 index 0000000..c9b7f70 --- /dev/null +++ b/categories/migrations/0006_auto_20170102_1856.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10 on 2017-01-02 21:56 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('categories', '0005_auto_20170102_1225'), + ] + + operations = [ + migrations.AlterField( + model_name='category', + name='visible', + field=models.BooleanField(default=True, verbose_name='visible'), + ), + ] diff --git a/categories/models.py b/categories/models.py index 9746049..3260715 100644 --- a/categories/models.py +++ b/categories/models.py @@ -6,11 +6,11 @@ from users.models import User class Category(models.Model): """Represents a Course """ - name = models.CharField(_("Name"), max_length = 100, blank=False, null=False, unique= True) - slug = AutoSlugField(_("Slug"),populate_from='name',unique=True) + name = models.CharField(_("Name"), max_length = 100, blank = False, null = False, unique = True) + slug = AutoSlugField(_("Slug"), populate_from = 'name', unique = True) description = models.CharField(_("description"), max_length = 300) - visible = models.BooleanField(_("visible")) - coordinators = models.ManyToManyField(User, related_name = _("coordinators"), blank=True) + visible = models.BooleanField(_("visible"), default = True) + coordinators = models.ManyToManyField(User, related_name = _("coordinators"), blank = True) create_date = models.DateTimeField(_('Creation Date'), auto_now_add = True) modified_date = models.DateTimeField(_('Modified Date'), auto_now_add = True) diff --git a/categories/templates/categories/create.html b/categories/templates/categories/create.html index 5b7fae3..5f97675 100644 --- a/categories/templates/categories/create.html +++ b/categories/templates/categories/create.html @@ -1,4 +1,4 @@ -{% extends 'categories/list.html' %} +{% extends template_extends %} {% load widget_tweaks static i18n permission_tags django_bootstrap_breadcrumbs switchevenodd %} diff --git a/categories/templates/categories/list.html b/categories/templates/categories/list.html index 2aebf73..673597d 100755 --- a/categories/templates/categories/list.html +++ b/categories/templates/categories/list.html @@ -81,12 +81,10 @@ - {% if coordinators %} -

{% trans "Coordinator(s): " %} - {% for coordinator in category.coordinators.all %} - {{coordinator.social_name}} - {% endfor %} -

+ {% if category.coordinators.all|length > 0 %} +

{% trans "Coordinator(s) " %}: + {{ category.coordinators.all|join:', ' }} +

{% else %}

{% trans "It doesn't possess coordinators" %}

{% endif %} diff --git a/categories/templates/categories/update.html b/categories/templates/categories/update.html index a8b7d28..2525752 100644 --- a/categories/templates/categories/update.html +++ b/categories/templates/categories/update.html @@ -1,4 +1,4 @@ -{% extends 'categories/list.html' %} +{% extends template_extends %} {% load static i18n %} {% load widget_tweaks django_bootstrap_breadcrumbs %} diff --git a/categories/views.py b/categories/views.py index 6690ee3..8ff0f14 100644 --- a/categories/views.py +++ b/categories/views.py @@ -87,7 +87,6 @@ class CreateCategory(views.SuperuserRequiredMixin, HasRoleMixin, LogMixin, Creat initial['name'] = category.name initial['visible'] = category.visible initial['coordinators'] = category.coordinators.all() - print(category.coordinators.all()) self.log_action = 'replicate' @@ -107,6 +106,11 @@ class CreateCategory(views.SuperuserRequiredMixin, HasRoleMixin, LogMixin, Creat else: context['title'] = _('Create Category') + if 'categories' in self.request.META.get('HTTP_REFERER'): + context['template_extends'] = 'categories/list.html' + else: + context['template_extends'] = 'subjects/list.html' + return context def form_valid(self, form): @@ -189,6 +193,11 @@ class UpdateCategory(LogMixin, UpdateView): context = super(UpdateCategory, self).get_context_data(**kwargs) context['title'] = _('Update Category') + if 'categories' in self.request.META.get('HTTP_REFERER'): + context['template_extends'] = 'categories/list.html' + else: + context['template_extends'] = 'subjects/list.html' + return context @log_decorator_ajax('category', 'view', 'category') -- libgit2 0.21.2