Пример #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()
Пример #2
0
def tag_remove(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 not in error.tags:
            return {'type': 'failure'}

        error.tags.remove(tag)
        error.save()
        Tag.removeOne(tag)
        return {'type': 'success'}
    except:
        return {'type': 'failure'}
Пример #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'}
Пример #4
0
def error_page(request):
    available_projects = request.registry.settings['projects']
    selected_project = get_selected_project(request)

    search = request.GET.get('search', '')
    show = request.GET.get('show', 'open')  # open, resolved, mine
    order_by = request.GET.get('order_by', 'date')
    direction = request.GET.get('direction', 'desc')

    if show not in ['open', 'resolved', 'mine']:
        show = 'open'

    errors = get_errors(request)

    return {
        'search': search,
        'errors': errors,
        'selected_project': selected_project,
        'available_projects': available_projects,
        'show': show,
        'order_by': order_by,
        'direction': direction,
        'tags': Tag.objects(),
        'users': User.objects(),
    }
Пример #5
0
def tag_remove(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 not in error.tags:
            return {'type': 'failure'}

        error.tags.remove(tag)
        error.save()
        Tag.removeOne(tag)
        return {'type': 'success'}
    except:
        return {'type': 'failure'}
Пример #6
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'}
Пример #7
0
def list(request):
    available_projects = request.registry.settings['projects']
    selected_project = get_selected_project(request)

    search = request.params.get('search', '')
    show = request.GET.getall('show')
    tags = request.GET.getall('tags')
    users = request.GET.getall('users')
    order_by = request.params.get('order', False)
    direction = request.params.get('direction', False)

    errors = Error.objects.find_for_list(selected_project, request.user, show)

    if search:
        errors = errors.search(search)

    if tags:
        errors.filter(tags__in=tags)

    if users:
        errors.filter(claimedby__in=users)
 
    if order_by != False and errors.count():
        if direction and direction == 'desc':
            order_by = '-' + order_by
        errors.order_by(order_by)

    page = request.params.get('page', '1')
    paginator = Paginator(errors, size_per_page=20, current_page=page)

    params = {
        'search': search,
        'errors': paginator.get_current_page(),
        'paginator': paginator,
        'selected_project': selected_project,
        'available_projects': available_projects,
        'show': show,
        'tags': Tag.objects(),
        'users': User.objects(),
        'get_error_count': lambda x: Error.objects.find_for_list(selected_project, request.user, x).count()
    }

    return render_to_response('error-list.html', params)