def tek_kullanici(cls, id, auth_token): auth_token_user = User.query.filter_by( id=User.token_sifre_coz(auth_token)).first() id_user = User.query.filter_by(id=id).first() if auth_token_user is None or id_user is None or id_user != auth_token_user: raise NotFound("Kullanıcı bulunamadı") return id_user
def tokena_gore_kullanici(token): resp = User.token_sifre_coz(token) user = User.query.filter_by(id=resp).first() if user is None: raise NotFound('Token geçerli değil') return { 'id': user.id, 'email': user.email, 'admin': user.admin, 'registered_on': str(user.registered_on) }
def tek_kategori(cls, tip, deger): kategori = None if deger is None or not deger.strip(): raise BadRequest("Id bulunamadı") if tip == "id": kategori = Kategori.query.filter_by(id=deger).first() elif tip == "url": kategori = Kategori.query.filter_by(url=deger).first() if kategori is None: raise NotFound("Kategori Bulunamadı") return kategori
def resim_ekle(): status = HTTPStatus.OK.real try: if 'resim' not in request.files: raise BadRequest("Resim alanı zorunlu") file = request.files['resim'] if file.filename == '': raise BadRequest("Resim alanı boş geçilemez") if file is None or \ '.' not in file.filename or \ file.filename.rsplit('.', 1)[1].lower() not in ALLOWED_EXTENSIONS: raise NotFound("Geçersiz resim.") # ext = file.filename.rsplit('.', 1)[1].lower() file.filename = str(uuid.uuid4()) + ".png" filename = secure_filename(file.filename) file.save("images/" + secure_filename(filename)) response = {"resim": filename} except Exception as e: response = {'Hata': str(e)} status = getStatus(e) return response, status
def get_resource(resource): if resource not in resource_dict: raise NotFound(5000) return resource_dict[resource]
def cikis(auth_token): if auth_token is None: raise NotFound("Token vermeniz gerekir") User.token_sifre_coz(auth_token) KaraListe.save_token(token=auth_token)
def tek_yazi_with_url(cls, yazi_url): yazi = Yazi.query.filter_by(url=yazi_url).first() if yazi is None: raise NotFound("Yazı Bulunamadı.") return yazi
def idye_gore_kategori(cls, kategori_id): kategori = Kategori.query.filter_by(id=kategori_id).first() if kategori is None or not kategori: raise NotFound("Kategori Bulunamadı.") return kategori
def first_or_404(self, description=None): rv = self.first() if rv is None: raise NotFound() return rv
def get_or_404(self, ident, description=None): rv = self.get(ident) if rv is None: raise NotFound() return rv
def page_not_found(): raise NotFound('page not found')