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
9be4e112
Commit
9be4e112
authored
Sep 30, 2019
by
John Red Medrano
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #226 in RMS/api-main-service from red-develop to RMSv2
* commit '
4d256b2e
': edit user and upload user picture
parents
88da5c8e
4d256b2e
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
106 additions
and
2 deletions
+106
-2
app/applicationlayer/management/account/serializer.py
app/applicationlayer/management/account/serializer.py
+18
-1
app/applicationlayer/management/account/views.py
app/applicationlayer/management/account/views.py
+88
-1
No files found.
app/applicationlayer/management/account/serializer.py
View file @
9be4e112
from
rest_framework
import
serializers
from
rest_framework
import
serializers
from
app.entities.models
import
User
,
Department
from
app.entities.models
import
User
,
Department
,
UserImage
import
ast
import
ast
from
django.contrib.auth.hashers
import
make_password
,
check_password
from
django.contrib.auth.hashers
import
make_password
,
check_password
import
re
import
re
...
@@ -38,6 +38,16 @@ class UserSerializer(serializers.ModelSerializer):
...
@@ -38,6 +38,16 @@ class UserSerializer(serializers.ModelSerializer):
)
)
class
UserEditSerializer
(
serializers
.
ModelSerializer
):
class
Meta
:
model
=
User
fields
=
(
'name'
,
'contact_no'
)
class
ChangeRequestList
(
serializers
.
ModelSerializer
):
class
ChangeRequestList
(
serializers
.
ModelSerializer
):
class
Meta
:
class
Meta
:
...
@@ -103,3 +113,10 @@ class ChangePasswordSerializer(serializers.Serializer):
...
@@ -103,3 +113,10 @@ class ChangePasswordSerializer(serializers.Serializer):
# )
# )
else
:
else
:
raise
serializers
.
ValidationError
(
'Please ensure the old password is correct and both new password & confirm password are the same.'
)
raise
serializers
.
ValidationError
(
'Please ensure the old password is correct and both new password & confirm password are the same.'
)
class
UserImageSerializer
(
serializers
.
ModelSerializer
):
class
Meta
:
model
=
UserImage
fields
=
'__all__'
read_only_fields
=
[
'createdby'
,
'modifiedby'
,
'created'
,
'modified'
]
app/applicationlayer/management/account/views.py
View file @
9be4e112
...
@@ -11,7 +11,9 @@ from django.contrib.auth import authenticate
...
@@ -11,7 +11,9 @@ from django.contrib.auth import authenticate
from
django.contrib.auth.hashers
import
check_password
from
django.contrib.auth.hashers
import
check_password
from
rest_framework.response
import
Response
from
rest_framework.response
import
Response
from
django.forms.models
import
model_to_dict
from
django.forms.models
import
model_to_dict
from
app.entities.models
import
User
,
EntityLog
,
PasswordReset
,
Application
from
app.entities.models
import
(
User
,
EntityLog
,
PasswordReset
,
Application
,
UserImage
)
from
app.helper.decorators
import
rms
,
error_safe
from
app.helper.decorators
import
rms
,
error_safe
from
django.contrib.auth.hashers
import
make_password
from
django.contrib.auth.hashers
import
make_password
from
django_filters
import
rest_framework
as
filters
from
django_filters
import
rest_framework
as
filters
...
@@ -19,6 +21,7 @@ from django_filters.rest_framework import DjangoFilterBackend
...
@@ -19,6 +21,7 @@ from django_filters.rest_framework import DjangoFilterBackend
from
rest_framework.filters
import
SearchFilter
,
OrderingFilter
from
rest_framework.filters
import
SearchFilter
,
OrderingFilter
from
app.applicationlayer.management.account.table_filters
import
AccountFilterset
from
app.applicationlayer.management.account.table_filters
import
AccountFilterset
from
app.applicationlayer.management.account
import
serializer
from
app.applicationlayer.management.account
import
serializer
from
app.helper.file_manager
import
FileHelper
from
app.applicationlayer.utils
import
(
from
app.applicationlayer.utils
import
(
CustomPagination
,
status_message_response
,
log_save
,
CustomPagination
,
status_message_response
,
log_save
,
main_threading
main_threading
...
@@ -294,3 +297,87 @@ class UserViewSet(viewsets.ModelViewSet):
...
@@ -294,3 +297,87 @@ class UserViewSet(viewsets.ModelViewSet):
data
=
{
"detail"
:
"Error"
},
data
=
{
"detail"
:
"Error"
},
status
=
status
.
HTTP_500_INTERNAL_SERVER_ERROR
status
=
status
.
HTTP_500_INTERNAL_SERVER_ERROR
)
)
@
action
(
detail
=
True
,
methods
=
[
'put'
],
url_path
=
'edit-profile'
,
name
=
"Edit User"
)
@
transaction
.
atomic
def
EditProfile
(
self
,
request
,
code
=
None
):
self
.
serializer_class
=
serializer
.
UserEditSerializer
serialized
=
self
.
get_serializer
(
data
=
request
.
data
)
if
serialized
.
is_valid
():
# form = copy.deepcopy(serialized.validated_data)
# form = request.data
# if form['new_password'] != form['new_password_confirm']:
# raise Exception('Passwords must match')
existingUser
=
User
.
objects
.
filter
(
code
=
code
)
pk
=
self
.
get_object
()
if
existingUser
:
# existingUser.first().set_password(form['new_password_confirm'])
fromObj
=
copy
.
copy
(
existingUser
.
first
())
existingUser
.
first
()
.
save
()
toObj
=
copy
.
copy
(
existingUser
.
first
())
log_save
(
enums
.
LogEnum
.
UPDATE
.
value
,
enums
.
LogEntitiesEnum
.
USER
.
value
,
int
(
pk
.
id
),
model_to_dict
(
fromObj
),
model_to_dict
(
toObj
)
)
return
Response
(
{
"message"
:
"User successfully edit"
},
status
=
status
.
HTTP_200_OK
)
else
:
raise
Exception
(
'User not found'
)
else
:
serialized
.
is_valid
(
raise_exception
=
True
)
return
Response
(
data
=
{
"detail"
:
"Error"
},
status
=
status
.
HTTP_500_INTERNAL_SERVER_ERROR
)
@
action
(
detail
=
True
,
methods
=
[
'put'
],
url_path
=
'picture'
,
name
=
"Uploads Profile Picture of User"
)
# @decorators.error_safe
@
transaction
.
atomic
def
UploadProfilePicture
(
self
,
request
,
code
=
None
):
existingUser
=
User
.
objects
.
filter
(
code
=
code
)
.
first
()
if
existingUser
:
eximages
=
UserImage
.
objects
.
filter
(
user_id
=
code
)
if
(
eximages
):
for
item
in
eximages
:
item
.
delete
()
# DELETE FROM PHYSICAL
FileHelper
.
DeleteFile
(
path
=
item
.
image
.
path
)
# self.serializer_class = serializer.UserImageSerializer
data
=
serializer
.
UserImageSerializer
(
data
=
request
.
data
)
data
.
is_valid
(
raise_exception
=
True
)
self
.
perform_create
(
data
)
headers
=
self
.
get_success_headers
(
data
.
data
)
return
Response
(
data
.
data
,
status
=
status
.
HTTP_201_CREATED
,
headers
=
headers
)
else
:
raise
ParseError
(
'User not found'
)
return
Response
(
data
=
{
"detail"
:
"Success"
})
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