Ejemplo n.º 1
0
def get_random_public_images():
    """
    This will return a list of 5 random images that are from public sources only.
    These will be displayed on the front page to be seen in all their glory
    """
    public_sources_list = Source.get_public_sources()

    # return empty list if no public sources
    if len(public_sources_list) == 0:
        return public_sources_list

    random_source_list = []
    random_image_list = []

    # get 5 random public sources
    for i in range(5):
        random_source = choice(public_sources_list)
        random_source_list.append(random_source)

    # get a random image from each randomly chosen public source
    for source in random_source_list:
        all_images = source.get_all_images()

        if len(all_images) == 0:
            continue

        random_image = choice(all_images)
        random_image_list.append(random_image)

    return random_image_list
Ejemplo n.º 2
0
def source_about(request):
    """
    Page that explains what Sources are and how to use them.
    """

    if request.user.is_authenticated():
        if Source.get_sources_of_user(request.user):
            user_status = 'has_sources'
        else:
            user_status = 'no_sources'
    else:
        user_status = 'anonymous'

    return render_to_response('images/source_about.html', {
        'user_status': user_status,
        'public_sources': Source.get_public_sources(),
        },
        context_instance=RequestContext(request)
    )
Ejemplo n.º 3
0
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'))
Ejemplo n.º 4
0
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)
        
        if your_sources:
            return render_to_response('images/source_list.html', {
                'your_sources': your_sources_dicts,
                'other_public_sources': other_public_sources,
                },
                context_instance=RequestContext(request)
            )

    return HttpResponseRedirect(reverse('source_about'))
Ejemplo n.º 5
0
def label_main(request, label_id):
    """
    Main page for a particular label
    """

    label = get_object_or_404(Label, id=label_id)

    sources_with_label = Source.objects.filter(labelset__labels=label).order_by('name')
    visible_sources_with_label = [s for s in sources_with_label if s.visible_to_user(request.user)]

    # Differentiate between the sources that the user is part of
    # and the other public sources.  Sort the source list accordingly, too.
    sources_of_user = Source.get_sources_of_user(request.user)

    source_types = []
    for s in visible_sources_with_label:
        if s in sources_of_user:
            source_types.append('mine')
        else:
            source_types.append('public')

    visible_sources_with_label = zip(source_types, visible_sources_with_label)
    visible_sources_with_label.sort(key=lambda x: x[0])  # Mine first, then public

    # Example patches.
    # TODO: don't hardcode the patch path
    example_annotations = Annotation.objects.filter(label=label, image__source__visibility=Source.VisibilityTypes.PUBLIC).exclude(user=get_robot_user()).order_by('?')[:5]
    patches = [dict(
                  annotation=a,
                  fullImage=a.image,
                  source=a.image.source,
                  patchPath="data/annotations/" + str(a.id) + ".jpg",
                  row=a.point.row,
                  col=a.point.column,
                  pointNum=a.point.point_number,
              )
              for a in example_annotations]

    for p in patches:
        generate_patch_if_doesnt_exist(p['patchPath'], p['annotation'])


    return render_to_response('annotations/label_main.html', {
        'label': label,
        'visible_sources_with_label': visible_sources_with_label,
        'patches': patches,
        },
        context_instance=RequestContext(request)
    )