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
35081e2a
Commit
35081e2a
authored
Nov 21, 2019
by
John Red Medrano
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added new endpoint download template for batch upload
parent
54165229
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
44 additions
and
1 deletion
+44
-1
app/applicationlayer/download/batch_upload/serializer.py
app/applicationlayer/download/batch_upload/serializer.py
+11
-0
app/applicationlayer/download/batch_upload/views.py
app/applicationlayer/download/batch_upload/views.py
+24
-0
app/applicationlayer/management/batchupload/views.py
app/applicationlayer/management/batchupload/views.py
+6
-1
app/applicationlayer/urls.py
app/applicationlayer/urls.py
+2
-0
env.template.ini
env.template.ini
+1
-0
No files found.
app/applicationlayer/download/batch_upload/serializer.py
0 → 100644
View file @
35081e2a
from
rest_framework
import
serializers
from
app.entities.models
import
MasterAttachment
class
BatchUploadSerializer
(
serializers
.
ModelSerializer
):
class
Meta
:
model
=
MasterAttachment
fields
=
'__all__'
read_only_fields
=
(
'created'
,
'createdby'
,
'modified'
,
'modifiedby'
,
'code'
,
)
app/applicationlayer/download/batch_upload/views.py
0 → 100644
View file @
35081e2a
from
rest_framework
import
viewsets
,
status
from
rest_framework.response
import
Response
from
app.entities.models
import
MasterAttachment
from
app.applicationlayer.utils
import
(
CustomPagination
,
status_message_response
,
log_save
)
# from django_filters.rest_framework import DjangoFilterBackend
from
app.applicationlayer.download.batch_upload.serializer
import
(
BatchUploadSerializer
)
import
os
import
configparser
config
=
configparser
.
ConfigParser
()
config_file
=
os
.
path
.
join
(
'./'
,
'env.ini'
)
config
.
read
(
config_file
)
class
BatchUploadFormatViewSet
(
viewsets
.
ModelViewSet
):
queryset
=
MasterAttachment
.
objects
.
filter
(
url__contains
=
config
[
'SETTINGS'
][
'BATCH_UPLOAD_FORMAT_FILENAME'
]
)
serializer_class
=
BatchUploadSerializer
app/applicationlayer/management/batchupload/views.py
View file @
35081e2a
...
...
@@ -93,7 +93,7 @@ class BatchUploadViewSet(viewsets.ModelViewSet):
# @decorators.error_safe
@
transaction
.
atomic
def
create
(
self
,
request
,
args
,
*
kwargs
):
def
create
(
self
,
request
,
*
*
kwargs
):
csv_file
=
request
.
FILES
[
'file'
]
df
=
pd
.
read_csv
(
csv_file
,
sep
=
','
,
skiprows
=
0
)
logged_user_type
=
request
.
user
.
user_type
...
...
@@ -126,6 +126,7 @@ class BatchUploadViewSet(viewsets.ModelViewSet):
)
.
first
()
if
user_department
==
None
:
msg
=
f
"company is not the same with the logged user at row {data + 2}"
transaction
.
set_rollback
(
True
)
return
Response
(
{
"message"
:
msg
},
status
=
status
.
HTTP_400_BAD_REQUEST
...
...
@@ -135,6 +136,7 @@ class BatchUploadViewSet(viewsets.ModelViewSet):
name__icontains
=
logged_user_department
)
elif
logged_user_type
==
enums_user
:
transaction
.
set_rollback
(
True
)
return
Response
(
{
"message"
:
"Logged User is not allowed"
},
status
=
status
.
HTTP_400_BAD_REQUEST
...
...
@@ -151,6 +153,7 @@ class BatchUploadViewSet(viewsets.ModelViewSet):
if
keys
[
'user_type'
]
.
lower
()
==
'super user'
and
logged_user_type
==
enums_super
:
user_type
=
enums
.
UserTypeEnum
.
SUPER_USER
.
value
elif
keys
[
'user_type'
]
.
lower
()
==
'super user'
and
logged_user_type
!=
enums_super
:
transaction
.
set_rollback
(
True
)
return
Response
(
{
"message"
:
f
"This user is not allowed to create super user. data error at row {data + 2}"
},
status
=
status
.
HTTP_201_CREATED
...
...
@@ -227,12 +230,14 @@ class BatchUploadViewSet(viewsets.ModelViewSet):
}
AllowedCompany
.
objects
.
create
(
**
privilege_object
)
except
IntegrityError
as
e
:
transaction
.
set_rollback
(
True
)
return
Response
(
{
"message"
:
f
"Duplicate user privilege at row {data + 2}"
},
status
=
status
.
HTTP_400_BAD_REQUEST
)
except
IntegrityError
as
e
:
transaction
.
set_rollback
(
True
)
return
Response
(
{
"message"
:
f
"Record already exist at row {data + 2}"
},
status
=
status
.
HTTP_400_BAD_REQUEST
...
...
app/applicationlayer/urls.py
View file @
35081e2a
...
...
@@ -15,6 +15,7 @@ from app.applicationlayer.management.delegation.views import DelegationViewSet
from
app.applicationlayer.download.accounts.views
import
UserDownloadRequest
from
app.applicationlayer.download.department.views
import
DepartmentDownloadRequest
from
app.applicationlayer.download.company.views
import
CompanyDownloadRequest
from
app.applicationlayer.download.batch_upload.views
import
BatchUploadFormatViewSet
router
=
routers
.
DefaultRouter
()
...
...
@@ -28,6 +29,7 @@ router.register(r'notifications', NotificationsViewset)
router
.
register
(
r'user-download'
,
UserDownloadRequest
)
router
.
register
(
r'department-download'
,
DepartmentDownloadRequest
)
router
.
register
(
r'company-download'
,
CompanyDownloadRequest
)
router
.
register
(
r'batch-upload-format'
,
BatchUploadFormatViewSet
)
router
.
register
(
r'delegations'
,
DelegationViewSet
)
router
.
register
(
r'extract-transform-load'
,
BatchUploadViewSet
)
...
...
env.template.ini
View file @
35081e2a
...
...
@@ -82,6 +82,7 @@ CORS_ORIGIN_ALLOW_ALL = True
[SETTINGS]
CONFIG
=
config.settings.staging
BATCH_UPLOAD_FORMAT_FILENAME
=
batch_uploadxxx.xlsx
[NOTIFICATION_EMAIL]
APPROVER_MESSAGE
=
has sent you an APPROVAL REQUEST for change request;RMS-ACTIONREQUIRED
...
...
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