Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Sign in
Toggle navigation
R
red-ci-cd
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
red-group-test
red-ci-cd
Commits
bea53060
Commit
bea53060
authored
Nov 29, 2019
by
John Red Medrano
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixing on batch upload
parent
e059317a
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
336 additions
and
16 deletions
+336
-16
app/applicationlayer/cms/form/header/views.py
app/applicationlayer/cms/form/header/views.py
+87
-12
app/applicationlayer/management/batchupload/views.py
app/applicationlayer/management/batchupload/views.py
+41
-4
app/helper/email_service/templates/CHANGE_REQUEST_TEMPLATE.html
...lper/email_service/templates/CHANGE_REQUEST_TEMPLATE.html
+127
-0
app/helper/email_service/templates/styles.css
app/helper/email_service/templates/styles.css
+81
-0
No files found.
app/applicationlayer/cms/form/header/views.py
View file @
bea53060
import
configparser
import
shutil
import
os
from
django.shortcuts
import
render
from
rest_framework
import
viewsets
from
rest_framework.views
import
APIView
...
...
@@ -64,6 +67,17 @@ from django_filters.rest_framework import DjangoFilterBackend
import
json
from
app.applicationlayer.utils
import
main_threading
from
django.core.files.base
import
ContentFile
from
django.conf
import
settings
from
io
import
BytesIO
from
django.http
import
HttpResponse
from
xhtml2pdf
import
pisa
config
=
configparser
.
ConfigParser
()
config_file
=
os
.
path
.
join
(
'./'
,
'env.ini'
)
config
.
read
(
config_file
)
APPROVER_MESSAGE
=
settings
.
APPROVER_MESSAGE
REQUESTOR_MESSAGE
=
settings
.
REQUESTOR_MESSAGE
REQUESTOR_REJECT_MESSAGE
=
settings
.
REQUESTOR_REJECT_MESSAGE
...
...
@@ -376,21 +390,21 @@ class ChangeRequestFormsViewset(viewsets.ModelViewSet):
# queryset = self.get_serializer_class().setup_eager_loading(self.queryset)
models
.
Notification
.
objects
.
filter
(
account_no
=
id_number
,
form_code
=
form_code
,
is_read
=
False
)
.
update
(
is_read
=
True
)
#
models.Notification.objects.filter(
#
account_no=id_number,
#
form_code=form_code,
#
is_read=False).update(is_read=True)
ROOM
=
id_number
SENDER
=
id_number
#
ROOM = id_number
#
SENDER = id_number
notif
=
send_broadcast_message
(
ROOM
,
SENDER
,
'UPDATE NOTIFICATIONS'
)
#
notif = send_broadcast_message(
#
ROOM,
#
SENDER,
#
'UPDATE NOTIFICATIONS'
#
)
main_threading
(
1
,
notif
)
#
main_threading(1, notif)
return
Response
(
serializer
.
data
)
...
...
@@ -495,6 +509,67 @@ class ChangeRequestFormsViewset(viewsets.ModelViewSet):
except
Exception
as
e
:
return
Response
(
e
,
status
=
status
.
HTTP_500_INTERNAL_SERVER_ERROR
)
@
action
(
methods
=
[
'GET'
],
detail
=
True
,
url_path
=
'form-download'
,
url_name
=
'form-download'
)
def
FormDownload
(
self
,
request
,
form_code
=
None
):
args
=
[
'CHANGE_REQUEST_TEMPLATE.html'
]
my_folder
=
os
.
path
.
join
(
settings
.
MEDIA_ROOT
,
f
'cr/{request.user.code}'
)
attch
=
models
.
ChangeRequestFormAttachments
.
objects
.
filter
(
form_code
=
str
(
form_code
)
)
.
values
(
'file_upload__url'
)
attch_list
=
[
data
[
'file_upload__url'
]
.
split
(
'/'
)[
1
]
for
data
in
attch
]
# print(attch.query)
# print(attch)
# print(attch_list)
if
os
.
path
.
isdir
(
my_folder
):
shutil
.
rmtree
(
my_folder
)
user_folder
=
os
.
mkdir
(
my_folder
)
for
data
in
args
:
F
=
open
(
os
.
path
.
join
(
settings
.
EMAIL_TEMPLATES_ROOT
,
data
),
'r'
)
result
=
BytesIO
()
pdf
=
pisa
.
pisaDocument
(
F
,
result
)
updated_file
=
ContentFile
(
result
.
getvalue
())
updated_file
.
name
=
f
"{data}.pdf"
completeName
=
os
.
path
.
join
(
os
.
path
.
join
(
settings
.
MEDIA_ROOT
,
f
'cr/{request.user.code}'
),
updated_file
.
name
)
file1
=
open
(
completeName
,
"w"
)
file1
.
close
()
# for file_name in attch_list:
# full_file_name = os.path.join(my_folder, file_name)
# if os.path.isfile(full_file_name):
# shutil.copy(full_file_name, dest)
print
(
attch
)
for
file_name
in
attch
:
a
=
os
.
path
.
join
(
settings
.
MEDIA_ROOT
,
file_name
[
'file_upload__url'
])
# full_file_name = os.path.join(my_folder, file_name['file_upload__url'])
# print(full_file_name)
if
os
.
path
.
isfile
(
a
):
print
(
'ddd'
)
shutil
.
copy
(
a
,
my_folder
)
else
:
print
(
'xxx'
)
test
=
shutil
.
make_archive
(
my_folder
+
'archive'
,
'zip'
,
my_folder
,
"."
)
response
=
HttpResponse
(
open
(
test
,
'rb'
),
content_type
=
'application/zip'
)
response
[
'Content-Disposition'
]
=
'attachment; filename=change request.zip'
return
response
@
transaction
.
atomic
()
@
action
(
...
...
app/applicationlayer/management/batchupload/views.py
View file @
bea53060
...
...
@@ -38,6 +38,15 @@ config = configparser.ConfigParser()
config_file
=
os
.
path
.
join
(
'./'
,
'env.ini'
)
config
.
read
(
config_file
)
from
django.conf
import
settings
from
io
import
BytesIO
from
django.http
import
HttpResponse
from
django.template.loader
import
get_template
from
xhtml2pdf
import
pisa
from
django.core.files.storage
import
FileSystemStorage
import
sys
import
os
import
zipfile
import
shutil
class
BatchUploadViewSet
(
viewsets
.
ModelViewSet
):
queryset
=
ExtractTransformLoad
.
objects
.
all
()
...
...
@@ -103,13 +112,41 @@ class BatchUploadViewSet(viewsets.ModelViewSet):
url_path
=
'pdf-instruction'
,
name
=
'how to upload bulk users'
)
def
testpdf
(
self
,
request
,
code
=
None
):
return
sender
.
to_pdf
()
F
=
open
(
os
.
path
.
join
(
settings
.
EMAIL_TEMPLATES_ROOT
,
'RMS-NEWUSER.html'
),
'r'
)
result
=
BytesIO
()
pdf
=
pisa
.
pisaDocument
(
F
,
result
)
updated_file
=
ContentFile
(
result
.
getvalue
())
updated_file
.
name
=
"cr_download.pdf"
my_folder
=
os
.
path
.
join
(
settings
.
MEDIA_ROOT
,
f
'cr/{request.user.code}'
)
if
os
.
path
.
isdir
(
my_folder
):
shutil
.
rmtree
(
my_folder
)
user_folder
=
os
.
mkdir
(
my_folder
)
completeName
=
os
.
path
.
join
(
os
.
path
.
join
(
settings
.
MEDIA_ROOT
,
f
'cr/{request.user.code}'
),
updated_file
.
name
)
file1
=
open
(
completeName
,
"w+"
)
# response = HttpResponse(open(my_folder, 'rb'), content_type='application/zip')
# response['Content-Disposition'] = 'attachment; filename=any_name_you_like.zip'
# return response
message
=
status_message_response
(
200
,
'success'
,
'test'
,
"sss"
)
return
Response
(
message
)
# return sender.to_pdf()
@
action
(
detail
=
False
,
methods
=
[
'get'
],
url_path
=
'user-instruction'
,
name
=
'how to upload bulk users'
)
def
UserInstruction
(
self
,
request
,
code
=
None
):
sender
.
to_pdf
()
self
.
serializer_class
=
BatchUploadSerializer
queryset
=
MasterAttachment
.
objects
.
filter
(
url__contains
=
config
[
'SETTINGS'
][
'BATCH_UPLOAD_FORMAT_FILENAME'
]
...
...
@@ -261,8 +298,8 @@ class BatchUploadViewSet(viewsets.ModelViewSet):
# user type authorization and user type per user
else
:
user_department
=
Department
.
objects
.
get
(
name__icontains
=
keys
[
'
department
'
]
user_department
=
Department
.
objects
.
filter
(
name__icontains
=
keys
[
'
Department_Code
'
]
)
default_app
=
Application
.
objects
.
filter
(
...
...
app/helper/email_service/templates/CHANGE_REQUEST_TEMPLATE.html
0 → 100644
View file @
bea53060
<!DOCTYPE html>
<html
lang=
"en"
>
<head>
<meta
charset=
"UTF-8"
>
<meta
name=
"viewport"
content=
"width=device-width, initial-scale=1_0"
>
<meta
http-equiv=
"X-UA-Compatible"
content=
"ie=edge"
>
<title>
Change Request Template
</title>
<link
rel=
"stylesheet"
href=
"./styles.css"
>
</head>
<body>
<h1>
Change Request Template
</h1>
<h2>
Requested To:
</h2>
<div
class=
"requested-to"
>
<div
class=
"input"
>
<label>
Company
</label>
<input
type=
"text"
value=
"{company_name}"
>
</div>
<div
class=
"input"
>
<label>
Department
</label>
<input
type=
"text"
value=
"{department_name}"
>
</div>
<div
class=
"input"
>
<label>
Template Name
</label>
<input
type=
"text"
value=
"{template}"
>
</div>
<div
class=
"input"
>
<label>
Point of Contact
</label>
<input
type=
"text"
value=
"{request_to_name_name}"
>
</div>
<div
class=
"input"
>
<label>
CR Number prefix
</label>
<input
type=
"text"
value=
"{id}"
>
</div>
<div
class=
"input"
>
<label>
Priority
</label>
<input
type=
"text"
value=
"{priority}"
>
</div>
<div
class=
"input"
>
<label>
Objective
</label>
<input
type=
"text"
value=
"{objective}"
>
</div>
<div
class=
"input"
>
<label>
Lead Time Required (Number of Days)
</label>
<input
type=
"text"
value=
"{target_date}"
>
</div>
<div
class=
"input"
>
<label>
Description
</label>
<input
type=
"text"
value=
"{description}"
>
</div>
</div>
<h2>
Created By:
</h2>
<div
class=
"input"
>
<label>
Name
</label>
<input
type=
"text"
value=
"{name}"
>
</div>
<div
class=
"input"
>
<label>
Department
</label>
<input
type=
"text"
value=
"{department_name}"
>
</div>
<div
class=
"input"
>
<label>
Contact Number
</label>
<input
type=
"text"
value=
"{contact_no}"
>
</div>
<div
class=
"table"
>
<h3>
Routing Table
</h3>
<table>
<thead>
<th>
Level
</th>
<th>
Company
</th>
<th>
Department
</th>
<th>
Name
</th>
<th>
Email
</th>
<th>
Contact
</th>
<th>
Delegation
</th>
<th>
Action
</th>
</thead>
<tbody>
<tr>
<td>
{approver_level}
</td>
<td>
{approver_company_name}
</td>
<td>
{approver_department_name}
</td>
<td>
{approver_name}
</td>
<td>
{approver_email}
</td>
<td>
{approver_contact_no}
</td>
<td>
{approver_delegation_name}
</td>
<td>
{approver_action}
</td>
</tr>
</tbody>
</table>
<h3>
Stakeholders
</h3>
<table>
<thead>
<th>
Company
</th>
<th>
Department
</th>
<th>
Name
</th>
<th>
Email
</th>
<th>
Contact
</th>
<th>
Delegation
</th>
<th>
Action
</th>
</thead>
<tbody>
<tr>
<td>
{stakeholder_company_name}
</td>
<td>
{stakeholder_department_name}
</td>
<td>
{stakeholder_name}
</td>
<td>
{stakeholder_email}
</td>
<td>
{stakeholder_contact_no}
</td>
<td>
{stakeholder_delegation_name}
</td>
<td>
{stakeholder_action}
</td>
</tr>
</tbody>
</table>
</div>
</body>
</html>
\ No newline at end of file
app/helper/email_service/templates/styles.css
0 → 100644
View file @
bea53060
*
{
box-sizing
:
border-box
;
padding
:
0
;
margin
:
0
;
}
body
{
font-family
:
Arial
,
Helvetica
,
sans-serif
;
margin
:
30px
200px
30px
200px
;
font-size
:
20px
;
color
:
#8B8B8B
}
h1
{
padding-bottom
:
80px
;
font-size
:
24px
;
font-weight
:
400
;
}
h2
{
font-size
:
22px
;
font-weight
:
400
;
margin-bottom
:
20px
;
}
h3
{
font-size
:
21px
;
font-weight
:
400
;
margin-bottom
:
20px
;
margin-top
:
20px
;
}
.requested-to
{
margin-top
:
20px
;
}
.input
{
margin-bottom
:
50px
;
}
label
{
font-size
:
19px
;
font-weight
:
700
;
color
:
#737373
;
}
input
{
display
:
block
;
width
:
500px
;
color
:
#8B8B8B
;
font-size
:
19px
;
border
:
none
;
padding-top
:
20px
;
margin-bottom
:
10px
;
border-bottom
:
2px
#919191
solid
;
}
table
,
th
,
td
{
border-bottom
:
1px
solid
#8B8B8B
;
border-collapse
:
collapse
;
}
th
{
text-align
:
left
;
}
tr
{
border-bottom
:
1px
solid
black
;
}
td
{
padding
:
8px
;
}
.table
{
margin-top
:
100px
;
font-size
:
16px
;
padding
:
50px
;
background-color
:
#F2F2F2
;
border-radius
:
25px
;
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment