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 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 mapdata(request): """Will return the track data of the activity as Geojson.""" item = get_item_from_request(request) if item.has_streams: gj = a2gj(item) else: gj = {} return JSONResponse(True, gj)
def _read(request): """If activity is not completely synced. Than sync it when opening""" item = get_item_from_request(request) if not item.has_streams: request.item = sync_activity(request) _ = request.translate msg = _('The activity was successfully synchronized with Strava') request.session.flash(msg, "success") return read(request)
def rest_read(request, callback=None): """Base method to handle read requests on the REST interface. Returns a JSON object of a specific item. :request: Current request :callback: Current function which is called after the item has been read. :returns: JSON object. """ handle_callback(request, callback, mode="pre,default") return JSONResponse(True, get_item_from_request(request))
def rest_read(request, callback=None): """Base method to handle read requests on the REST interface. Returns a JSON object of a specific item. :request: Current request :callback: Current function which is called after the item has been read. :returns: JSON object. """ handle_callback(request, callback) return JSONResponse(True, get_item_from_request(request))
def rest_delete(request, callback=None): """Deletes an item of type clazz. The item is deleted based on the unique id value provided in the matchtict object in the current DELETE request. The data will be deleted without any futher confirmation! :clazz: Class of item to delete :request: Current request :returns: JSON object. """ item = get_item_from_request(request) request.db.delete(item) return JSONResponse(True, item)
def build_breadcrumbs(request, sitetree): """Will return a list of breadcrumbs based on the current request and the given sitetree. :request: Current request :sitetree: dictionary of the sitetree :returns: List of breadcrumbs. """ # Only build the sitemap if the modul is part of the sitemap and an # item is actually selected from ringo.views.request import get_item_from_request pip = request.path_info_peek() if pip in sitetree: if request.matchdict: item = get_item_from_request(request) path = walk_site_tree(sitetree, pip, item, request) request.session["breadcrumbs"] = path request.session.save() else: if request.path.find("create") > -1: item = get_item_from_request(request) modul = get_item_modul(request, item) path = request.session.get("breadcrumbs", []) return list(reversed(path)) + [(modul.get_label(), None)] # Reset the breadcrumbs for any other url. This means the # breadcrumbs are reseted every time the user calls an # overview page e.g. As the overview pages are usually the # entry point for a new working proccess the previous # context is lost so the breadcrumbs are. request.session["breadcrumbs"] = [] return [] else: request.session["breadcrumbs"] = [] return [] path = list(reversed(path)) if path: path[-1] = (path[-1][0], None) return path
def print_(request): handle_history(request) handle_params(request) item = get_item_from_request(request) renderer = PrintDialogRenderer(request, item) form = renderer.form if (request.method == 'POST' and is_confirmed(request) and form.validate(request.params)): template = form.data.get('printtemplates')[0] out = _render_template(request, template, item) return _build_final_response(out, request, template) else: clazz = item.__class__ rvalue = {} rvalue['dialog'] = renderer.render() rvalue['clazz'] = clazz rvalue['item'] = item return rvalue
def restore(request): clazz = request.context.__model__ _ = request.translate handle_params(request) handle_history(request) item = get_item_from_request(request) item_label = get_item_modul(request, clazz).get_label(plural=True) mapping = {'item_type': item_label, 'item': item} item.trash_state_id = 1 route_name = get_action_routename(item, 'update') url = request.route_path(route_name, id=item.id) msg = _('Restored ${item} from trash successfully.', mapping=mapping) log_msg = u'User {user.login} restored {item_label} {item.id}'.format( item_label=item_label, item=item, user=request.user) log.info(log_msg) request.session.flash(msg, 'success') transaction.commit() return HTTPFound(location=url)
def burndown_view(request): """Returns a SVG grafic representing the burndown chart of the sprint""" _ = request.translate sprint = get_item_from_request(request) chart = pygal.Line(height=200, x_label_rotation=20, show_legend=False, style=CleanStyle, margin=0, margin_bottom=20 ) chart.x_labels = map(str, get_x_labels(sprint)) history = get_estimate_history(sprint) chart.add(_('Progress'), history) ideal = map(lambda x: None, range(0, len(history))) ideal[-1] = 0 ideal[0] = sprint.size or history[0] chart.add(_('Ideal'), ideal) response = Response(chart.render(), content_type="image/svg+xml") return response
def sync_activity(request): activity = get_item_from_request(request) client = Client(access_token=get_access_token(request)) strava = client.get_activity(activity.strava_id) # Sync description this is not included in the activity overview. if strava.description: activity.description = strava.description # Activities can have many streams, you can request desired stream types # 'time', 'latlng', 'altitude', 'heartrate', 'temp' types = [ 'time', 'latlng', 'distance', 'altitude', 'velocity_smooth', 'heartrate', 'cadence', 'watts', 'temp', 'moving', 'grade_smooth' ] streams = client.get_activity_streams(activity.strava_id, types=types) if "time" in streams: activity.time_stream = streams["time"].data if "latlng" in streams: activity.latlng_stream = streams["latlng"].data if "distance" in streams: activity.distance_stream = streams["distance"].data if "altitude" in streams: activity.altitude_stream = streams["altitude"].data if "velocity_smooth" in streams: activity.velocity_smooth_stream = streams["velocity_smooth"].data if "heartrate" in streams: activity.heartrate_stream = streams["heartrate"].data if "cadence" in streams: activity.cadence_stream = streams["cadence"].data if "watts" in streams: activity.watts_stream = streams["watts"].data if "temp" in streams: activity.temp_stream = streams["temp"].data if "moving" in streams: activity.moving_stream = streams["moving"].data if "grade_smooth" in streams: activity.grade_smoth_stream = streams["grade_smooth"].data return activity
def rest_update(request, callback=None): """Updates an item of type clazz. The item is loaded based on the unique id value provided in the matchtict object in the current request. The item will be updated with the data submitted in the current PUT request. Before updating the item the data will be validated against the "update" form of the item. If the validation fails the item will not be updated. In all cases the item is return as JSON object with the item and updated values back to the client. The JSON Response will include further details on the reason why the validation failed. :request: Current request :returns: JSON object. """ item = get_item_from_request(request) form = get_item_form('update', request) if form.validate(request.params): item.save(form.data, request) return JSONResponse(True, item) else: # Validation fails! return item return JSONResponse(False, item)
def delete(request, callback=None): item = get_item_from_request(request) return _handle_delete_request(request, [item], callback)
def anonymize(request): handle_history(request) handle_params(request) item = get_item_from_request(request) return _handle_anonymize_request(request, [item])
def delete(request, callback=None): item = get_item_from_request(request) handle_history(request) handle_params(request) return _handle_delete_request(request, [item], callback)
def evaluate(request): handle_history(request) handle_params(request) item = get_item_from_request(request) return _handle_evaluation_request(request, [item])