示例#1
0
文件: views.py 项目: DevangS/CoralNet
def index(request):
    """
    This view renders the front page.
    """

    if request.user.is_authenticated():
        return HttpResponseRedirect(reverse("source_list"))

    # Here we get the map sources
    map_sources = get_map_sources()

    list_thumbnails = []
    # Here we get a list of a list of images, these will be displayed
    # within each of the description windows.
    # the latest images source will not be passed into the javascript functions
    for source in map_sources:
        list_thumbnails.append((source["latest_images"], source["id"]))
        del source["latest_images"]

    # and here we get 5 random public images
    images = get_random_public_images()

    # Gather some stats
    total_sources = Source.objects.all().count()
    total_images = Image.objects.all().count()
    human_annotations = Point.objects.filter(image__status__annotatedByHuman=True).count()
    robot_annotations = Point.objects.filter(image__status__annotatedByRobot=True).count()
    total_annotations = human_annotations + robot_annotations

    return render_to_response(
        "lib/index.html",
        {
            "google_maps_api_key": settings.GOOGLE_MAPS_API_KEY,
            "map_sources": map_sources,
            "total_sources": total_sources,
            "total_images": total_images,
            "total_annotations": total_annotations,
            "human_annotations": human_annotations,
            "robot_annotations": robot_annotations,
            "images": images,
            "list_thumbnails": list_thumbnails,
        },
        context_instance=RequestContext(request),
    )
示例#2
0
文件: views.py 项目: DevangS/CoralNet
def source_list(request):
    """
    Page with a list of the user's Sources.
    Redirect to the About page if the user isn't logged in or doesn't have any Sources.
    """

    if request.user.is_authenticated():
        your_sources = Source.get_sources_of_user(request.user)
        your_sources_dicts = [dict(id=s.id,
                                   name=s.name,
                                   your_role=s.get_member_role(request.user),)
                              for s in your_sources]
        other_public_sources = Source.get_other_public_sources(request.user)

        # Here we get the map sources
        map_sources = get_map_sources()

        list_thumbnails = []
        # Here we get a list of a list of images, these will be displayed
        # within each of the description windows.
        # the latest images source will not be passed into the javascript functions
        for source in map_sources:
            list_thumbnails.append((source["latest_images"],source["id"]))
            del source["latest_images"]
        
        if your_sources:
            return render_to_response('images/source_list.html', {
                'your_sources': your_sources_dicts,
                'map_sources': map_sources,
                'google_maps_api_key': settings.GOOGLE_MAPS_API_KEY,
                'other_public_sources': other_public_sources,
                'list_thumbnails': list_thumbnails,
                },
                context_instance=RequestContext(request)
            )

    # not used
    return HttpResponseRedirect(reverse('source_about'))