Ejemplo n.º 1
0
def get_submission(request, project, submission):
    submissions = Submission.objects.filter(
        name=submission,
        submissionbuild__product__name=project
        ).prefetch_related(
            'submissionbuild_set__group__imagebuild_set',
            'owner',
            'gittree',
            )
    if submissions:
        sng = SubmissionGroup(submissions)
        bdg = sng.buildgroup(project)
        detail = {
            'submission': submission,
            'target_project': project,
            'commit': sorted(list(sng.commit)),
            'submitter': sorted([u.email for u in sng.owner]),
            'download_url': bdg.download_url if bdg else '',
            'git_trees': sorted([g.gitpath for g in sng.gittree]),
            'images': sorted([
                (i.name, i.STATUS[i.status])
                for i in bdg.imagebuild_set.all()]) if bdg else [],
        }
        return HttpResponse(
            json.dumps(detail),
            content_type="application/json")
    else:
        return HttpResponseNotFound(
            json.dumps({'reason': 'submission can not be found'}),
            content_type="application/json")
Ejemplo n.º 2
0
def get_submission(request, project, submission):
    submissions = Submission.objects.filter(
        name=submission,
        submissionbuild__product__name=project).prefetch_related(
            'submissionbuild_set__group__imagebuild_set',
            'owner',
            'gittree',
        )
    if submissions:
        sng = SubmissionGroup(submissions)
        bdg = sng.buildgroup(project)
        detail = {
            'submission':
            submission,
            'target_project':
            project,
            'commit':
            sorted(list(sng.commit)),
            'submitter':
            sorted([u.email for u in sng.owner]),
            'download_url':
            bdg.download_url if bdg else '',
            'git_trees':
            sorted([g.gitpath for g in sng.gittree]),
            'images':
            sorted([(i.name, i.STATUS[i.status])
                    for i in bdg.imagebuild_set.all()]) if bdg else [],
        }
        return HttpResponse(json.dumps(detail),
                            content_type="application/json")
    else:
        return HttpResponseNotFound(json.dumps(
            {'reason': 'submission can not be found'}),
                                    content_type="application/json")
Ejemplo n.º 3
0
def snapshot(request, pkid):
    snapshot = get_object_or_404(Snapshot, id=pkid)
    groups = SubmissionGroup.group(snapshot.submissions)

    # get snapshots with the same product
    snapshots = list(Snapshot.snapshots_with_same_product(snapshot.product))
    st_len = len(snapshots)
    first_item = False
    last_item = False
    pre_st = None
    next_st = None
    current_index = snapshots.index(snapshot)
    if current_index == 0:
        first_item = True
    else:
        pre_st = snapshots[current_index-1]
    if current_index == (st_len -1):
        last_item = True
    else:
        next_st = snapshots[current_index+1]
    return render(request, 'submissions/read/single/snapshot.html', {
            'snapshot': snapshot,
            'groups': groups,
            'pre_st': pre_st,
            'next_st': next_st,
            'first_item': first_item,
            'last_item': last_item,
            })
Ejemplo n.º 4
0
def search(request):
    """Search submissions by keyword """
    querystring = request.GET.get('kw')
    if not querystring:
        return HttpResponseBadRequest('error')
    kw = parse_query_string(querystring)
    st = kw.pop('status', None) if kw else None
    subs = Submission.objects.select_related('owner', 'gittree', 'product')
    if kw:
        query = make_query_conditions(kw)
        subs = subs.filter(query)
    else:
        subs = subs.all()

    show_snapshot = False
    if st:
        if st == DISPLAY_STATUS['OPENED']:
            subs = {sub for sub in subs if sub.opened}
        if st == DISPLAY_STATUS['REJECTED']:
            subs = {sub for sub in subs if sub.rejected}
        if st == DISPLAY_STATUS['ACCEPTED']:
            subs = {sub for sub in subs if sub.accepted}
            show_snapshot = True

    return render(
        request,
        'submissions/summary.html',
        {'title': 'Search result for "%s"' % querystring,
         'results': SubmissionGroup.group(subs, st),
         'keyword': querystring,
         'show_snapshot': show_snapshot
        })
