Beispiel #1
0
def profile():

    mylogger.debug(message='request.vars:%s' %request.vars)

    person_mapper = PERSON_MAPPER()

    _person_id = auth.user.id

    _person = person_mapper.find(person_id=_person_id)[0] # an existing PERSON

    form = PERSON_FORM(person=_person, readonly_fields=[ 'email', 'creator', 'custom_permission', 'custom_entity', 'is_admin' ]).get_form()

    if form.accepts(request.vars, session, dbio=False):

        mylogger.debug(message='form.vars:%s' %form.vars)

        _person.first_name = form.vars['first_name']
        _person.last_name = form.vars['last_name']
        _person.contact = form.vars['contact']

        # saving the user
        person_mapper.save_or_update(_person)

        session.flash=cc.get_string("PERSON_UPDATED")

        redirect(URL(request.application, 'default', 'index'))

    else:

        return dict(form = form)
Beispiel #2
0
def delete():

    person_mapper = PERSON_MAPPER()

    person_id = request.args[0]

    mylogger.debug(message='person_id:%s' %person_id)

    _person = person_mapper.find(person_id=person_id)[0]

    for child in  person_mapper.find(creator_id=person_id):
        child.creator = None
        person_mapper.save_or_update(child)

    person_mapper.delete(_person)

    redirect(URL(request.application, request.controller, 'list_reload.html', args=person_id, vars=request.vars))
Beispiel #3
0
def toogle_disable():

    mylogger.debug(message='request.vars:%s' %request.vars)

    person_mapper = PERSON_MAPPER()

    _person_id = request.args[0] # an id
    _person = person_mapper.find(person_id=_person_id)[0] # an existing PERSON

    if _person.is_disabled():
        _person.enable()
    else:
        _person.disable()

    # saving the user
    person_mapper.save_or_update(_person)

    session.flash=cc.get_string("PERSON_UPDATED")

    return json.dumps({'success': True})
Beispiel #4
0
def _create():

    mylogger.debug(message='request.vars:%s' %request.vars)
    mylogger.debug(message='request.args:%s' %request.args)

    person_mapper = PERSON_MAPPER()
    entity_mapper = ENTITY_MAPPER()

    _person_id = request.args[0] if len(request.args) > 0 else None # an id or None
    if _person_id is None:
        _person = person_mapper.create()
    else:
        _person = person_mapper.find(person_id=_person_id)[0]

    _all_entity_id = entity_mapper.find(role='all_entity')[0].id

    form = PERSON_FORM(person=_person).get_form()

    if form.accepts(request.vars, session, dbio=False):
        mylogger.debug(message='form.vars:%s' %form.vars)

        is_virtual = 'is_virtual' in request.vars
        mylogger.debug(message='is_virtual:%s' %is_virtual)

        _person.first_name = form.vars['first_name']
        _person.last_name = form.vars['last_name']
        _person.email = form.vars['email']
        _person.contact = form.vars['email'] # initializing the contact with the email address

        if 'custom_permission' in form.vars.keys():
            _person.permissions = [ PERMISSION(name=_permission_name) for _permission_name in form.vars['custom_permission'] ]

        if 'custom_entity' in form.vars.keys():
            _custom_entity = form.vars['custom_entity']
            if type(_custom_entity) is not ListType:
                _custom_entity = [ _custom_entity ]

            if str(_all_entity_id) in _custom_entity:
                _custom_entity = [ _all_entity_id ]
            _person.entities = [ entity_mapper.find(entity_id=_entity_id)[0] for _entity_id in _custom_entity ]

        if is_virtual:
            # this is a new person
            # sending an email to the creator
            message = cc.get_string("PERSON_VIRTUAL_CREATION_MESSAGE_BODY") %(_person.first_name + ' ' + \
                                                                              _person.last_name, \
                                                                              _person.email, \
                                                                              _person.password)

            _creator = person_mapper.find(person_id=auth.user.id)[0]

            # enabling the new person
            _person.enable()
            _person.virtual=True

            mail_sent = mail.send(_creator.email, subject= cc.get_string("PERSON_VIRTUAL_CREATION_MESSAGE_SUBJECT"), message=message)

            if mail_sent:
                # saving the user
                _new_person_id = person_mapper.save_or_update(_person)

                session.flash=cc.get_string("EMAIL_SENT")
            else:
                del(_person)

                session.flash=cc.get_string("ERROR") + mail.error

        # sending an email to the new user
        elif _person.new_person:

            message = cc.get_string("PERSON_CREATION_MESSAGE_BODY") %(_person.first_name + ' ' + \
                                                        _person.last_name, \
                                                        _person.email, \
                                                        settings['application_url'], \
                                                        _person.password_key)

            mail_sent = mail.send(_person.email, subject= cc.get_string("PERSON_CREATION_MESSAGE_SUBJECT"), message=message)

            if mail_sent:
                # saving the user
                _new_person_id = person_mapper.save_or_update(_person)

                session.flash=cc.get_string("EMAIL_SENT")
            else:
                del(_person)

                mylogger.error(message='mail.error:%s' % mail.error)
                session.flash=cc.get_string("ERROR") + str(mail.error)

                redirect(URL(request.application, request.controller, 'page_reload'))
        else:
            # saving the user
            _new_person_id = person_mapper.save_or_update(_person)

            session.flash=cc.get_string("PERSON_UPDATED")

        mylogger.debug(message='_person:%s' %_person)
        cc.clear_menu_cache()

        if _person_id is not None:
            redirect(URL(request.application, request.controller, 'list_reload', args=_person.id, vars=request.vars))
        else:
            redirect(URL(request.application, request.controller, 'page_reload', vars={'member': _new_person_id, 'display_by': 'person'}))

    else:

        return dict(form=form, all_entities_id=_all_entity_id)