Commit dee54f993fd636e4ac1f21463620b758e97a3f94
Exists in
master
and in
3 other branches
Merge branch 'refactoring' of https://github.com/amadeusproject/amadeuslms into refactoring
Showing
5 changed files
with
154 additions
and
113 deletions
Show diff stats
amadeus/static/css/base/amadeus.css
| @@ -126,6 +126,19 @@ | @@ -126,6 +126,19 @@ | ||
| 126 | margin-bottom: 15px; | 126 | margin-bottom: 15px; |
| 127 | } | 127 | } |
| 128 | 128 | ||
| 129 | +.ms-container { | ||
| 130 | + width: 100% !important; | ||
| 131 | +} | ||
| 132 | + | ||
| 133 | +#coordinators_accordion .panel-heading { | ||
| 134 | + background: #FFFFFF; | ||
| 135 | + border: none; | ||
| 136 | +} | ||
| 137 | + | ||
| 138 | +#coordinators_accordion .panel-collapse { | ||
| 139 | + padding: 10px; | ||
| 140 | +} | ||
| 141 | + | ||
| 129 | /* category app ends */ | 142 | /* category app ends */ |
| 130 | 143 | ||
| 131 | .clearfix{ | 144 | .clearfix{ |
540 Bytes
| @@ -0,0 +1,118 @@ | @@ -0,0 +1,118 @@ | ||
| 1 | +{% load widget_tweaks static i18n switchevenodd %} | ||
| 2 | + | ||
| 3 | +<form method="post" action="" enctype="multipart/form-data"> | ||
| 4 | + {% csrf_token %} | ||
| 5 | + {% for field in form %} | ||
| 6 | + {% if field.auto_id == 'id_coordinators' %} | ||
| 7 | + <div class="panel-group" id="coordinators_accordion" role="tablist" aria-multiselectable="true"> | ||
| 8 | + <div class="panel panel-info"> | ||
| 9 | + <div class="panel-heading"> | ||
| 10 | + <div class="row"> | ||
| 11 | + <div class="col-md-12"> | ||
| 12 | + <a data-parent="#coordinators_accordion" data-toggle="collapse" href="#coords"> | ||
| 13 | + <h4 class="panel-title"> | ||
| 14 | + <button class="btn btn-default btn-xs text-center cat-selector"><i class="fa fa-angle-right fa-2x" aria-hidden="true"></i></button><label for="{{ field.auto_id }}">{{ field.label }}</label> | ||
| 15 | + </h4> | ||
| 16 | + </a> | ||
| 17 | + </div> | ||
| 18 | + </div> | ||
| 19 | + </div> | ||
| 20 | + <div id="coords" class="panel-collapse collapse"> | ||
| 21 | + <p><em>{% trans 'Atribute coordinators role to users' %}:</em></p> | ||
| 22 | + {% render_field field class='form-control' %} | ||
| 23 | + </div> | ||
| 24 | + </div> | ||
| 25 | + </div> | ||
| 26 | + {% else %} | ||
| 27 | + <div class="form-group {% if form.has_error %} has-error {% endif %} is-fileinput"> | ||
| 28 | + {% if field.auto_id != 'id_visible' %} | ||
| 29 | + <label for="{{ field.auto_id }}">{{ field.label }}</label> | ||
| 30 | + {% endif %} | ||
| 31 | + {% if field.auto_id == 'id_visible' %} | ||
| 32 | + <div class="checkbox"> | ||
| 33 | + <label for="{{ field.auto_id }}"> | ||
| 34 | + {% render_field field %} {{field.label}} | ||
| 35 | + </label> | ||
| 36 | + </div> | ||
| 37 | + {% elif field.auto_id == 'id_description' %} | ||
| 38 | + {% render_field field class='form-control text_wysiwyg' %} | ||
| 39 | + {% else %} | ||
| 40 | + {% render_field field class='form-control' %} | ||
| 41 | + {% endif %} | ||
| 42 | + <span class="help-block">{{ field.help_text }}</span> | ||
| 43 | + {% if field.errors %} | ||
| 44 | + <div class="row"> | ||
| 45 | + </br> | ||
| 46 | + <div class="alert alert-danger alert-dismissible" role="alert"> | ||
| 47 | + <button type="button" class="close" data-dismiss="alert" aria-label="Close"> | ||
| 48 | + <span aria-hidden="true">×</span> | ||
| 49 | + </button> | ||
| 50 | + <ul> | ||
| 51 | + {% for error in field.errors %} | ||
| 52 | + <li>{{ error }}</li> | ||
| 53 | + {% endfor %} | ||
| 54 | + </ul> | ||
| 55 | + </div> | ||
| 56 | + </div> | ||
| 57 | + {% endif %} | ||
| 58 | + </div> | ||
| 59 | + {% endif %} | ||
| 60 | + {% endfor %} | ||
| 61 | + <div class="row text-center"> | ||
| 62 | + <input type="submit" value="{% trans 'Register' %}" class="btn btn-primary btn-raised" /> | ||
| 63 | + </div> | ||
| 64 | +</form> | ||
| 65 | + | ||
| 66 | +<script type="text/javascript"> | ||
| 67 | + $('#id_coordinators').multiSelect({ | ||
| 68 | + selectableHeader: "<input type='text' class='form-control search-input category-search-users' autocomplete='off' placeholder='{% trans "try an username" %} '>", | ||
| 69 | + selectionHeader: "<input type='text' class='form-control search-input category-search-users' autocomplete='off' placeholder='{% trans "try an username" %} '>", | ||
| 70 | + afterInit: function(ms){ | ||
| 71 | + var that = this, | ||
| 72 | + $selectableSearch = that.$selectableUl.prev(), | ||
| 73 | + $selectionSearch = that.$selectionUl.prev(), | ||
| 74 | + selectableSearchString = '#'+that.$container.attr('id')+' .ms-elem-selectable:not(.ms-selected)', | ||
| 75 | + selectionSearchString = '#'+that.$container.attr('id')+' .ms-elem-selection.ms-selected'; | ||
| 76 | + | ||
| 77 | + that.qs1 = $selectableSearch.quicksearch(selectableSearchString) | ||
| 78 | + .on('keydown', function(e){ | ||
| 79 | + if (e.which === 40){ | ||
| 80 | + that.$selectableUl.focus(); | ||
| 81 | + return false; | ||
| 82 | + } | ||
| 83 | + }); | ||
| 84 | + | ||
| 85 | + that.qs2 = $selectionSearch.quicksearch(selectionSearchString) | ||
| 86 | + .on('keydown', function(e){ | ||
| 87 | + if (e.which == 40){ | ||
| 88 | + that.$selectionUl.focus(); | ||
| 89 | + return false; | ||
| 90 | + } | ||
| 91 | + }); | ||
| 92 | + }, | ||
| 93 | + afterSelect: function(){ | ||
| 94 | + this.qs1.cache(); | ||
| 95 | + this.qs2.cache(); | ||
| 96 | + }, | ||
| 97 | + afterDeselect: function(){ | ||
| 98 | + this.qs1.cache(); | ||
| 99 | + this.qs2.cache(); | ||
| 100 | + } | ||
| 101 | + });// Used to create multi-select css style | ||
| 102 | + | ||
| 103 | + $('.collapse').on('show.bs.collapse', function (e) { | ||
| 104 | + if($(this).is(e.target)){ | ||
| 105 | + var btn = $(this).parent().find('.fa-angle-right'); | ||
| 106 | + | ||
| 107 | + btn.switchClass("fa-angle-right", "fa-angle-down", 250, "easeInOutQuad"); | ||
| 108 | + } | ||
| 109 | + }); | ||
| 110 | + | ||
| 111 | + $('.collapse').on('hide.bs.collapse', function (e) { | ||
| 112 | + if($(this).is(e.target)){ | ||
| 113 | + var btn = $(this).parent().find('.fa-angle-down'); | ||
| 114 | + | ||
| 115 | + btn.switchClass("fa-angle-down", "fa-angle-right", 250, "easeInOutQuad"); | ||
| 116 | + } | ||
| 117 | + }); | ||
| 118 | +</script> | ||
| 0 | \ No newline at end of file | 119 | \ No newline at end of file |
categories/templates/categories/create.html
| 1 | -{% extends 'categories/home.html' %} | 1 | +{% extends 'categories/list.html' %} |
| 2 | 2 | ||
| 3 | {% load widget_tweaks static i18n permission_tags django_bootstrap_breadcrumbs switchevenodd %} | 3 | {% load widget_tweaks static i18n permission_tags django_bootstrap_breadcrumbs switchevenodd %} |
| 4 | 4 | ||
| 5 | {% block breadcrumbs %} | 5 | {% block breadcrumbs %} |
| 6 | - {{ block.super }} | ||
| 7 | - {% breadcrumb 'Create Category' 'categories:create' %} | 6 | + {{ block.super }} |
| 7 | + {% breadcrumb 'Create Category' 'categories:create' %} | ||
| 8 | {% endblock %} | 8 | {% endblock %} |
| 9 | 9 | ||
| 10 | {% block content %} | 10 | {% block content %} |
| 11 | -<div class="card card-content"> | ||
| 12 | - <div class="card-body"> | ||
| 13 | - <form method="post" action="" enctype="multipart/form-data"> | ||
| 14 | - {% csrf_token %} | ||
| 15 | - {% for field in form %} | ||
| 16 | - <div class="form-group {% if form.has_error %} has-error {% endif %} is-fileinput"> | ||
| 17 | - {% if field.auto_id != 'id_visible' %} | ||
| 18 | - <label for="{{ field.auto_id }}">{{ field.label }}</label> | ||
| 19 | - {% endif %} | ||
| 20 | - {% if field.auto_id == 'id_init_register_date' or field.auto_id == 'id_end_register_date' or field.auto_id == 'id_init_date' or field.auto_id == 'id_end_date'%} | ||
| 21 | - <input type="text" class="form-control date-picker" name="{{field.name}}" value="{{field.value|date}}" min="{{now|date:'SHORT_DATE_FORMAT'}}"> | ||
| 22 | - {% elif field.auto_id == 'id_visible' %} | ||
| 23 | - <div class="checkbox"> | ||
| 24 | - <label for="{{ field.auto_id }}"> | ||
| 25 | - {% render_field field %} {{field.label}} | ||
| 26 | - </label> | ||
| 27 | - </div> | ||
| 28 | - {% elif field.auto_id == 'id_description' %} | ||
| 29 | - {% render_field field class='form-control text_wysiwyg' %} | ||
| 30 | - | ||
| 31 | - | ||
| 32 | - {% comment %} | ||
| 33 | - | ||
| 34 | - {% endcomment %} | ||
| 35 | - {% elif field.auto_id == 'id_coordinators' %} | ||
| 36 | - <select id="{{field.auto_id}}" multiple="multiple" class="form-control" | ||
| 37 | - style="position: absolute; left: -9999px;" name="coordinators"> | ||
| 38 | - | ||
| 39 | - {% for value, name in form.fields.coordinators.choices %} | ||
| 40 | - <option value="{{value}}">{{name}}</option> | ||
| 41 | - {% endfor %} | ||
| 42 | - </select> | ||
| 43 | - | ||
| 44 | - {% else %} | ||
| 45 | - {% render_field field class='form-control' %} | ||
| 46 | - {% endif %} | ||
| 47 | - <span class="help-block">{{ field.help_text }}</span> | ||
| 48 | - {% if field.errors %} | ||
| 49 | - <div class="row"> | ||
| 50 | - </br> | ||
| 51 | - <div class="alert alert-danger alert-dismissible" role="alert"> | ||
| 52 | - <button type="button" class="close" data-dismiss="alert" aria-label="Close"> | ||
| 53 | - <span aria-hidden="true">×</span> | ||
| 54 | - </button> | ||
| 55 | - <ul> | ||
| 56 | - {% for error in field.errors %} | ||
| 57 | - <li>{{ error }}</li> | ||
| 58 | - {% endfor %} | ||
| 59 | - </ul> | ||
| 60 | - </div> | ||
| 61 | - </div> | ||
| 62 | - {% endif %} | ||
| 63 | - </div> | ||
| 64 | - {% endfor %} | ||
| 65 | - <div class="row text-center"> | ||
| 66 | - <input type="submit" value="{% trans 'Register' %}" class="btn btn-primary btn-raised" /> | ||
| 67 | - </div> | ||
| 68 | - </form> | 11 | + <div class="card card-content"> |
| 12 | + <div class="card-body"> | ||
| 13 | + {% include 'categories/_form.html' %} | ||
| 14 | + </div> | ||
| 69 | </div> | 15 | </div> |
| 70 | -</div> | ||
| 71 | -</br> | ||
| 72 | -</br> | ||
| 73 | -</br> | ||
| 74 | -<script type="text/javascript"> | ||
| 75 | - var locale = navigator.language || navigator.userLanguage; | ||
| 76 | - $('.date-picker').datepicker({ | ||
| 77 | - language: locale, | ||
| 78 | - }); | ||
| 79 | - | ||
| 80 | - $('#id_coordinators').multiSelect({ | ||
| 81 | - selectableHeader: "<input type='text' class='search-input category-search-users' autocomplete='off' placeholder='{% trans "try an username" %} '>", | ||
| 82 | - selectionHeader: "<input type='text' class='search-input category-search-users' autocomplete='off' placeholder='{% trans "try an username" %} '>", | ||
| 83 | - afterInit: function(ms){ | ||
| 84 | - var that = this, | ||
| 85 | - $selectableSearch = that.$selectableUl.prev(), | ||
| 86 | - $selectionSearch = that.$selectionUl.prev(), | ||
| 87 | - selectableSearchString = '#'+that.$container.attr('id')+' .ms-elem-selectable:not(.ms-selected)', | ||
| 88 | - selectionSearchString = '#'+that.$container.attr('id')+' .ms-elem-selection.ms-selected'; | ||
| 89 | - | ||
| 90 | - that.qs1 = $selectableSearch.quicksearch(selectableSearchString) | ||
| 91 | - .on('keydown', function(e){ | ||
| 92 | - if (e.which === 40){ | ||
| 93 | - that.$selectableUl.focus(); | ||
| 94 | - return false; | ||
| 95 | - } | ||
| 96 | - }); | ||
| 97 | - | ||
| 98 | - that.qs2 = $selectionSearch.quicksearch(selectionSearchString) | ||
| 99 | - .on('keydown', function(e){ | ||
| 100 | - if (e.which == 40){ | ||
| 101 | - that.$selectionUl.focus(); | ||
| 102 | - return false; | ||
| 103 | - } | ||
| 104 | - }); | ||
| 105 | - }, | ||
| 106 | - afterSelect: function(){ | ||
| 107 | - this.qs1.cache(); | ||
| 108 | - this.qs2.cache(); | ||
| 109 | - }, | ||
| 110 | - afterDeselect: function(){ | ||
| 111 | - this.qs1.cache(); | ||
| 112 | - this.qs2.cache(); | ||
| 113 | - } | ||
| 114 | - });// Used to create multi-select css style | ||
| 115 | -</script> | 16 | + <br clear="all"> |
| 17 | + <br clear="all"> | ||
| 116 | {% endblock %} | 18 | {% endblock %} |
| 117 | \ No newline at end of file | 19 | \ No newline at end of file |
categories/views.py
| @@ -32,7 +32,6 @@ class IndexView(views.SuperuserRequiredMixin, LoginRequiredMixin, ListView): | @@ -32,7 +32,6 @@ class IndexView(views.SuperuserRequiredMixin, LoginRequiredMixin, ListView): | ||
| 32 | template_name = 'categories/list.html' | 32 | template_name = 'categories/list.html' |
| 33 | context_object_name = 'categories' | 33 | context_object_name = 'categories' |
| 34 | 34 | ||
| 35 | - | ||
| 36 | def get_queryset(self): | 35 | def get_queryset(self): |
| 37 | result = super(IndexView, self).get_queryset() | 36 | result = super(IndexView, self).get_queryset() |
| 38 | 37 | ||
| @@ -77,8 +76,6 @@ class CreateCategory(views.SuperuserRequiredMixin, HasRoleMixin, LogMixin, Creat | @@ -77,8 +76,6 @@ class CreateCategory(views.SuperuserRequiredMixin, HasRoleMixin, LogMixin, Creat | ||
| 77 | template_name = 'categories/create.html' | 76 | template_name = 'categories/create.html' |
| 78 | success_url = reverse_lazy('categories:index') | 77 | success_url = reverse_lazy('categories:index') |
| 79 | 78 | ||
| 80 | - | ||
| 81 | - | ||
| 82 | def get_initial(self): | 79 | def get_initial(self): |
| 83 | initial = super(CreateCategory, self).get_initial() | 80 | initial = super(CreateCategory, self).get_initial() |
| 84 | 81 | ||
| @@ -89,19 +86,25 @@ class CreateCategory(views.SuperuserRequiredMixin, HasRoleMixin, LogMixin, Creat | @@ -89,19 +86,25 @@ class CreateCategory(views.SuperuserRequiredMixin, HasRoleMixin, LogMixin, Creat | ||
| 89 | initial['description'] = category.description | 86 | initial['description'] = category.description |
| 90 | initial['name'] = category.name | 87 | initial['name'] = category.name |
| 91 | initial['visible'] = category.visible | 88 | initial['visible'] = category.visible |
| 92 | - | ||
| 93 | 89 | ||
| 94 | self.log_action = 'replicate' | 90 | self.log_action = 'replicate' |
| 95 | 91 | ||
| 96 | self.log_context['replicated_category_id'] = category.id | 92 | self.log_context['replicated_category_id'] = category.id |
| 97 | self.log_context['replicated_category_name'] = category.name | 93 | self.log_context['replicated_category_name'] = category.name |
| 98 | self.log_context['replicated_category_slug'] = category.slug | 94 | self.log_context['replicated_category_slug'] = category.slug |
| 95 | + | ||
| 99 | return initial | 96 | return initial |
| 100 | 97 | ||
| 101 | def get_context_data(self, **kwargs): | 98 | def get_context_data(self, **kwargs): |
| 102 | context = super(CreateCategory, self).get_context_data(**kwargs) | 99 | context = super(CreateCategory, self).get_context_data(**kwargs) |
| 103 | context['users_count'] = User.objects.all().count() | 100 | context['users_count'] = User.objects.all().count() |
| 104 | context['switch'] = True | 101 | context['switch'] = True |
| 102 | + | ||
| 103 | + if self.kwargs.get('slug'): | ||
| 104 | + context['title'] = _('Replicate Category') | ||
| 105 | + else: | ||
| 106 | + context['title'] = _('Create Category') | ||
| 107 | + | ||
| 105 | return context | 108 | return context |
| 106 | 109 | ||
| 107 | 110 | ||
| @@ -145,7 +148,6 @@ class DeleteCategory(LogMixin, DeleteView): | @@ -145,7 +148,6 @@ class DeleteCategory(LogMixin, DeleteView): | ||
| 145 | model = Category | 148 | model = Category |
| 146 | template_name = 'categories/delete.html' | 149 | template_name = 'categories/delete.html' |
| 147 | 150 | ||
| 148 | - | ||
| 149 | def delete(self, request, *args, **kwargs): | 151 | def delete(self, request, *args, **kwargs): |
| 150 | category = get_object_or_404(Category, slug = self.kwargs.get('slug')) | 152 | category = get_object_or_404(Category, slug = self.kwargs.get('slug')) |
| 151 | subjects = Subject.objects.filter(category = category) | 153 | subjects = Subject.objects.filter(category = category) |
| @@ -181,7 +183,6 @@ class UpdateCategory(LogMixin, UpdateView): | @@ -181,7 +183,6 @@ class UpdateCategory(LogMixin, UpdateView): | ||
| 181 | login_url = reverse_lazy("users:login") | 183 | login_url = reverse_lazy("users:login") |
| 182 | redirect_field_name = 'next' | 184 | redirect_field_name = 'next' |
| 183 | 185 | ||
| 184 | - | ||
| 185 | def get_success_url(self): | 186 | def get_success_url(self): |
| 186 | self.log_context['category_id'] = self.object.id | 187 | self.log_context['category_id'] = self.object.id |
| 187 | self.log_context['category_name'] = self.object.name | 188 | self.log_context['category_name'] = self.object.name |
| @@ -191,8 +192,15 @@ class UpdateCategory(LogMixin, UpdateView): | @@ -191,8 +192,15 @@ class UpdateCategory(LogMixin, UpdateView): | ||
| 191 | 192 | ||
| 192 | objeto = self.object.name | 193 | objeto = self.object.name |
| 193 | messages.success(self.request, _('Category "%s" updated successfully!')%(objeto)) | 194 | messages.success(self.request, _('Category "%s" updated successfully!')%(objeto)) |
| 195 | + | ||
| 194 | return reverse_lazy('categories:index') | 196 | return reverse_lazy('categories:index') |
| 195 | 197 | ||
| 198 | + def get_context_data(self, **kwargs): | ||
| 199 | + context = super(UpdateCategory, self).get_context_data(**kwargs) | ||
| 200 | + context['title'] = _('Update Category') | ||
| 201 | + | ||
| 202 | + return context | ||
| 203 | + | ||
| 196 | @log_decorator_ajax('category', 'view', 'category') | 204 | @log_decorator_ajax('category', 'view', 'category') |
| 197 | def category_view_log(request, category): | 205 | def category_view_log(request, category): |
| 198 | action = request.GET.get('action') | 206 | action = request.GET.get('action') |