Ejemplo n.º 5
0
def snapshot(request, pkid):
    snapshot = get_object_or_404(Snapshot, id=pkid)
    groups = SubmissionGroup.group(snapshot.submissions)

    # get snapshots with the same product
    snapshots = list(Snapshot.snapshots_with_same_product(snapshot.product))
    st_len = len(snapshots)
    first_item = False
    last_item = False
    pre_st = None
    next_st = None
    current_index = snapshots.index(snapshot)
    if current_index == 0:
        first_item = True
    else:
        pre_st = snapshots[current_index - 1]
    if current_index == (st_len - 1):
        last_item = True
    else:
        next_st = snapshots[current_index + 1]
    return render(
        request, 'submissions/read/single/snapshot.html', {
            'snapshot': snapshot,
            'groups': groups,
            'pre_st': pre_st,
            'next_st': next_st,
            'first_item': first_item,
            'last_item': last_item,
        })
Ejemplo n.º 6
0
def search(request):
    """Search submissions by keyword """
    querystring = request.GET.get('kw')
    if not querystring:
        return HttpResponseBadRequest('error')
    kw = parse_query_string(querystring)
    st = kw.pop('status', None) if kw else None
    subs = Submission.objects.select_related('owner', 'gittree', 'product')
    if kw:
        query = make_query_conditions(kw)
        subs = subs.filter(query)
    else:
        subs = subs.all()

    show_snapshot = False
    if st:
        if st == DISPLAY_STATUS['OPENED']:
            subs = {sub for sub in subs if sub.opened}
        if st == DISPLAY_STATUS['REJECTED']:
            subs = {sub for sub in subs if sub.rejected}
        if st == DISPLAY_STATUS['ACCEPTED']:
            subs = {sub for sub in subs if sub.accepted}
            show_snapshot = True

    return render(
        request, 'submissions/summary.html', {
            'title': 'Search result for "%s"' % querystring,
            'results': SubmissionGroup.group(subs, st),
            'keyword': querystring,
            'show_snapshot': show_snapshot
        })
Ejemplo n.º 7
0
def rejected(request):
    """
    All rejected submissions
    """
    subs = [sub for sub in get_submissions() if sub.rejected]
    return render(request, 'submissions/summary.html', {
        'title': 'All rejected submissions',
        'results': SubmissionGroup.group(subs, DISPLAY_STATUS['REJECTED']),
        'keyword': 'status:%s' % DISPLAY_STATUS['REJECTED'],
        })
Ejemplo n.º 8
0
def accepted(request):
    """
    All accepted submissions
    """
    subs = [sub for sub in get_submissions() if sub.accepted]
    return render(request, 'submissions/summary.html', {
        'title': 'All accepted submissions',
        'results': SubmissionGroup.group(subs, DISPLAY_STATUS['ACCEPTED']),
        'keyword': 'status:%s' % DISPLAY_STATUS['ACCEPTED'],
        'show_snapshot': True,
        })
Ejemplo n.º 9
0
def rejected(request):
    """
    All rejected submissions
    """
    subs = [sub for sub in get_submissions() if sub.rejected]
    return render(
        request, 'submissions/summary.html', {
            'title': 'All rejected submissions',
            'results': SubmissionGroup.group(subs, DISPLAY_STATUS['REJECTED']),
            'keyword': 'status:%s' % DISPLAY_STATUS['REJECTED'],
        })
Ejemplo n.º 10
0
def mine(request):
    """
    All my (the logged-in user) opened submissions
    TODO: add menu as all did, show opened, rejected, accepted
    """
    subs = [sub for sub in get_submissions(owner=request.user) if sub.opened]
    return render(request, 'submissions/summary.html', {
        'title': 'My submissions',
        'results': SubmissionGroup.group(subs, DISPLAY_STATUS['OPENED']),
        'keyword': 'status:%s owner:%s' % (DISPLAY_STATUS['OPENED'],
                                           request.user.email)
        })
