src/ldt/ldt/ldt_utils/views/front.py
author cavaliet
Mon, 09 Jan 2012 18:58:42 +0100
changeset 339 c6a6ea1ce091
parent 338 631c0edee9ea
child 347 271235724f54
permissions -rw-r--r--
First step of player page in front. Old version of metadata player integrated.

from django.conf import settings
from django.contrib.auth.decorators import login_required
from django.contrib.auth.models import Group, User
from django.core.urlresolvers import reverse
from django.http import HttpResponseServerError
from django.shortcuts import render_to_response, get_object_or_404
from django.template import RequestContext
from guardian.shortcuts import get_objects_for_group
from ldt.ldt_utils.models import Content, Project
from ldt.security.utils import add_change_attr


@login_required
def front_home(request):
    # Get the 3 last annotated contents
    last_contents = Content.objects.all()[:3]
    # Get the most annotated contents
    most_contents = Content.objects.all()[4:12]
    # Get the active groups
    active_groups = Group.objects.exclude(name=settings.PUBLIC_GROUP_NAME)[:5]
    
    
    is_gecko = ((request.META['HTTP_USER_AGENT'].lower().find("firefox")) > -1);

    return render_to_response("front/front_home.html",
                              {'last_contents': last_contents, 'most_contents':most_contents, 'active_groups':active_groups,
                               'is_gecko': is_gecko},
                              context_instance=RequestContext(request))


@login_required
def group_info(request, group_id):
    # Get the active group
    group = Group.objects.get(id=group_id)
    # list of contents annotated by the group (or everyone)
    everyone = Group.objects.get(name=settings.PUBLIC_GROUP_NAME)
    content_list = get_objects_for_group(group, 'ldt_utils.view_content') | get_objects_for_group(everyone, 'ldt_utils.view_content')
    # Group's users
    users = User.objects.filter(groups__in=[group])
    
    is_gecko = ((request.META['HTTP_USER_AGENT'].lower().find("firefox")) > -1);

    return render_to_response("front/front_group.html",
                              {'group': group, 'content_list':content_list, 'users':users,
                               'is_gecko': is_gecko},
                              context_instance=RequestContext(request))


@login_required
def annot_content(request, content_iri_id):
    # Get the wanted content
    content = Content.objects.get(iri_id=content_iri_id)
    # The main project for the content
    proj = Project.objects.filter(contents__in=[content])[0]
    # Vars for player
    player_id = "player_project_" + proj.ldt_id
    
    json_url = reverse("ldt.ldt_utils.views.json.project_json_id", args=[proj.ldt_id])
    player_width = 550
    player_height = 380
    stream_mode = proj.stream_mode
    if stream_mode != "video":
        stream_mode = 'radio'
    
    is_gecko = ((request.META['HTTP_USER_AGENT'].lower().find("firefox")) > -1);


    return render_to_response("front/front_player.html",
                              {'content': content, 'project':proj, 'player_id': player_id, 
                              'json_url': json_url, 'player_width':player_width, 'player_height':player_height, 'stream_mode':stream_mode,
                               'is_gecko': is_gecko},
                              context_instance=RequestContext(request))