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
84de2368
Commit
84de2368
authored
Dec 16, 2019
by
Gladys Forte
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
instructions pdf
parent
871f239b
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
162 additions
and
23 deletions
+162
-23
app/applicationlayer/management/batchupload/gen_instruction.py
...pplicationlayer/management/batchupload/gen_instruction.py
+82
-0
app/applicationlayer/management/batchupload/serializer.py
app/applicationlayer/management/batchupload/serializer.py
+1
-1
app/applicationlayer/management/batchupload/views.py
app/applicationlayer/management/batchupload/views.py
+74
-10
app/entities/models.py
app/entities/models.py
+5
-5
media/uploads/instruction.pdf
media/uploads/instruction.pdf
+0
-0
media/uploads/user_format.csv
media/uploads/user_format.csv
+0
-7
No files found.
app/applicationlayer/management/batchupload/gen_instruction.py
0 → 100644
View file @
84de2368
# from rest_framework.views import APIView
# from rest_framework import viewsets, status
# from rest_framework.response import Response
# from reportlab.lib.enums import TA_JUSTIFY, TA_RIGHT, TA_LEFT, TA_CENTER
# from reportlab.lib.pagesizes import letter
# from reportlab.lib.styles import getSampleStyleSheet, ParagraphStyle
# import reportlab
# from reportlab.lib.pagesizes import A4
# from django.http import FileResponse
# from django.shortcuts import HttpResponse
# import io
# import subprocess
# import datetime
# from reportlab.lib.pagesizes import letter
# from reportlab.platypus import SimpleDocTemplate, Paragraph, Spacer, Image
# from reportlab.lib.styles import getSampleStyleSheet, ParagraphStyle
# from reportlab.lib.units import inch
# from reportlab.pdfbase.ttfonts import TTFont
# from reportlab.pdfbase import pdfmetrics
# from reportlab.lib.colors import red, black, navy, white, green
# from reportlab.platypus import Paragraph, SimpleDocTemplate, XBox, Indenter, XPreformatted
# class PDF2(APIView):
# def get(self, request, format=None):
# doc = SimpleDocTemplate("instruction.pdf",
# pagesize=A,
# rightMargin=72,
# leftMargin=72,
# topMargin=72,
# bottomMargin=18)
# Story = []
# styles=getSampleStyleSheet()
# styles.add(ParagraphStyle(name='Justify', alignment=TA_JUSTIFY, fontName='Helvetica', fontSize=12))
# styles.add(ParagraphStyle('reminder',
# fontName='Helvetica',
# fontSize=13,
# leading=28,
# textColor=red))
# items = [
# "1. To be able to add multiple users in the system, you must first <u>Download the</u>",
# "<font color=white>....</font><u>template.</u>",
# "2. This file includes a sample entry as your basis for adding users in the file",
# "3. This file also includes all the Departments currently in the system, as your basis",
# "<font color=white>....</font>in indicating privileges for each user. ",
# "4. Make sure to indicate the Department Code, Department Name and Company",
# "<font color=white>....</font>Name (Department details) that you would want the user to access.",
# "5. If the user should have access to multiple Departments, just repeat all the details",
# "<font color=white>....</font>of the user and change the Department details and privileges assignment in each",
# "<font color=white>....</font>line for the user.",
# "6. Take note of the following Application Abbreviations, to be indicated in the",
# "<font color=white>...</font>Application and Default Application (default_app) column of the CSV file: ",
# "<font color=white>...</font>6.1.<b>RMS</b> is Resource Management System",
# "<font color=white>...</font>6.2.<b>CMS</b> is Change Request Management System",
# "<font color=white>...</font>6.3.<b>AMS</b> is Asset Management System",
# "7. The template is in CSV format, after filling up the details, make sure that the file is",
# "<font color=white>....</font>still saved in CSV format before uploading in the system."
# ]
# ptext = '<font size=13>IMPORTANT REMINDERS</font>'
# Story.append(Paragraph(ptext, styles["reminder"]))
# Story.append(Spacer(1, 15))
# for item in items:
# ptext = '<font size=12>' + item + '</font>'
# Story.append(Paragraph(ptext, styles["Justify"]))
# Story.append(Spacer(1, 12))
# doc.build(Story)
# return Response(
# {"results": "attachments"},
# status=status.HTTP_200_OK
# )
\ No newline at end of file
app/applicationlayer/management/batchupload/serializer.py
View file @
84de2368
...
...
@@ -32,7 +32,7 @@ class BatchUploadSerializer(serializers.ModelSerializer):
class
BatchUpload
Serializer
(
serializers
.
ModelSerializer
):
class
UserInstruction
Serializer
(
serializers
.
ModelSerializer
):
class
Meta
:
model
=
MasterAttachment
fields
=
'__all__'
...
...
app/applicationlayer/management/batchupload/views.py
View file @
84de2368
...
...
@@ -49,6 +49,12 @@ import os
import
zipfile
import
shutil
from
reportlab.platypus
import
SimpleDocTemplate
,
Spacer
,
Paragraph
from
reportlab.lib.styles
import
getSampleStyleSheet
,
ParagraphStyle
from
reportlab.lib.pagesizes
import
A4
from
reportlab.lib.enums
import
TA_JUSTIFY
,
TA_RIGHT
,
TA_LEFT
,
TA_CENTER
from
reportlab.lib.colors
import
red
class
BatchUploadViewSet
(
viewsets
.
ModelViewSet
):
queryset
=
ExtractTransformLoad
.
objects
.
all
()
.
order_by
(
'-created'
)
serializer_class
=
ExtractTransformLoadSerializer
...
...
@@ -122,7 +128,7 @@ class BatchUploadViewSet(viewsets.ModelViewSet):
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
)
...
...
@@ -132,8 +138,6 @@ class BatchUploadViewSet(viewsets.ModelViewSet):
# response['Content-Disposition'] = 'attachment; filename=any_name_you_like.zip'
# return response
message
=
status_message_response
(
200
,
'success'
,
...
...
@@ -148,18 +152,79 @@ class BatchUploadViewSet(viewsets.ModelViewSet):
url_path
=
'user-instruction'
,
name
=
'how to upload bulk users'
)
def
UserInstruction
(
self
,
request
,
code
=
None
):
self
.
serializer_class
=
BatchUploadSerializer
queryset
=
MasterAttachment
.
objects
.
filter
(
url__contains
=
config
[
'SETTINGS'
][
'BATCH_UPLOAD_FORMAT_FILENAME'
]
)
attach_instruc
=
MasterAttachment
.
objects
.
filter
(
attch_ref
=
'etl_instruction'
)
if
attach_instruc
:
attach_instruc
.
first
()
.
delete
()
outfilename
=
"instruction.pdf"
outfiledir
=
'media/uploads/'
outfilepath
=
os
.
path
.
join
(
outfiledir
,
outfilename
)
doc
=
SimpleDocTemplate
(
outfilepath
,
pagesize
=
A4
,
rightMargin
=
72
,
leftMargin
=
72
,
topMargin
=
72
,
bottomMargin
=
18
)
instruction_data
=
[]
styles
=
getSampleStyleSheet
()
styles
.
add
(
ParagraphStyle
(
name
=
'Justify'
,
alignment
=
TA_JUSTIFY
,
fontName
=
'Helvetica'
,
fontSize
=
12
))
styles
.
add
(
ParagraphStyle
(
'reminder'
,
fontName
=
'Helvetica'
,
fontSize
=
13
,
leading
=
28
,
textColor
=
red
))
items
=
[
"1. To be able to add multiple users in the system, you must first <u>Download the</u>"
,
"<font color=white>....</font><u>template.</u>"
,
"2. This file includes a sample entry as your basis for adding users in the file"
,
"3. This file also includes all the Departments currently in the system, as your basis"
,
"<font color=white>....</font>in indicating privileges for each user. "
,
"4. Make sure to indicate the Department Code, Department Name and Company"
,
"<font color=white>....</font>Name (Department details) that you would want the user to access."
,
"5. If the user should have access to multiple Departments, just repeat all the details"
,
"<font color=white>...</font>of the user and change the Department details and privileges assignment in each"
,
"<font color=white>...</font>line for the user."
,
"6. Take note of the following Application Abbreviations, to be indicated in the"
,
"<font color=white>...</font>Application and Default Application (default_app) column of the CSV file: "
,
"<font color=white>...</font>6.1.<b>RMS</b> is Resource Management System"
,
"<font color=white>...</font>6.2.<b>CMS</b> is Change Request Management System"
,
"<font color=white>...</font>6.3.<b>AMS</b> is Asset Management System"
,
"7. The template is in CSV format, after filling up the details, make sure that the file "
,
"<font color=white>...</font>is still saved in CSV format before uploading in the system."
]
ptext
=
'<font size=13>IMPORTANT REMINDERS</font>'
instruction_data
.
append
(
Paragraph
(
ptext
,
styles
[
"reminder"
]))
instruction_data
.
append
(
Spacer
(
1
,
15
))
for
item
in
items
:
ptext
=
'<font size=12>'
+
item
+
'</font>'
instruction_data
.
append
(
Paragraph
(
ptext
,
styles
[
"Justify"
]))
instruction_data
.
append
(
Spacer
(
1
,
12
))
doc
.
build
(
instruction_data
)
uploaded
=
MasterAttachment
.
objects
.
create
(
url
=
'uploads/instruction.pdf'
,
attch_ref
=
'etl_instruction'
)
self
.
serializer_class
=
BatchUploadSerializer
queryset
=
MasterAttachment
.
objects
.
filter
(
id
=
uploaded
.
id
)
page
=
self
.
paginate_queryset
(
queryset
)
serializer
=
self
.
get_serializer
(
page
,
many
=
True
)
message
=
status_message_response
(
200
,
'success'
,
''
,
'
User Upload Instruction is found
'
,
serializer
.
data
)
return
self
.
get_paginated_response
(
message
)
...
...
@@ -183,7 +248,7 @@ class BatchUploadViewSet(viewsets.ModelViewSet):
'Privilege_Department'
,
'Privilege_Department_Code'
)
data
=
{
'Username'
:
[
"ob-john"
],
'Name'
:
[
"John Doe"
],
...
...
@@ -441,7 +506,6 @@ class BatchUploadViewSet(viewsets.ModelViewSet):
df
=
pd
.
DataFrame
(
send_mail
)
df
.
to_csv
(
"users.csv"
,
index
=
False
)
args
=
[
"users.csv"
,
logged_user_email
]
main_threading
(
args
,
sender
.
batch_email_admin
)
...
...
app/entities/models.py
View file @
84de2368
...
...
@@ -527,12 +527,12 @@ class MasterAttachment(models.Model):
attch_ref
=
models
.
TextField
()
def
delete
(
self
,
*
args
,
**
kwargs
):
print
(
self
.
url
.
name
)
if
os
.
path
.
isfile
(
self
.
url
.
path
):
os
.
remove
(
self
.
url
.
path
)
#
def delete(self,*args,**kwargs):
#
print(self.url.name)
#
if os.path.isfile(self.url.path):
#
os.remove(self.url.path)
super
(
MasterAttachment
,
self
)
.
delete
(
*
args
,
**
kwargs
)
#
super(MasterAttachment, self).delete(*args,**kwargs)
class
Meta
:
db_table
=
'master_attachments'
...
...
media/uploads/instruction.pdf
View file @
84de2368
No preview for this file type
media/uploads/user_format.csv
deleted
100644 → 0
View file @
871f239b
Username,Name,Company,Department,Department_Code,Email,Contact_No,Application,Default_app,Privilege_Company,Privilege_Department,Privilege_Department_Code,Create_CR,Create_Template,View_All_CR,Approve_CR
ob-john,John Doe,Oneberry Technologies Pte Ltd,Business Development,DEPARTMENT-20191121-0000064,johndoe@gmail.com,123456,"cms,ams",cms,Oneberry Technologies Pte Ltd,Business Development,DEPARTMENT-20191121-0000064,Yes,No,Yes,Yes
,,,,,,,,,Please use this department code as reference,,,,,,
,,,,,,,,,Oneberry Technologies Pte Ltd,Business Development,DEPARTMENT-20191121-0000064,,,,
,,,,,,,,,Jurong Town Corporation,Security Division,DEPARTMENT-20191121-0000061,,,,
,,,,,,,,,Jurong Town Corporation,Facilities Management,DEPARTMENT-20191121-0000062,,,,
,,,,,,,,,Jurong Town Corporation,Warehouse Department,DEPARTMENT-20191121-0000065,,,,
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