Commit 775f2bc388c622fc4b07bccbce01c3658173769b
1 parent
32fa886a
Exists in
master
and in
3 other branches
added subject to apps, modified delete message and checked for condition on categories index
Showing
4 changed files
with
12 additions
and
3 deletions
Show diff stats
amadeus/settings.py
categories/templates/categories/delete.html
... | ... | @@ -14,7 +14,7 @@ |
14 | 14 | <!-- Put ONLY your content here!!! --> |
15 | 15 | <form id="delete_form" action="{% url 'categories:delete' category.slug %}" method="post"> |
16 | 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 | 18 | </form> |
19 | 19 | </div> |
20 | 20 | <!-- Modal Footer --> | ... | ... |
categories/templates/categories/list.html
... | ... | @@ -23,7 +23,9 @@ |
23 | 23 | {% endfor %} |
24 | 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 | 30 | <!-- Code for listing categories --> |
29 | 31 | <div class="col-md-12 cards-content"> | ... | ... |
categories/views.py
... | ... | @@ -83,6 +83,12 @@ class DeleteCategory(HasRoleMixin, DeleteView): |
83 | 83 | model = Category |
84 | 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 | 93 | def get_success_url(self): |
88 | 94 | ... | ... |