Commit 775f2bc388c622fc4b07bccbce01c3658173769b

Authored by Felipe Henrique de Almeida Bormann
1 parent 32fa886a

added subject to apps, modified delete message and checked for condition on categories index

amadeus/settings.py
@@ -55,7 +55,8 @@ INSTALLED_APPS = [ @@ -55,7 +55,8 @@ INSTALLED_APPS = [
55 'users', 55 'users',
56 'notifications', 56 'notifications',
57 'log', 57 'log',
58 - 'categories' 58 + 'categories',
  59 + 'subjects'
59 ] 60 ]
60 61
61 MIDDLEWARE_CLASSES = [ 62 MIDDLEWARE_CLASSES = [
categories/templates/categories/delete.html
@@ -14,7 +14,7 @@ @@ -14,7 +14,7 @@
14 <!-- Put ONLY your content here!!! --> 14 <!-- Put ONLY your content here!!! -->
15 <form id="delete_form" action="{% url 'categories:delete' category.slug %}" method="post"> 15 <form id="delete_form" action="{% url 'categories:delete' category.slug %}" method="post">
16 {% csrf_token %} 16 {% csrf_token %}
17 - <p>{% trans 'Are you sure you want to delete the category' %} "{{category.name}}"?</p> 17 + <p>{% trans 'Are you sure you want to delete the category' %} "{{category.name}}"? {% trans "All its data will be lost and can't be recovered" %}</p>
18 </form> 18 </form>
19 </div> 19 </div>
20 <!-- Modal Footer --> 20 <!-- Modal Footer -->
categories/templates/categories/list.html
@@ -23,7 +23,9 @@ @@ -23,7 +23,9 @@
23 {% endfor %} 23 {% endfor %}
24 {% endif %} 24 {% endif %}
25 25
26 -<a href="{% url 'categories:create' %}"><button id="create-category"> {% trans "Create Category" %}</button></a> 26 +{% if user.is_staff %}
  27 + <a href="{% url 'categories:create' %}"><button id="create-category"> {% trans "Create Category" %}</button></a>
  28 +{% endif %}
27 29
28 <!-- Code for listing categories --> 30 <!-- Code for listing categories -->
29 <div class="col-md-12 cards-content"> 31 <div class="col-md-12 cards-content">
categories/views.py
@@ -83,6 +83,12 @@ class DeleteCategory(HasRoleMixin, DeleteView): @@ -83,6 +83,12 @@ class DeleteCategory(HasRoleMixin, DeleteView):
83 model = Category 83 model = Category
84 template_name = 'categories/delete.html' 84 template_name = 'categories/delete.html'
85 85
  86 + def dispatch(self, *args, **kwargs):
  87 + category = get_object_or_404(Category, slug = self.kwargs.get('slug'))
  88 + if len(category.subject_set) > 0:
  89 + return self.handle_no_permission()
  90 +
  91 + return super(DeleteCategory, self).dispatch(*args, **kwargs)
86 92
87 def get_success_url(self): 93 def get_success_url(self):
88 94