Commit 5bce8d3391faf4ced140ba7e1e75852d62bc514c
1 parent
dee54f99
Exists in
master
and in
3 other branches
Adjusting category crud
Showing
3 changed files
with
13 additions
and
105 deletions
Show diff stats
categories/templates/categories/_form.html
... | ... | @@ -59,7 +59,7 @@ |
59 | 59 | {% endif %} |
60 | 60 | {% endfor %} |
61 | 61 | <div class="row text-center"> |
62 | - <input type="submit" value="{% trans 'Register' %}" class="btn btn-primary btn-raised" /> | |
62 | + <input type="submit" value="{% trans 'Save' %}" class="btn btn-primary btn-raised" /> | |
63 | 63 | </div> |
64 | 64 | </form> |
65 | 65 | ... | ... |
categories/templates/categories/update.html
1 | -{% extends 'categories/home.html' %} | |
1 | +{% extends 'categories/list.html' %} | |
2 | 2 | |
3 | 3 | {% load static i18n %} |
4 | 4 | {% load widget_tweaks django_bootstrap_breadcrumbs %} |
5 | 5 | |
6 | 6 | {% block breadcrumbs %} |
7 | 7 | {{ block.super }} |
8 | - {% breadcrumb 'Update' 'categories:update' category.slug %} | |
8 | + {% with 'Update '|add:category.slug as bread_slug %} | |
9 | + {% breadcrumb bread_slug 'categories:update' %} | |
10 | + {% endwith %} | |
9 | 11 | {% endblock %} |
10 | 12 | |
11 | 13 | {% block content %} |
12 | -</br> | |
13 | -<div class="card card-content"> | |
14 | - <div class="card-body"> | |
15 | - <form method="post" action="" enctype="multipart/form-data"> | |
16 | - {% csrf_token %} | |
17 | - {% for field in form %} | |
18 | - <div class="form-group {% if form.has_error %} has-error {% endif %} is-fileinput"> | |
19 | - {% if field.auto_id != 'id_visible' %} | |
20 | - <label for="{{ field.auto_id }}">{{ field.label }}</label> | |
21 | - {% endif %} | |
22 | - {% 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'%} | |
23 | - <input type="text" class="form-control date-picker" name="{{field.name}}" value="{{field.value|date:'SHORT_DATE_FORMAT'}}" min="{{now|date:'SHORT_DATE_FORMAT'}}"> | |
24 | - {% elif field.auto_id == 'id_visible' %} | |
25 | - <div class="checkbox"> | |
26 | - <label for="{{ field.auto_id }}"> | |
27 | - {% render_field field %} {{field.label}} | |
28 | - </label> | |
29 | - </div> | |
30 | - {% elif field.auto_id == 'id_description' %} | |
31 | - {% render_field field class='form-control text_wysiwyg' %} | |
32 | - {% else %} | |
33 | - {% render_field field class='form-control' %} | |
34 | - {% endif %} | |
35 | - <span class="help-block">{{ field.help_text }}</span> | |
36 | - {% if field.errors %} | |
37 | - <div class="row"> | |
38 | - </br> | |
39 | - <div class="alert alert-danger alert-dismissible" role="alert"> | |
40 | - <button type="button" class="close" data-dismiss="alert" aria-label="Close"> | |
41 | - <span aria-hidden="true">×</span> | |
42 | - </button> | |
43 | - <ul> | |
44 | - {% for error in field.errors %} | |
45 | - <li>{{ error }}</li> | |
46 | - {% endfor %} | |
47 | - </ul> | |
48 | - </div> | |
49 | - </div> | |
50 | - {% endif %} | |
51 | - </div> | |
52 | - {% endfor %} | |
53 | - <div class="row text-center"> | |
54 | - <input type="submit" value="{% trans 'Update' %}" class="btn btn-primary btn-raised" /> | |
55 | - </div> | |
56 | - </form> | |
14 | + <div class="card card-content"> | |
15 | + <div class="card-body"> | |
16 | + {% include 'categories/_form.html' %} | |
17 | + </div> | |
57 | 18 | </div> |
58 | -</div> | |
59 | -</br> | |
60 | -</br> | |
61 | -</br> | |
62 | -<script type="text/javascript"> | |
63 | - var locale = navigator.language || navigator.userLanguage; | |
64 | - $('.date-picker').datepicker({ | |
65 | - language: locale, | |
66 | - }); | |
19 | + <br clear="all" /> | |
20 | + <br clear="all" /> | |
67 | 21 | |
68 | - $('#id_coordinators').multiSelect({ | |
69 | - selectableHeader: "<input type='text' class='search-input category-search-users' autocomplete='off' placeholder='{% trans "try an username" %} '>", | |
70 | - selectionHeader: "<input type='text' class='search-input category-search-users' autocomplete='off' placeholder='{% trans "try an username" %} '>", | |
71 | - afterInit: function(ms){ | |
72 | - var that = this, | |
73 | - $selectableSearch = that.$selectableUl.prev(), | |
74 | - $selectionSearch = that.$selectionUl.prev(), | |
75 | - selectableSearchString = '#'+that.$container.attr('id')+' .ms-elem-selectable:not(.ms-selected)', | |
76 | - selectionSearchString = '#'+that.$container.attr('id')+' .ms-elem-selection.ms-selected'; | |
77 | - | |
78 | - that.qs1 = $selectableSearch.quicksearch(selectableSearchString) | |
79 | - .on('keydown', function(e){ | |
80 | - if (e.which === 40){ | |
81 | - that.$selectableUl.focus(); | |
82 | - return false; | |
83 | - } | |
84 | - }); | |
85 | - | |
86 | - that.qs2 = $selectionSearch.quicksearch(selectionSearchString) | |
87 | - .on('keydown', function(e){ | |
88 | - if (e.which == 40){ | |
89 | - that.$selectionUl.focus(); | |
90 | - return false; | |
91 | - } | |
92 | - }); | |
93 | - }, | |
94 | - afterSelect: function(){ | |
95 | - this.qs1.cache(); | |
96 | - this.qs2.cache(); | |
97 | - }, | |
98 | - afterDeselect: function(){ | |
99 | - this.qs1.cache(); | |
100 | - this.qs2.cache(); | |
101 | - } | |
102 | - });// Used to create multi-select css style | |
103 | -</script> | |
104 | 22 | {% endblock %} |
105 | 23 | \ No newline at end of file | ... | ... |
categories/views.py
... | ... | @@ -86,6 +86,8 @@ class CreateCategory(views.SuperuserRequiredMixin, HasRoleMixin, LogMixin, Creat |
86 | 86 | initial['description'] = category.description |
87 | 87 | initial['name'] = category.name |
88 | 88 | initial['visible'] = category.visible |
89 | + initial['coordinators'] = category.coordinators.all() | |
90 | + print(category.coordinators.all()) | |
89 | 91 | |
90 | 92 | self.log_action = 'replicate' |
91 | 93 | |
... | ... | @@ -107,18 +109,6 @@ class CreateCategory(views.SuperuserRequiredMixin, HasRoleMixin, LogMixin, Creat |
107 | 109 | |
108 | 110 | return context |
109 | 111 | |
110 | - | |
111 | - def get_form(self, form_class=None): | |
112 | - """ | |
113 | - Returns an instance of the form to be used in this view. | |
114 | - """ | |
115 | - #print(self.kwargs) | |
116 | - if form_class is None: | |
117 | - form_class = self.get_form_class() | |
118 | - | |
119 | - | |
120 | - return form_class(**self.get_form_kwargs()) | |
121 | - | |
122 | 112 | def form_valid(self, form): |
123 | 113 | self.object = form.save() |
124 | 114 | ... | ... |