Exemplo n.º 1
0
 def get_cfg(self, model, req, **kwargs):
     if isinstance(self.model, str):
         self.model = ExtModel(_name_to_class(self.model))
     ret = []
     col = self.model.get_column(self.field)
     colfld = col.get_editor_cfg(req, in_form=True, initval=self.value)
     if colfld:
         colfld['name'] = self.name
         coldef = col.default(req)
         if (kwargs.get('use_defaults',
                        False)) and (coldef
                                     is not None) and (not self.value):
             colfld['value'] = coldef
         if self.extra_config:
             colfld.update(self.extra_config)
         ret = [colfld]
         extra = col.append_field()
         while extra:
             ecol = self.model.get_column(extra)
             ecolfld = ecol.get_editor_cfg(req,
                                           in_form=True,
                                           initval=self.value)
             if ecolfld:
                 ecoldef = ecol.default(req)
                 if (kwargs.get('use_defaults', False)) and (
                         ecoldef is not None) and (not self.value):
                     ecolfld['value'] = ecoldef
                 ret.append(ecolfld)
                 extra = ecol.append_field()
             else:
                 break
         return ret
Exemplo n.º 2
0
    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}
Exemplo n.º 3
0
	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
			}
Exemplo n.º 4
0
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' : []
		}
	}
Exemplo n.º 5
0
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
	}
Exemplo n.º 6
0
 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}
Exemplo n.º 7
0
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': []}}
Exemplo n.º 8
0
	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
		}
Exemplo n.º 9
0
	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
		}
Exemplo n.º 10
0
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
	}
Exemplo n.º 11
0
	def get_cfg(self, model, req, **kwargs):
		if isinstance(self.model, str):
			self.model = ExtModel(_name_to_class(self.model))
		ret = []
		col = self.model.get_column(self.field)
		colfld = col.get_editor_cfg(req, in_form=True, initval=self.value)
		if colfld:
			colfld['name'] = self.name
			coldef = col.default(req)
			if (kwargs.get('use_defaults', False)) and (coldef is not None) and (not self.value):
				colfld['value'] = coldef
			if self.extra_config:
				colfld.update(self.extra_config)
			ret = [colfld]
			extra = col.append_field()
			while extra:
				ecol = self.model.get_column(extra)
				ecolfld = ecol.get_editor_cfg(req, in_form=True, initval=self.value)
				if ecolfld:
					ecoldef = ecol.default(req)
					if (kwargs.get('use_defaults', False)) and (ecoldef is not None) and (not self.value):
						ecolfld['value'] = ecoldef
					ret.append(ecolfld)
					extra = ecol.append_field()
				else:
					break
			return ret
Exemplo n.º 12
0
class ExternalWizardField(CustomWizardField):
    """
	Generates wizard fields from arbitrary models.
	"""
    def __init__(self, cls, fldname, name=None, value=None, extra_config=None):
        if name is None:
            name = fldname
        self.name = name
        self.model = cls
        self.field = fldname
        self.value = value
        self.extra_config = extra_config

    def get_cfg(self, model, req, **kwargs):
        if isinstance(self.model, str):
            self.model = ExtModel(_name_to_class(self.model))
        ret = []
        col = self.model.get_column(self.field)
        colfld = col.get_editor_cfg(req, in_form=True, initval=self.value)
        if colfld:
            colfld['name'] = self.name
            coldef = col.default(req)
            if (kwargs.get('use_defaults',
                           False)) and (coldef
                                        is not None) and (not self.value):
                colfld['value'] = coldef
            if self.extra_config:
                colfld.update(self.extra_config)
            ret = [colfld]
            extra = col.append_field()
            while extra:
                ecol = self.model.get_column(extra)
                ecolfld = ecol.get_editor_cfg(req,
                                              in_form=True,
                                              initval=self.value)
                if ecolfld:
                    ecoldef = ecol.default(req)
                    if (kwargs.get('use_defaults', False)) and (
                            ecoldef is not None) and (not self.value):
                        ecolfld['value'] = ecoldef
                    ret.append(ecolfld)
                    extra = ecol.append_field()
                else:
                    break
            return ret
