Esempio n. 1
0
def dashboard(request,
              template_name='reviews/dashboard.html',
              local_site_name=None):
    """
    The dashboard view, showing review requests organized by a variety of
    lists, depending on the 'view' parameter.

    Valid 'view' parameters are:

        * 'outgoing'
        * 'to-me'
        * 'to-group'
        * 'starred'
        * 'watched-groups'
        * 'incoming'
        * 'mine'
    """
    view = request.GET.get('view', None)

    if local_site_name:
        local_site = get_object_or_404(LocalSite, name=local_site_name)
        if not local_site.is_accessible_by(request.user):
            return _render_permission_denied(request)
    else:
        local_site = None

    if view == "watched-groups":
        # This is special. We want to return a list of groups, not
        # review requests.
        grid = WatchedGroupDataGrid(request, local_site=local_site)
    else:
        grid = DashboardDataGrid(request, local_site=local_site)

    return grid.render_to_response(template_name)
Esempio n. 2
0
def manifest(request, manifest_class):
    # TODO: Move this function into ReviewRequest, once it's flexible enough.
    #       Right now it's a duplicate of what's in review_detail.
    def get_last_activity_timestamp(review_request):
        review_timestamp = 0

        if request.user.is_authenticated():
            try:
                last_draft_review = Review.objects.filter(
                    review_request=review_request, user=request.user, public=False
                ).latest()
                review_timestamp = last_draft_review.timestamp
            except Review.DoesNotExist:
                pass

        # Find out if we can bail early. Generate an ETag for this.
        timestamps = [review_request.last_updated]
        draft = review_request.get_draft()

        if draft:
            timestamps.append(draft.last_updated)

        return get_latest_timestamp(timestamps)

    def add_urls_from_datagrid(urls, datagrid, view, group=None):
        datagrid.load_state()

        datagrid_params = "view=%s" % view

        if group:
            datagrid_params += "&group=%s" % group

        datagrid_url = "%s%s?%s" % (url_prefix, reverse("dashboard"), datagrid_params)

        urls.append({"url": datagrid_url, "matchQuery": {"hasAll": datagrid_params}})

        highlighting = get_enable_highlighting(request.user)

        for obj_info in datagrid.rows:
            review_request = obj_info["object"]
            assert isinstance(review_request, ReviewRequest)

            if review_request.id in found_review_requests:
                continue

            found_review_requests[review_request.id] = True

            # Grab the latest activity timestamp.
            # TODO: Make this common between here and review_detail.
            timestamp = get_last_activity_timestamp(review_request)

            if not info["latest_timestamp"] or timestamp > info["latest_timestamp"]:
                info["latest_timestamp"] = timestamp

            urls.append({"url": url_prefix + review_request.get_absolute_url()})

            try:
                diffset = review_request.diffset_history.diffsets.latest()

                view_diff_url = url_prefix + reverse("view_diff", args=[review_request.id])

                urls += [{"url": view_diff_url}, {"url": url_prefix + reverse("raw_diff", args=[review_request.id])}]

                files = get_diff_files(diffset, None, None, highlighting, False)

                # Break the list of files into pages
                siteconfig = SiteConfiguration.objects.get_current()
                paginator = Paginator(
                    files, siteconfig.get("diffviewer_paginate_by"), siteconfig.get("diffviewer_paginate_orphans")
                )

                for pagenum in paginator.page_range:
                    urls.append({"url": "%s?page=%d" % (view_diff_url, pagenum)})
            except DiffSet.DoesNotExist:
                pass

            for screenshot in review_request.screenshots.all():
                urls += [
                    {"url": url_prefix + screenshot.get_absolute_url()},
                    {"url": url_prefix + screenshot.image.url},
                    {"url": url_prefix + screenshot.get_thumbnail_url()},
                ]

    info = {"latest_timestamp": None}

    found_review_requests = {}

    site = Site.objects.get_current()
    siteconfig = SiteConfiguration.objects.get_current()
    url_prefix = "%s://%s" % (siteconfig.get("site_domain_method"), site.domain)

    urls = [{"url": url_prefix + "/dashboard/"}, {"url": url_prefix + "/", "redirect": url_prefix + "/dashboard/"}]

    urls += get_media_urls()

    # Start grabbing all the review requests on the first page of each
    # datagrid.
    for view in ["incoming", "to-me", "starred"]:
        datagrid = DashboardDataGrid(request, view=view)
        datagrid.profile_columns_field = None
        datagrid.default_columns = ["summary"]
        add_urls_from_datagrid(urls, datagrid, view)

    for review_group in request.user.review_groups.all():
        datagrid = DashboardDataGrid(request, view="to-group", group=review_group.name)
        datagrid.profile_columns_field = None
        datagrid.default_columns = ["summary"]
        add_urls_from_datagrid(urls, datagrid, "to-group", review_group.name)

    version = "%s-%s-%s" % (request.user.username, settings.AJAX_SERIAL, settings.MEDIA_SERIAL)

    if info["latest_timestamp"]:
        version += "-%d" % mktime(info["latest_timestamp"].timetuple())

    # TODO: ETags
    return manifest_class(request, version, urls)