Exemplo 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
Exemplo 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)
    )