| author | verrierj |
| Fri, 27 Jan 2012 17:21:56 +0100 | |
| changeset 480 | 5cc5afa71d7e |
| parent 452 | 8e9494006e7b |
| child 482 | c802e00c7131 |
| permissions | -rw-r--r-- |
|
338
631c0edee9ea
First commit for front pages. View, templates, and css img added.
cavaliet
parents:
diff
changeset
|
1 |
from django.conf import settings |
|
631c0edee9ea
First commit for front pages. View, templates, and css img added.
cavaliet
parents:
diff
changeset
|
2 |
from django.contrib.auth.decorators import login_required |
|
631c0edee9ea
First commit for front pages. View, templates, and css img added.
cavaliet
parents:
diff
changeset
|
3 |
from django.contrib.auth.models import Group, User |
|
339
c6a6ea1ce091
First step of player page in front. Old version of metadata player integrated.
cavaliet
parents:
338
diff
changeset
|
4 |
from django.core.urlresolvers import reverse |
|
443
ef326411c1fe
Prepare url, front.py, js and template to load annotation preview.
cavaliet
parents:
409
diff
changeset
|
5 |
from django.http import HttpResponse, HttpResponseServerError |
|
338
631c0edee9ea
First commit for front pages. View, templates, and css img added.
cavaliet
parents:
diff
changeset
|
6 |
from django.shortcuts import render_to_response, get_object_or_404 |
|
631c0edee9ea
First commit for front pages. View, templates, and css img added.
cavaliet
parents:
diff
changeset
|
7 |
from django.template import RequestContext |
|
445
ba508b671698
view annotation_preview returns a true annotation serialized in JSON
verrierj
parents:
444
diff
changeset
|
8 |
from django.utils import simplejson |
|
338
631c0edee9ea
First commit for front pages. View, templates, and css img added.
cavaliet
parents:
diff
changeset
|
9 |
from guardian.shortcuts import get_objects_for_group |
| 480 | 10 |
from ldt.ldt_utils.models import Content, Project |
| 348 | 11 |
from ldt.ldt_utils.views.workspace import search_index as ws_search_index, search_listing as ws_search_listing |
12 |
from ldt.security.utils import add_change_attr |
|
| 409 | 13 |
from tagging.models import Tag, TaggedItem |
|
338
631c0edee9ea
First commit for front pages. View, templates, and css img added.
cavaliet
parents:
diff
changeset
|
14 |
|
|
631c0edee9ea
First commit for front pages. View, templates, and css img added.
cavaliet
parents:
diff
changeset
|
15 |
|
|
631c0edee9ea
First commit for front pages. View, templates, and css img added.
cavaliet
parents:
diff
changeset
|
16 |
@login_required |
|
631c0edee9ea
First commit for front pages. View, templates, and css img added.
cavaliet
parents:
diff
changeset
|
17 |
def front_home(request): |
|
631c0edee9ea
First commit for front pages. View, templates, and css img added.
cavaliet
parents:
diff
changeset
|
18 |
# Get the 3 last annotated contents |
|
354
ecd4d57d0b40
Last annotated contents can be retrieved using the field content.last_annotated
verrierj
parents:
348
diff
changeset
|
19 |
last_contents = Content.objects.order_by('-last_annotated')[:3] |
|
338
631c0edee9ea
First commit for front pages. View, templates, and css img added.
cavaliet
parents:
diff
changeset
|
20 |
# Get the most annotated contents |
| 347 | 21 |
most_contents = Content.objects.order_by('-nb_annotation')[:8] |
|
338
631c0edee9ea
First commit for front pages. View, templates, and css img added.
cavaliet
parents:
diff
changeset
|
22 |
# Get the active groups |
|
631c0edee9ea
First commit for front pages. View, templates, and css img added.
cavaliet
parents:
diff
changeset
|
23 |
active_groups = Group.objects.exclude(name=settings.PUBLIC_GROUP_NAME)[:5] |
| 409 | 24 |
# Get the main tag list |
|
444
2711eef17092
Update front tag list management with settings/config.
cavaliet
parents:
443
diff
changeset
|
25 |
front_tags = settings.FRONT_TAG_LIST |
|
2711eef17092
Update front tag list management with settings/config.
cavaliet
parents:
443
diff
changeset
|
26 |
|
|
338
631c0edee9ea
First commit for front pages. View, templates, and css img added.
cavaliet
parents:
diff
changeset
|
27 |
|
|
631c0edee9ea
First commit for front pages. View, templates, and css img added.
cavaliet
parents:
diff
changeset
|
28 |
is_gecko = ((request.META['HTTP_USER_AGENT'].lower().find("firefox")) > -1); |
|
631c0edee9ea
First commit for front pages. View, templates, and css img added.
cavaliet
parents:
diff
changeset
|
29 |
|
|
631c0edee9ea
First commit for front pages. View, templates, and css img added.
cavaliet
parents:
diff
changeset
|
30 |
return render_to_response("front/front_home.html", |
|
444
2711eef17092
Update front tag list management with settings/config.
cavaliet
parents:
443
diff
changeset
|
31 |
{'last_contents': last_contents, 'most_contents':most_contents, 'active_groups':active_groups, 'front_tags':front_tags, |
|
338
631c0edee9ea
First commit for front pages. View, templates, and css img added.
cavaliet
parents:
diff
changeset
|
32 |
'is_gecko': is_gecko}, |
|
631c0edee9ea
First commit for front pages. View, templates, and css img added.
cavaliet
parents:
diff
changeset
|
33 |
context_instance=RequestContext(request)) |
|
631c0edee9ea
First commit for front pages. View, templates, and css img added.
cavaliet
parents:
diff
changeset
|
34 |
|
|
631c0edee9ea
First commit for front pages. View, templates, and css img added.
cavaliet
parents:
diff
changeset
|
35 |
|
|
631c0edee9ea
First commit for front pages. View, templates, and css img added.
cavaliet
parents:
diff
changeset
|
36 |
@login_required |
|
631c0edee9ea
First commit for front pages. View, templates, and css img added.
cavaliet
parents:
diff
changeset
|
37 |
def group_info(request, group_id): |
|
631c0edee9ea
First commit for front pages. View, templates, and css img added.
cavaliet
parents:
diff
changeset
|
38 |
# Get the active group |
|
631c0edee9ea
First commit for front pages. View, templates, and css img added.
cavaliet
parents:
diff
changeset
|
39 |
group = Group.objects.get(id=group_id) |
|
631c0edee9ea
First commit for front pages. View, templates, and css img added.
cavaliet
parents:
diff
changeset
|
40 |
# list of contents annotated by the group (or everyone) |
|
631c0edee9ea
First commit for front pages. View, templates, and css img added.
cavaliet
parents:
diff
changeset
|
41 |
everyone = Group.objects.get(name=settings.PUBLIC_GROUP_NAME) |
|
631c0edee9ea
First commit for front pages. View, templates, and css img added.
cavaliet
parents:
diff
changeset
|
42 |
content_list = get_objects_for_group(group, 'ldt_utils.view_content') | get_objects_for_group(everyone, 'ldt_utils.view_content') |
|
631c0edee9ea
First commit for front pages. View, templates, and css img added.
cavaliet
parents:
diff
changeset
|
43 |
# Group's users |
| 404 | 44 |
users = User.objects.filter(groups__in=[group]).exclude(is_superuser=True) |
|
338
631c0edee9ea
First commit for front pages. View, templates, and css img added.
cavaliet
parents:
diff
changeset
|
45 |
|
|
631c0edee9ea
First commit for front pages. View, templates, and css img added.
cavaliet
parents:
diff
changeset
|
46 |
is_gecko = ((request.META['HTTP_USER_AGENT'].lower().find("firefox")) > -1); |
|
631c0edee9ea
First commit for front pages. View, templates, and css img added.
cavaliet
parents:
diff
changeset
|
47 |
|
|
631c0edee9ea
First commit for front pages. View, templates, and css img added.
cavaliet
parents:
diff
changeset
|
48 |
return render_to_response("front/front_group.html", |
|
631c0edee9ea
First commit for front pages. View, templates, and css img added.
cavaliet
parents:
diff
changeset
|
49 |
{'group': group, 'content_list':content_list, 'users':users, |
|
631c0edee9ea
First commit for front pages. View, templates, and css img added.
cavaliet
parents:
diff
changeset
|
50 |
'is_gecko': is_gecko}, |
|
631c0edee9ea
First commit for front pages. View, templates, and css img added.
cavaliet
parents:
diff
changeset
|
51 |
context_instance=RequestContext(request)) |
|
631c0edee9ea
First commit for front pages. View, templates, and css img added.
cavaliet
parents:
diff
changeset
|
52 |
|
|
631c0edee9ea
First commit for front pages. View, templates, and css img added.
cavaliet
parents:
diff
changeset
|
53 |
|
|
339
c6a6ea1ce091
First step of player page in front. Old version of metadata player integrated.
cavaliet
parents:
338
diff
changeset
|
54 |
@login_required |
| 364 | 55 |
def all_contents(request): |
| 409 | 56 |
# Get the tag parameter if possible |
57 |
tag_label = request.GET.get("tag") |
|
| 364 | 58 |
# Get all the public contents group |
| 409 | 59 |
if tag_label is None : |
60 |
content_list = add_change_attr(request.user, Content.safe_objects.all()) |
|
61 |
else : |
|
62 |
content_list = TaggedItem.objects.get_by_model(add_change_attr(request.user, Content.safe_objects.all()), '"'+tag_label+'"') |
|
63 |
# Get the main tag list |
|
|
444
2711eef17092
Update front tag list management with settings/config.
cavaliet
parents:
443
diff
changeset
|
64 |
front_tags = settings.FRONT_TAG_LIST |
|
2711eef17092
Update front tag list management with settings/config.
cavaliet
parents:
443
diff
changeset
|
65 |
# Get the all tags list |
| 409 | 66 |
tag_cloud = get_content_tags() |
| 364 | 67 |
|
68 |
is_gecko = ((request.META['HTTP_USER_AGENT'].lower().find("firefox")) > -1); |
|
69 |
||
70 |
return render_to_response("front/front_all_contents.html", |
|
|
444
2711eef17092
Update front tag list management with settings/config.
cavaliet
parents:
443
diff
changeset
|
71 |
{'content_list':content_list, 'tag_label':tag_label, 'front_tags':front_tags, 'tag_cloud':tag_cloud, |
| 364 | 72 |
'is_gecko': is_gecko}, |
73 |
context_instance=RequestContext(request)) |
|
74 |
||
75 |
||
76 |
@login_required |
|
| 399 | 77 |
def annot_content(request, content_iri_id, project_id=None, cutting_id=None): |
|
339
c6a6ea1ce091
First step of player page in front. Old version of metadata player integrated.
cavaliet
parents:
338
diff
changeset
|
78 |
# Get the wanted content |
|
c6a6ea1ce091
First step of player page in front. Old version of metadata player integrated.
cavaliet
parents:
338
diff
changeset
|
79 |
content = Content.objects.get(iri_id=content_iri_id) |
| 377 | 80 |
# Get the content src to see if it is a youtube video |
81 |
youtube_url = None |
|
82 |
if content.src is not None and "youtube.com" in content.src: |
|
83 |
youtube_url = content.src |
|
| 404 | 84 |
|
| 399 | 85 |
# If project id is not set, we get the default project for the content |
| 404 | 86 |
if project_id is None or project_id == "_": |
87 |
front_proj = content.front_project |
|
88 |
if front_proj: |
|
89 |
proj = front_proj |
|
90 |
else: |
|
91 |
# The main project for the content |
|
92 |
proj = Project.safe_objects.filter(contents__in=[content])[0] |
|
| 480 | 93 |
else: |
| 404 | 94 |
proj = Project.safe_objects.get(ldt_id=project_id) |
| 409 | 95 |
|
|
339
c6a6ea1ce091
First step of player page in front. Old version of metadata player integrated.
cavaliet
parents:
338
diff
changeset
|
96 |
# Vars for player |
|
c6a6ea1ce091
First step of player page in front. Old version of metadata player integrated.
cavaliet
parents:
338
diff
changeset
|
97 |
player_id = "player_project_" + proj.ldt_id |
|
338
631c0edee9ea
First commit for front pages. View, templates, and css img added.
cavaliet
parents:
diff
changeset
|
98 |
|
| 400 | 99 |
if cutting_id is None : |
100 |
json_url = reverse("ldt.ldt_utils.views.json.project_json_id", args=[proj.ldt_id]) |
|
101 |
else : |
|
102 |
json_url = reverse("ldt.ldt_utils.views.json.project_json_cutting_id", args=[proj.ldt_id, cutting_id]) |
|
|
339
c6a6ea1ce091
First step of player page in front. Old version of metadata player integrated.
cavaliet
parents:
338
diff
changeset
|
103 |
player_width = 550 |
|
c6a6ea1ce091
First step of player page in front. Old version of metadata player integrated.
cavaliet
parents:
338
diff
changeset
|
104 |
player_height = 380 |
|
c6a6ea1ce091
First step of player page in front. Old version of metadata player integrated.
cavaliet
parents:
338
diff
changeset
|
105 |
stream_mode = proj.stream_mode |
|
c6a6ea1ce091
First step of player page in front. Old version of metadata player integrated.
cavaliet
parents:
338
diff
changeset
|
106 |
if stream_mode != "video": |
|
c6a6ea1ce091
First step of player page in front. Old version of metadata player integrated.
cavaliet
parents:
338
diff
changeset
|
107 |
stream_mode = 'radio' |
|
c6a6ea1ce091
First step of player page in front. Old version of metadata player integrated.
cavaliet
parents:
338
diff
changeset
|
108 |
|
|
c6a6ea1ce091
First step of player page in front. Old version of metadata player integrated.
cavaliet
parents:
338
diff
changeset
|
109 |
is_gecko = ((request.META['HTTP_USER_AGENT'].lower().find("firefox")) > -1); |
|
c6a6ea1ce091
First step of player page in front. Old version of metadata player integrated.
cavaliet
parents:
338
diff
changeset
|
110 |
|
|
c6a6ea1ce091
First step of player page in front. Old version of metadata player integrated.
cavaliet
parents:
338
diff
changeset
|
111 |
|
|
c6a6ea1ce091
First step of player page in front. Old version of metadata player integrated.
cavaliet
parents:
338
diff
changeset
|
112 |
return render_to_response("front/front_player.html", |
|
c6a6ea1ce091
First step of player page in front. Old version of metadata player integrated.
cavaliet
parents:
338
diff
changeset
|
113 |
{'content': content, 'project':proj, 'player_id': player_id, |
| 377 | 114 |
'json_url': json_url, 'player_width':player_width, 'player_height':player_height, 'stream_mode':stream_mode, 'youtube_url':youtube_url, |
|
339
c6a6ea1ce091
First step of player page in front. Old version of metadata player integrated.
cavaliet
parents:
338
diff
changeset
|
115 |
'is_gecko': is_gecko}, |
|
c6a6ea1ce091
First step of player page in front. Old version of metadata player integrated.
cavaliet
parents:
338
diff
changeset
|
116 |
context_instance=RequestContext(request)) |
|
c6a6ea1ce091
First step of player page in front. Old version of metadata player integrated.
cavaliet
parents:
338
diff
changeset
|
117 |
|
|
c6a6ea1ce091
First step of player page in front. Old version of metadata player integrated.
cavaliet
parents:
338
diff
changeset
|
118 |
|
| 348 | 119 |
@login_required |
120 |
def search_index(request): |
|
121 |
return ws_search_index(request, front_template=True) |
|
122 |
||
123 |
||
124 |
@login_required |
|
125 |
def search_listing(request): |
|
126 |
return ws_search_listing(request, front_template=True) |
|
| 409 | 127 |
|
128 |
||
129 |
def get_content_tags(limit=None, steps=10): |
|
130 |
if limit is None: |
|
131 |
return Tag.objects.cloud_for_model(Content, steps=steps) |
|
132 |
else : |
|
133 |
return Tag.objects.cloud_for_model(Content, steps=steps)[:limit] |