Exemplo n.º 1
0
    def edit(self, track_id, **kw):
        user = handler.user.get_user_in_session(request)
        if track_id is not None:
            if not checker.can_edit_track(user, track_id):
                flash("You haven't the right to edit any tracks which is not yours", 'error')
                raise redirect('/tracks')

        widget = form.EditTrack(action=url('/tracks/edit/%s' % track_id)).req()

        track = DBSession.query(Track).filter(Track.id == track_id).first()

        d = {}
        d['name'] = track.name
        if track.parameters is None or not 'color' in track.parameters:
            cc = constants.default_track_color
        else:
            cc = track.parameters['color']
        d['track_id'] = track_id
        d['color'] = cc
        if 'pid' in kw:
            d['pid'] = kw['pid']
        widget.value = d
        if request.method == 'GET':
            return dict(title='Edit track', page='track', widget=widget, color=cc)

        if request.method == 'POST':
            try:
                widget.validate(kw)
            except twc.ValidationError as e:
                return dict(title='Edit track', page='track', widget=e.widget, color=cc)
        handler.track.edit(track=track, name=kw.get('name', None), color=kw.get('color', None))
        raise redirect('/tracks', {'pid': kw.get('pid', None)})
Exemplo n.º 2
0
 def delete(self, track_id, **kw):
     user = handler.user.get_user_in_session(request)
     if track_id is not None:
         if not checker.can_edit_track(user, track_id):
             return reply.error(request, "You haven't the right to delete any tracks which is not yours", '/tracks', {'error': 'wrong credential'})
         handler.track.delete_track(track_id=track_id)
     red = '/tracks'
     if 'pid' in kw:
         red += '?pid=%s' % kw['pid']
     return reply.normal(request, 'Track successfully deleted.', red, {'success': 'track deleted'})