Ejemplo n.º 11
0
def accepted(request):
    """
    All accepted submissions
    """
    subs = [sub for sub in get_submissions() if sub.accepted]
    return render(
        request, 'submissions/summary.html', {
            'title': 'All accepted submissions',
            'results': SubmissionGroup.group(subs, DISPLAY_STATUS['ACCEPTED']),
            'keyword': 'status:%s' % DISPLAY_STATUS['ACCEPTED'],
            'show_snapshot': True,
        })
Ejemplo n.º 12
0
def mine(request):
    """
    All my (the logged-in user) opened submissions
    TODO: add menu as all did, show opened, rejected, accepted
    """
    subs = [sub for sub in get_submissions(owner=request.user) if sub.opened]
    return render(
        request, 'submissions/summary.html', {
            'title':
            'My submissions',
            'results':
            SubmissionGroup.group(subs, DISPLAY_STATUS['OPENED']),
            'keyword':
            'status:%s owner:%s' %
            (DISPLAY_STATUS['OPENED'], request.user.email)
        })
Ejemplo n.º 13
0
def detail(request, tag):
    """
    Detail info about a submission group identified by certain tag
    """
    groups = SubmissionGroup.group(
        Submission.objects.filter(name=tag.rstrip('/')))
    if not groups:
        raise Http404

    assert len(groups) == 1  # because it's group by tag
    sgroup = groups[0]
    bgroups = submission_group_to_build_groups(sgroup)

    return render(request, 'submissions/detail.html', {
        'sgroup': sgroup,
        'bgroups': bgroups,
    })
Ejemplo n.º 14
0
def detail(request, tag):
    """
    Detail info about a submission group identified by certain tag
    """
    groups = SubmissionGroup.group(
        Submission.objects.filter(name=tag.rstrip('/')))
    if not groups:
        raise Http404

    assert len(groups) == 1  # because it's group by tag
    sgroup = groups[0]
    bgroups = submission_group_to_build_groups(sgroup)

    return render(
        request,
        'submissions/detail.html',
        {'sgroup': sgroup,
         'bgroups': bgroups,
        })
Ejemplo n.º 15
0
def snapshot_by_product(request, product_id, offset=0, limit=10):
    """
        if change limit, please also update the value in template:
        iris/submissions/templates/submissions/read/multiple/snapshots.html
    """

    pro = Product.objects.get(pk=product_id)
    all_snapshots = Snapshot.snapshots_with_same_product(pro)

    offset = int(offset)
    limit = int(limit)
    end = offset + limit
    more_data = True
    if end >= len(all_snapshots):
        more_data = False

    snapshots = all_snapshots[offset:end]
    for snapshot in snapshots:
        groups = SubmissionGroup.group(snapshot.submissions)
        snapshot.groups = sorted(groups,
                                 key=lambda group: group.name,
                                 reverse=True)

    if request.is_ajax():
        response = render(
            request, 'submissions/read/multiple/snapshot_submissions.html', {
                'snapshots': snapshots,
                'product': pro,
            })
        response['X-No-More'] = more_data
        return response
    else:
        return render(request, 'submissions/read/multiple/snapshots.html', {
            'snapshots': snapshots,
            'product': pro,
            'more_data': more_data,
        })
Ejemplo n.º 16
0
def snapshot_by_product(request, product_id, offset=0, limit=10):
    """
        if change limit, please also update the value in template:
        iris/submissions/templates/submissions/read/multiple/snapshots.html
    """

    pro = Product.objects.get(pk=product_id)
    all_snapshots = Snapshot.snapshots_with_same_product(pro)

    offset = int(offset)
    limit = int(limit)
    end = offset + limit
    more_data = True
    if end >= len(all_snapshots):
        more_data = False

    snapshots = all_snapshots[offset:end]
    for snapshot in snapshots:
        groups = SubmissionGroup.group(snapshot.submissions)
        snapshot.groups = sorted(groups,
                                key=lambda group: group.name,
                                reverse=True)

    if request.is_ajax():
        response = render(request, 'submissions/read/multiple/snapshot_submissions.html', {
                'snapshots': snapshots,
                'product': pro,
        })
        response['X-No-More'] = more_data
        return response
    else:
        return render(request, 'submissions/read/multiple/snapshots.html', {
                'snapshots': snapshots,
                'product': pro,
                'more_data': more_data,
            })