Пример #1
0
 def get(self, request, pk):
     try:
         user = request.user
         self.check_ownership(user, pk)
         queryset = self.get_queryset()
         serializer = PharmacyMSISerializer(queryset, many=True)
         return Response(serializer.data)
     except Exception as e:
         if self.message:
             raise AcceptableException(detail=self.message)
         else:
             raise AcceptableException(detail={"error": str(e)})
Пример #2
0
 def delete(self, request, pk):
     try:
         user = request.user
         self.check_ownership(user, pk)
         msi = PharmacyMSI.objects.get(id=pk)
         msi.delete()
         return Response(
             {'success': "İlaç deposu bilgileri başarıyla silindi"})
     except Exception as e:
         if self.message:
             raise AcceptableException(detail=self.message)
         else:
             raise AcceptableException(detail={"error": str(e)})
Пример #3
0
 def update(self, instance, validated_data):
     try:
         valid = self.validation(validated_data['name'])
         if valid:
             instance.name = validated_data['name']
             instance.updated_date = timezone.now()
             instance.updated_by = self.context['request'].user
             instance.save()
             return instance
     
     except Exception as e:
         if self.message:
             raise AcceptableException(detail=self.message)
         else:
             raise AcceptableException(detail={"error": e})
Пример #4
0
 def create(self, validated_data):
     try:
         user = self.context['request'].user
         if user.pharmacy:
             self.check_have(user.pharmacy, validated_data['ms'])
             validated_data['created_by'] = user
             validated_data['pharmacy'] = user.pharmacy
             return PharmacyMSI.objects.create(**validated_data)
         else:
             self.message = {"error": "Herhangi bir eczaneye sahip olmadığınız için ilaç deposu bilgisi oluşturamazsınız"}
             raise Exception
     except Exception as e:
         if self.message:
             raise AcceptableException(detail=self.message)
         else:
             raise AcceptableException(detail={"error": str(e)})
Пример #5
0
    def create(self, validated_data):
        try:
            valid = self.validation(validated_data['name'])
            if valid:
                user = self.context['request'].user
                validated_data['created_by'] = user
                pharmacy = self.check_pharmacy(user)
                group = Group.objects.create(**validated_data)
                group.administrators.add(user.id)
                pharmacy.groups.add(group)
                return group

        except Exception as e:
            if self.message:
                raise AcceptableException(detail=self.message)
            else:
                raise AcceptableException(detail={"error": str(e)})
Пример #6
0
 def get(self, request):
     try:
         return JsonResponse(list(City.objects.all().values("id", "name")),
                             safe=False)
     except Exception as e:
         raise AcceptableException(
             detail={
                 "error": "Şehir bilgileri çekilirken bir sorun oluştu"
             })
Пример #7
0
 def update(self, instance, validated_data):
     try:
         user = self.context['request'].user
         if user.pharmacy:
             self.check_ownership(instance.pharmacy.id, user.id)
             instance.pharmacy_code = validated_data['pharmacy_code']
             instance.username = validated_data['username']
             instance.password = validated_data['password']
             instance.updated_by = user
             instance.updated_date = timezone.now()
             instance.save()
             return instance
         else:
             self.message = {"error": "Herhangi bir eczaneye sahip olmadığınız için ilaç deposu bilgisini güncelleyemezsiniz"}
             raise Exception
     except Exception as e:
         if self.message:
             raise AcceptableException(detail=self.message)
         else:
             raise AcceptableException(detail={"error": str(e)})
Пример #8
0
 def create(self, validated_data):
     try:
         user = self.context['request'].user
         self.check_pharmacy(user)
         self.check_gln(validated_data['gln_number'])
         #groups = self.check_group(user)
         validated_data['created_by'] = user
         pharmacy = Pharmacy.objects.create(**validated_data)
         '''
         # eczane oluşturulurken kullanıcının yonetici oldugu grup var ise gruba eklemesi için yazmışım ama bunu sildim.
         # CÜNKÜ ECZANESİ OLMAYAN GRUP OLUŞTURAMAZ
         if groups:
             for group in groups:
                 pharmacy.groups.add(group.id)
         '''
         User.objects.filter(id=user.id).update(pharmacy=pharmacy)
         return pharmacy
     except Exception as e:
         if self.message:
             raise AcceptableException(detail=self.message)
         else:
             print(e)
             raise AcceptableException(detail={"error": e})
Пример #9
0
 def update(self, instance, validated_data):
     try:
         user = self.context['request'].user
         self.check_ownership(instance.id, user.id)
         self.check_gln(validated_data['gln_number'], instance.id)
         instance.name = validated_data['name']
         instance.first_phone = validated_data['first_phone']
         instance.second_phone = validated_data['second_phone']
         instance.address = validated_data['address']
         instance.tax_administration = validated_data['tax_administration']
         instance.tax_number = validated_data['tax_number']
         instance.identification_number = validated_data['identification_number']
         instance.gln_number = validated_data['gln_number']
         instance.state = validated_data['state']
         instance.updated_by = user
         instance.updated_date = timezone.now()
         instance.save()
         return instance
     except Exception as e:
         if self.message:
             raise AcceptableException(detail=self.message)
         else:
             print(e)
             raise AcceptableException(detail={"error": e})
Пример #10
0
 def get(self, request):
     try:
         pharmacy_msies = PharmacyMSI.objects.filter(
             pharmacy=request.user.pharmacy).values("pharmacy_code",
                                                    "username", "password",
                                                    "ms", "pharmacy", "id",
                                                    "ms__name")
         if len(pharmacy_msies) > 0:
             return JsonResponse(list(pharmacy_msies), safe=False)
         else:
             return Response({
                 "error":
                 "Şimdiye kadar herhangi bir ecza deposuna ait bilgi oluşturmadınız"
             })
     except Exception as e:
         raise AcceptableException(detail={"error": "Hatalı işlem"})
Пример #11
0
 def delete(self, request, pk):
     raise AcceptableException(
         detail={
             "error":
             "Bu işlemi yapmak için yetkiniz yoktur. Eczane silmek için lütfen sistem yöneticisi ile iletişime geçin"
         })
Пример #12
0
 def destroy(self, validated_data):
     raise AcceptableException(detail={"error": "asdasdsad"})