Exemple #1
0
class UserPasswordUpdateSerializer(BasePlainSerializer):
    oldPassword = miniproject_base_serializer.CharField(
        min_length=5,
        max_length=35,
        required=True,
        allow_blank=False,
        error_messages={
            'required': 'Old password required',
            'required_code': 400,
            'blank': 'Old password may not be blank',
            'blank_code': 300
        })
    password = miniproject_base_serializer.CharField(
        min_length=5,
        max_length=35,
        required=True,
        allow_blank=False,
        error_messages={
            'required': 'Password required',
            'required_code': 400,
            'blank': 'Password may not be blank',
            'blank_code': 300
        })
    passwordConfirmation = miniproject_base_serializer.CharField(
        min_length=5,
        max_length=35,
        required=True,
        allow_blank=False,
        error_messages={
            'required': 'Confirmation password required',
            'required_code': 400,
            'blank': 'Confirmation password may not be blank',
            'blank_code': 300
        })
Exemple #2
0
class GetDebitDetailSerializer(BaseSerializer):
    credit = miniproject_base_serializer.SerializerMethodField()
    debit = miniproject_base_serializer.SerializerMethodField()
    debit_user_id =miniproject_base_serializer.SerializerMethodField()
    credit_date = miniproject_base_serializer.SerializerMethodField()
    debit_date = miniproject_base_serializer.CharField(source='get_debit_user_date')
    credit_user_id = miniproject_base_serializer.SerializerMethodField()
    total_balance = miniproject_base_serializer.SerializerMethodField()

    class Meta:
        model = AccountManagement
        fields = ('note','debit_user_id','credit','debit','credit_date','debit_date','credit_user_id','total_balance')

    def get_credit(self, accountmanagement):
        return '-'

    def get_debit(self, accountmanagement):
        return accountmanagement.price

    def get_debit_user_id(self, accountmanagement):
        return accountmanagement.debit_user.id

    def get_credit_date(self, accountmanagement):
        return ''

    def get_credit_user_id(self, accountmanagement):
        return accountmanagement.credit_user.id

    def get_total_balance(self, accountmanagement):
        return 0
Exemple #3
0
class GetUserProfileSerializer(BaseSerializer):
    userId = miniproject_base_serializer.CharField(source='get_user_id')
    mobile_number = miniproject_base_serializer.CharField(source='get_phone')
    business_address = miniproject_base_serializer.CharField(
        source='get_business_address')
    user_role = miniproject_base_serializer.CharField(source='get_user_role')
    # profile_photo = serializers.SerializerMethodField()
    demo_photo = miniproject_base_serializer.SerializerMethodField()

    class Meta:
        model = User
        fields = ('userId', 'mobile_number', 'photo', 'business_name',
                  'business_address', 'username', 'user_role', 'demo_photo')

    def get_demo_photo(self, obj):

        return obj.profile_photo.url
Exemple #4
0
class ForgotpasswordSerializer(BasePlainSerializer):
    mobile_number = miniproject_base_serializer.CharField(
        required=True,
        error_messages={
            'required': 'Please enter your mobile number',
            'required_code': 400,
            'blank': 'Your mobile number may not be blank',
            'blank_code': 300
        })
Exemple #5
0
class GetUserListSerializer(BaseSerializer):
    userId = miniproject_base_serializer.CharField(source='get_user_id')
    mobile_number = miniproject_base_serializer.CharField(source='get_phone')
    business_address = miniproject_base_serializer.CharField(
        source='get_business_address')
    # user_role = miniproject_base_serializer.CharField(source='get_user_role')
    business_photo = miniproject_base_serializer.CharField(
        source='get_business_photo')
    push_token = miniproject_base_serializer.CharField(source='get_push_token')
    createdDate = miniproject_base_serializer.SerializerMethodField()

    class Meta:
        model = User
        fields = ('userId', 'mobile_number', 'business_name',
                  'business_address', 'business_photo', 'push_token',
                  'createdDate')

    def get_createdDate(self, user):
        return helper.datetimeToStringDateTime(user.created_date_time,
                                               constants.DATE_FORMAT)
