def update_childrens_full_path(): store_location_id = request.args[0] mylogger.debug(message='store_location_id:%s' % store_location_id) store_location_mapper = STORE_LOCATION_MAPPER() _store_location = store_location_mapper.find( store_location_id=store_location_id)[0] # updating childrens full path for _children in _store_location.retrieve_children(): mylogger.debug(message='_children:%s' % _children) _children.compute_and_set_full_path() store_location_mapper.update(_children) # and current store location full path #_store_location.compute_and_set_full_path() #store_location_mapper.update(_store_location) cc.clear_menu_cache() redirect( URL(request.application, request.controller, 'list_reload', args=_store_location.entity.id))
def update(): ''' update one of the authenticated user entity ''' form = crud.update(db.entity, request.args(0), onaccept=cc.clear_menu_cache(), next=URL(request.application, request.controller, 'list_reload', args=request.args(0), vars=request.vars)) cc.clear_menu_cache() return dict(form=form)
def create(): form = crud.create(db.store_location, onaccept=lambda form: cc.clear_menu_cache(), next=URL(request.application, request.controller, 'page_reload', vars=request.vars)) return dict(form=form)
def delete(): store_location_id = request.args[0] store_location_mapper = STORE_LOCATION_MAPPER() _store_location = store_location_mapper.find( store_location_id=store_location_id)[0] form = crud.delete(db.store_location, store_location_id, next=URL(request.application, request.controller, 'list_reload', args=_store_location.entity.id)) cc.clear_menu_cache() return dict(form=form)
def delete(): entity_mapper = ENTITY_MAPPER() entity_id = request.args[0] mylogger.debug(message='entity_id:%s' % entity_id) _entity = entity_mapper.find(entity_id=entity_id)[0] entity_mapper.delete(_entity) cc.clear_menu_cache() redirect( URL(request.application, request.controller, 'list_reload.html', args=entity_id, vars=request.vars))
def create(): ''' create a new entity ''' person_mapper = PERSON_MAPPER() auth_user = person_mapper.find(person_id=auth.user.id)[0] db.entity.role.default = '' form = crud.create( db.entity, onaccept=lambda form: (auth.add_membership(group_id=form.vars.id) if not auth_user.is_all_entity() else None, cc.clear_menu_cache()), next=URL(request.application, request.controller, 'page_reload', vars=request.vars)) cc.clear_menu_cache() return dict(form=form)
def update(): mylogger.debug(message='request.vars:%s' % request.vars) _store_location_id = request.args[0] form = crud.update(db.store_location, _store_location_id, onaccept=lambda form: cc.clear_menu_cache(), next=URL(request.application, request.controller, 'update_childrens_full_path', args=request.args[0])) return dict(form=form)
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)