Commit 5bce8d3391faf4ced140ba7e1e75852d62bc514c

Authored by Zambom
1 parent dee54f99

Adjusting category crud

categories/templates/categories/_form.html
@@ -59,7 +59,7 @@ @@ -59,7 +59,7 @@
59 {% endif %} 59 {% endif %}
60 {% endfor %} 60 {% endfor %}
61 <div class="row text-center"> 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 </div> 63 </div>
64 </form> 64 </form>
65 65
categories/templates/categories/update.html
1 -{% extends 'categories/home.html' %} 1 +{% extends 'categories/list.html' %}
2 2
3 {% load static i18n %} 3 {% load static i18n %}
4 {% load widget_tweaks django_bootstrap_breadcrumbs %} 4 {% load widget_tweaks django_bootstrap_breadcrumbs %}
5 5
6 {% block breadcrumbs %} 6 {% block breadcrumbs %}
7 {{ block.super }} 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 {% endblock %} 11 {% endblock %}
10 12
11 {% block content %} 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">&times;</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 </div> 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 {% endblock %} 22 {% endblock %}
105 \ No newline at end of file 23 \ No newline at end of file
categories/views.py
@@ -86,6 +86,8 @@ class CreateCategory(views.SuperuserRequiredMixin, HasRoleMixin, LogMixin, Creat @@ -86,6 +86,8 @@ class CreateCategory(views.SuperuserRequiredMixin, HasRoleMixin, LogMixin, Creat
86 initial['description'] = category.description 86 initial['description'] = category.description
87 initial['name'] = category.name 87 initial['name'] = category.name
88 initial['visible'] = category.visible 88 initial['visible'] = category.visible
  89 + initial['coordinators'] = category.coordinators.all()
  90 + print(category.coordinators.all())
89 91
90 self.log_action = 'replicate' 92 self.log_action = 'replicate'
91 93
@@ -107,18 +109,6 @@ class CreateCategory(views.SuperuserRequiredMixin, HasRoleMixin, LogMixin, Creat @@ -107,18 +109,6 @@ class CreateCategory(views.SuperuserRequiredMixin, HasRoleMixin, LogMixin, Creat
107 109
108 return context 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 def form_valid(self, form): 112 def form_valid(self, form):
123 self.object = form.save() 113 self.object = form.save()
124 114