Commit bc49fac021682c83e0271cce27dbccf479d133aa
1 parent
fc681d05
Exists in
master
and in
3 other branches
update view complete and cycle has success message at the end
Showing
4 changed files
with
86 additions
and
2 deletions
Show diff stats
categories/templates/categories/list.html
... | ... | @@ -61,7 +61,7 @@ |
61 | 61 | <li><a href="{% url 'categories:replicate' category.slug %}"><i class="fa fa-files-o fa-fw" aria-hidden="true"></i>{% trans 'Replicate' %}</a></li> |
62 | 62 | {% endif %} |
63 | 63 | |
64 | - <li><a href="#"><i class="fa fa-pencil fa-fw" aria-hidden="true"></i>{% trans 'Edit' %}</a></li> | |
64 | + <li><a href="{% url 'categories:update' category.slug %}"><i class="fa fa-pencil fa-fw" aria-hidden="true"></i>{% trans 'Edit' %}</a></li> | |
65 | 65 | <li><a href="javascript:delete_course.get('{% url 'categories:delete' category.slug %}?view=index','#category','#modal_course')"><i class="fa fa-trash fa-fw" aria-hidden="true"></i> {% trans 'Remove' %}</a></li> |
66 | 66 | </ul> |
67 | 67 | </div> | ... | ... |
... | ... | @@ -0,0 +1,68 @@ |
1 | +{% extends 'categories/home.html' %} | |
2 | + | |
3 | +{% load static i18n %} | |
4 | +{% load widget_tweaks django_bootstrap_breadcrumbs %} | |
5 | + | |
6 | +{% block breadcrumbs %} | |
7 | + {{ block.super }} | |
8 | + {% breadcrumb 'Update' 'categories:update' category.slug %} | |
9 | +{% endblock %} | |
10 | + | |
11 | +{% 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_public' %} | |
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_public' %} | |
25 | + <div class="checkbox"> | |
26 | + <label> | |
27 | + <input type="checkbox" name="{{field.name}}" {% if field.value %}checked="checked"{% endif %}><span class="checkbox-material"></span> {{field.name}} | |
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> | |
57 | + </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 | + }); | |
67 | +</script> | |
68 | +{% endblock %} | |
0 | 69 | \ No newline at end of file | ... | ... |
categories/urls.py
... | ... | @@ -6,4 +6,5 @@ urlpatterns = [ |
6 | 6 | url(r'^create/$', views.CreateCategory.as_view(), name='create'), |
7 | 7 | url(r'^delete/(?P<slug>[\w_-]+)/$', views.DeleteCategory.as_view(), name='delete'), |
8 | 8 | url(r'^replicate/(?P<slug>[\w_-]+)/$', views.CreateCategory.as_view(), name='replicate'), |
9 | + url(r'^update/(?P<slug>[\w_-]+)/$', views.UpdateCategory.as_view(), name='update'), | |
9 | 10 | ] |
10 | 11 | \ No newline at end of file | ... | ... |
categories/views.py
1 | 1 | from django.shortcuts import render, get_object_or_404 |
2 | -from django.views.generic import ListView, CreateView, DeleteView | |
2 | +from django.views.generic import ListView, CreateView, DeleteView, UpdateView | |
3 | 3 | from .models import Category |
4 | 4 | from django.core.urlresolvers import reverse_lazy |
5 | 5 | from rolepermissions.verifications import has_role |
... | ... | @@ -127,3 +127,18 @@ class DeleteCategory(DeleteView): |
127 | 127 | |
128 | 128 | return reverse_lazy('categories:index') |
129 | 129 | |
130 | + | |
131 | +class UpdateCategory(UpdateView): | |
132 | + model = Category | |
133 | + form_class = CategoryForm | |
134 | + template_name = 'categories/update.html' | |
135 | + | |
136 | + login_url = reverse_lazy("users:login") | |
137 | + redirect_field_name = 'next' | |
138 | + | |
139 | + | |
140 | + def get_success_url(self): | |
141 | + messages.success(self.request, _('Category "%s" updated successfully!')%(objeto)) | |
142 | + return reverse_lazy('categories:index') | |
143 | + | |
144 | + | ... | ... |