コード例 #1
0
ファイル: labels.py プロジェクト: kelp404/Salmon
def add_label(request, project_id):
    project = ProjectModel.get_by_id(long(project_id))
    if project is None:
        raise Http404
    form = LabelForm(**json.loads(request.body))
    if not form.validate():
        raise Http400
    if request.user.permission != UserPermission.root and\
                    request.user.key().id() not in project.root_ids:
        raise Http403
    label = LabelModel(
        title=form.title.data,
        project=project,
    )
    label.put()
    return JsonResponse(label)
コード例 #2
0
ファイル: labels.py プロジェクト: kelp404/Salmon
def get_labels(request, project_id):
    project = ProjectModel.get_by_id(long(project_id))
    if project is None:
        raise Http404
    if request.user.permission != UserPermission.root and\
                    request.user.key().id() not in project.member_ids:
        raise Http403
    labels = LabelModel.all().filter('project =', project.key()).order('title').fetch(100)
    return JsonResponse([x.dict() for x in labels])
コード例 #3
0
ファイル: labels.py プロジェクト: kelp404/Salmon
def delete_label(request, project_id, label_id):
    project = ProjectModel.get_by_id(long(project_id))
    if project is None:
        raise Http404
    if request.user.permission != UserPermission.root and\
                    request.user.key().id() not in project.root_ids:
        raise Http403
    label = LabelModel.get_by_id(long(label_id))
    label.delete()
    return HttpResponse()
コード例 #4
0
ファイル: projects.py プロジェクト: kelp404/Salmon
def get_project(request, project_id):
    project = ProjectModel.get_by_id(long(project_id))
    if project is None:
        raise Http404('not found the project %s' % project_id)
    if request.user.permission != UserPermission.root and\
                    request.user.key().id() not in project.member_ids:
        raise Http403
    labels = LabelModel.all().filter('project =', project.key()).order('title').fetch(100)

    result = project.dict()
    result['members'] = [x.dict() for x in UserModel.get_by_id(project.member_ids) if not x is None]
    result['labels'] = [x.dict() for x in labels]
    return JsonResponse(result)
コード例 #5
0
def count_issues(request, project_id):
    request_dict = request.GET.dict()
    if "label_ids" in request_dict:
        del request_dict["label_ids"]
    form = IssueSearchForm(label_ids=request.GET.getlist("label_ids"), **request_dict)
    project = ProjectModel.get_by_id(long(project_id))
    if project is None:
        raise Http404
    labels = LabelModel.all().filter("project =", project.key()).fetch(100)

    def append_floor_query(query):
        # floor filter
        if form.floor_lowest.data != 0:
            query = query.filter("floor >=", form.floor_lowest.data)
        if form.floor_highest.data != 0:
            query = query.filter("floor <=", form.floor_highest.data)
        return query

    def append_label_query(query):
        # label filter
        form.label_ids.data = [long(x) for x in form.label_ids.data if x]
        for label_id in form.label_ids.data:
            query = query.filter("label_ids in", [label_id])
        return query

    def append_close_query(query):
        # is_close filter
        if form.status.data == "open":
            query = query.filter("is_close =", False)
        elif form.status.data == "closed":
            query = query.filter("is_close =", True)
        return query

    def append_order_query(query):
        # order
        if form.floor_lowest.data | form.floor_highest.data == 0:
            query = query.order("-create_time")
        else:
            query = query.order("floor").order("-create_time")
        return query

    query = IssueModel.all().filter("project =", project.key())
    query = append_floor_query(query)
    query = append_label_query(query)
    query = query.filter("is_close =", True)
    query = append_order_query(query)
    count_closed = query.count()

    query = IssueModel.all().filter("project =", project.key())
    query = append_floor_query(query)
    query = append_label_query(query)
    query = query.filter("is_close =", False)
    query = append_order_query(query)
    count_open = query.count()

    count_labels = {}
    for label in labels:
        query = IssueModel.all().filter("project =", project.key())
        query = append_floor_query(query)
        query = append_close_query(query)
        query = query.filter("label_ids in", [label.key().id()])
        query = append_order_query(query)
        count_labels[str(label.key().id())] = query.count()

    result = {"all": count_open + count_closed, "open": count_open, "closed": count_closed, "labels": count_labels}
    return JsonResponse(result)