def update(request, callback=None, renderers=None, validators=None, values=None): """Base method to handle update requests. This view will render a update form to update items on (GET) requests. It the user submits the data (POST) that the data will be validated. If validation is successfull the item will be saved in the datebase and the callback method will be called. Finally a redirect to either the backurl or the edit or read mode of the item will be triggered. If the validation fails, the form will be rendered again. :request: Current request :callback: Current function which is called after the item has been read. :renderers: Dictionary of external renderers which should be used for renderering some form elements. :validators: List of external formbar validators which should be added to the form for validation :values: Dictionary of additional values which will be available in the form :returns: Dictionary or Redirect. """ handle_history(request) handle_params(request) if values is None: values = {} values['_roles'] = [str(r.name) for r in request.user.roles] form = get_item_form('update', request, renderers, validators, values) if request.POST: if handle_POST_request(form, request, callback, 'update', renderers): return handle_redirect_on_success(request) rvalues = get_return_value(request) rvalues['form'] = render_item_form(request, form, values) return rvalues
def ownership(request, callback=None, renderers=None): """Base method to handle requests to change the ownership. :request: Current request :callback: Current function which is called after the item has been read. :returns: Dictionary. """ handle_history(request) handle_params(request) clazz = request.context.__model__ item_label = get_item_modul(request, clazz).get_label() form = get_ownership_form(request) if request.POST: item = get_item_from_request(request) old_gid = str(item.gid) old_uid = str(item.uid) new_gid = str(request.params.get('group')) new_uid = str(request.params.get('owner')) if handle_POST_request(form, request, callback, 'update', renderers): if old_uid != new_uid: log_msg = u'User {user.login} changed uid of {item_label} '\ '{item.id} from {old} -> {new}'\ .format(item_label=item_label, item=item, user=request.user, old=old_uid, new=new_uid) log.info(log_msg) if old_gid != new_gid: log_msg = u'User {user.login} changed gid of {item_label} '\ '{item.id} from {old} -> {new}'\ .format(item_label=item_label, item=item, user=request.user, old=old_gid, new=new_gid) log.info(log_msg) return handle_redirect_on_success(request) rvalues = get_return_value(request) rvalues['form'] = get_rendered_ownership_form(request) return rvalues
def update(request, callback=None, renderers=None, validators=None, values=None): """Base method to handle update requests. This view will render a update form to update items on (GET) requests. It the user submits the data (POST) that the data will be validated. If validation is successfull the item will be saved in the datebase and the callback method will be called. Finally a redirect to either the backurl or the edit or read mode of the item will be triggered. If the validation fails, the form will be rendered again. :request: Current request :callback: Current function which is called after the item has been read. :renderers: Dictionary of external renderers which should be used for renderering some form elements. :validators: List of external formbar validators which should be added to the form for validation :values: Dictionary of additional values which will be available in the form :returns: Dictionary or Redirect. """ if values is None: values = {} values['_roles'] = [str(r.name) for r in request.user.roles] form = get_item_form('update', request, renderers, validators, values) if request.POST: if handle_POST_request(form, request, callback, 'update', renderers): return handle_redirect_on_success(request) rvalues = get_return_value(request) rvalues['form'] = render_item_form(request, form) return rvalues
def ownership(request, callback=None, renderers=None): """Base method to handle requests to change the ownership. :request: Current request :callback: Current function which is called after the item has been read. :returns: Dictionary. """ clazz = request.context.__model__ item_label = get_item_modul(request, clazz).get_label() form = get_ownership_form(request) if request.POST: item = get_item_from_request(request) old_gid = str(item.gid) old_uid = str(item.uid) new_gid = str(request.params.get('group')) new_uid = str(request.params.get('owner')) if handle_POST_request(form, request, callback, 'update', renderers): if old_uid != new_uid: log_msg = u'User {user.login} changed uid of {item_label} '\ '{item.id} from {old} -> {new}'\ .format(item_label=item_label, item=item, user=request.user, old=old_uid, new=new_uid) log.info(log_msg) if old_gid != new_gid: log_msg = u'User {user.login} changed gid of {item_label} '\ '{item.id} from {old} -> {new}'\ .format(item_label=item_label, item=item, user=request.user, old=old_gid, new=new_gid) log.info(log_msg) return handle_redirect_on_success(request) rvalues = get_return_value(request) rvalues['form'] = get_rendered_ownership_form(request) return rvalues
def create(request, callback=None, renderers=None, validators=None): """Base method to handle create requests. This view will render a create form to update items on (GET) requests. It the user submits the data (POST) that the data will be validated. If validation is successfull the item will be saved in the datebase and the callback method will be called. Finally a redirect to either the backurl or the edit or read mode of the item will be triggered. If the validation fails, the form will be rendered again. :request: Current request :callback: Current function which is called after the item has been read. :renderers: Dictionary of external renderers which should be used for renderering some form elements. :validators: List of external formbar validators which should be added to the form for validation :returns: Dictionary or Redirect. """ handle_history(request) params = handle_params(request) # Create a new item clazz = request.context.__model__ try: factory = clazz.get_item_factory(request) except TypeError: # Old version of get_item_factory method which does not take an # request parameter. factory = clazz.get_item_factory() factory._request = request # Only create a new item if there isn't already an item in the # request.context. This can happen if we define a custom view for # create where the item gets created before to set some default # values e.g (See create function of forms) if not request.context.item: request.context.item = factory.create(request.user, {}) form = get_item_form(params.get("form", "create"), request, renderers, validators) if request.POST and 'blobforms' not in request.params: if handle_POST_request(form, request, callback, 'create', renderers): return handle_redirect_on_success(request) rvalues = get_return_value(request) values = {'_roles': [str(r.name) for r in request.user.roles]} values.update(params.get('values', {})) rvalues['form'] = render_item_form(request, form, values, False) return rvalues
def create(request, callback=None, renderers=None, validators=None, values=None): """Base method to handle create requests. This view will render a create form to update items on (GET) requests. It the user submits the data (POST) that the data will be validated. If validation is successfull the item will be saved in the datebase and the callback method will be called. Finally a redirect to either the backurl or the edit or read mode of the item will be triggered. If the validation fails, the form will be rendered again. :request: Current request :callback: Current function which is called after the item has been read. :renderers: Dictionary of external renderers which should be used for renderering some form elements. :validators: List of external formbar validators which should be added to the form for validation :values: Dictionary of additional values which will be available in the form :returns: Dictionary or Redirect. """ handle_history(request) params = handle_params(request) # Create a new item clazz = request.context.__model__ try: factory = clazz.get_item_factory(request) except TypeError: # Old version of get_item_factory method which does not take an # request parameter. factory = clazz.get_item_factory() factory._request = request # Only create a new item if there isn't already an item in the # request.context. This can happen if we define a custom view for # create where the item gets created before to set some default # values e.g (See create function of forms) if not request.context.item: request.context.item = factory.create(request.user, {}) if values is None: values = {} values['_roles'] = [str(r.name) for r in request.user.roles] values.update(params.get('values', {})) # FIXME: "form_values" seems to be only used in one single # application (efa). For now we will leave this here to not break # any things but it should be removed. # See https://github.com/ringo-framework/ringo/issues/31 # (ti) <2016-10-18 21:51> form_values = request.session.get("form_values") or {} values.update(form_values) request.session["form_values"] = None request.session.save() form = get_item_form(params.get("form", "create"), request, renderers, validators, values=values) if request.POST and 'blobforms' not in request.params: if handle_POST_request(form, request, callback, 'create', renderers): return handle_redirect_on_success(request) rvalues = get_return_value(request) rvalues['form'] = render_item_form(request, form, validate=False) return rvalues