| author | ymh <ymh.work@gmail.com> |
| Tue, 22 Jan 2013 11:25:55 +0100 | |
| changeset 1075 | 66c7a0826bd7 |
| parent 1021 | 56ecf04fe605 |
| child 1115 | 7fc32e1b2abf |
| child 1156 | 662721dc606b |
| 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.models import Group, User |
| 740 | 3 |
from django.core.paginator import Paginator, InvalidPage, EmptyPage |
|
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 |
| 482 | 5 |
from django.shortcuts import render_to_response |
|
338
631c0edee9ea
First commit for front pages. View, templates, and css img added.
cavaliet
parents:
diff
changeset
|
6 |
from django.template import RequestContext |
|
631c0edee9ea
First commit for front pages. View, templates, and css img added.
cavaliet
parents:
diff
changeset
|
7 |
from guardian.shortcuts import get_objects_for_group |
| 480 | 8 |
from ldt.ldt_utils.models import Content, Project |
| 563 | 9 |
from ldt.ldt_utils.forms import SearchForm |
| 710 | 10 |
from ldt.ldt_utils.views.content import get_content_tags |
| 563 | 11 |
from ldt.ldt_utils.views.workspace import get_search_results |
| 1013 | 12 |
from tagging.models import TaggedItem |
|
997
947c8ad09bd6
change of method to have absolute url for static file in views
grandjoncl
parents:
995
diff
changeset
|
13 |
from ldt.utils.url import absstatic |
| 563 | 14 |
import base64 |
15 |
||
|
338
631c0edee9ea
First commit for front pages. View, templates, and css img added.
cavaliet
parents:
diff
changeset
|
16 |
|
|
631c0edee9ea
First commit for front pages. View, templates, and css img added.
cavaliet
parents:
diff
changeset
|
17 |
|
|
631c0edee9ea
First commit for front pages. View, templates, and css img added.
cavaliet
parents:
diff
changeset
|
18 |
def front_home(request): |
|
631c0edee9ea
First commit for front pages. View, templates, and css img added.
cavaliet
parents:
diff
changeset
|
19 |
# Get the 3 last annotated contents |
|
795
923429f142ea
Possibility to list a content on the front or not, with a private media. A media can be private, and the content public (listed or not)
rougeronj
parents:
762
diff
changeset
|
20 |
last_contents = Content.safe_objects.order_by('-stat_annotation__last_annotated').exclude(stat_annotation__nb_annotations=0)[:3] |
|
338
631c0edee9ea
First commit for front pages. View, templates, and css img added.
cavaliet
parents:
diff
changeset
|
21 |
# Get the most annotated contents |
|
795
923429f142ea
Possibility to list a content on the front or not, with a private media. A media can be private, and the content public (listed or not)
rougeronj
parents:
762
diff
changeset
|
22 |
most_contents = Content.safe_objects.order_by('-stat_annotation__nb_annotations')[:8] |
|
338
631c0edee9ea
First commit for front pages. View, templates, and css img added.
cavaliet
parents:
diff
changeset
|
23 |
# Get the active groups |
|
631c0edee9ea
First commit for front pages. View, templates, and css img added.
cavaliet
parents:
diff
changeset
|
24 |
active_groups = Group.objects.exclude(name=settings.PUBLIC_GROUP_NAME)[:5] |
| 409 | 25 |
# Get the main tag list |
|
444
2711eef17092
Update front tag list management with settings/config.
cavaliet
parents:
443
diff
changeset
|
26 |
front_tags = settings.FRONT_TAG_LIST |
|
702
d50cb79f96ee
Add category cloud in front and media page. Correct js pagination in workspace. Languages updated.
cavaliet
parents:
602
diff
changeset
|
27 |
# Get the all tags list |
|
d50cb79f96ee
Add category cloud in front and media page. Correct js pagination in workspace. Languages updated.
cavaliet
parents:
602
diff
changeset
|
28 |
tag_cloud = get_content_tags() |
|
444
2711eef17092
Update front tag list management with settings/config.
cavaliet
parents:
443
diff
changeset
|
29 |
|
|
338
631c0edee9ea
First commit for front pages. View, templates, and css img added.
cavaliet
parents:
diff
changeset
|
30 |
|
|
631c0edee9ea
First commit for front pages. View, templates, and css img added.
cavaliet
parents:
diff
changeset
|
31 |
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
|
32 |
|
|
631c0edee9ea
First commit for front pages. View, templates, and css img added.
cavaliet
parents:
diff
changeset
|
33 |
return render_to_response("front/front_home.html", |
|
444
2711eef17092
Update front tag list management with settings/config.
cavaliet
parents:
443
diff
changeset
|
34 |
{'last_contents': last_contents, 'most_contents':most_contents, 'active_groups':active_groups, 'front_tags':front_tags, |
|
702
d50cb79f96ee
Add category cloud in front and media page. Correct js pagination in workspace. Languages updated.
cavaliet
parents:
602
diff
changeset
|
35 |
'tag_cloud': tag_cloud, 'is_gecko': is_gecko}, |
|
338
631c0edee9ea
First commit for front pages. View, templates, and css img added.
cavaliet
parents:
diff
changeset
|
36 |
context_instance=RequestContext(request)) |
|
631c0edee9ea
First commit for front pages. View, templates, and css img added.
cavaliet
parents:
diff
changeset
|
37 |
|
|
631c0edee9ea
First commit for front pages. View, templates, and css img added.
cavaliet
parents:
diff
changeset
|
38 |
|
|
631c0edee9ea
First commit for front pages. View, templates, and css img added.
cavaliet
parents:
diff
changeset
|
39 |
def group_info(request, group_id): |
|
631c0edee9ea
First commit for front pages. View, templates, and css img added.
cavaliet
parents:
diff
changeset
|
40 |
# Get the active group |
|
631c0edee9ea
First commit for front pages. View, templates, and css img added.
cavaliet
parents:
diff
changeset
|
41 |
group = Group.objects.get(id=group_id) |
|
631c0edee9ea
First commit for front pages. View, templates, and css img added.
cavaliet
parents:
diff
changeset
|
42 |
# 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
|
43 |
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
|
44 |
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
|
45 |
# Group's users |
| 404 | 46 |
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
|
47 |
|
|
631c0edee9ea
First commit for front pages. View, templates, and css img added.
cavaliet
parents:
diff
changeset
|
48 |
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
|
49 |
|
|
631c0edee9ea
First commit for front pages. View, templates, and css img added.
cavaliet
parents:
diff
changeset
|
50 |
return render_to_response("front/front_group.html", |
|
631c0edee9ea
First commit for front pages. View, templates, and css img added.
cavaliet
parents:
diff
changeset
|
51 |
{'group': group, 'content_list':content_list, 'users':users, |
|
631c0edee9ea
First commit for front pages. View, templates, and css img added.
cavaliet
parents:
diff
changeset
|
52 |
'is_gecko': is_gecko}, |
|
631c0edee9ea
First commit for front pages. View, templates, and css img added.
cavaliet
parents:
diff
changeset
|
53 |
context_instance=RequestContext(request)) |
|
631c0edee9ea
First commit for front pages. View, templates, and css img added.
cavaliet
parents:
diff
changeset
|
54 |
|
|
631c0edee9ea
First commit for front pages. View, templates, and css img added.
cavaliet
parents:
diff
changeset
|
55 |
|
| 504 | 56 |
|
| 364 | 57 |
def all_contents(request): |
| 740 | 58 |
# Get the page number parameter if possible |
59 |
page = request.GET.get("page") or 1 |
|
|
762
292b15799db2
quick search in media title in the front. Languages updated.
cavaliet
parents:
741
diff
changeset
|
60 |
# Get the medias title filter if possible |
|
292b15799db2
quick search in media title in the front. Languages updated.
cavaliet
parents:
741
diff
changeset
|
61 |
media_title = request.GET.get("title") |
|
292b15799db2
quick search in media title in the front. Languages updated.
cavaliet
parents:
741
diff
changeset
|
62 |
tag_label = None |
|
292b15799db2
quick search in media title in the front. Languages updated.
cavaliet
parents:
741
diff
changeset
|
63 |
if media_title is None : |
|
292b15799db2
quick search in media title in the front. Languages updated.
cavaliet
parents:
741
diff
changeset
|
64 |
# Get the tag parameter if possible |
|
292b15799db2
quick search in media title in the front. Languages updated.
cavaliet
parents:
741
diff
changeset
|
65 |
tag_label = request.GET.get("tag") |
|
292b15799db2
quick search in media title in the front. Languages updated.
cavaliet
parents:
741
diff
changeset
|
66 |
# Get all the public contents group |
|
292b15799db2
quick search in media title in the front. Languages updated.
cavaliet
parents:
741
diff
changeset
|
67 |
if tag_label is None : |
|
795
923429f142ea
Possibility to list a content on the front or not, with a private media. A media can be private, and the content public (listed or not)
rougeronj
parents:
762
diff
changeset
|
68 |
content_list = Content.safe_objects.all() |
|
762
292b15799db2
quick search in media title in the front. Languages updated.
cavaliet
parents:
741
diff
changeset
|
69 |
else : |
|
795
923429f142ea
Possibility to list a content on the front or not, with a private media. A media can be private, and the content public (listed or not)
rougeronj
parents:
762
diff
changeset
|
70 |
content_list = TaggedItem.objects.get_by_model(Content.safe_objects.all(), '"'+tag_label+'"') |
| 409 | 71 |
else : |
|
795
923429f142ea
Possibility to list a content on the front or not, with a private media. A media can be private, and the content public (listed or not)
rougeronj
parents:
762
diff
changeset
|
72 |
content_list = Content.safe_objects.filter(title__icontains=media_title) |
|
762
292b15799db2
quick search in media title in the front. Languages updated.
cavaliet
parents:
741
diff
changeset
|
73 |
|
| 740 | 74 |
|
75 |
nb = settings.LDT_FRONT_MEDIA_PER_PAGE |
|
76 |
if page=="x": |
|
77 |
nb = content_list.count() |
|
78 |
||
79 |
paginator = Paginator(content_list, nb) |
|
80 |
try: |
|
81 |
results = paginator.page(page) |
|
82 |
except (EmptyPage, InvalidPage): |
|
83 |
results = paginator.page(paginator.num_pages) |
|
84 |
||
| 409 | 85 |
# Get the main tag list |
|
444
2711eef17092
Update front tag list management with settings/config.
cavaliet
parents:
443
diff
changeset
|
86 |
front_tags = settings.FRONT_TAG_LIST |
|
2711eef17092
Update front tag list management with settings/config.
cavaliet
parents:
443
diff
changeset
|
87 |
# Get the all tags list |
| 409 | 88 |
tag_cloud = get_content_tags() |
| 364 | 89 |
|
90 |
is_gecko = ((request.META['HTTP_USER_AGENT'].lower().find("firefox")) > -1); |
|
91 |
||
92 |
return render_to_response("front/front_all_contents.html", |
|
|
762
292b15799db2
quick search in media title in the front. Languages updated.
cavaliet
parents:
741
diff
changeset
|
93 |
{'results':results, 'tag_label':tag_label, 'media_title':media_title, 'front_tags':front_tags, 'tag_cloud':tag_cloud, |
| 364 | 94 |
'is_gecko': is_gecko}, |
95 |
context_instance=RequestContext(request)) |
|
96 |
||
97 |
||
| 399 | 98 |
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
|
99 |
# Get the wanted content |
|
c6a6ea1ce091
First step of player page in front. Old version of metadata player integrated.
cavaliet
parents:
338
diff
changeset
|
100 |
content = Content.objects.get(iri_id=content_iri_id) |
| 543 | 101 |
# Get the content src to see if it is a youtube/dailymotion video |
|
833
20acf3b3b2f0
Embed code corrections : jsonp problem solved, complete adresses in embed_player, display metadataplayer on click when needed, select code on button click, iframe code available in the embed popup
grandjoncl
parents:
795
diff
changeset
|
102 |
annotation_block = True |
| 543 | 103 |
external_url = None |
| 552 | 104 |
if content.src is not None: |
105 |
for external_src in settings.EXTERNAL_STREAM_SRC: |
|
106 |
if external_src in content.src: |
|
107 |
external_url = content.src |
|
108 |
break |
|
| 404 | 109 |
|
| 399 | 110 |
# If project id is not set, we get the default project for the content |
| 404 | 111 |
if project_id is None or project_id == "_": |
|
741
45d814511958
Content PUT api endpoint to add an annotation to a content without giving a project id. #35
cavaliet
parents:
740
diff
changeset
|
112 |
proj = content.get_or_create_front_project() |
| 480 | 113 |
else: |
| 404 | 114 |
proj = Project.safe_objects.get(ldt_id=project_id) |
|
517
2ae1a476a69d
Medias with no annotations are not displayed on front home page
verrierj
parents:
511
diff
changeset
|
115 |
|
|
339
c6a6ea1ce091
First step of player page in front. Old version of metadata player integrated.
cavaliet
parents:
338
diff
changeset
|
116 |
# Vars for player |
|
c6a6ea1ce091
First step of player page in front. Old version of metadata player integrated.
cavaliet
parents:
338
diff
changeset
|
117 |
player_id = "player_project_" + proj.ldt_id |
|
338
631c0edee9ea
First commit for front pages. View, templates, and css img added.
cavaliet
parents:
diff
changeset
|
118 |
|
| 400 | 119 |
if cutting_id is None : |
120 |
json_url = reverse("ldt.ldt_utils.views.json.project_json_id", args=[proj.ldt_id]) |
|
|
517
2ae1a476a69d
Medias with no annotations are not displayed on front home page
verrierj
parents:
511
diff
changeset
|
121 |
else: |
| 400 | 122 |
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
|
123 |
player_width = 550 |
|
c6a6ea1ce091
First step of player page in front. Old version of metadata player integrated.
cavaliet
parents:
338
diff
changeset
|
124 |
player_height = 380 |
|
c6a6ea1ce091
First step of player page in front. Old version of metadata player integrated.
cavaliet
parents:
338
diff
changeset
|
125 |
stream_mode = proj.stream_mode |
|
c6a6ea1ce091
First step of player page in front. Old version of metadata player integrated.
cavaliet
parents:
338
diff
changeset
|
126 |
if stream_mode != "video": |
|
c6a6ea1ce091
First step of player page in front. Old version of metadata player integrated.
cavaliet
parents:
338
diff
changeset
|
127 |
stream_mode = 'radio' |
|
c6a6ea1ce091
First step of player page in front. Old version of metadata player integrated.
cavaliet
parents:
338
diff
changeset
|
128 |
|
|
c6a6ea1ce091
First step of player page in front. Old version of metadata player integrated.
cavaliet
parents:
338
diff
changeset
|
129 |
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
|
130 |
|
|
c6a6ea1ce091
First step of player page in front. Old version of metadata player integrated.
cavaliet
parents:
338
diff
changeset
|
131 |
|
|
c6a6ea1ce091
First step of player page in front. Old version of metadata player integrated.
cavaliet
parents:
338
diff
changeset
|
132 |
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
|
133 |
{'content': content, 'project':proj, 'player_id': player_id, |
| 543 | 134 |
'json_url': json_url, 'player_width':player_width, 'player_height':player_height, 'stream_mode':stream_mode, 'external_url':external_url, |
|
833
20acf3b3b2f0
Embed code corrections : jsonp problem solved, complete adresses in embed_player, display metadataplayer on click when needed, select code on button click, iframe code available in the embed popup
grandjoncl
parents:
795
diff
changeset
|
135 |
'is_gecko': is_gecko, 'annotation_block':annotation_block}, |
|
339
c6a6ea1ce091
First step of player page in front. Old version of metadata player integrated.
cavaliet
parents:
338
diff
changeset
|
136 |
context_instance=RequestContext(request)) |
|
c6a6ea1ce091
First step of player page in front. Old version of metadata player integrated.
cavaliet
parents:
338
diff
changeset
|
137 |
|
|
c6a6ea1ce091
First step of player page in front. Old version of metadata player integrated.
cavaliet
parents:
338
diff
changeset
|
138 |
|
| 348 | 139 |
def search_index(request): |
| 563 | 140 |
language_code = request.LANGUAGE_CODE[:2] |
| 570 | 141 |
nb = 0 |
142 |
results = [] |
|
143 |
search = '' |
|
144 |
field = 'all' |
|
| 602 | 145 |
content_tag = None |
|
997
947c8ad09bd6
change of method to have absolute url for static file in views
grandjoncl
parents:
995
diff
changeset
|
146 |
colorurl=absstatic(request, "ldt/swf/ldt/pkg/color.xml") |
|
947c8ad09bd6
change of method to have absolute url for static file in views
grandjoncl
parents:
995
diff
changeset
|
147 |
i18nurl=absstatic(request, "ldt/swf/ldt/pkg/i18n") |
|
947c8ad09bd6
change of method to have absolute url for static file in views
grandjoncl
parents:
995
diff
changeset
|
148 |
baseurl=absstatic(request, "ldt/swf/ldt/") |
| 570 | 149 |
sform = SearchForm(request.GET) |
| 563 | 150 |
if sform.is_valid(): |
151 |
search = sform.cleaned_data["search"] |
|
| 570 | 152 |
field = sform.cleaned_data["field"] |
153 |
page = sform.cleaned_data["page"] or 1 |
|
| 599 | 154 |
# If asked, we filter the request with only the contents tagged with content_tag |
155 |
content_tag = sform.cleaned_data["content_tag"] |
|
156 |
content_list = None |
|
157 |
if content_tag is not None and content_tag != "" : |
|
158 |
content_list = TaggedItem.objects.get_by_model(Content.objects.all(), '"'+content_tag+'"') |
|
| 1021 | 159 |
results, nb, nb_segment = get_search_results(request, search, field, page, content_list) |
| 348 | 160 |
|
|
997
947c8ad09bd6
change of method to have absolute url for static file in views
grandjoncl
parents:
995
diff
changeset
|
161 |
|
| 1021 | 162 |
return render_to_response('front/front_search_results.html', {'results': results, 'nb_results' : nb, 'nb_segment':nb_segment, 'search' : search, 'field': field, 'tag_label':content_tag, 'colorurl': colorurl, 'i18nurl': i18nurl, 'language': language_code, 'baseurl': baseurl}, context_instance=RequestContext(request)) |
| 409 | 163 |
|
164 |
||
| 710 | 165 |