def post(self, request): try: ustDuzeyHak = request.data["highlevelRight"] subeId = request.data["subeId"] if "subeId" in request.data else -1 arananSube = None if subeId == -1: return createErrorResponse(404, {"message": "Branch not found"}) else: arananSube = iliskiVarMi(request.user, subeId) if arananSube is None: return createErrorResponse(404, {"message": "Branch not found"}) stFilter = "" if request.user.is_superuser: stFilter = SubeTemsilcisi.objects.filter(sube__id=subeId)[0] elif request.user.is_staff: kul_id = request.user.id stFilter = SubeTemsilcisi.objects.filter( sube__id=subeId, kullanici__id=kul_id)[0] if stFilter is None or stFilter.ustduzey_hak is False: ustDuzeyHak = False serialized = UserSerializer(data=request.data) # subeAuthorized = iliskiliSubeler(request.user) if subeId > -1 and iliskiVarMi(request.user, subeId): if serialized.is_valid(): createdUser = User.objects.create_user( email=request.data['email'], username=request.data['username'], password=request.data['password'], first_name=request.data['firstname'], last_name=request.data['lastname'], is_staff=True) createdUser.save() yeniSubeIliskisi = SubeTemsilcisi(sube=stFilter.sube, kullanici=createdUser, ustduzey_hak=ustDuzeyHak) yeniSubeIliskisi.save() return Response(serialized.data, status=status.HTTP_201_CREATED) else: return createErrorResponse(404, serialized.errors) else: return Response(serialized.errors, status=status.HTTP_400_BAD_REQUEST) except Exception as exception: traceback.print_exc() return createErrorResponse(500, {"error": str(exception.__class__)})
def post(self, request: Request): try: q = request.data kayitId = q.get("kayit_id") if kayitId is not None and kayitId > -1: girisler = MusteriGirisi.objects.filter(id=kayitId) if girisler.count() > 0: giris: MusteriGirisi = girisler[0] sube = iliskiVarMi(request.user, giris.secili_sube.id) if request.user.is_superuser or sube is not None: if containsInDictionaryKey(q, ["cikis_tarih", "ucret"]): cikis_tarih = dateUtilParse(q.get("cikis_tarih")) giris.cikis_tarih = cikis_tarih giris.ucret = q.get("ucret") giris.save() return createErrorResponse( 200, {"message": "Record updated"}) else: return createErrorResponse( 403, {"message": "Unauthorized for this branch"}) else: return createErrorResponse(404, {"message": "Record not found"}) else: return createErrorResponse( 400, {"message": "Record not provided correctly"}) except Exception as exception: traceback.print_exc() return createErrorResponse(500, {"error": str(exception.__class__)})
def post(self, request): load = request.data subeid = load.get("sube_id") if subeid is not None: subeid = int(subeid) if iliskiVarMi(request.user, subeid) is not None: musteri = try_fetch(load.get("musteri_id"), load.get("musteri_isim"), load.get("musteri_soyisim"), load.get("musteri_email"), load.get("musteri_tel"), False) if musteri is not None: krediler = MusteriKredi.objects.filter(musteri=musteri, sube__id=subeid) ra = [] if krediler is not None: for kredi in krediler: ra.append(MusteriKrediSerializer(kredi).data) return Response(ra) else: return Response([]) else: return Response([]) else: return Response({"message": "Şube yetkisi bulunamadı"}, status=401) else: return Response( {"message": "Girilen gerekli bilgiler geçerli değil"}, status=400)
def get(self, request, sube=-1): if (sube > -1): if request.user.is_superuser or iliskiVarMi(request.user, sube) is not None: iliskiler = SubeTemsilcisi.objects.filter(sube__id=sube) calisanlar_parsed = [ self.__combineTemsil(iliski) for iliski in iliskiler ] return createErrorResponse(202, calisanlar_parsed) else: return createErrorResponse(403, {"message": "Unauthorized branch"}) else: if request.user.is_superuser: iliskiler = SubeTemsilcisi.objects.filter() calisanlar_parsed = [ self.__combineTemsil(iliski) for iliski in iliskiler ] return createErrorResponse(202, calisanlar_parsed) else: subeler = iliskiliSubeler(request.user) iliskiler = SubeTemsilcisi.objects.filter(sube__in=subeler) calisanlar_parsed = [ self.__combineTemsil(iliski) for iliski in iliskiler ] return createErrorResponse(202, calisanlar_parsed)
def _generic_control(request, subePreprovide=None) -> (bool, Response): """Controls is branch provided and is user any privaliges Return 1: when controlling if has a issue, return false. Else then, it is true Return 2: If has issue, response will be returned. But there is no issue, nothing returned""" sube_ = "" if subePreprovide is None: sube_: str = request.query_params["sube_id"] else: sube_ = subePreprovide if type(sube_) is int or sube_.isnumeric(): sube = int(sube_) flag = False if (request.user.is_superuser): flag = True else: iliski = iliskiVarMi(request.user, sube) if iliski is not None: flag = True if flag: return True, None return False, createErrorResponse(200, paginated_expenses) else: return False, createErrorResponse(404, {"message": "Branch not found"}) else: return False, createErrorResponse(400, {"message": "Branch is missing"})
def get(self, request: Request): """@sadeceCikmayanlar çıkış tarihi eklenmemiş kayıtları gösterir @subeFiltre""" sadeceCikmayanlar = False subeFiltre = -1 if request.query_params.get("sadece-cikmayanlar") == "1": sadeceCikmayanlar = True subeId: str = request.query_params.get("sube-id") if (subeId != "" and subeId is not None and re.match("^([0-9].*)$", subeId) is not None): subeFiltre = int(subeId) customersQ = MusteriGirisi.objects if sadeceCikmayanlar: customersQ = customersQ.filter(cikis_tarih__isnull=True) relations = iliskiliSubeler(request.user) # admin control if request.user.is_superuser: customerEntries = None if subeFiltre == -1: customerEntries = MusteriGirisi.objects.order_by("-id").all() else: customerEntries = MusteriGirisi.objects.filter( secili_sube__id=subeFiltre).order_by("-id") paginated = pagination(customerEntries, request.query_params.get("page"), request.query_params.get("size")) return Response(makeArraySerializationsQuery(paginated)) # if not admin but staff elif request.user.is_staff: if subeFiltre > -1: iliskiliSube = iliskiVarMi(request.user, subeFiltre, relations) if iliskiliSube is not None: customerEntries = customersQ.filter( secili_sube=iliskiliSube).order_by("-id") paginated = pagination(customerEntries, request.query_params.get("page"), request.query_params.get("size")) return Response(makeArraySerializationsQuery(paginated)) else: return createErrorResponse( 403, { "message": "You aren't related with ŞUBE(Branch)" + str(subeFiltre) }, ) else: customerEntries = customersQ.filter( secili_sube__in=relations).order_by("-id") return Response( makeArraySerializationsQuery(customerEntries.all()))
def get(self, request, randevuId): if randevuId is None: return createErrorResponse(400, {"message": "randevu Id not provided"}) else: randevular = Randevu.objects.filter(id=randevuId) randevu = randevular[0] if randevular.count() > 0 else None if randevu is not None: iliski = iliskiVarMi(request.user, randevu.secili_sube.id) if iliski is not None or request.user.is_superuser: randevu.delete() return Response({"message": "Appointment deleted"}, 200) else: return Response({"message": "You are unauthorized for this branch"}, 403) else: return Response({"message": "Randevu not found"}, 404)
def get(self, request : Request): try: subeId: str = request.query_params.get("sube-id") if request.user.is_superuser: if subeId is not None and subeId.isnumeric(): query = Randevu.objects.filter(secili_sube__id=int(subeId)).order_by("-id") paginated = pagination(query, request.query_params.get("page"), request.query_params.get("size")); return Response(self.__convertAppointments(paginated)) else: paginated = pagination(Randevu.objects.order_by("-id"), request.query_params.get("page"), request.query_params.get("size")).order_by("-id") return Response(self.__convertAppointments(paginated)) else: query = Randevu.objects if subeId is not None and subeId.isnumeric(): temsil = iliskiVarMi(request.user, int(subeId)) if temsil is not None: query = query.filter(secili_sube=temsil.sube).order_by("-id") paginated = pagination(query, request.query_params.get("page"), request.query_params.get("size")) return Response(self.__convertAppointments(paginated)) else: return createErrorResponse(403, {"message": "You aren't authenticated with this branch"}) else: iliskiliBranchler = iliskiliSubeler(request.user) query = Randevu.objects.filter(secili_sube__in=iliskiliBranchler).order_by("-id") paginated = pagination(query, request.query_params.get("page"), request.query_params.get("size")) return Response(self.__convertAppointments(paginated)) except Exception as exception: traceback.print_exc() return createErrorResponse(500, {"error": str(exception.__class__)})
def get(self, request: Request): subeFiltre = None subeId: str = request.query_params.get("sube-id") if (subeId != "" and subeId is not None and re.match("^([0-9].*)$", subeId) is not None): subeFiltre = int(subeId) temsil = iliskiVarMi(request.user, subeFiltre) if request.user.is_superuser or temsil is not None: rd = [] musteriIds = MusteriGirisi.objects.filter( secili_sube__id=subeFiltre).values_list('musteri', flat=True) musteriler = Musteri.objects.filter(id__in=musteriIds) # sube__id=subeFiltre # krediler = for musteri in musteriler: rd.append(MusteriSerializer(musteri).data) return Response(rd) else: return createErrorResponse(404, {"message": "Sube is not found"}) else: return createErrorResponse(400, {"message": "Sube id is invalid"})
def post(self, request): try: data: dict = request.data if containsInDictionaryKey( data, [ "musteri_isim", "musteri_soyisim", "musteri_email", "musteri_tel", "hizmet_turu", "giris_tarih", "secili_sube", "calisan" ] # optional fields = ucret, cikisTarihi ) or containsInDictionaryKey(data, [ "musteri_id", "hizmet_turu", "giris_tarih", "secili_sube", "calisan" ] # optional fields = ucret, cikisTarihi ): ilgili_calisan_id = data.get("calisan") bulunanCalisan = SubeTemsilcisi.objects.filter( kullanici__id=int(ilgili_calisan_id), sube__id=int(data.get("secili_sube"))) email, tel = "", "" if ("musteri_email" in data.keys()): email = data.get("musteri_email") if ("musteri_tel" in data.keys()): tel = data.get("musteri_tel") musteri = try_fetch(data.get("musteri_id"), data.get("musteri_isim"), data.get("musteri_soyisim"), email, tel) if bulunanCalisan.count() > -1: cikis_tarih = None giris_tarih = dateUtilParse(data.get("giris_tarih")) ucret = data.get("ucret") prim = data.get("prim") calisan = None calisanId = data.get("calisan") if calisanId is not None and calisanId.isnumeric(): calisan = User.objects.filter(id=int(calisanId)) if (calisan is None): calisan = request.user if data.get("cikis_tarih") is not None: cikis_tarih = dateUtilParse(data.get("cikis_tarih")) iliski = iliskiVarMi(request.user, data.get("secili_sube")) calisanIliski = SubeTemsilcisi.objects.filter( kullanici=calisan[0], sube=data.get("secili_sube"))[0] if request.user.is_superuser or iliski is not None: if data.get("kredi_ekle") is True or data.get( "kredi_tuket") is True: tuketilecek_kredi_turu = data.get( "kredi_tuketim_turu") eklenecek_kredi_turu = data.get( "kredi_eklenme_turu") eklenecek_kredi, ek_taze = None, None tuketilecek_kredi, tk_taze = None, None if data.get("kredi_ekle") and eklenecek_kredi_turu and \ eklenecek_kredi_turu.isspace() is not True: eklenecek_kredi, ek_taze = MusteriKredi.objects.get_or_create( musteri=musteri, sube=iliski.sube, hizmet_turu=eklenecek_kredi_turu) if eklenecek_kredi: # kredi ekleme kredi_eklenecek_sayi = data.get( "credit_will_be_added") if kredi_eklenecek_sayi is not None and kredi_eklenecek_sayi > 0: eklenecek_kredi.sayi += kredi_eklenecek_sayi if data.get("kredi_tuket") and tuketilecek_kredi_turu and \ tuketilecek_kredi_turu.isspace() is not True: if (eklenecek_kredi is not None) and ( eklenecek_kredi_turu == tuketilecek_kredi_turu): tuketilecek_kredi = eklenecek_kredi else: tuketilecek_kredi, tk_taze = MusteriKredi.objects. \ get_or_create(musteri=musteri, sube=iliski.sube, hizmet_turu=tuketilecek_kredi_turu) if tuketilecek_kredi: if tuketilecek_kredi.sayi > 0: tuketilecek_kredi.sayi -= 1 else: return createErrorResponse( 400, { "message": "Müşterinin kredi hakkı bulunmamaktadır" }) if eklenecek_kredi and \ (tuketilecek_kredi is None or tuketilecek_kredi.id != eklenecek_kredi.id): eklenecek_kredi.save() if tuketilecek_kredi: tuketilecek_kredi.save() musteriKayit = MusteriGirisi( musteri=musteri, hizmet_turu=data.get("hizmet_turu"), secili_sube=iliski.sube, giris_tarih=giris_tarih, cikis_tarih=cikis_tarih, odeme_yontemi=data.get("odeme_yontemi"), ucret=ucret if ucret is not None else 0, calisan=calisanIliski.kullanici, prim=prim) musteriKayit.save() return createErrorResponse( 200, MusteriGirisiSerializer(musteriKayit).data) else: return createErrorResponse( 403, { "message": "You aren't related with ŞUBE(Branch)" + str(request.data.get("sube")) }, ) else: createErrorResponse( 404, {"message": "Corresponding User in branch not found"}) else: return createErrorResponse( 400, { "message": """1 field or more than 1 fields are missing. Needed "isim", "soyisim" (first - last names),"hizmetTipi" (service type), "subeId" (branch identify),"tarih" (date with hours) fields """ }, ) # except Exception as exception: traceback.print_exc() return createErrorResponse(500, {"error": str(exception.__class__)})