Exemple #6
0
class UserRemoveSerializer(BasePlainSerializer):
    user_id = miniproject_base_serializer.CharField(
        required=True,
        error_messages={
            'required': 'User id required.',
            'required_code': 400,
            'invalid_choice': 'Invalid user id',
            'invalid_code': 451,
            'blank': 'User id may not blank',
            'blank_code': 300
        })
Exemple #7
0
class SetPasswordSerializer(BasePlainSerializer):
    set_password_token = miniproject_base_serializer.CharField(
        required=True,
        error_messages={
            'required': 'Please enter your set password token',
            'required_code': 400,
            'blank': 'Your set password token may not be blank',
            'blank_code': 300
        })

    password = miniproject_base_serializer.CharField(
        min_length=5,
        max_length=35,
        allow_blank=False,
        required=True,
        error_messages={
            'required': 'Please enter a password',
            'required_code': 400,
            'blank': 'Password may not be blank',
            'blank_code': 300,
            'invalid': 'Invalid password',
            'invalid_code': 500
        })
Exemple #8
0
class UserSignInSerializer(BasePlainSerializer):
    mobile_number = miniproject_base_serializer.CharField(
        required=True,
        error_messages={
            'required': 'Please enter your mobile number',
            'required_code': 400,
            'blank': 'Mobile number can not be blank',
            'blank_code': 300,
            'invalid': 'Invalid mobile number',
            'invalid_code': 500
        })
    password = miniproject_base_serializer.CharField(
        min_length=5,
        max_length=35,
        allow_blank=False,
        required=True,
        error_messages={
            'required': 'Please enter a password',
            'required_code': 400,
            'blank': 'Password may not be blank',
            'blank_code': 300,
            'invalid': 'Invalid password',
            'invalid_code': 500
        })
Exemple #9
0
class FCMTokenSerializer(BasePlainSerializer):
    fcm_token = miniproject_base_serializer.CharField(required=False,
                                                      allow_blank=True,
                                                      default='',
                                                      error_messages={
                                                          'invalid':
                                                          'Invalid fcm token',
                                                          'invalid_code': 500
                                                      })

    def update(self, instance, validated_data):
        user = instance
        fcm_token = validated_data['fcm_token']

        # if fcm_token not in user.fcm_token:
        user.fcm_token = []
        user.save()
        user.fcm_token.append(fcm_token)
        user.save()

        return user
Exemple #10
0
class GetBankdetailSerializer(BaseSerializer):
    bank_id = miniproject_base_serializer.CharField(source='get_bank_id')
    class Meta:
        model = BankDetails
        fields = ('bank_id','bank_name','bank_account_number','ifac_code','branch_name','bank_location')
Exemple #11
0
class ManageBankSerializer(BaseSerializer):
    bank_name = miniproject_base_serializer.CharField(required=True, error_messages={
        'required': 'Bank name is required',
        'invalid' : 'Invalid bank name',
        'blank': 'Bank name may not be blank',
        'blank_code' : 300,
        'invalid' : 'Invalid bank name',
        'invalid_code' : 500
    })

    bank_account_number = miniproject_base_serializer.CharField(required=True, error_messages={
        'required': 'Bank account number is required',
        'invalid' : 'Invalid bank account number',
        'blank': 'Bank account number may not be blank',
        'blank_code' : 300,
        'invalid' : 'Invalid bank account number',
        'invalid_code' : 500
    })

    ifac_code = miniproject_base_serializer.CharField(required=True, error_messages={
        'required': 'Ifac code is required',
        'invalid' : 'Invalid ifac code',
        'blank': 'Ifac code may not be blank',
        'blank_code' : 300,
        'invalid' : 'Invalid ifac code',
        'invalid_code' : 500
    })

    branch_name = miniproject_base_serializer.CharField(required=True, error_messages={
        'required': 'Branch name is required',
        'invalid' : 'Invalid branch name',
        'blank': 'Branch name may not be blank',
        'blank_code' : 300,
        'invalid' : 'Invalid branch name',
        'invalid_code' : 500
    })

    bank_location = miniproject_base_serializer.CharField(required=True, error_messages={
        'required': 'Bank location is required',
        'invalid' : 'Invalid bank location',
        'blank': 'Bank location may not be blank',
        'blank_code' : 300,
        'invalid' : 'Invalid bank location',
        'invalid_code' : 500
    })

    class Meta:
        model = BankDetails
        fields = ('bank_name','bank_account_number','ifac_code','branch_name','bank_location')

    def create(self, validated_data):
        bank_details = BankDetails(
            user = validated_data['user'],
            bank_name=validated_data['bank_name'],
            bank_account_number=validated_data['bank_account_number'],
            ifac_code=validated_data['ifac_code'],
            branch_name=validated_data['branch_name'],
            bank_location=validated_data['bank_location']
        )
        bank_details.save()
        return validated_data
