Beispiel #1
0
 def get(self, request, format=None):
     #import ipdb; ipdb.set_trace()
     submitter_id = request.GET.get('submitter_id')
     submitter = EmailUser.objects.get(id=submitter_id)
     serializer = UserSerializer(submitter, context={'request': request})
     response = Response(serializer.data)
     return response
Beispiel #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 add_cache_control(Response(data))

        serializer  = UserSerializer(request.user)
Beispiel #3
0
 def update_personal(self, request, *args, **kwargs):
     try:
         instance = self.get_object()
         serializer = PersonalSerializer(instance,data=request.data)
         serializer.is_valid(raise_exception=True)
         instance = serializer.save()
         serializer = UserSerializer(instance)
         return add_cache_control(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))
Beispiel #4
0
    def update_address(self, request, *args, **kwargs):
        try:
            instance = self.get_object()
            # residential address
            residential_serializer = UserAddressSerializer(
                data=request.data.get('residential_address'))
            residential_serializer.is_valid(raise_exception=True)
            residential_address, created = Address.objects.get_or_create(
                line1=residential_serializer.validated_data['line1'],
                locality=residential_serializer.validated_data['locality'],
                state=residential_serializer.validated_data['state'],
                country=residential_serializer.validated_data['country'],
                postcode=residential_serializer.validated_data['postcode'],
                user=instance)
            instance.residential_address = residential_address
            # postal address
            postal_address_data = request.data.get('postal_address')
            if request.data.get('postal_same_as_residential'):
                instance.postal_same_as_residential = True
                instance.postal_address = residential_address
            elif postal_address_data:
                postal_serializer = UserAddressSerializer(
                    data=postal_address_data)
                postal_serializer.is_valid(raise_exception=True)
                postal_address, created = Address.objects.get_or_create(
                    line1=postal_serializer.validated_data['line1'],
                    locality=postal_serializer.validated_data['locality'],
                    state=postal_serializer.validated_data['state'],
                    country=postal_serializer.validated_data['country'],
                    postcode=postal_serializer.validated_data['postcode'],
                    user=instance)
                instance.postal_address = postal_address
                instance.postal_same_as_residential = False

            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))
Beispiel #5
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 add_cache_control(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))
Beispiel #6
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 add_cache_control(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))
Beispiel #7
0
 def get(self, request, format=None):
     #logger.info('request user: {}'.format(request.user))
     serializer  = UserSerializer(request.user, context={'request':request})
     #logger.info('user serializer data: {}'.format(serializer.data))
     response = Response(serializer.data)
     return add_cache_control(response)