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