def _wizcb_submit_hdl(wiz, em, step, act, val, req): xcls = cls if isinstance(xcls, str): xcls = _name_to_class(xcls) sess = DBSession() fieldIDs = json.loads(val['field_id']) templateName = val['template'] templId = val['templ_id'] for fid in fieldIDs: resvalue = { 'templ_id': templId, 'field_id': fid, 'template': templateName, 'field': sess.query(PDNSFieldType).filter( PDNSFieldType.id == fid).first() } em = ExtModel(xcls) obj = xcls() em.set_values(obj, resvalue, req, True) sess.add(obj) sess.flush() print("TROLOLO") return {'do': 'close', 'reload': True}
def _wizcb_submit_hdl(wiz, em, step, act, val, req): xcls = cls if isinstance(xcls, str): xcls = _name_to_class(xcls) sess = DBSession() cfg = get_current_registry().settings fieldIDs = json.loads(val['field_id']) fieldlist = val['field'] templateName = val['template'] templId = val['templ_id'] for fid in fieldIDs: resvalue = {'templ_id' : templId, 'field_id' : fid, 'template' : templateName, 'field' : sess.query(PDNSFieldType).filter(PDNSFieldType.id==fid).first() } em = ExtModel(xcls) obj = xcls() em.set_values(obj, resvalue, req, True) sess.add(obj) sess.flush() print("TROLOLO") return { 'do' : 'close', 'reload' : True }
def dyn_ticket_uwiz_update(params, request): tid = int(params['ticketid']) del params['ticketid'] sess = DBSession() model = ExtModel(Ticket) ticket = sess.query(Ticket).get(tid) if ticket is None: raise KeyError('Invalid ticket ID') for param in ('tstid', 'toid', 'name', 'descr'): if param in params: del params[param] # TODO: ENTITIES_LIST if not request.has_permission('TICKETS_CHANGE_STATE'): if 'ttrid' in params: del params['ttrid'] if not request.has_permission('TICKETS_CHANGE_FLAGS'): if 'flags' in params: del params['flags'] # TODO: USERS_LIST # TODO: GROUPS_LIST sess.execute(SetVariable('ticketid', ticket.id)) if 'ttrid' in params: ttr_id = params['ttrid'] if ttr_id: ttr_id = int(ttr_id) trans = sess.query(TicketStateTransition).get(ttr_id) if trans: sess.execute(SetVariable('ttrid', trans.id)) trans.apply(ticket) del params['ttrid'] if 'show_client' in params: show_cl = params['show_client'].lower() if show_cl in {'true', '1', 'on'}: show_cl = True else: show_cl = False del params['show_client'] else: show_cl = False sess.execute(SetVariable('show_client', npbool(show_cl))) if ('comments' in params) and request.has_permission('TICKETS_COMMENT', request.context, request): sess.execute(SetVariable('comments', params['comments'])) del params['comments'] else: sess.execute(SetVariable('comments', None)) model.set_values(ticket, params, request) sess.flush() sess.execute(SetVariable('tcid', None)) return { 'success' : True, 'action' : { 'do' : 'close', 'redraw' : [] } }
def _wizcb_future_submit(wiz, step, act, val, req): sess = DBSession() em = ExtModel(FuturePayment) obj = FuturePayment() em.set_values(obj, val, req, True) sess.add(obj) return { 'do' : 'close', 'reload' : True }
def _wizcb_aent_submit(wiz, em, step, act, val, req): sess = DBSession() em = ExtModel(AccessEntity) obj = AccessEntity() # Work around field name clash if 'state' in val: del val['state'] em.set_values(obj, val, req, True) sess.add(obj) return {'do': 'close', 'reload': True}
def dyn_ticket_uwiz_update(params, request): tid = int(params['ticketid']) del params['ticketid'] sess = DBSession() model = ExtModel(Ticket) ticket = sess.query(Ticket).get(tid) if ticket is None: raise KeyError('Invalid ticket ID') for param in ('tstid', 'toid', 'name', 'descr'): if param in params: del params[param] # TODO: ENTITIES_LIST if not request.has_permission('TICKETS_CHANGE_STATE'): if 'ttrid' in params: del params['ttrid'] if not request.has_permission('TICKETS_CHANGE_FLAGS'): if 'flags' in params: del params['flags'] # TODO: USERS_LIST # TODO: GROUPS_LIST sess.execute(SetVariable('ticketid', ticket.id)) if 'ttrid' in params: ttr_id = params['ttrid'] if ttr_id: ttr_id = int(ttr_id) trans = sess.query(TicketStateTransition).get(ttr_id) if trans: sess.execute(SetVariable('ttrid', trans.id)) trans.apply(ticket) del params['ttrid'] if 'show_client' in params: show_cl = params['show_client'].lower() if show_cl in {'true', '1', 'on'}: show_cl = True else: show_cl = False del params['show_client'] else: show_cl = False sess.execute(SetVariable('show_client', npbool(show_cl))) if ('comments' in params) and request.has_permission( 'TICKETS_COMMENT', request.context, request): sess.execute(SetVariable('comments', params['comments'])) del params['comments'] else: sess.execute(SetVariable('comments', None)) model.set_values(ticket, params, request) sess.flush() sess.execute(SetVariable('tcid', None)) return {'success': True, 'action': {'do': 'close', 'redraw': []}}
def _wizcb_submit_hdl(wiz, em, step, act, val, req): xcls = cls if isinstance(xcls, str): xcls = _name_to_class(xcls) sess = DBSession() em = ExtModel(xcls) obj = xcls() em.set_values(obj, val, req, True) sess.add(obj) return { 'do' : 'close', 'reload' : True }
def _wizcb_aent_submit(wiz, em, step, act, val, req): sess = DBSession() em = ExtModel(AccessEntity) obj = AccessEntity() # Work around field name clash if 'state' in val: del val['state'] em.set_values(obj, val, req, True) sess.add(obj) return { 'do' : 'close', 'reload' : True }
def _wizcb_stashio_submit(wiz, step, act, val, req): sess = DBSession() em = ExtModel(StashIO) obj = StashIO() em.set_values(obj, val, req, True) sess.add(obj) if obj.difference: stash = sess.query(Stash).get(obj.stash_id) if stash: stash.amount += obj.difference return { 'do' : 'close', 'reload' : True }
def _wizcb_submit_hdl(wiz, em, step, act, val, req): xcls = cls if isinstance(xcls, str): xcls = _name_to_class(xcls) sess = DBSession() cfg = get_current_registry().settings mailer = get_mailer(req) userIDs = json.loads(val['userid']) userlist = val['user'] templateName = val['template'] templId = val['templid'] receiver = None sender = cfg.get('netprofile.mailing.sender', '*****@*****.**') sendername = cfg.get('sender.name', 'localadmin') mailhost = cfg.get('mail.host', 'localhost') for userid in userIDs: resvalue = {'userid' : userid} user = sess.query(AccessEntity).filter(AccessEntity.id==userid).first() subscr = sess.query(MailingSubscription).filter(MailingSubscription.userid==userid).first() #a long try-except statement to check if user is in mailing list try: if subscr.issubscribed is True: templateBody = sess.query(MailingTemplate).filter(MailingTemplate.id==templId).first().body resvalue['user'] = user resvalue['template'] = templateBody resvalue['templid'] = templId if user.parent: try: receiver = user.parent.email except AttributeError: #raise error here print("################### USER'S PARENT HAVE NO EMAIL ATTRIBUTE #######################") if receiver is not None: msg_text = Attachment(data=templateBody, content_type='text/plain; charset=\'utf-8\'', disposition='inline', transfer_encoding='quoted-printable' ) msg_html = Attachment(data=templateBody, content_type='text/html; charset=\'utf-8\'', disposition='inline', transfer_encoding='quoted-printable' ) message = Message( subject=(templateName), sender=sender, recipients=(receiver,), body=msg_text, html=msg_html ) mailer.send(message) resvalue['letteruid'] = hashlib.md5((templateBody + user.nick + str(datetime.datetime.now())).encode()).hexdigest() em = ExtModel(xcls) obj = xcls() em.set_values(obj, resvalue, req, True) sess.add(obj) sess.flush() else: print("################### USER HAVE NO EMAIL #######################") except AttributeError: print("########################## USER NOT IN SUBSCR LIST ###########################") return { 'do' : 'close', 'reload' : True }