Exemple #12
0
class ManageAccountSerializer(BaseSerializer):
    price = miniproject_base_serializer.IntegerField(required=True, error_messages={
        'required': 'User type is required',
        'invalid' : 'Invalid user type'
    })

    current_time = miniproject_base_serializer.DateTimeField(required=True, error_messages={
        'required': 'Current time type is required',
        'invalid' : 'Invalid current time'
    })

    note = miniproject_base_serializer.CharField(required=True, error_messages={
        'required': 'Please enter a note',
        'required_code' : 400,
        'blank': 'Note may not be blank',
        'blank_code' : 300,
        'invalid' : 'Invalid note',
        'invalid_code' : 500
    })

    user_id =  miniproject_base_serializer.CharField(required=True, error_messages={
        'required': 'Please enter a user id',
        'required_code' : 400,
        'blank': 'User id may not be blank',
        'blank_code' : 300,
        'invalid' : 'Invalid user id',
        'invalid_code' : 500
    })

    class Meta:
        model = AccountManagement
        fields = ('price','current_time','note','user_id')

    def create(self, validated_data):
        try:
            user = User.objects.get(id = validated_data['user_id'])
        except User.DoesNotExist:
            raise serializers.ValidationError('Invalid user id')

        account_management = AccountManagement(
            price = validated_data['price'],
            current_time = validated_data['current_time'],
            note = validated_data['note'],
            credit_user = user,
            debit_user = validated_data['user']
        )
        account_management.save()
        message = validated_data['user'].business_name + ' is pay ' +  str(validated_data['price']) + 'rs.'
        for token in user.fcm_token:
            fb_service.sendNotification(
                message, 
                '', 
                {   
                    'notification_type': 'accountation', 
                    'last_timestamp': 'test',
                    'receiver_id' : str(user.id),
                    'sender_id' : str(validated_data['user'].id),
                    'user_name' : validated_data['user'].username,
                    'user_initial':'test',
                    'show_notification': 'true'
                },
                token
            )
        return account_management
Exemple #13
0
class UserSignUpSerializer(BaseSerializer):
    mobile_number = miniproject_base_serializer.CharField(
        required=True,
        error_messages={
            'required': 'Please enter your mobile number',
            'required_code': 400,
            'blank': 'Your mobile number may not be blank',
            'blank_code': 300
        })
    business_name = miniproject_base_serializer.CharField(
        required=True,
        error_messages={
            'required': 'Please enter your business name',
            'required_code': 400,
            'blank': 'Business name can not be blank',
            'blank_code': 300,
            'invalid': 'Invalid business name',
            'invalid_code': 500
        })
    password = miniproject_base_serializer.CharField(
        min_length=5,
        max_length=35,
        required=True,
        error_messages={
            'required': 'Please enter a password',
            'required_code': 400,
            'blank': 'Password may not be blank',
            'blank_code': 300,
            'min_length': "Password has at least 5 characters",
            'min_length_code': 251,
            'max_length': "Password has no more than 35 characters",
            'max_length_code': 351,
        })
    passwordConfirmation = miniproject_base_serializer.CharField(
        min_length=5,
        max_length=35,
        required=True,
        error_messages={
            'required': 'Please enter a confirm password',
            'required_code': 400,
            'blank': 'Password may not be blank',
            'blank_code': 300,
            'min_length': "Confirm password has at least 5 characters",
            'min_length_code': 251,
            'max_length': "Confirm password has no more than 35 characters",
            'max_length_code': 351,
        })

    business_photo = miniproject_base_serializer.FileField(
        required=False,
        default='',
        allow_empty_file=True,
        error_messages={
            'invalid': 'Invalid business photo',
            'invalid_code': 500
        })

    # user_type = miniproject_base_serializer.IntegerField(required=True, error_messages={
    #     'required': 'User type is required',
    #     'invalid' : 'Invalid user type'
    # })

    business_address = miniproject_base_serializer.CharField(
        required=True,
        error_messages={
            'required': 'Please enter your business address',
            'required_code': 400,
            'blank': 'Business address can not be blank',
            'blank_code': 300,
            'invalid': 'Invalid business address',
            'invalid_code': 500
        })

    class Meta:
        model = User
        fields = ('mobile_number', 'password', 'passwordConfirmation',
                  'business_name', 'business_photo', 'business_address')
        extra_kwargs = {
            'password': {
                'write_only': True
            },
            'passwordConfirmation': {
                'write_only': True
            }
        }

    def create(self, validated_data):
        if User.objects.filter(phone=validated_data['mobile_number']).exists():
            raise ValidationError(
                'User is aleary exist with this mobile number.', code="45")

        if validated_data['password'] != validated_data['passwordConfirmation']:
            raise ValidationError(
                'Password and confirm password did not match', code="42")

        permissions = UserPermission(is_admin=False)
        permissions.save()

        user = User(
            phone=validated_data['mobile_number'],
            business_name=validated_data['business_name'],
            address=validated_data['business_address'],
            # user_type = validated_data['user_type'],
            permissions=permissions)
        user.set_password(validated_data['password'])

        user.save()

        if 'business_photo' in validated_data and validated_data[
                'business_photo']:
            user.business_photo = validated_data['business_photo']
            user.save()

        return user
Exemple #14
0
class UserProfileSerializer(BasePlainSerializer):
    mobile_number = miniproject_base_serializer.IntegerField(
        required=False,
        default=0,
        error_messages={
            'invalid': 'Invalid mobile number',
            'invalid_code': 500
        })

    business_name = miniproject_base_serializer.CharField(
        required=False,
        allow_blank=True,
        default='',
        error_messages={
            # 'required': 'Please enter your business name',
            # 'required_code' : 400,
            # 'blank': 'Your business name may not be blank',
            # 'blank_code' : 300
            'invalid': 'Invalid business name',
            'invalid_code': 500
        })

    business_address = miniproject_base_serializer.CharField(
        required=False,
        allow_blank=True,
        default='',
        error_messages={
            # 'required' : 'Please address',
            # 'required_code' : 400,
            # 'blank': 'Address may not be blank',
            # 'blank_code' : 300
            'invalid': 'Invalid business address',
            'invalid_code': 500
        })

    name = miniproject_base_serializer.CharField(
        required=False,
        allow_blank=True,
        default='',
        error_messages={
            # 'required' : 'Please address',
            # 'required_code' : 400,
            # 'blank': 'Address may not be blank',
            # 'blank_code' : 300
            'invalid': 'Invalid business address',
            'invalid_code': 500
        })

    def update(self, instance, validated_data):
        user = instance

        if 'mobile_number' in validated_data and validated_data[
                'mobile_number']:
            user_list = User.objects.filter(
                phone=validated_data['mobile_number']).exclude(
                    phone=user.phone)
            if len(user_list) != 0:
                raise ValidationError(
                    'User is aleary exist with this mobile number.', code=450)
            user.phone = validated_data['mobile_number']

        if 'business_name' in validated_data and validated_data[
                'business_name']:
            user.business_name = validated_data['business_name']

        if 'business_address' in validated_data and validated_data[
                'business_address']:
            user.address = validated_data['business_address']

        if 'name' in validated_data and validated_data['name']:
            user.username = validated_data['name']

        user.save()
        return user