def qry(self): """ProjeMesaj BaseQuery""" system_user = SessionHandler.system_user() sp_id = system_user['person_id'] return DB.session.query(ProjeMesaj).join( Proje, ProjeMesaj.proje_id == Proje.id).join( Mesaj, Mesaj.id == ProjeMesaj.mesaj_id).join( Person, Mesaj.gonderen == Person.id).add_columns( Proje.proje_basligi, Proje.id.label("proje_id"), Proje.proje_no, Mesaj.okundu, Mesaj.gonderim_zamani, Mesaj.baslik, Person.ad.label("gonderen_ad"), Person.soyad.label("gonderen_soyad")).filter( Mesaj.gonderen == sp_id)
def signal_sender(log=True, notification=False, sms=False, email=False, database=False, notification_sender=None, notification_receiver=None, notification_message=None, notification_title=None, proje_id=None, **payload): """ User aktivitelerinden olusan eventlerin track edilmesini ve gerekli ise yeni actionlar alinmasini saglayan metot. Examples: For only log purposes: log_message = "Message to log" signal_sender(payload={"log_message": log_message}) For sending notification: payload = { "nesne": "Rol", "nesne_id": 5, "ekstra_mesaj": "5 idli Rol update edildi.", "notification_receiver": 27, "notification_title": "Rol Update Başarılı", } ntf_message = "Message to send as a notification" signal_sender(notification=True, notification_message=ntf_message, **payload) // sender göndermediğimiz için sender current_user oldu. Args: log (bool): Log kaydi olsun/olmasin notification (bool): System notificationi gonderilsin/gonderilmesin sms (bool): Sms gonderilsin/gonderilmesin email (bool): Email gonderilsin/gonderilmesin database (bool): notification_sender (str): notification_message (str): **payload (dict): Gelen parametrelerin tetikleyecegi actiona gore gerekecek datayi iceren dictionary * nesne (str): adi, * nesne_id (int): id, * etkilenen_nesne (str): adi, * etkilenen_nesne (int): id, * ekstra_mesaj (str): , Returns: """ payload.update({ "zaman": datetime.now(), "session": session.get("_id"), "context": session.get("activity_context"), "user_id": current_user.id, "username": current_user.username, "user_role_id": session.get('current_user_role'), "role_id": session.get('current_role'), "role_name": session.get('current_role_name'), "remote_ip": request.remote_addr, "tarayici_bilgisi": request.headers.get('User-Agent'), "host": request.headers.get('Host'), "origin": request.headers.get('Origin'), "referer": request.headers.get('Referer'), "cookie": request.headers.get('Cookie'), "endpoint_url": request.base_url, "method": request.method, }) sender = current_app._get_current_object() # pylint: disable=protected-access if log: activity_log_signal.send(sender, **payload) if notification: if not notification_sender: system_user = SessionHandler.system_user() notification_sender = system_user['person_id'] if not notification_message: notification_message = payload['ekstra_mesaj'] payload['notification_message'] = notification_message payload['notification_sender'] = notification_sender payload['notification_receiver'] = notification_receiver payload['notification_title'] = notification_title payload['proje_id'] = proje_id notification_signal.send(sender, **payload) if sms: sms_signal.send(sender, **payload) if email: system_user = SessionHandler.system_user() payload['email_system_person_id'] = system_user['person_id'] email_signal.send(sender, **payload) if database: # todo: database pass
def mail_gonder(recipients: list, subject, content_text, sender, proje_id=None, **mail_params): """ Recipients = [ { "email": "*****@*****.**" "person_id": 1 }, { "email": "*****@*****.**" "person_id": 2 }, ] :param recipients: list of dict :param sender: mesaji gonderen kisinin person id si. Genel olarak system userdir. :param subject: mesaj konusu :param content_text: mesaj içerigi :param proje_id: eger gonderilecek mail proje ile alakali ise proje mesajlarina eklenmesi icin bu parametre gereklidir :param mail_params: send_mail_with_template icin gerekli parametreleri icerir :return: """ with app.app_context(): if not sender: system_user = SessionHandler.system_user() sender = system_user["user_id"] email_list = [] person_ids = [] for recipient in recipients: email_list.append(recipient["email"]) person_ids.append(recipient["person_id"]) send_mail_with_template(recipients=email_list, sender=None, subject=subject, content_text=content_text, **mail_params) for person_id in person_ids: try: mesaj = Mesaj(gonderen=sender, alici=person_id, baslik=subject, metin=content_text, gonderim_zamani=datetime.now(), mesaj_tipi=MesajTipleri.eposta) DB.session.add(mesaj) DB.session.flush() if proje_id: proje_mesaj = ProjeMesaj(mesaj_id=mesaj.id, proje_id=proje_id) DB.session.add(proje_mesaj) DB.session.commit() except Exception as exc: DB.session.rollback() current_app.logger.error( "Mail gönderilmeye calisilirken bir hata ile " "karsilasildi. Hata: {}".format(exc))