def post_rol_degistir(self): """Rol degistirme ekrani kayit""" cache = current_app.extensions['redis'] rol_form = RolForm(request.form) role_id = int(rol_form.roles.data) user_role = UserRole.query.filter_by(user_id=self.user_id, role_id=role_id).first() session['current_user_role'] = user_role.id session['current_role'] = role_id cache.set( current_app.config['USER_LAST_LOGIN_ROLE_ID_CACHE_KEY'].format( user_id=self.user_id), session['current_role']) role = user_role.role session['current_role_name'] = role.name signal_payload = { "message_type": USER_ACTIVITY_MESSAGES.get("common").get( "gecerli_rol_degistir").type_index, "ekstra_mesaj": "{} adlı kullanıcı gecerli rolunu {} olarak degistirdi.".format( current_user.username, role.name) } signal_sender(**signal_payload) return redirect(url_for('kullanici_profil.rol_degistir'))
def bap_duyuru_sil(duyuru_id): """Belirli bir bap duyurusunu getirir""" # tipi duyuru, birim tipi bap, id si 'duyuru_id' olan icerigi getirir silinecek_duyuru = DB.session.query(Icerik).filter( Icerik.tipi == IcerikTipi.duyuru, Icerik.birim_tipi == IcerikBirimTipi.bap, Icerik.id == duyuru_id).one() DB.session.delete(silinecek_duyuru) DB.session.commit() signal_payload = { "message_type": USER_ACTIVITY_MESSAGES.get("icerik").get( "bap_duyuru_sil").type_index, "nesne": 'Icerik', "nesne_id": duyuru_id, "ekstra_mesaj": "{} adli user, {} id'li icerik(bap duyuru) sildi.".format( current_user.username, duyuru_id) } signal_sender(**signal_payload) return jsonify(status="success")
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 post_avatar_guncelle(self): """Avatar guncelle post""" user = self.qry.one() avatar = request.files.get('avatar', None) try: if avatar: user.avatar = avatar DB.session.commit() signal_payload = { "message_type": USER_ACTIVITY_MESSAGES.get("common").get( "profil_fotograf_guncelle").type_index, "nesne": 'User', "nesne_id": user.id, "ekstra_mesaj": "{} adlı kullanıcı profil fotoğrafını güncelledi.".format( user.username) } signal_sender(**signal_payload) flash(_("Avatariniz guncellendi.")) else: flash( _("Avatarınızı güncellemek için bir resim seçmelisiniz.")) except ValueError as vexc: flash(str(vexc)) return redirect(url_for('kullanici_profil.avatar'))
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 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 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 bap_duyuru_guncelle(duyuru_id): """Belirli bir bap duyurusunu getirir""" bap_duyuru = request.get_json() duyuru_formu = BapDuyuruForm(**bap_duyuru) # tipi duyuru, birim tipi bap olan duyuruyu getirir guncellenecek_duyuru = DB.session.query(Icerik).filter( Icerik.tipi == IcerikTipi.duyuru, Icerik.birim_tipi == IcerikBirimTipi.bap, Icerik.id == duyuru_id).one() guncellenecek_duyuru.update_obj_data(duyuru_formu.data) DB.session.commit() signal_payload = { "message_type": USER_ACTIVITY_MESSAGES.get("icerik").get( "bap_duyuru_guncelle").type_index, "nesne": 'Icerik', "nesne_id": guncellenecek_duyuru.id, "ekstra_mesaj": "{} adli user, {} id'li icerik(bap duyuru) guncelledi.".format( current_user.username, guncellenecek_duyuru.id) } signal_sender(**signal_payload) return jsonify(status="success")
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 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 gundem_sablon_duzenle_post(): """Gundem Sablonu Duzenleme Kayit""" sablon_id = request.args['sablon_id'] sablon = DB.session.query( GundemSablon ).filter( GundemSablon.id == sablon_id ).one_or_none() gundem_sablon_duzenle_form = GundemSablonDuzenleForm(request.form) sablon.sablon_tipi = gundem_sablon_duzenle_form.duzenle.sablon_tipi.data sablon.kategori = gundem_sablon_duzenle_form.duzenle.kategori.data sablon.aciklama = gundem_sablon_duzenle_form.duzenle.aciklama.data sablon.karar = gundem_sablon_duzenle_form.duzenle.karar.data DB.session.commit() signal_payload = { "message_type": USER_ACTIVITY_MESSAGES.get("bap").get("gundem_sablon_guncelle").type_index, "nesne": 'Gundem Sablon', "nesne_id": sablon.id, "ekstra_mesaj": "{} adlı kullanıcı {} id'li gundem sablonu guncelledi.".format( current_user.username, sablon.id ) } signal_sender(**signal_payload) return redirect(url_for('bap_yonetimi.GundemSablonlariView:liste'))
def bap_sablon_guncelle(sablon_id): """Belirli bir bap sablonu gunceller""" sablon_data = request.get_json() sablon_formu = VarsayilanSablonYuklemeForm(**sablon_data) sablon = DB.session.query(Sablon).filter(Sablon.id == sablon_id).one() sablon.adi = sablon_formu.sablon_adi.data sablon.query_id = sablon_formu.query_helper_id.data sablon.kullanilabilir_mi = sablon_formu.sablon_kullanilabilir_mi.data if not sablon.file and sablon_formu.sablon_text.data: sablon.sablon_text = sablon_formu.sablon_text.data DB.session.commit() signal_payload = { "message_type": USER_ACTIVITY_MESSAGES.get("ayarlar").get( "bap_sablon_guncelle").type_index, "nesne": 'Sablon', "nesne_id": sablon.id, "ekstra_mesaj": "{} adli user, {} id'li bap sablon guncelledi.".format( current_user.username, sablon.id) } signal_sender(**signal_payload) return jsonify(status="success")
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 logout(): """ Kullanıcı oturumunu kapatır. """ signal_payload = { "message_type": USER_ACTIVITY_MESSAGES.get("auth").get("logout").type_index, "nesne": 'User', "nesne_id": current_user.id, "ekstra_mesaj": "{} adlı kullanıcı çıkış yaptı.".format(current_user.username), } signal_sender(**signal_payload) last_login_role = { current_app.config['USER_LAST_LOGIN_ROLE_ID_CACHE_KEY'].format(user_id=current_user.id): session.get('current_role'), current_app.config['USER_LAST_LOGIN_ROLE_NAME_CACHE_KEY'].format(user_id=current_user.id): session.get('current_role_name') } SessionHandler.session_logout_flush(is_authenticated=False, last_role=last_login_role) logout_user() return redirect(url_for('anasayfa.BapAnasayfaView:bap_anasayfa'))
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 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 duzenlenebilir_mi(self, proje_id, rapor_id): # pylint: disable=R0201 """ Proje raporunun duzenlenebilirligini degistirmek icin kullanilir """ rapor = DB.session.query(ProjeRapor).filter( ProjeRapor.proje_id == proje_id, ProjeRapor.id == rapor_id).one() rapor.duzenlenebilir_mi = not rapor.duzenlenebilir_mi DB.session.commit() signal_payload = { "message_type": USER_ACTIVITY_MESSAGES.get("bap").get( "proje_raporu_duzenlenebilir").type_index, "nesne": 'Proje Rapor', "nesne_id": rapor.id, "ekstra_mesaj": "{} adlı kullanıcı, {} id'li proje raporunu düzenlenebilir " "yaptı.".format(current_user.username, rapor.id) } signal_sender(**signal_payload) if rapor.duzenlenebilir_mi: flash(_("Seçtiğiniz rapor artık düzenlenebilir.")) else: flash(_("Seçtiğiniz raporun düzenlenebilirliğini kaldırdınız.")) return redirect( url_for('proje.proje_rapor_index_get', proje_id=proje_id))
def rapor_dosyasi_sil(self, proje_id, rapor_id): # pylint: disable=R0201 """ Proje raporunu silmek icin kullanilir """ rapor = DB.session.query(ProjeRapor).filter( ProjeRapor.proje_id == proje_id, ProjeRapor.id == rapor_id).one() rapor.file_id = None DB.session.commit() signal_payload = { "message_type": USER_ACTIVITY_MESSAGES.get("bap").get( "proje_rapor_dosyasi_sil").type_index, "nesne": 'Proje Rapor', "nesne_id": rapor.id, "etkilenen_nesne": "Proje", "etkilenen_nesne_id": proje_id, "ekstra_mesaj": "{} adlı kullanıcı, {} id'li proje raporunun dosyasini kaldırdı.". format(current_user.username, rapor_id) } signal_sender(**signal_payload) flash(_("Rapor dosyası başarıyla kaldırıldı.")) return redirect( url_for('proje.proje_rapor_index_get', proje_id=proje_id))
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 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 post_hakem_proje_degerlendirme_istekleri(self, proje_hakem_id, proje_id): # pylint: disable=R0201 """ Hakem degerlendirmesi kabul veya reddi icin kullanilir. """ proje_hakemi = DB.session.query(ProjeHakemleri).options( joinedload(ProjeHakemleri.proje).load_only(Proje.proje_no)).filter( ProjeHakemleri.id == proje_hakem_id, ProjeHakemleri.davet_durumu == ProjeHakemDavetDurumlari.gonderildi).one() hakem = DB.session.query(Hakem.id.label("hakem_id")).options( lazyload('*')).filter( Hakem.person_id == current_user.person.id).one() if proje_hakemi: if proje_hakemi.hakem_id != hakem.hakem_id: return jsonify(status="error"), 500 davet_durumu = request.get_json().get('davet_durumu') proje_hakemi.davet_durumu = davet_durumu DB.session.commit() if proje_hakemi.davet_durumu == ProjeHakemDavetDurumlari.kabul_edildi: message = "hakemlik davetini kabul etti" else: message = "hakemlik davetini reddetti" extra_message = """{} adlı kullanıcı({} id'li hakem),{} numaralı projenin {}""".format( current_user.username, hakem.hakem_id, proje_hakemi.proje.proje_no, message) signal_payload = { "message_type": USER_ACTIVITY_MESSAGES.get("bap").get( "degerlendirme_teklifi_cevaplandi").type_index, "nesne": 'Proje Hakemleri', "nesne_id": proje_hakemi.id, "ekstra_mesaj": extra_message } signal_sender(**signal_payload) for bap_admin in bap_yetkili_and_admin_ids(): payload = { "notification_receiver": bap_admin.person_id, "notification_title": proje_hakemi.davet_durumu.value, "notification_message": "{} adlı kullanıcı {} numaralı projenin {}".format( current_user.username, proje_hakemi.proje.proje_no, message), } signal_sender(log=False, notification=True, **payload) return jsonify(status="success") return abort(400)
def post_belge_sablonlari(self): """ Varsayilan belge sablonlari yukleme ekrani """ form = self.form() sablon_dosya = request.files.get(form.sablon_dosya.name, None) sablon_text = form.sablon_text.data if not sablon_text and not sablon_dosya: flash(_("Dosya yüklemelisiniz veya şablon metni girmelisiniz")) elif sablon_text and sablon_dosya: flash(_("Aynı anda dosya yükleyip şablon metni giremezsiniz.")) else: if form.validate(): sablon_tipi_id = form.sablon_tipi_id.data sablon_adi = form.sablon_adi.data kullanilabilir_mi = form.sablon_kullanilabilir_mi.data query_helper_id = form.query_helper_id.data sablon_dosya_id = None if sablon_dosya: _sablon = File(content=sablon_dosya) DB.session.add(_sablon) DB.session.flush() sablon_dosya_id = _sablon.id sablon = Sablon(file=sablon_dosya_id, sablon_tipi_id=sablon_tipi_id, sablon_text=sablon_text or "", module_name="BAP", adi=sablon_adi, kullanilabilir_mi=kullanilabilir_mi, query_id=query_helper_id) DB.session.add(sablon) DB.session.commit() flash("Belge Şablonu başarıyla yüklenmiştir.") form = self.form() signal_payload = { "message_type": USER_ACTIVITY_MESSAGES.get("ayarlar").get( "bap_sablon_kaydet").type_index, "nesne": 'Sablon', "nesne_id": sablon.id, "ekstra_mesaj": "{} adli user, {} id'li bap sablonu kaydetti.".format( current_user.username, sablon.id) } signal_sender(**signal_payload) sablonlar = DB.session.query(Sablon).order_by(Sablon.updated_at).all() return render_template("varsayilan_sablonlar.html", sablon_form=form, sablonlar=sablonlar)
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 kurum_kodlari_kaydet(): """ Butce kodlarinin kaydedildigi view """ butce_kodlari_form = ButceKodlari(request.form) universite_id = SessionHandler.universite_id() if not butce_kodlari_form.validate(): flash(_("Lütfen hatalı yerleri düzeltip tekrar deneyin.")) fonksiyonel_kodlar_form = FonksiyonelKodlar() hesap_kodu_search_form = HesapKodlariSearch() return render_template( 'butce_kodlari_listeleme.html', fonksiyonel_kodlar=fonksiyonel_kodlar_form, hesap_kodu_search_form=hesap_kodu_search_form, butce_kodlari_formu=butce_kodlari_form) butce_kodlari_form_data = dict(butce_kodlari_form.data) butce_kodlari_form_data.pop('csrf_token') eski_genel_ayarlar = DB.session.query(GenelAyarlar).filter_by( universite_id=universite_id, aktif_mi=True).first() if eski_genel_ayarlar: yeni_data = eski_genel_ayarlar.to_dict()["bap_butce"] yeni_data.update(butce_kodlari_form_data) yeni_ayarlar = genel_ayarlar_guncelle( eski_genel_ayarlar, guncellenecek_field="bap_butce", yeni_data=yeni_data) else: yeni_ayarlar = GenelAyarlar(universite_id=universite_id, bap_butce=butce_kodlari_form_data) DB.session.add(yeni_ayarlar) DB.session.commit() flash(_("İşlem başarıyla gerçekleşti.")) signal_payload = { "message_type": USER_ACTIVITY_MESSAGES.get("bap").get( "butce_kodlari_kaydet").type_index, "nesne": 'GenelAyarlar', "nesne_id": yeni_ayarlar.id, "ekstra_mesaj": "{} adlı kullanıcı, bap bütçe kurum kodları ayarlarını güncelledi." .format(current_user.username) } signal_sender(**signal_payload) return redirect( url_for("butce.ButceKodlariView:butce_kodlari_goruntuleme"))
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 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 degerlendirme_kaydet(degerlendirme_id): degerlendirme_formu = ProjeDegerlendirmeFormu(request.form) degerlendirme = DB.session.query(ProjeDegerlendirmeleri).options( joinedload(ProjeDegerlendirmeleri.rapor).joinedload( ProjeRapor.proje).load_only("proje_no")).filter( ProjeDegerlendirmeleri.id == degerlendirme_id).one() degerlendirme.degerlendirme = degerlendirme_formu.degerlendirme_metni.data degerlendirme.degerlendirme_sonuclandi_mi = degerlendirme_formu.degerlendirme_tamamlandi_mi.data degerlendirme.degerlendirme_gonderim_tarihi = datetime.now() degerlendirme.sonuc = degerlendirme_formu.degerlendirme_sonucu.data DB.session.commit() if degerlendirme.degerlendirme_sonuclandi_mi: for bap_admin in bap_yetkili_and_admin_ids(): payload = { "notification_receiver": bap_admin.person_id, "notification_title": "{} Değerlendirmesi Tamamlandı".format( degerlendirme.rapor.rapor_tipi.value), "notification_message": "{} adlı kullanıcı {} numaralı projenin {} değerlendirmesini tamamladı. Değerlendirme sonucu {}" .format(current_user.username, degerlendirme.rapor.proje.proje_no, degerlendirme.rapor.rapor_tipi.value, degerlendirme.sonuc.value), } signal_sender(log=False, notification=True, **payload) signal_payload = { "message_type": USER_ACTIVITY_MESSAGES.get("bap").get( "proje_degerlendirdi").type_index, "nesne": 'ProjeDegerlendirmeleri', "nesne_id": degerlendirme.id, "ekstra_mesaj": "{} adlı kullanıcı {} numaralı projenin {} değerlendirmesini tamamladı. Değerlendirme sonucu {}" .format(current_user.username, degerlendirme.rapor.proje.proje_no, degerlendirme.rapor.rapor_tipi.value, degerlendirme.sonuc.value) } signal_sender(**signal_payload) return redirect( url_for('hakem_dashboard.HakemDashboard:proje_listesi'))
def proje_calisani_sil(proje_id, calisan_id): """ Daha önce projeye kaydedilmiş çalışanı siler. """ try: try: silinecek_calisan = DB.session.query( ProjeCalisanlari).filter_by(id=calisan_id, proje_id=proje_id).one() except NoResultFound as exc: DB.session.rollback() CustomErrorHandler.error_handler( hata="Var olmayan bir id ile proje çalışanı silinmeye " "çalışıldı. Proje id: {}, Hata: {}".format(proje_id, exc)) return jsonify(status="error"), 400 DB.session.delete(silinecek_calisan) if silinecek_calisan.person: DB.session.delete(silinecek_calisan.person) DB.session.commit() signal_payload = { "message_type": USER_ACTIVITY_MESSAGES.get("bap").get( "proje_calisani_sil").type_index, "nesne": 'Proje Calisanlari', "nesne_id": calisan_id, "etkilenen_nesne": "Proje", "etkilenen_nesne_id": proje_id, "ekstra_mesaj": "{} adlı kullanıcı, proje çalışanını projeden sildi.".format( current_user.username) } signal_sender(**signal_payload) return jsonify(status="success") 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 jsonify(status="error"), 400