Пример #1
0
 def update_address(self, request, *args, **kwargs):
     try:
         instance = self.get_object()
         serializer = UserAddressSerializer(data=request.data)
         serializer.is_valid(raise_exception=True)
         address, created = Address.objects.get_or_create(
             line1 = serializer.validated_data['line1'],
             locality = serializer.validated_data['locality'],
             state = serializer.validated_data['state'],
             country = serializer.validated_data['country'],
             postcode = serializer.validated_data['postcode'],
             user = instance
         )
         instance.residential_address = address
         instance.save()
         serializer = UserSerializer(instance)
         return Response(serializer.data);
     except serializers.ValidationError:
         print(traceback.print_exc())
         raise
     except ValidationError as e:
         print(traceback.print_exc())
         raise serializers.ValidationError(repr(e.error_dict))
     except Exception as e:
         print(traceback.print_exc())
         raise serializers.ValidationError(str(e))
Пример #2
0
    def get(self, request, format=None):
        data = cache.get('department_users')
        if not data:
            retrieve_department_users()
            data = cache.get('department_users')
        return Response(data)

        serializer  = UserSerializer(request.user)
Пример #3
0
 def update_contact(self, request, *args, **kwargs):
     try:
         instance = self.get_object()
         serializer = ContactSerializer(instance,data=request.data)
         serializer.is_valid(raise_exception=True)
         instance = serializer.save()
         serializer = UserSerializer(instance)
         return Response(serializer.data);
     except serializers.ValidationError:
         print(traceback.print_exc())
         raise
     except ValidationError as e:
         print(traceback.print_exc())
         raise serializers.ValidationError(repr(e.error_dict))
     except Exception as e:
         print(traceback.print_exc())
         raise serializers.ValidationError(str(e))
Пример #4
0
 def upload_id(self, request, *args, **kwargs):
     try:
         instance = self.get_object()
         instance.upload_identification(request)
         with transaction.atomic():
             instance.save()
             instance.log_user_action(EmailUserAction.ACTION_ID_UPDATE.format(
             '{} {} ({})'.format(instance.first_name, instance.last_name, instance.email)), request)
         serializer = UserSerializer(instance, partial=True)
         return Response(serializer.data)
     except serializers.ValidationError:
         print(traceback.print_exc())
         raise
     except ValidationError as e:
         print(traceback.print_exc())
         raise serializers.ValidationError(repr(e.error_dict))
     except Exception as e:
         print(traceback.print_exc())
         raise serializers.ValidationError(str(e))
Пример #5
0
 def update_system_settings(self, request, *args, **kwargs):
     try:
         instance = self.get_object()
         # serializer = UserSystemSettingsSerializer(data=request.data)
         # serializer.is_valid(raise_exception=True)
         user_setting, created = UserSystemSettings.objects.get_or_create(
             user=instance)
         serializer = UserSystemSettingsSerializer(user_setting,
                                                   data=request.data)
         serializer.is_valid(raise_exception=True)
         #instance.residential_address = address
         serializer.save()
         instance = self.get_object()
         serializer = UserSerializer(instance)
         return Response(serializer.data)
     except serializers.ValidationError:
         print(traceback.print_exc())
         raise
     except ValidationError as e:
         print(traceback.print_exc())
         raise serializers.ValidationError(repr(e.error_dict))
     except Exception as e:
         print(traceback.print_exc())
         raise serializers.ValidationError(str(e))
Пример #6
0
 def get(self, request, format=None):
     serializer  = UserSerializer(request.user)
     return Response(serializer.data)
Пример #7
0
 def get(self, request, format=None):
     serializer = UserSerializer(request.user, context={'request': request})
     return Response(serializer.data)