Commit 4871aa0b0facb1f898274da6884a22bf63027002
1 parent
5ad748c4
Exists in
master
and in
3 other branches
update subject view is working 100%
Showing
6 changed files
with
135 additions
and
5 deletions
Show diff stats
categories/views.py
... | ... | @@ -198,7 +198,7 @@ class UpdateCategory(LogMixin, UpdateView): |
198 | 198 | context['settings_menu_active'] = "settings_menu_active" |
199 | 199 | else: |
200 | 200 | context['template_extends'] = 'subjects/list.html' |
201 | - context['subjects_menu_active'] = 'subjects_menu_active'; | |
201 | + context['subjects_menu_active'] = 'subjects_menu_active' | |
202 | 202 | |
203 | 203 | return context |
204 | 204 | ... | ... |
subjects/forms.py
subjects/templates/subjects/subject_card.html
... | ... | @@ -20,7 +20,7 @@ |
20 | 20 | </a> |
21 | 21 | <ul class="dropdown-menu pull-right" aria-labelledby="moreActions"> |
22 | 22 | <li><a href="{% url 'subjects:replicate' subject.slug %}"><i class="fa fa-files-o fa-fw" aria-hidden="true"></i>{% trans 'Replicate' %}</a></li> |
23 | - <li><a href="#"><i class="fa fa-pencil fa-fw" aria-hidden="true"></i>{% trans 'Edit' %}</a></li> | |
23 | + <li><a href="{% url 'subjects:update' subject.slug %}"><i class="fa fa-pencil fa-fw" aria-hidden="true"></i>{% trans 'Edit' %}</a></li> | |
24 | 24 | <li><a href="#"><i class="fa fa-trash fa-fw" aria-hidden="true"></i> {% trans 'Remove' %}</a></li> |
25 | 25 | </ul> |
26 | 26 | {% endif %} |
... | ... | @@ -81,7 +81,7 @@ |
81 | 81 | </a> |
82 | 82 | <ul class="dropdown-menu pull-right" aria-labelledby="moreActions"> |
83 | 83 | <li><a href="{% url 'subjects:replicate' subject.slug %}"><i class="fa fa-files-o fa-fw" aria-hidden="true"></i>{% trans 'Replicate' %}</a></li> |
84 | - <li><a href="#"><i class="fa fa-pencil fa-fw" aria-hidden="true"></i>{% trans 'Edit' %}</a></li> | |
84 | + <li><a href="{% url 'subjects:update' subject.slug %}"><i class="fa fa-pencil fa-fw" aria-hidden="true"></i>{% trans 'Edit' %}</a></li> | |
85 | 85 | <li><a href="#"><i class="fa fa-trash fa-fw" aria-hidden="true"></i> {% trans 'Remove' %}</a></li> |
86 | 86 | </ul> |
87 | 87 | {% endif %} | ... | ... |
... | ... | @@ -0,0 +1,107 @@ |
1 | +{% extends template_extends %} | |
2 | + | |
3 | +{% load static i18n %} | |
4 | +{% load widget_tweaks django_bootstrap_breadcrumbs %} | |
5 | + | |
6 | +{% block breadcrumbs %} | |
7 | + {{ block.super }} | |
8 | + {% with 'Update '|add:object.slug as bread_slug %} | |
9 | + {% breadcrumb bread_slug 'subjects:update' %} | |
10 | + {% endwith %} | |
11 | +{% endblock breadcrumbs %} | |
12 | + | |
13 | +{% block content %} | |
14 | + <div class="card card-content"> | |
15 | + <div class="card-body"> | |
16 | + <form method="post" action="" enctype="multipart/form-data"> | |
17 | + {% csrf_token %} | |
18 | + {% for field in form %} | |
19 | + {% if field.auto_id == 'id_students' %} | |
20 | + <div class="panel-group" id="coordinators_accordion" role="tablist" aria-multiselectable="true"> | |
21 | + <div class="panel panel-info"> | |
22 | + <div class="panel-heading"> | |
23 | + <div class="row"> | |
24 | + <div class="col-md-12"> | |
25 | + <a data-parent="#coordinators_accordion" data-toggle="collapse" href="#students"> | |
26 | + <h4 class="panel-title"> | |
27 | + <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> | |
28 | + </h4> | |
29 | + </a> | |
30 | + </div> | |
31 | + </div> | |
32 | + </div> | |
33 | + <div id="students" class="panel-collapse collapse"> | |
34 | + <p><em>{% trans 'Attribute students to subject' %}:</em></p> | |
35 | + {% render_field field class='form-control' %} | |
36 | + </div> | |
37 | + </div> | |
38 | + </div> | |
39 | + {% elif field.auto_id == 'id_professor' %} | |
40 | + <div class="panel-group" id="professors_accordion" role="tablist" aria-multiselectable="true"> | |
41 | + <div class="panel panel-info"> | |
42 | + <div class="panel-heading"> | |
43 | + <div class="row"> | |
44 | + <div class="col-md-12"> | |
45 | + <a data-parent="#professors_accordion" data-toggle="collapse" href="#professors"> | |
46 | + <h4 class="panel-title"> | |
47 | + <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> | |
48 | + </h4> | |
49 | + </a> | |
50 | + </div> | |
51 | + </div> | |
52 | + </div> | |
53 | + <div id="professors" class="panel-collapse collapse"> | |
54 | + <p><em>{% trans 'Attribute professors to subject' %}:</em></p> | |
55 | + {% render_field field class='form-control' %} | |
56 | + </div> | |
57 | + </div> | |
58 | + </div> | |
59 | + {% elif field.auto_id == 'id_markers'%} | |
60 | + <label> {{field.label}} </label> | |
61 | + {% render_field field class='form-control' data-role="tagsinput" %} | |
62 | + {% else %} | |
63 | + <div class="form-group {% if form.has_error %} has-error {% endif %} is-fileinput"> | |
64 | + {% if field.auto_id != 'id_visible' %} | |
65 | + <label for="{{ field.auto_id }}">{{ field.label }}</label> | |
66 | + {% endif %} | |
67 | + {% if field.auto_id == 'id_visible' %} | |
68 | + <div class="checkbox"> | |
69 | + <label for="{{ field.auto_id }}"> | |
70 | + {% render_field field %} {{field.label}} | |
71 | + </label> | |
72 | + </div> | |
73 | + {% elif field.auto_id == 'id_description' or field.auto_id == 'id_description_brief' %} | |
74 | + {% render_field field class='form-control text_wysiwyg' %} | |
75 | + {% else %} | |
76 | + {% render_field field class='form-control' %} | |
77 | + {% endif %} | |
78 | + <span class="help-block">{{ field.help_text }}</span> | |
79 | + {% if field.errors %} | |
80 | + <div class="row"> | |
81 | + </br> | |
82 | + <div class="alert alert-danger alert-dismissible" role="alert"> | |
83 | + <button type="button" class="close" data-dismiss="alert" aria-label="Close"> | |
84 | + <span aria-hidden="true">×</span> | |
85 | + </button> | |
86 | + <ul> | |
87 | + {% for error in field.errors %} | |
88 | + <li>{{ error }}</li> | |
89 | + {% endfor %} | |
90 | + </ul> | |
91 | + </div> | |
92 | + </div> | |
93 | + {% endif %} | |
94 | + </div> | |
95 | + {% endif %} | |
96 | + | |
97 | + {% endfor %} | |
98 | + <div class="row text-center"> | |
99 | + <input type="submit" value="{% trans 'Save' %}" class="btn btn-primary btn-raised" /> | |
100 | + </div> | |
101 | + </form> | |
102 | + </div> | |
103 | + </div> | |
104 | + <br clear="all" /> | |
105 | + <br clear="all" /> | |
106 | + | |
107 | +{% endblock %} | |
0 | 108 | \ No newline at end of file | ... | ... |
subjects/urls.py
... | ... | @@ -6,5 +6,6 @@ urlpatterns = [ |
6 | 6 | url(r'^$', views.IndexView.as_view(), name='index'), |
7 | 7 | url(r'^(?P<option>[\w_-]+)/$', views.IndexView.as_view(), name='index'), |
8 | 8 | url(r'^create/(?P<slug>[\w_-]+)/$', views.SubjectCreateView.as_view(), name='create'), |
9 | - url(r'^replicate/(?P<subject_slug>[\w_-]+)$', views.SubjectCreateView.as_view(), name='replicate'), | |
9 | + url(r'^replicate/(?P<subject_slug>[\w_-]+)/$', views.SubjectCreateView.as_view(), name='replicate'), | |
10 | + url(r'^update/(?P<slug>[\w_-]+)/$', views.SubjectUpdateView.as_view(), name='update'), | |
10 | 11 | ] |
11 | 12 | \ No newline at end of file | ... | ... |
subjects/views.py
... | ... | @@ -175,3 +175,26 @@ class SubjectCreateView(CreateView): |
175 | 175 | return reverse_lazy('subjects:index') |
176 | 176 | |
177 | 177 | |
178 | + | |
179 | + | |
180 | +class SubjectUpdateView(LogMixin, UpdateView): | |
181 | + | |
182 | + model = Subject | |
183 | + form_class = CreateSubjectForm | |
184 | + template_name = 'subjects/update.html' | |
185 | + | |
186 | + login_url = reverse_lazy("users:login") | |
187 | + redirect_field_name = 'next' | |
188 | + def get_context_data(self, **kwargs): | |
189 | + context = super(SubjectUpdateView, self).get_context_data(**kwargs) | |
190 | + context['title'] = _('Update Subject') | |
191 | + context['template_extends'] = 'base.html' | |
192 | + context['subjects_menu_active'] = 'subjects_menu_active' | |
193 | + return context | |
194 | + | |
195 | + def get_success_url(self): | |
196 | + | |
197 | + | |
198 | + messages.success(self.request, _('Subject "%s" was updated on "%s" successfully!')%(self.object.name, self.object.category.name )) | |
199 | + return reverse_lazy('subjects:index') | |
200 | + | ... | ... |