diff --git a/amadeus/static/css/base/amadeus.css b/amadeus/static/css/base/amadeus.css index 1aa6f72..ade19ca 100755 --- a/amadeus/static/css/base/amadeus.css +++ b/amadeus/static/css/base/amadeus.css @@ -73,7 +73,7 @@ a:focus { /* side bar menu ends*/ /* category app starts */ -.category-panel > .panel-heading, .subject-panel > .panel-heading, .special-panel > .panel-heading, .topic-panel > .panel-heading { +.category-panel > .panel-heading, .subject-panel > .panel-heading, .special-panel > .panel-heading, .topic-panel > .panel-heading, .group-panel > .panel-heading { padding: 2px 0px; } diff --git a/amadeus/static/css/themes/green.css b/amadeus/static/css/themes/green.css index aa538cf..578b447 100644 --- a/amadeus/static/css/themes/green.css +++ b/amadeus/static/css/themes/green.css @@ -59,6 +59,14 @@ a, a:focus, a:hover { background-color: #039BE5 !important; } +.group-panel > .panel-heading { + background-color: #FFFFFF !important; +} + +.group-panel .panel-title, .group-panel .category-header i, .group-panel .category-course-link { + color: #000000 !important; +} + .topic-panel > .panel-heading { background-color: #7BA5B9 !important; } diff --git a/students_group/forms.py b/students_group/forms.py index d2fc2ca..70760b6 100644 --- a/students_group/forms.py +++ b/students_group/forms.py @@ -2,6 +2,8 @@ from django import forms from django.utils.translation import ugettext_lazy as _ +from subjects.models import Subject + from .models import StudentsGroup class StudentsGroupForm(forms.ModelForm): @@ -11,6 +13,11 @@ class StudentsGroupForm(forms.ModelForm): super(StudentsGroupForm, self).__init__(*args, **kwargs) self.subject = kwargs['initial'].get('subject', None) + + if self.instance.id: + self.subject = self.instance.subject + + self.fields['participants'].queryset = self.subject.students.all() def clean_name(self): name = self.cleaned_data.get('name', '') diff --git a/students_group/migrations/0002_auto_20170118_1800.py b/students_group/migrations/0002_auto_20170118_1800.py new file mode 100644 index 0000000..9df0284 --- /dev/null +++ b/students_group/migrations/0002_auto_20170118_1800.py @@ -0,0 +1,17 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10 on 2017-01-18 21:00 +from __future__ import unicode_literals + +from django.db import migrations + +from django.contrib.postgres.operations import UnaccentExtension + +class Migration(migrations.Migration): + + dependencies = [ + ('students_group', '0001_initial'), + ] + + operations = [ + UnaccentExtension() + ] diff --git a/students_group/templates/groups/_form.html b/students_group/templates/groups/_form.html new file mode 100644 index 0000000..a8bda33 --- /dev/null +++ b/students_group/templates/groups/_form.html @@ -0,0 +1,113 @@ +{% load widget_tweaks static i18n %} + +
+ {% csrf_token %} + {% for field in form %} + {% if field.auto_id == 'id_participants' %} +
+
+ +
+

{% trans 'Attribute students to group' %}:

+ {% render_field field class='form-control' %} +
+
+
+ {% else %} +
+ + + {% if field.auto_id == 'id_description' %} + {% render_field field class='form-control text_wysiwyg' %} + {% else %} + {% render_field field class='form-control' %} + {% endif %} +
+ {% endif %} + + {{ field.help_text }} + + {% if field.errors %} +
+
+ +
+ {% endif %} + {% endfor %} +
+ +
+
+ + \ No newline at end of file diff --git a/students_group/templates/groups/create.html b/students_group/templates/groups/create.html index 26c297a..c8aaa9d 100644 --- a/students_group/templates/groups/create.html +++ b/students_group/templates/groups/create.html @@ -4,15 +4,24 @@ {% block breadcrumbs %} {{ block.super }} - - {% trans 'Create Group' as bread %} - {% breadcrumb bread 'groups:create' subject.slug %} + + {% if group %} + {% trans 'Replicate: ' as bread %} + + {% with bread|add:group.name as bread_slug %} + {% breadcrumb bread_slug 'groups:replicate' subject.slug group.slug %} + {% endwith %} + {% else %} + {% trans 'Create Group' as bread %} + {% breadcrumb bread 'groups:create' subject.slug %} + {% endif %} {% endblock %} {% block content %}
+ {% include 'groups/_form.html' %}
diff --git a/students_group/templates/groups/index.html b/students_group/templates/groups/index.html index 17ac1a7..90d418c 100644 --- a/students_group/templates/groups/index.html +++ b/students_group/templates/groups/index.html @@ -27,14 +27,43 @@ {% endif %}
-
- {% trans "Create Group" %} +
{% for group in groups %} + + {% endfor %} {% pagination request paginator page_obj %} diff --git a/students_group/templates/groups/update.html b/students_group/templates/groups/update.html new file mode 100644 index 0000000..94056b8 --- /dev/null +++ b/students_group/templates/groups/update.html @@ -0,0 +1,25 @@ +{% extends 'groups/index.html' %} + +{% load i18n django_bootstrap_breadcrumbs %} + +{% block breadcrumbs %} + {{ block.super }} + + {% trans 'Update: ' as bread %} + + {% with bread|add:group.name as bread_slug %} + {% breadcrumb bread_slug 'groups:update' subject.slug group.slug %} + {% endwith %} +{% endblock %} + +{% block content %} +
+
+
+ {% include 'groups/_form.html' %} +
+
+
+
+
+{% endblock %} diff --git a/students_group/urls.py b/students_group/urls.py index 11e4581..59ea5a5 100644 --- a/students_group/urls.py +++ b/students_group/urls.py @@ -4,4 +4,6 @@ from . import views urlpatterns = [ url(r'^(?P[\w_-]+)/$', views.IndexView.as_view(), name='index'), url(r'^create/(?P[\w_-]+)/$', views.CreateView.as_view(), name='create'), + url(r'^update/(?P[\w_-]+)/(?P[\w_-]+)/$', views.UpdateView.as_view(), name='update'), + url(r'^replicate/(?P[\w_-]+)/(?P[\w_-]+)/$', views.CreateView.as_view(), name='replicate'), ] \ No newline at end of file diff --git a/students_group/views.py b/students_group/views.py index daf1bb9..9fe3c3b 100644 --- a/students_group/views.py +++ b/students_group/views.py @@ -70,6 +70,13 @@ class CreateView(LoginRequiredMixin, generic.edit.CreateView): slug = self.kwargs.get('slug', '') initial['subject'] = get_object_or_404(Subject, slug = slug) + + if self.kwargs.get('group_slug'): + group = get_object_or_404(StudentsGroup, slug = self.kwargs['group_slug']) + initial = initial.copy() + initial['description'] = group.description + initial['name'] = group.name + initial['participants'] = group.participants.all() return initial @@ -95,9 +102,51 @@ class CreateView(LoginRequiredMixin, generic.edit.CreateView): context['subject'] = subject + if self.kwargs.get('group_slug'): + group = get_object_or_404(StudentsGroup, slug = self.kwargs['group_slug']) + + context['title'] = _('Replicate Group') + + context['group'] = group + return context def get_success_url(self): messages.success(self.request, _('The group "%s" was created successfully!')%(self.object.name)) + return reverse_lazy('groups:index', kwargs = {'slug': self.object.subject.slug}) + +class UpdateView(LoginRequiredMixin, generic.UpdateView): + login_url = reverse_lazy("users:login") + redirect_field_name = 'next' + + template_name = 'groups/update.html' + model = StudentsGroup + form_class = StudentsGroupForm + context_object_name = 'group' + + def dispatch(self, request, *args, **kwargs): + slug = self.kwargs.get('sub_slug', '') + subject = get_object_or_404(Subject, slug = slug) + + if not has_subject_permissions(request.user, subject): + return redirect(reverse_lazy('subjects:home')) + + return super(UpdateView, self).dispatch(request, *args, **kwargs) + + def get_context_data(self, **kwargs): + context = super(UpdateView, self).get_context_data(**kwargs) + + context['title'] = _('Update Group') + + slug = self.kwargs.get('sub_slug', '') + subject = get_object_or_404(Subject, slug = slug) + + context['subject'] = subject + + return context + + def get_success_url(self): + messages.success(self.request, _('The group "%s" was updated successfully!')%(self.object.name)) + return reverse_lazy('groups:index', kwargs = {'slug': self.object.subject.slug}) \ No newline at end of file -- libgit2 0.21.2