Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
AlekSIS-Core
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Terraform modules
Monitor
Service Desk
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
AlekSIS®
Official
AlekSIS-Core
Commits
cdc4fcbb
Verified
Commit
cdc4fcbb
authored
4 years ago
by
Jonathan Weth
Browse files
Options
Downloads
Patches
Plain Diff
Add a common class-based delete view (including template)
parent
297fdc37
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!331
Add a common class-based delete view (including template)
Pipeline
#3043
passed
4 years ago
Stage: test
Stage: build
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
aleksis/core/mixins.py
+11
-1
11 additions, 1 deletion
aleksis/core/mixins.py
aleksis/core/templates/core/pages/delete.html
+25
-0
25 additions, 0 deletions
aleksis/core/templates/core/pages/delete.html
aleksis/core/templatetags/data_helpers.py
+12
-0
12 additions, 0 deletions
aleksis/core/templatetags/data_helpers.py
with
48 additions
and
1 deletion
aleksis/core/mixins.py
+
11
−
1
View file @
cdc4fcbb
...
...
@@ -16,7 +16,7 @@ from django.http import HttpResponse
from
django.utils.functional
import
lazy
from
django.utils.translation
import
gettext
as
_
from
django.views.generic
import
CreateView
,
UpdateView
from
django.views.generic.edit
import
ModelFormMixin
from
django.views.generic.edit
import
DeleteView
,
ModelFormMixin
import
reversion
from
easyaudit.models
import
CRUDEvent
...
...
@@ -375,6 +375,16 @@ class AdvancedEditView(UpdateView, SuccessMessageMixin):
pass
class
AdvancedDeleteView
(
DeleteView
):
success_message
:
Optional
[
str
]
=
None
def
delete
(
self
,
request
,
*
args
,
**
kwargs
):
r
=
super
().
delete
(
request
,
*
args
,
**
kwargs
)
if
self
.
success_message
:
messages
.
success
(
self
.
request
,
self
.
success_message
)
return
r
class
SchoolTermRelatedExtensibleModel
(
ExtensibleModel
):
"""
Add relation to school term.
"""
...
...
This diff is collapsed.
Click to expand it.
aleksis/core/templates/core/pages/delete.html
0 → 100644
+
25
−
0
View file @
cdc4fcbb
{% extends "core/base.html" %}
{% load data_helpers i18n %}
{% block browser_title %}
{% verbose_name_object object as object_name %}
{% blocktrans with object_name=object_name %}Delete {{ object_name }}{% endblocktrans %}
{% endblock %}
{% block content %}
{% verbose_name_object object as object_name %}
<p
class=
"flow-text"
>
{% blocktrans with object_name=object_name object=object %}
Do you really want to delete the {{ object_name }} "{{ object }}"?
{% endblocktrans %}
</p>
<form
method=
"post"
action=
""
>
{% csrf_token %}
<button
type=
"submit"
class=
"btn red waves-effect waves-light"
>
<i
class=
"material-icons left"
>
delete
</i>
{% trans "Delete" %}
</button>
</form>
{% endblock %}
This diff is collapsed.
Click to expand it.
aleksis/core/templatetags/data_helpers.py
+
12
−
0
View file @
cdc4fcbb
...
...
@@ -3,6 +3,7 @@ from typing import Any, Optional, Union
from
django
import
template
from
django.contrib.contenttypes.models
import
ContentType
from
django.db.models
import
Model
register
=
template
.
Library
()
...
...
@@ -33,6 +34,17 @@ def verbose_name(app_label: str, model: str, field: Optional[str] = None) -> str
return
ct
.
_meta
.
verbose_name
.
title
()
@register.simple_tag
def
verbose_name_object
(
model
:
Model
,
field
:
Optional
[
str
]
=
None
)
->
str
:
"""
Get a verbose name of a model or a field by a model or an instance of a model.
"""
if
field
:
# Field
return
model
.
_meta
.
get_field
(
field
).
verbose_name
.
title
()
else
:
# Whole model
return
model
.
_meta
.
verbose_name
.
title
()
@register.simple_tag
def
parse_json
(
value
:
Optional
[
str
]
=
None
)
->
Union
[
dict
,
None
]:
"""
Template tag for parsing JSON from a string.
"""
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment