Ejemplo n.º 1
0
 def post(self, request, format=None):
     serializer = Bookings_serializer(data=request.data)
     if serializer.is_valid():
         serializer.save()
         time = serializer.data['btime']
         date = serializer.data['bdate']
         message = 'Congratulations! Your appointment is confirmed for ' + str(
             date) + ' at ' + str(time[0])
         profile = Account.objects.filter(
             username=request.data['docusername'])
         D_serial = AccountSerializer(profile, many=True)
         Doc = Doctor_profile.objects.filter(
             username=request.data['docusername'])
         Doc_ser = Doctor_profile_serializer(Doc, many=True)
         patient = Account.objects.filter(
             username=request.data['patientusername'])
         P_serial = AccountSerializer(patient, many=True)
         email_id = [D_serial.data[0]['email'], P_serial.data[0]['email']]
         self.send_email(message, email_id)
         history = {
             'username': request.data['patientusername'],
             'issue': request.data['issue'],
             'date': request.data['bdate'],
             'expenditure': Doc_ser.data[0]['hourly_charge'],
             'doctor': request.data['docusername']
         }
         patient_history_serializer = Patient_history_serializer(
             data=history)
         if patient_history_serializer.is_valid():
             patient_history_serializer.save()
         return Response(True, status=status.HTTP_201_CREATED)
     else:
         return Response(False, status=status.HTTP_400_BAD_REQUEST)
Ejemplo n.º 2
0
class InvoiceSerializer(serializers.ModelSerializer):

    from_account = AccountSerializer(read_only=True)
    to_account = AccountSerializer(read_only=True)
    invoice_lines = ProductSerializer(many=True, read_only=True)
    address = AddressSerializer(read_only=True)
    invoice_changes = InvoiceChangesSerializer(many=True, read_only=True)

    class Meta:
        model = Invoice
        fields = '__all__'
        read_only_fields = ('from_account', 'to_account', 'invoice_lines',
                            'address', 'created_at', 'updated_at', 'comment',
                            'target', 'invoice_changes')
Ejemplo n.º 3
0
class PostOverviewSerializer(serializers.ModelSerializer):
    top_answer = AnswerSerializer(source='get_top_answer', read_only=True)
    author = AccountSerializer(source='get_author_info')

    class Meta:
        model = Post
        fields = ('id', 'title', 'body', 'pub_date', 'author', 'votes_total',
                  'top_answer')
Ejemplo n.º 4
0
def all_accounts(request):
    user = request.user
    current_account = user.account
    if current_account:
        accounts = Account.objects.all().exclude(pk=current_account.id)
    else:
        accounts = Account.objects.all()
    return SuccessResponse(
        AccountSerializer(accounts, many=True).data, status.HTTP_200_OK)
Ejemplo n.º 5
0
def single_account(request, pk):
    if request.method == 'GET':
        try:
            pk_account = Account.objects.get(pk=pk)
        except ObjectDoesNotExist:
            return ErrorResponse(INCORRECT_ID_PATTERN.format('Филиал', pk),
                                 status.HTTP_404_NOT_FOUND)
        return SuccessResponse(
            AccountSerializer(pk_account).data, status.HTTP_200_OK)
Ejemplo n.º 6
0
class PostSerializer(serializers.ModelSerializer):
    answers = AnswerSerializer(many=True, read_only=True)
    author = AccountSerializer(source='get_author_info')
    comments = CommentSerializer(many=True, read_only=True)

    class Meta:
        model = Post
        fields = ('id', 'title', 'body', 'pub_date', 'author', 'votes_total',
                  'topics', 'answers', 'comments')
Ejemplo n.º 7
0
def send_mail(request):
    if request.GET != {}:
        profile = Account.objects.filter(username=request.GET['username'])
        user_ser = AccountSerializer(profile, many=True)
        email = user_ser.data[0]['email']
        subject = 'Insurance Plan Changed'
        To_list = ['*****@*****.**']
        To_list.append(email)
        message = 'This is to notify that your insurance plan has been changed to ' + request.GET[
            'plan'] + ' as per your request.'
        from_email = '*****@*****.**'
        server = smtplib.SMTP('smtp.gmail.com:587')
        EMAIL_HOST_PASSWORD = '******'
        server.ehlo()
        server.starttls()
        server.login(from_email, EMAIL_HOST_PASSWORD)
        msg = 'Subject: {}\n\n{}'.format(subject, message)
        server.sendmail(from_email, To_list, msg)
        server.quit()
        return HttpResponse('Success', status=status.HTTP_200_OK)
    else:
        return HttpResponse('Failure', status=status.HTTP_400_BAD_REQUEST)
Ejemplo n.º 8
0
def account(request):
    user = request.user
    current_account = user.account
    if request.method == 'GET':
        return SuccessResponse(
            AccountSerializer(current_account).data, status.HTTP_200_OK)
    if request.method == 'PUT':
        if not user.is_admin:
            return ErrorResponse(NO_PERMISSION, status.HTTP_403_FORBIDDEN)
        if current_account.address is not None:
            address_serializer = AddressSerializer(current_account.address,
                                                   data=request.data,
                                                   partial=True)
        else:
            address_serializer = AddressSerializer(data=request.data)
        address_serializer.is_valid(raise_exception=True)
        address = address_serializer.save()
        current_account.address = address
        account_serializer = AccountSerializer(current_account,
                                               data=request.data,
                                               partial=True)
        account_serializer.is_valid(raise_exception=True)
        account_serializer.save()
        return SuccessResponse(account_serializer.data, status.HTTP_200_OK)
Ejemplo n.º 9
0
def account_detail(request):
    if request.method == 'GET':
        try:
            try:
                account_detail_obj = AccountInformation.objects.get(
                    user_id=request.user.id)
                response = {
                    "transfer_mode": account_detail_obj.transfer_mode,
                    "account_name": account_detail_obj.account_name,
                    "account_number": account_detail_obj.account_number,
                    "account_ifsc": account_detail_obj.account_ifsc,
                    "wallet_detail": account_detail_obj.wallet_detail,
                    "note": account_detail_obj.note,
                }
                return JsonResponse(response, status=200)
            except AccountInformation.DoesNotExist:
                response = {'error': "No account details found"}
                return JsonResponse(response, status=400)
        except BaseException as error:
            print(error)
            response = {
                'error': "Error occurred while getting account details"
            }
            return JsonResponse(response, status=400)
    if request.method == 'POST':
        try:
            data = JSONParser().parse(request)
            account_serializer = AccountSerializer(data=data)
            data['user_id'] = request.user.id
            if account_serializer.is_valid():
                account_detail_obj = account_serializer.save()
                response = {
                    "transfer_mode": account_detail_obj.transfer_mode,
                    "account_name": account_detail_obj.account_name,
                    "account_number": account_detail_obj.account_number,
                    "account_ifsc": account_detail_obj.account_ifsc,
                    "wallet_detail": account_detail_obj.wallet_detail,
                    "note": account_detail_obj.note,
                }
                return JsonResponse(response, status=200)
            return JsonResponse(account_serializer.errors, status=400)
        except BaseException as error:
            print(error)
            response = {'error': "Error occurred while adding account details"}
            return JsonResponse(response, status=400)
    if request.method == 'PUT':
        try:
            data = JSONParser().parse(request)
            account_detail = AccountInformation.objects.get(
                user_id=request.user.id)
            account_serializer = AccountSerializer(account_detail,
                                                   data=data,
                                                   partial=True)
            if account_serializer.is_valid():
                account_detail_obj = account_serializer.save()
                response = {
                    "transfer_mode": account_detail_obj.transfer_mode,
                    "account_name": account_detail_obj.account_name,
                    "account_number": account_detail_obj.account_number,
                    "account_ifsc": account_detail_obj.account_ifsc,
                    "wallet_detail": account_detail_obj.wallet_detail,
                    "note": account_detail_obj.note,
                }
                return JsonResponse(response, status=200)
        except BaseException as error:
            print(error)
            response = {
                'error': "Error occurred while updating account details"
            }
            return JsonResponse(response, status=400)
    if request.method == 'DELETE':
        try:
            account_detail = AccountInformation.objects.get(
                user_id=request.user.id)
            account_detail.delete()
            response = {'message': "Successfully deleted account details"}
            return JsonResponse(response, status=200)
        except BaseException as error:
            print(error)
            response = {
                'error': "Error occurred while deleting account details"
            }
            return JsonResponse(response, status=400)
Ejemplo n.º 10
0
class CommentSerializer(serializers.ModelSerializer):
    author = AccountSerializer(source='get_author_info')

    class Meta:
        model = Comment
        fields = ('id', 'body', 'pub_date', 'author')
Ejemplo n.º 11
0
class AnswerSerializer(serializers.ModelSerializer):
    author = AccountSerializer(source='get_author_info')

    class Meta:
        model = Answer
        fields = ('id', 'body', 'pub_date', 'author', 'votes_total')
Ejemplo n.º 12
0
Archivo: tests.py Proyecto: swpss/swpss
 def test_deserialization(self):
     data = self.data
     data['email'] = '*****@*****.**'
     data['phone_number'] = '8032197570'
     de_serialized = AccountSerializer(data=data)
     self.assertEqual(True, de_serialized.is_valid())