Beispiel #1
0
def view(request):
    available_projects = request.registry.settings['projects']
    selected_project = get_selected_project(request)

    error_id = request.matchdict['id']
    try:
        error = Error.objects(project=selected_project['id']).with_id(error_id)
    except:
        return HTTPNotFound()

    comment_schema = CommentsSchema()
    comment_form = Form(comment_schema, buttons=('submit',), formid="comment_form")

    tag_schema = TagSchema()
    tag_form = Form(tag_schema, buttons=('submit',), formid="tag_form")

    if 'submit' in request.POST:
        form_id = request.POST['__formid__']
        controls = request.POST.items()

        if form_id == 'comment_form':
            try:
                values = comment_form.validate(controls)

                error.comments.append(Comment(
                    author=request.user,
                    content=values['comment'],
                    created=int(time())
                ))
                error.save()

                url = request.route_url('error_view', project=selected_project['id'], id=error_id)
                return HTTPFound(location=url)
            except ValidationFailure, e:
                comment_form_render = e.render()
        elif form_id == 'tag_form':
            try:
                values = tag_form.validate(controls)

                # build a list of comma seperated, non empty tags
                tags = [t.strip() for t in values['tag'].split(',') if t.strip() != '']

                changed = False
                for tag in tags:
                    if tag not in error.tags:
                        error.tags.append(tag)
                        changed = True
                        Tag.create(tag).save()

                if changed:
                    error.save()

                url = request.route_url('error_view', project=selected_project['id'], id=error_id)
                return HTTPFound(location=url)
            except ValidationFailure, e:
                tag_form_render = e.render()
Beispiel #2
0
def tag_add(request):
    tag = request.matchdict['tag']
    error_id = request.matchdict['id']
    selected_project = get_selected_project(request)

    try:
        error = Error.objects(project=selected_project['id']).with_id(error_id)
        if tag in error.tags:
            return {'type': 'failure'}

        error.tags.append(tag)
        error.save()
        Tag.create(tag).save()
        return {'type': 'success'}
    except:
        return {'type': 'failure'}
Beispiel #3
0
def tag_add(request):
    tag = request.matchdict['tag']
    error_id = request.matchdict['id']
    selected_project = get_selected_project(request)

    try:
        error = Error.objects(project=selected_project['id']).with_id(error_id)
        if tag in error.tags:
            return {'type': 'failure'}

        error.tags.append(tag)
        error.save()
        Tag.create(tag).save()
        return {'type': 'success'}
    except:
        return {'type': 'failure'}