Exemplo n.º 13
0
class ExternalWizardField(CustomWizardField):
    """
    Generates wizard fields from arbitrary models.
    """
    def __init__(self, cls, fldname, name=None, value=None, extra_config=None):
        if name is None:
            name = fldname
        self.name = name
        self.model = cls
        self.field = fldname
        self.value = value
        self.extra_config = extra_config

    def get_cfg(self, model, req, **kwargs):
        if isinstance(self.model, str):
            self.model = ExtModel(_name_to_class(self.model))
        ret = []
        col = self.model.get_column(self.field)
        colfld = col.get_editor_cfg(req, in_form=True, initval=self.value)
        if colfld:
            colfld['name'] = self.name
            coldef = col.default(req)
            if (kwargs.get('use_defaults', False)
                    and coldef is not None
                    and not self.value):
                colfld['value'] = coldef
            if self.extra_config:
                colfld.update(self.extra_config)
            ret = [colfld]
            extra = col.append_field()
            while extra:
                ecol = self.model.get_column(extra)
                ecolfld = ecol.get_editor_cfg(req, in_form=True,
                                              initval=self.value)
                if ecolfld:
                    ecoldef = ecol.default(req)
                    if (kwargs.get('use_defaults', False)
                            and ecoldef is not None
                            and not self.value):
                        ecolfld['value'] = ecoldef
                    ret.append(ecolfld)
                    extra = ecol.append_field()
                else:
                    break
            return ret
Exemplo n.º 14
0
def dyn_ticket_uwiz(params, request):
    tid = int(params['ticketid'])
    sess = DBSession()
    loc = request.localizer
    trans = [{
        'name':
        'ttrid',
        'boxLabel':
        '<div class="np-xradiolabel"><div class="title">%s</div>%s</div>' %
        (html_escape(loc.translate(_('No changes')), True),
         html_escape(loc.translate(_('Do not change ticket state.')), True)),
        'inputValue':
        '',
        'checked':
        True
    }]
    ticket = sess.query(Ticket).get(tid)
    if ticket is None:
        raise KeyError('Invalid ticket ID')
    model = ExtModel(Ticket)
    ch_model = ExtModel(TicketChange)
    fields = []
    if request.has_permission('ENTITIES_LIST'):
        fields.append(
            ExternalWizardField(
                model,
                'entity',
                value=ticket.entity,
                extra_config={
                    'readOnly':
                    not bool(request.has_permission('TICKETS_CHANGE_ENTITY'))
                }))
    if request.has_permission('TICKETS_CHANGE_STATE'):
        for tr in ticket.state.transitionmap_to:
            label = '<div class="np-xradiolabel"><div class="title">%s</div>%s</div>' % (
                html_escape(tr.name, True),
                html_escape((tr.description if tr.description else ''), True))
            trans.append({
                'name': 'ttrid',
                'boxLabel': label,
                'inputValue': tr.id
            })
        fields.append(
            ExtJSWizardField({
                'xtype': 'radiogroup',
                'fieldLabel': loc.translate(_('Transition')),
                'vertical': True,
                'columns': 1,
                'items': trans
            }))
    if request.has_permission('TICKETS_CHANGE_FLAGS'):
        fields.append(ExternalWizardField(model, 'flags', value=ticket.flags))
    if request.has_permission('USERS_LIST'):
        fields.append(
            ExternalWizardField(
                model,
                'assigned_user',
                value=ticket.assigned_user,
                extra_config={
                    'readOnly':
                    not bool(request.has_permission('TICKETS_CHANGE_UID'))
                }))
    if request.has_permission('GROUPS_LIST'):
        fields.append(
            ExternalWizardField(
                model,
                'assigned_group',
                value=ticket.assigned_group,
                extra_config={
                    'readOnly':
                    not bool(request.has_permission('TICKETS_CHANGE_GID'))
                }))
    fields.extend(
        (ExternalWizardField(model, 'ticketid', value=ticket.id),
         CompositeWizardField(
             ExternalWizardField(
                 model,
                 'assigned_time',
                 value=ticket.assigned_time,
                 extra_config={
                     'readOnly':
                     not bool(request.has_permission('TICKETS_CHANGE_DATE'))
                 }),
             ExtJSWizardField({
                 'xtype': 'button',
                 'text': 'Schedule',
                 'iconCls': 'ico-schedule',
                 'margin': '0 0 0 2',
                 'itemId': 'btn_sched'
             })),
         ExternalWizardField(
             model,
             'archived',
             value=ticket.archived,
             extra_config={
                 'readOnly':
                 not bool(request.has_permission('TICKETS_ARCHIVAL'))
             }), ExternalWizardField(ch_model, 'show_client', value=False)))
    if request.has_permission('TICKETS_COMMENT'):
        fields.append(ExternalWizardField(ch_model, 'comments'))
    wiz = Wizard(Step(*fields), title=_('Update ticket'))
    ret = {
        'success': True,
        'fields': wiz.get_cfg(model, request, use_defaults=True)
    }
    return ret
Exemplo n.º 15
0
	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
			}