def gundem_guncelle(gundem_id): """Gundem guncellemek icin kullanilir""" user_id = current_user.id gundem_data = request.get_json() gundem_formu = ToplantiGundem(**gundem_data) try: gundem = DB.session.query(BapGundem).filter_by(id=gundem_id).one() except NoResultFound as exc: DB.session.rollback() CustomErrorHandler.error_handler( hata="Olmayan bir gündem güncellenmeye çalışıldı." "Gündem id: {}, User id: {}, Hata: {}".format( gundem_id, user_id, exc) ) return jsonify(status="error"), 400 try: gundem_data = gundem_formu.data gundem_data.pop("proje_id") gundem_data.pop("gundem_id") if gundem_data.get("gundem_sira_no") is None: gundem_data.pop("gundem_sira_no") gundem.update_obj_data(gundem_data) except SQLAlchemyError as exc: DB.session.rollback() CustomErrorHandler.error_handler( hata="Toplanti gündem güncellenmeye calisilirken bir hata olustu." "Gundem id: {}, User id: {}, Hata: {}".format( gundem_id, user_id, exc) ) return jsonify(status="error"), 400 signal_payload = { "message_type": USER_ACTIVITY_MESSAGES.get("toplanti").get( "gundem_guncelle").type_index, "nesne": 'BAP Gundem', "nesne_id": gundem_id, "ekstra_mesaj": "{username} adlı kullanıcı toplanti gundemini guncelledi.".format( username=current_user.username), } signal_sender(**signal_payload) DB.session.commit() toplanti_tarihi = gundem.toplanti.toplanti_tarihi.strftime( "%d.%m.%Y") if gundem.toplanti and gundem.toplanti.toplanti_tarihi else "Toplantı tarihi belirtilmedi" data = { "toplanti_tarihi": toplanti_tarihi, "gundem_tipi": gundem.tipi.value, "gundem_aciklama": gundem.aciklama, "gundem_karar": gundem.karar, "toplanti_id": gundem.toplanti_id } return jsonify(status="success", gundem_data=data)
def gundem_sil(toplanti_id, gundem_id): """ Gündemi toplanti gundemleri arasindan cikarmak icin kullanılır. """ user_id = current_user.id try: cikarilacak_gundem = DB.session.query(BapGundem).filter_by( toplanti_id=toplanti_id, id=gundem_id).one() cikarilacak_gundem.toplanti_id = None DB.session.commit() except SQLAlchemyError as exc: DB.session.rollback() CustomErrorHandler.error_handler( hata="Gündem silinirken bir hata oluştu.Gundem id: {}, Toplanti id:" " {}, User id: {}, Hata: {}".format(gundem_id, toplanti_id, user_id, exc) ) return jsonify(status="error"), 400 signal_payload = { "message_type": USER_ACTIVITY_MESSAGES.get("toplanti").get( "toplanti_gundem_cikar").type_index, "nesne": 'BAP Gundem', "nesne_id": gundem_id, "etkilenen_nesne": "BAP Toplanti", "etkilenen_nesne_id": toplanti_id, "ekstra_mesaj": "{username} adlı kullanıcı {gundem_id} id'li gundemi toplanti " "gundemleri arasindan cikardi.".format(username=current_user.username, gundem_id=gundem_id), } signal_sender(**signal_payload) return jsonify(status="success")
def get_gundem(gundem_id): """Belirli bir toplanti gundemini almak icin kullaniriz""" user_id = current_user.id try: gundem = DB.session.query(BapGundem).options( joinedload(BapGundem.proje).load_only("proje_basligi", "proje_no", "id").lazyload( "*"), raiseload("*") ).filter_by(id=gundem_id).one() except NoResultFound as exc: CustomErrorHandler.error_handler( hata="Var olmayan bir gundeme ulasilmalay calisildi. User id: {}, " "Gundem id: {}, Hata: {}".format(user_id, gundem_id, exc)) return abort(404) gundem_data = { "gundemId": gundem_id, "sablonId": gundem.sablon_id, "ekDosyaId": gundem.ek_dosya_id, "karar": gundem.karar, "aciklama": gundem.aciklama, "tipi": gundem.tipi.name, "kararDurumu": gundem.karar_durum.name, "gundemSiraNo": gundem.gundem_sira_no, "yonetimeBilgiNotu": gundem.yonetime_bilgi_notu, "kisiyeOzelNot": gundem.kisiye_ozel_not, "projeBasligi": gundem.proje.proje_basligi, "projeId": gundem.proje_id, "projeNo": gundem.proje.proje_no } return jsonify(status="success", gundemData=gundem_data)
def rol_ekle_set(): """Request bodysinde gelen rolün veritabanına kaydedildiği metottur.""" selected_permissions = set(request.get_json().get('selected_permissions', [])) updated_rol_name = request.get_json().get('rol_adi') permissions_to_add_ids = [ptoa[0] for ptoa in PermissionModel.query.with_entities(PermissionModel.id).filter( PermissionModel.name.in_(selected_permissions)).all()] try: rol = Role(name=updated_rol_name) DB.session.add(rol) DB.session.commit() if permissions_to_add_ids: for perm in permissions_to_add_ids: DB.session.add(RolePermission(role_id=rol.id, permission_id=perm)) DB.session.commit() signal_payload = { "message_type": USER_ACTIVITY_MESSAGES.get("yonetim").get( "yeni_rol_ekle").type_index, "nesne": 'Role', "nesne_id": rol.id, "ekstra_mesaj": "Yeni rol eklendi: {}".format(rol.name), } signal_sender(**signal_payload) except SQLAlchemyError as exc: DB.session.rollback() CustomErrorHandler.error_handler() return jsonify(status="error"), 400 return jsonify(status="success")
def rol_sil(role_id): """ Rol silme işini yapan view metodu. Args: role_id: Returns: """ try: Role.query.filter_by(id=role_id).delete() DB.session.commit() payload = { "message_type": USER_ACTIVITY_MESSAGES.get("yonetim").get("rol_sil").type_index, "nesne": "Rol", "nesne_id": role_id, "ekstra_mesaj": "{} isimli kullanıcı {} id'li rolu sildi.".format( current_user.username, role_id), "notification_receiver": current_user.person.personel.id, "notification_title": "Rol silme başarılı", } # todo: notification mesajinda id(name kullanilabilir) var kullanici icin anlamli degil. ntf_message = "Rol silme başarılı. {} idli rol başarıyla kaldırıldı.".format(role_id) signal_sender(notification=True, notification_message=ntf_message, **payload) return jsonify(status="success") except UnmappedInstanceError as exc: DB.session.rollback() CustomErrorHandler.error_handler() except IntegrityError as exc: # todo permission, user, gibi role ile alakalı modellerin listelerini döndür DB.session.rollback() CustomErrorHandler.error_handler() return jsonify(status="error"), 409 return jsonify(status="error"), 400
def gundem_sira_no_guncelle(toplanti_id): """ Rowreorder datatable da gundem sirasinda bir degisiklik oldugunda ilgili gündemlerin sira numarasini degistirmek icin kullanılan view """ gundem_data = request.get_json() user_id = current_user.id try: guncellenecek_gundem = DB.session.query(BapGundem).filter_by( id=gundem_data["gundem_id"], toplanti_id=toplanti_id).one() except SQLAlchemyError as exc: DB.session.rollback() CustomErrorHandler.error_handler( hata="Gundem sira no guncellenirken hata olustu. Gundem id: {}, " "User id: {}, Hata: {}".format(gundem_data["gundem_id"], user_id, exc)) return abort(400) guncellenecek_gundem.gundem_sira_no = int(gundem_data["gundem_sira_no"]) DB.session.commit() signal_payload = { "message_type": USER_ACTIVITY_MESSAGES.get("toplanti").get( "gundem_sira_degistir").type_index, "nesne": 'BAP Gundem', "etkilenen_nesne": "BAP Toplanti", "etkilenen_nesne_id": toplanti_id, "ekstra_mesaj": "{username} adlı kullanıcı toplanti gundem sirasini degistirdi.".format( username=current_user.username), } signal_sender(**signal_payload) return jsonify(status="success")
def hakem_oneri_sil(proje_id, oneri_id): """ Daha önce proje için önerilip kaydedilmiş hakem önerisini siler """ try: silinecek_oneri = DB.session.query(HakemOneri).filter_by( id=oneri_id, proje_id=proje_id).first() DB.session.delete(silinecek_oneri) DB.session.commit() signal_payload = { "message_type": USER_ACTIVITY_MESSAGES.get("bap").get( "hakem_onerisi_kaldirildi").type_index, "nesne": 'Hakem Oneri', "nesne_id": oneri_id, "etkilenen_nesne": "Proje", "etkilenen_nesne_id": proje_id, "ekstra_mesaj": "{} adlı kullanıcı, {} {} kişiyi hakem önerilerinden " "kaldırdı.".format(current_user.username, silinecek_oneri.ad, silinecek_oneri.soyad) } signal_sender(**signal_payload) return jsonify(status="success") except SQLAlchemyError as exc: DB.session.rollback() CustomErrorHandler.error_handler( hata="Proje idsi %s olan projeye hakem önerisi silinmeye" "çalışılırken bir sorun oluştu. Hata: %s" % ( proje_id, exc) ) return jsonify(status="error"), 400
def file_information(self, file_id): """ Dosya hakkında bilgi almak için kullanılır Args: file_id: dosya id Returns:{"name": "dosya adı", "type": "image/png", "uploadedAt": "2018-03-29 06:51:30", "url": "/file/download/{}".format(file_id), "deleteUrl": "/file/delete/{}".format(file_id), "deleteType": "DELETE"} """ try: file = DB.session.query(File).filter_by(id=file_id).one() except NoResultFound: return jsonify({"files": [{"error": _("Dosya Bulunamadi")}]}) except Exception as exc: CustomErrorHandler.error_handler() return jsonify({"error": _("Bir Hata Olustu Daha Sonra Tekrar Deneyiniz")}) return jsonify({"name": file.content.filename, "type": file.content.content_type, "uploadedAt": file.content.uploaded_at, "url": self.DOWNLOAD_URL.format(file_id), "deleteUrl": self.DELETE_URL.format(file_id), "deleteType": self.DELETE_TYPE})
def toplanti_gundem_listele(toplanti_id): """Toplanti gundemlerini listeler""" user_id = current_user.id gundem_form = ToplantiGundem() try: toplanti = DB.session.query(BapToplanti).options( joinedload(BapToplanti.gundemler).joinedload( BapGundem.proje).load_only("id", "proje_no", "proje_basligi").lazyload("*"), raiseload("*") ).filter_by(id=toplanti_id).one() except NoResultFound as exc: DB.session.rollback() CustomErrorHandler.error_handler( hata="Var olmayan bir toplanti id ile istek gönderildi.User id: {}," " Hata: {}".format(user_id, exc)) return abort(404) gundem_sayisi = len(toplanti.gundemler) gundem_form.gundem_sira_no.choices = [(i + 1, str(i + 1)) for i in range(gundem_sayisi)] # sablon tipi id '51' Yönetim Kurulu Tutanak Şablonunu temsil etmektedir. toplanti_tutanak_sablonu = DB.session.query(Sablon.id.label("sablon_id"), Sablon.sablon_tipi_id.label("sablon_tipi_id")).filter( Sablon.sablon_tipi_id == 51).order_by(desc(Sablon.updated_at)).first() return render_template('toplanti_gundemleri.html', gundemler=toplanti.gundemler, gundem_form=gundem_form, toplanti_id=toplanti_id, toplanti_sonuclandi_mi=toplanti.sonuclandi_mi, toplanti_tutanak_sablon_id=toplanti_tutanak_sablonu.sablon_id, sablon_type_id=toplanti_tutanak_sablonu.sablon_tipi_id)
def proje_durum_kaydet(proje_id): request_json = request.get_json() form = request_json['form'] kod = request_json['kod'] try: template = project_management_methods_post[kod](proje_id=proje_id, code=kod, form=form) if not template: return jsonify(status="success") if type(template) is str: return jsonify(status="error", template=template, code=kod, hata_mesaji=""), 400 return jsonify( status="error", template=template[0], code=kod, hata_mesaji=template[1] if len(template) > 1 else ""), 400 except Exception as exc: DB.session.rollback() CustomErrorHandler.error_handler( hata="Proje ile ilgili işlem yapılırken bir hata oluştu" "Hata: {}, Proje id: {}".format(exc, proje_id)) return jsonify(status="error", template=None), 500
def get_odeme_emri(self, muhasebe_fis_id): """ Odeme emri sablonunu ilgili muhasebe fisi alanlari ile render edip kullaniciya doner """ try: muhasebe_fisi_data = BapQueryHelpers.get_muhasebe_fisi_bilgileri( muhasebe_fis_id) # sablon tipi id 49 --> Ödeme Emri Şablonu odeme_emri_sablonu = DB.session.query(Sablon).filter( Sablon.sablon_tipi_id == 49, Sablon.kullanilabilir_mi == True).order_by( desc(Sablon.updated_at)).first() muhasebe_fisi = DB.session.query(MuhasebeFisi).filter( MuhasebeFisi.id == muhasebe_fis_id).first() muhasebe_fisi.odeme_emri_tamamlandi = True DB.session.commit() return render_template_string(odeme_emri_sablonu.sablon_text, data=muhasebe_fisi_data) except Exception as exc: DB.session.rollback() CustomErrorHandler.error_handler( hata="Muhasebe fişi ödeme emrine çevrilirken bir hata " "oluştu.Hata: {}, Muhasebe Fisi id: {}".format( muhasebe_fis_id, exc)) return abort(500)
def gundem_sablon_sil(sablon_id): """Gundem Sablonu Silme""" sablon = DB.session.query( GundemSablon ).filter( GundemSablon.id == sablon_id ).one_or_none() if sablon: DB.session.delete(sablon) DB.session.commit() signal_payload = { "message_type": USER_ACTIVITY_MESSAGES.get("bap").get("gundem_sablon_sil").type_index, "nesne": 'Gundem Sablon', "nesne_id": sablon.id, "ekstra_mesaj": "{} adlı kullanıcı {} id'li gundem sablonu sildi.".format( current_user.username, sablon.id ) } signal_sender(**signal_payload) return jsonify(status='success') DB.session.rollback() CustomErrorHandler.error_handler() return jsonify(status="error"), 400
def proje_hakem_sil(proje_id, proje_hakem_id): """ Seçilen hakemin projehakem davet durumunu cikarildi olarak degistirir. """ try: proje_hakem = DB.session.query(ProjeHakemleri).filter( ProjeHakemleri.proje_id == proje_id, ProjeHakemleri.id == proje_hakem_id).one() proje_hakem.davet_durumu = ProjeHakemDavetDurumlari.cikarildi DB.session.commit() signal_payload = { "message_type": USER_ACTIVITY_MESSAGES.get("bap").get("hakem_atama_sil").type_index, "nesne": 'Proje Hakemleri', "nesne_id": proje_id, "ekstra_mesaj": "{} adlı kullanıcı, {} id'li hakemi proje hakemleri arasindan " "cikardi.".format(current_user.username, proje_hakem_id) } signal_sender(**signal_payload) return jsonify(status="success") except SQLAlchemyError as exc: DB.session.rollback() CustomErrorHandler.error_handler( hata="Proje idsi %s olan proje hakemleri arasından %s idli hakemi çıkarmaya " "çalışılırken bir sorun oluştu. Hata: %s" % ( proje_id, proje_hakem_id, exc) ) return jsonify(status="error"), 400
def dosya_sil(): belge_id = request.get_json()['file_id'] try: BAPBelge.query.filter(BAPBelge.id == belge_id).delete() DB.session.commit() except Exception as exc: CustomErrorHandler.error_handler( hata="BAP Belge silinirken bir hata" "oluştu.Hata: {}".format(exc)) return jsonify(status="error"), 400 signal_payload = { "message_type": USER_ACTIVITY_MESSAGES.get("yonetim").get( "bap_belge_silindi").type_index, "nesne": 'BAPBelge', "nesne_id": belge_id, "ekstra_mesaj": "BAP Belge silindi: {}".format(belge_id), } signal_sender(**signal_payload) return jsonify(status="success")
def harici_arastirmaci_kaydet(self, proje_id): """ Proje çalışanlarına üniversite dışı araştırmacı kaydetmek için kullanılır. """ harici_arastirmaci_data = request.get_json() adi = harici_arastirmaci_data.pop("ad") soyad = harici_arastirmaci_data.pop("soyad") email = harici_arastirmaci_data.pop("email") try: yeni_person = Person(ad=adi, soyad=soyad, birincil_eposta=email) DB.session.add(yeni_person) DB.session.flush() harici_arastirmaci_ozgecmis_id = self.ozgecmis_kaydet( ozgecmis_text=harici_arastirmaci_data.pop( "ozgecmis_text", None), ozgecmis_file_id=harici_arastirmaci_data.pop( "ozgecmis_file_id", None)) yeni_harici_arastirmaci = ProjeCalisanlari( proje_id=proje_id, ozgecmis_id=harici_arastirmaci_ozgecmis_id, person_id=yeni_person.id, **harici_arastirmaci_data) DB.session.add(yeni_harici_arastirmaci) DB.session.commit() signal_payload = { "message_type": USER_ACTIVITY_MESSAGES.get("bap").get( "projeye_harici_arastirmaci_eklendi").type_index, "nesne": 'Proje Calisanlari', "nesne_id": yeni_harici_arastirmaci.id, "etkilenen_nesne": "Proje", "etkilenen_nesne_id": proje_id, "ekstra_mesaj": "{} adlı kullanıcı, {} {} adlı kisiyi üniversite dışı arastırmacı " "olarak kaydetti.".format(current_user.username, adi, soyad) } signal_sender(**signal_payload) return jsonify(status="success", calisan={ "id": yeni_harici_arastirmaci.id, "ad": adi, "soyad": soyad, "gorevi": yeni_harici_arastirmaci.projedeki_gorevi }) except SQLAlchemyError as exc: DB.session.rollback() CustomErrorHandler.error_handler( hata="Proje idsi %s olan projeye harici araştırmacı atamaya" "çalışılırken bir sorun oluştu. Hata: %s" % (proje_id, exc)) return jsonify(status="error"), 400
def file_delete(file_id): """ Dosya silmek için kullanılır. jquery file upload ui kütüphanesine göre değer dönülür. Args: file_id: dosya id Returns: {filename: "True"} """ try: file = DB.session.query(File).filter_by(id=file_id).one() filename = file.content.filename DB.session.delete(file) DB.session.commit() signal_payload = { "message_type": USER_ACTIVITY_MESSAGES.get("common").get("dosya_sil").type_index, "nesne": 'File', "nesne_id": file_id, "ekstra_mesaj": "{} adlı kullanıcı, {} adlı dosyayı sildi.".format( current_user.username, filename) } signal_sender(**signal_payload) except NoResultFound: return jsonify({"files": [{"error": "dosya bulunamadi"}]}) except Exception as exc: CustomErrorHandler.error_handler() return jsonify({"error": _("Bir Hata Olustu Daha Sonra Tekrar Deneyiniz")}) return jsonify({filename: "True"})
def idari_personel_sil(self): idari_personel_id = request.get_json()['idari_personel_id'] idari_personel = DB.session.query(BapIdariPersonel).filter( BapIdariPersonel.id == idari_personel_id).first() idari_personel.gorevde_mi = False try: DB.session.commit() signal_payload = { "message_type": USER_ACTIVITY_MESSAGES.get("yonetim").get( "idari_personel_sil").type_index, "nesne": 'Personel', "nesne_id": idari_personel.personel_id, "ekstra_mesaj": " {} idari personel idsine sahip personel idari personel görevi pasifleştirildi " .format(idari_personel.personel_id) } signal_sender(**signal_payload) return jsonify(status="success") except Exception as exc: DB.session.rollback() CustomErrorHandler.error_handler( hata="İdari personel silinmeye çalışıldı. Hata: {}".format( exc)) return jsonify(status="error"), 400
def yeni_basvuru(tur_id): """Yeni proje başvurusu formları""" user_id = current_user.id try: p_tur = DB.session.query(ProjeTuru).filter_by( id=tur_id, basvuru_aktif_mi=True, guncel_mi=True).one() except NoResultFound as exc: CustomErrorHandler.error_handler( hata="Güncel olmayan veya var olmayan bir proje türü ile proje " "basvurusu yapılmaya çalışıldı. Hata: {}, User id: {}, " "Proje turu id: {}".format(exc, user_id, tur_id)) return abort(404) proje_tur_dict = proje_turu_to_dict(p_tur) # basvuruyu yapan ogretim elamanininin id sini getirir ogretim_elemani = DB.session.query( OgretimElemani.id.label("ogretim_elemani_id")).join( Personel, OgretimElemani.personel_id == Personel.id).join( Person, Personel.person_id == Person.id).filter( Person.user_id == current_user.id).one() yurutucu_id = ogretim_elemani.ogretim_elemani_id yeni_basvuru_formu = basvuru_formu_restriction(proje_tur_dict) yeni_basvuru_formu.proje_personeli.yurutucu.yurutucu_id.data = yurutucu_id yeni_proje = Proje(proje_turu=p_tur.id, proje_turu_numarasi=p_tur.tur_kodu, yurutucu=yurutucu_id, user_id=user_id) DB.session.add(yeni_proje) DB.session.flush() proje_no = "{}{}".format(date.today().year, yeni_proje.id) yeni_proje.proje_no = proje_no # proje_basvuru_durumu=ProjeBasvuruDurumu.taslak DB.session.commit() signal_payload = { "message_type": USER_ACTIVITY_MESSAGES.get("bap").get( "proje_basvuru_basla").type_index, "nesne": 'Proje', "nesne_id": yeni_proje.id, "ekstra_mesaj": "{} adlı kullanıcı, {} kategorisine proje başvuru islemine " "basladi.".format(current_user.username, p_tur.kategori) } signal_sender(**signal_payload) # yeni_basvuru_formu.proje_id.data = yeni_proje.id return render_template( 'arastirma_projesi_basvuru/arastirma_proje_basvurusu.html', yeni_basvuru_formu=yeni_basvuru_formu, proje_tur_dict=proje_tur_dict, proje_id=yeni_proje.id, revizyon_bekleniyor_mu=False, uyari_mesajlari=proje_tur_dict.get("genel_uyari_mesajlari", None))
def get_proje_calisani(proje_id, calisan_id): """ Var olan bir çalışanı almak için kullanılır. """ try: try: calisan = DB.session.query(ProjeCalisanlari).options( lazyload(ProjeCalisanlari.ogrenci), lazyload(ProjeCalisanlari.personel), joinedload(ProjeCalisanlari.person).load_only( "ad", "soyad"), joinedload(ProjeCalisanlari.fakulte).load_only("ad"), joinedload(ProjeCalisanlari.bolum).load_only("ad"), joinedload(ProjeCalisanlari.hitap_unvan).load_only( "ad", "kod")).filter_by(id=calisan_id, proje_id=proje_id).one() except NoResultFound as exc: CustomErrorHandler.error_handler( hata="Var olmayan bir id ile proje çalışanı alınmaya " "çalışıldı. Proje id: {}, Hata: {}".format(proje_id, exc)) return abort(404) except SQLAlchemyError as exc: DB.session.rollback() CustomErrorHandler.error_handler( hata= "Proje çalışanı silinmeye çalışırken hata ile karşılaşıldı. " "Proje id: {}, Calisan id: {}, Hata: {}".format( proje_id, calisan_id, exc)) return abort(400) data = calisan.to_dict() data["projeye_katkisi"] = float( calisan.projeye_katkisi) if calisan.projeye_katkisi else float(0) data.update({ "ozgecmis_text": calisan.ozgecmis.tecrube, "ozgecmis_file_id": calisan.ozgecmis.file_id }) if calisan.person: hitap_unvan_ad = "" if calisan.hitap_unvan: hitap_unvan_ad = "{} {}".format( calisan.hitap_unvan.kod, calisan.hitap_unvan.ad if calisan.hitap_unvan else "") data.update({ "hitap_unvan_ad": hitap_unvan_ad, "fakulte_ad": calisan.fakulte.ad if calisan.fakulte else "", "bolum_ad": calisan.bolum.ad if calisan.bolum else "", "ad": calisan.person.ad, "soyad": calisan.person.soyad, }) return jsonify(status="success", calisan=data)
def render_gundem_sablonu(): """ İki farklı kullanımı mevcut Belirli bir gündemin gündem tipini degistirmeye calisildigi durumda Gündem id ve gündem tipi verisine(gundem verisinden ilgili projenin id si bulunur) gore ilgili sablonu render edip karar ve aciklama verisini döner. Belirli bir proje icin gundem olusturmaya calisirken proje id ve gundem tipi verisiyle kullanilabilir """ try: gundem_id = request.get_json().get("gundem_id", None) sablon_tipi = request.get_json().get("sablon_tipi", None) proje_id = request.get_json().get("proje_id", None) gundem_sablonu = DB.session.query( GundemSablon.id.label("sablon_id"), GundemSablon.karar.label("karar"), GundemSablon.aciklama.label("aciklama"), ).filter( GundemSablon.sablon_tipi == sablon_tipi ).order_by(desc(GundemSablon.updated_at)).first() if gundem_id: gundem = DB.session.query( BapGundem.aciklama.label("aciklama"), BapGundem.karar.label("karar"), BapGundem.proje_id.label("proje_id") ).options( lazyload("*") ).filter(BapGundem.id == gundem_id).first() proje_id = gundem.proje_id if not gundem_sablonu: return jsonify(status="error"), 500 gundem_proje_data_query = BapQueryHelpers.get_gundem_sablon_proje_data_query() proje_gundem_sablon_data = gundem_proje_data_query.filter( Proje.id == proje_id ).first() karar_text = render_template_string(gundem_sablonu.karar, proje=proje_gundem_sablon_data) aciklama_text = render_template_string(gundem_sablonu.aciklama, proje=proje_gundem_sablon_data) data = { "karar": karar_text, "aciklama": aciklama_text, "sablon_id": gundem_sablonu.sablon_id } return jsonify(status="success", data=data) except Exception as exc: CustomErrorHandler.error_handler( hata="Gündemi tipine göre şablon metni render " "edilirken bir hata meydana geldi. " "Hata: {}".format(exc)) return jsonify(status="error"), 500
def get_proje_taslak_with_id(proje_id): """Id'si verilen kaydedilmiş taslak projeyi getirir""" user_id = current_user.id try: proje = DB.session.query(Proje).filter_by( id=proje_id, proje_basvuru_durumu=ProjeBasvuruDurumu.taslak).one() except NoResultFound as exc: CustomErrorHandler.error_handler( hata= "Basvuru durumu taslak olmayan veya var olmayan bir proje ile " "proje basvurusu taslağına ulaşılmaya calışıldı. Hata: {}, " "User id: {}, Proje id: {}".format(exc, user_id, proje_id)) return abort(404) proje_turu = get_proje_turu_with_related_field(proje.proje_turu) if not proje_turu: # todo: current app logger customerror handlera cevrilecek CustomErrorHandler.error_handler( hata= "Güncel olmayan bir proje türünün kayıtlı taslagına ulaşılmaya" " çalışıldı. User id: {}, Proje id: {}".format( user_id, proje_id)) flash( "Taslak kaydı yaptığınız projenin başvuru koşulları BAP birimi tarafından " "güncellenmiştir. Lütfen güncel proje türü üzerinden tekrar başvurunuzu " "gerçekleştiriniz.") return redirect( url_for("proje.ProjeBasvuruView:basvuru_icin_proje_turu_sec")) proje_turu_dict = proje_turu_to_dict(proje_turu) yurutucu_calisan_id = None yurutucu_calisan = DB.session.query(ProjeCalisanlari).filter_by( proje_id=proje_id, personel_id=proje.yurutucu).first() if yurutucu_calisan: yurutucu_calisan_id = yurutucu_calisan.id form_data = get_proje_data(proje_turu_dict, proje) proje_formu = basvuru_formu_restriction( proje_turu_dict=proje_turu_dict, **form_data) return render_template( 'arastirma_projesi_basvuru/arastirma_proje_basvurusu.html', yeni_basvuru_formu=proje_formu, proje_tur_dict=proje_turu.to_dict(), proje_id=proje_id, proje_hakem_onerileri=proje.proje_hakem_onerileri, proje_calisanlari=[ calisan for calisan in proje.proje_calisanlari if not ( proje.yurutucu and proje.yurutucu == calisan.personel_id) ], yurutucu_calisan_id=yurutucu_calisan_id, taslak_mi=True, revizyon_bekleniyor_mu=False, uyari_mesajlari=proje_turu_dict.get("genel_uyari_mesajlari", None))
def satinalma_urunler_listele(self, satinalma_id): """ Satinalma ürünlerine ulasmak icin kullanilir :param satinalma_id: satinalma_id(int) :return: http response """ try: satinalma = get_satinalma_with_related_fields(satinalma_id=satinalma_id) states_info = get_satinalma_next_states_info(satinalma_id=satinalma_id) actions_info = get_satinalma_actions_info(satinalma_id=satinalma_id) proje = DB.session.query(Proje).filter(Proje.id == satinalma.proje_id).first() talep_kalemleri_with_siparis_info = [] for talep_kalemi in satinalma.talep_kalemleri: data = { "kalem_adi": talep_kalemi.proje_kalemi.ad, "kalem_gerekce": talep_kalemi.proje_kalemi.gerekce, "birim": talep_kalemi.proje_kalemi.birim.value, "miktar": talep_kalemi.talep_miktari, "tutar": talep_kalemi.proje_kalemi.toplam_butce / talep_kalemi.proje_kalemi.toplam_miktar * talep_kalemi.talep_miktari, "teknik_sartname_id": talep_kalemi.teknik_sartname_file_id, "firma_adi": "-", "teslimat_suresi": "-", "kdv_dahil_teklif": 0, "siparis_takip_no": "-", "siparis_durumu": "-" } if talep_kalemi.siparis_takip: kdv_dahil_teklif = kdv_dahil_fiyat_hesabi(talep_kalemi.siparis_takip.kazanan_firma_teklif.teklif, talep_kalemi.siparis_takip.kazanan_firma_teklif.kdv_orani) data.update({ "firma_adi": talep_kalemi.siparis_takip.kazanan_firma_teklif.satinalma_teklif.firma.adi, "teslimat_suresi": talep_kalemi.siparis_takip.kazanan_firma_teklif.teslimat_suresi, "kdv_dahil_teklif": kdv_dahil_teklif, "siparis_takip_no": talep_kalemi.siparis_takip.siparis_numarasi, "siparis_durumu": talep_kalemi.siparis_takip.siparis_durumu.value if talep_kalemi.siparis_takip.siparis_durumu else "-" }) talep_kalemleri_with_siparis_info.append(data) except Exception as exc: CustomErrorHandler.error_handler(hata="Satinalma ürün listesi görüntülenirken hata oluştu." "Hata: {}, Satinalma id: {}".format(satinalma_id, exc) ) return abort(500) return render_template("satinalma_dashboard/satinalma_urunler.html", talep_kalemleri_with_siparis_info=talep_kalemleri_with_siparis_info, satinalma=satinalma, satinalma_id=satinalma_id, proje=proje, actions_info=actions_info, states_info=states_info)
def confirm_token(token, expiration=7200): serializer = URLSafeTimedSerializer(current_app.config['SECRET_KEY']) try: email = serializer.loads(token, salt=current_app.config['SECRET_SALT_KEY'], max_age=expiration) except BadSignature as exc: CustomErrorHandler.error_handler( hata="Bir hata meydana geldi. Hata: {}".format(str(exc))) return False return email
def formlar_ve_belgeler_ayarlar_kaydet(): form = AnaSayfaDosyaAyarlari(request.form) ana_sayfa_dosya = request.files.get(form.file_id.name, None) dosya_id = None if not form.validate(): flash("Lütfen uygun dosya uzantısı olan bir dosya yükleyiniz.") return redirect( url_for( 'ana_sayfa_yonetimi.FormlarVeBelgelerAyarlarView:formlar_ve_belgeler_ayarlar' )) if ana_sayfa_dosya: bap_belge = BAPBelge() _ana_sayfa_dosya = File(content=ana_sayfa_dosya) try: DB.session.add(_ana_sayfa_dosya) DB.session.flush() bap_belge.file_id = _ana_sayfa_dosya.id dosya_id = _ana_sayfa_dosya.id bap_belge.adi = ana_sayfa_dosya.filename bap_belge.tur = BAPBelgeTipi.formlar_ve_belgeler DB.session.add(bap_belge) DB.session.commit() except Exception as exc: DB.session.rollback() CustomErrorHandler.error_handler( hata="Formlar ve Belgeler oluşturulurken hata" "oluştu.Hata: {}".format(exc)) flash("Lütfen uygun dosya uzantısı olan bir dosya yükleyiniz.") return redirect( url_for( 'ana_sayfa_yonetimi.FormlarVeBelgelerAyarlarView:formlar_ve_belgeler_ayarlar' )) signal_payload = { "message_type": USER_ACTIVITY_MESSAGES.get("yonetim").get( "formlar_ve_belgeler_eklendi").type_index, "nesne": 'Formlar ve Belgeler Ayarları', "nesne_id": dosya_id, "ekstra_mesaj": "Formlar ve Belgeler eklendi: {}".format(dosya_id), } signal_sender(**signal_payload) flash("Formlar ve Belgeler başarılı bir şekilde kaydedilmiştir.") return redirect( url_for( 'ana_sayfa_yonetimi.FormlarVeBelgelerAyarlarView:formlar_ve_belgeler_ayarlar' ))
def islem_gecmisi(self, proje_id): """ Projenin islem gecmisine ulasmak icin kullanilir :param proje_id: proje_id(int) :return: http response """ proje_yurutucusu_mu = ProjeYurutucusu().fulfill(user=current_user) params = {"proje_id": proje_id} try: proje = DB.session.query(Proje).options( joinedload(Proje.proje_yurutucu).load_only("id").joinedload( OgretimElemani.personel).load_only("id").joinedload( Personel.person).load_only("ad", "soyad"), lazyload(Proje.proje_detayi), lazyload(Proje.kabul_edilen_proje_hakemleri), lazyload(Proje.proje_hakem_onerileri), lazyload(Proje.proje_destekleyen_kurulus), lazyload(Proje.proje_kalemleri), ).filter( Proje.id == proje_id, or_( Proje.proje_basvuru_durumu == ProjeBasvuruDurumu.tamamlandi, Proje.proje_basvuru_durumu == ProjeBasvuruDurumu.revizyon_bekleniyor)).first() next_states_info = get_next_states_info(proje_id=proje_id) actions_info = get_actions_info(proje_id=proje_id) islem_listesi = DB.session.query(AppStateTracker). \ filter(AppStateTracker.params.contains(params), or_(AppStateTracker.job_type == JobTypes.project_state_change, AppStateTracker.job_type == JobTypes.project_action)). \ join(Person, Person.user_id == AppStateTracker.triggered_by). \ join(AppState, AppStateTracker.state_id == AppState.id). \ add_columns( AppState.state_code, Person.ad, Person.soyad, ).all() except Exception as exc: CustomErrorHandler.error_handler( hata="Proje işlem geçmişi görüntülenirken hata oluştu." "Hata: {}, Proje id: {}".format(proje_id, exc)) return abort(500) return render_template("dashboard/proje_islem_gecmisi.html", islem_listesi=islem_listesi, proje_id=proje_id, proje=proje, next_states_info=next_states_info, actions_info=actions_info, proje_yurutucusu_mu=proje_yurutucusu_mu)
def firma_faaliyet_belgesi_indir(firma_id): """Firma Listesi Ekrani""" firma = DB.session.query(BapFirma).get(firma_id) try: belge = DB.session.query(File).filter( File.id == firma.firma_faaliyet_belgesi_id).one() return send_file(belge.file_object, attachment_filename=belge.content.file.filename, as_attachment=True, mimetype=belge.content.file.content_type) except Exception as exc: CustomErrorHandler.error_handler() return abort(400)
def toplanti_kaydet(): """ Formda kaydedilen gundemler ve tarih/saat ile yeni bir toplantı olusturur. Returns: """ form_nesne = ToplantiOlusturForm(request.form) toplantiya_alinanlar = list( filter(lambda x: x['toplantiya_alinsin'], form_nesne.data['gundem_listesi'])) if form_nesne.validate() and toplantiya_alinanlar: try: toplanti = BapToplanti(toplanti_durumu=ToplantiDurumu.gerceklestirilmedi, ekleyen_id=current_user.id) DB.session.add(toplanti) DB.session.flush() for ind, top_al in enumerate(toplantiya_alinanlar): gundem_id = top_al['id'] gundem = BapGundem.query.get(gundem_id) gundem.toplanti_id = toplanti.id toplanti.toplanti_tarihi = form_nesne.data['toplanti_tarih_saat'] DB.session.commit() signal_payload = { "message_type": USER_ACTIVITY_MESSAGES.get("toplanti").get( "toplanti_olustur").type_index, "nesne": 'BapToplanti', "nesne_id": toplanti.id, "ekstra_mesaj": "{user} kullanıcısı, {gundemler} idli gündemlerle, {toplanti} " "idli yeni toplantı " "oluşturdu.".format( user=current_user.username, gundemler=list(map(lambda x: x['id'], toplantiya_alinanlar)), toplanti=toplanti.id ) } signal_sender(**signal_payload) return redirect(url_for('index')) except SQLAlchemyError as e: DB.session.rollback() CustomErrorHandler.error_handler( hata="{} kullanıcısı bir toplantı oluşturmaya çalışırken hata " "meydana geldi. hata: {}".format(current_user.username, e)) flash(_("Bir hata meydana geldi. İşleminiz kaydedilemedi.")) return redirect(url_for('.ToplantiOlusturView:toplanti_maddeleri_listele')) else: flash('Formu doğru doldurduğunuzdan emin olunuz.') return redirect(url_for('.ToplantiOlusturView:toplanti_maddeleri_listele'))
def onay(token): email = None try: email = confirm_token(token) except Exception as exc: CustomErrorHandler.error_handler() person = DB.session.query(Person).filter( or_(Person.birincil_eposta == email, Person.ikincil_eposta == email)).first() firma = DB.session.query(BapFirma).filter( BapFirma.yetkili_email == email).first() if (person and person.personel ) or not firma: # personelse onaylama islemi yapilmaz return redirect(url_for('auth.login')) pw = random_pw() username = email password = sha512(pw.encode()).hexdigest() kullanici = User(username=username, password=password, email=email) DB.session.add(kullanici) if firma: kisi = Person(ad=firma.yetkili_adi, soyad=firma.yetkili_soyadi, birincil_eposta=firma.yetkili_email) DB.session.add(kisi) kullanici.person = kisi bap_firma = DB.session.query(Role).filter( Role.name == "BAP Firma").first() firma_role = UserRole( user_id=kullanici.id, role_id=bap_firma.id, rol_tipi=RolTipleri.firma, ) DB.session.add(firma_role) DB.session.commit() flash( "Eposta başarıyla onaylandı. Giriş bilgileriniz eposta adresinize yollanmıştır." ) send_mail_with_template( recipients=[username], subject="Zopsedu Sisteme Giriş Bilgileri", content_text=f"Kullanıcı Adı: {username} Şifre {pw}") return redirect(url_for('auth.login'))
def toplanti_sonuclandir(toplanti_id): """YK toplantisini sonuclandir""" toplanti_katilimci_kayit = DB.session.query(ToplantiKatilimci).filter( ToplantiKatilimci.toplanti_id == toplanti_id).first() if not toplanti_katilimci_kayit: flash("Lütfen sonuçlandırmadan önce toplantıya katılımcı ekleyiniz") return redirect(url_for("toplanti.toplanti_gundem_listele", toplanti_id=toplanti_id)) try: degerlendirmemis_gundem_sayisi = DB.session.query( BapGundem ).filter( BapGundem.toplanti_id == toplanti_id, BapGundem.karar_durum == KararDurumu.degerlendirilmedi ).count() if degerlendirmemis_gundem_sayisi: flash("Toplantıda değerlendirilmemiş gündemler mevcut. " "Lütfen gündemleri değerlendirin veya toplantıdan çıkarınız.") return redirect(url_for("toplanti.toplanti_gundem_listele", toplanti_id=toplanti_id)) toplanti = DB.session.query(BapToplanti).options(lazyload("*")).filter_by( id=toplanti_id).one() toplanti.sonuclandi_mi = True toplanti.toplanti_durumu = ToplantiDurumu.gerceklestirildi flash("Toplantı başarılı bir şekilde sonuçlandırıldı.") DB.session.commit() signal_payload = { "message_type": USER_ACTIVITY_MESSAGES.get("toplanti").get( "toplanti_sonuclandirildi").type_index, "nesne": 'BAP Toplanti', "nesne_id": toplanti.id, "ekstra_mesaj": "{} adlı kullanıcı bap toplantisini sonuçlandırdı.".format( current_user.username), } signal_sender(**signal_payload) except Exception as exc: DB.session.rollback() CustomErrorHandler.error_handler( hata="Var olmayan bir toplanti id ile istek gönderildi.User id: {}," " Hata: {}".format(current_user.id, exc)) return abort(404) return redirect(url_for("toplanti.toplanti_gundem_listele", toplanti_id=toplanti_id))
def fulfill(self, user, request=None): proje_id = req.view_args['proje_id'] try: proje = DB.session.query( Proje.id, Proje.proje_basvuru_durumu, Proje.user_id).filter_by(id=proje_id).one() if proje.proje_basvuru_durumu == ProjeBasvuruDurumu.tamamlandi: return False except SQLAlchemyError as exc: CustomErrorHandler.error_handler( hata= "Proje id ve user id ile projeyi get yaparken bir hata oluştur" ". Hata: {}, Proje Id: {}, User Id: {}".format( exc, proje_id, user.id)) return False return True