Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
scheduling-system
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
External wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
SMASCH
scheduling-system
Commits
e455165e
Commit
e455165e
authored
5 years ago
by
Piotr Gawron
Browse files
Options
Downloads
Patches
Plain Diff
when there is a problem with save/modify/delete mail template show error message to the user
parent
7e788917
No related branches found
Branches containing commit
No related tags found
1 merge request
!227
Resolve "exception should be handled properly"
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
smash/web/views/mails.py
+26
-11
26 additions, 11 deletions
smash/web/views/mails.py
with
26 additions
and
11 deletions
smash/web/views/mails.py
+
26
−
11
View file @
e455165e
...
...
@@ -4,23 +4,19 @@ from wsgiref.util import FileWrapper
from
django.contrib
import
messages
from
django.http
import
HttpResponse
from
django.shortcuts
import
get_object_or_404
from
django.shortcuts
import
redirect
,
get_object_or_404
from
django.urls
import
reverse_lazy
from
django.views.generic
import
CreateView
from
django.views.generic
import
DeleteView
from
django.views.generic
import
ListView
from
django.views.generic
import
UpdateView
from
web.docx_helper
import
merge_files
from
.
import
WrappedView
from
.
import
wrap_response
from
..forms.mail_template
import
MailTemplateForm
from
..models
import
StudySubject
,
Visit
,
Appointment
,
MailTemplate
,
Voucher
from
..models.constants
import
MAIL_TEMPLATE_CONTEXT_SUBJECT
,
MAIL_TEMPLATE_CONTEXT_VISIT
,
\
MAIL_TEMPLATE_CONTEXT_APPOINTMENT
,
MAIL_TEMPLATE_CONTEXT_VOUCHER
from
..forms.mail_template
import
MailTemplateForm
from
.
import
wrap_response
from
django.shortcuts
import
redirect
,
get_object_or_404
MIMETYPE_DOCX
=
'
application/vnd.openxmlformats-officedocument.wordprocessingml.document
'
CONTEXT_TYPES_MAPPING
=
{
...
...
@@ -46,29 +42,41 @@ class MailTemplatesListView(ListView, WrappedView):
}
return
context
def
mail_template_add
(
request
):
if
request
.
method
==
'
POST
'
:
form
=
MailTemplateForm
(
request
.
POST
,
request
.
FILES
)
if
form
.
is_valid
():
form
.
save
()
try
:
form
.
save
()
except
:
messages
.
add_message
(
request
,
messages
.
ERROR
,
'
There was a problem when saving template.
'
'
Contact system administrator.
'
)
return
redirect
(
'
web.views.mail_templates
'
)
else
:
form
=
MailTemplateForm
()
return
wrap_response
(
request
,
'
mail_templates/add.html
'
,
{
'
form
'
:
form
})
def
mail_template_edit
(
request
,
pk
):
template
=
get_object_or_404
(
MailTemplate
,
pk
=
pk
)
if
request
.
method
==
'
POST
'
:
form
=
MailTemplateForm
(
request
.
POST
,
request
.
FILES
,
instance
=
template
)
if
form
.
is_valid
():
form
.
save
()
return
redirect
(
'
web.views.mail_templates
'
)
try
:
form
.
save
()
return
redirect
(
'
web.views.mail_templates
'
)
except
:
messages
.
add_message
(
request
,
messages
.
ERROR
,
'
There was a problem when updating template.
'
'
Contact system administrator.
'
)
return
wrap_response
(
request
,
'
mail_templates/edit.html
'
,
{
'
form
'
:
form
,
'
mail_template
'
:
template
})
else
:
form
=
MailTemplateForm
(
instance
=
template
)
return
wrap_response
(
request
,
'
mail_templates/edit.html
'
,
{
'
form
'
:
form
,
'
mail_template
'
:
template
})
class
MailTemplatesDeleteView
(
DeleteView
,
WrappedView
):
model
=
MailTemplate
success_url
=
reverse_lazy
(
'
web.views.mail_templates
'
)
...
...
@@ -76,7 +84,13 @@ class MailTemplatesDeleteView(DeleteView, WrappedView):
def
delete
(
self
,
request
,
*
args
,
**
kwargs
):
messages
.
success
(
request
,
"
Template deleted
"
)
return
super
(
MailTemplatesDeleteView
,
self
).
delete
(
request
,
*
args
,
**
kwargs
)
try
:
return
super
(
MailTemplatesDeleteView
,
self
).
delete
(
request
,
*
args
,
**
kwargs
)
except
:
messages
.
add_message
(
request
,
messages
.
ERROR
,
'
There was a problem when deleting template.
'
'
Contact system administrator.
'
)
return
redirect
(
'
web.views.mail_templates
'
)
def
generate
(
request
,
mail_template_id
,
instance_id
):
mail_template
=
get_object_or_404
(
MailTemplate
,
id
=
mail_template_id
)
...
...
@@ -90,6 +104,7 @@ def generate(request, mail_template_id, instance_id):
response
[
'
Content-Disposition
'
]
=
'
attachment; filename={}.docx
'
.
format
(
mail_template
.
name
)
return
response
def
generate_for_vouchers
(
request
):
ids
=
request
.
GET
.
get
(
'
voucher_id
'
,
''
).
split
(
'
,
'
)
vouchers
=
[]
...
...
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