5 from django.utils.html import escape |
5 from django.utils.html import escape |
6 from django.utils.translation import ugettext as _ |
6 from django.utils.translation import ugettext as _ |
7 from ldt.ldt_utils.models import Project |
7 from ldt.ldt_utils.models import Project |
8 from ldt.ldt_utils.projectserializer import ProjectSerializer |
8 from ldt.ldt_utils.projectserializer import ProjectSerializer |
9 import ldt.auth as ldt_auth |
9 import ldt.auth as ldt_auth |
|
10 from guardian.shortcuts import get_objects_for_user |
10 |
11 |
11 def project_json_id(request, id): |
12 def project_json_id(request, id): |
12 |
13 |
13 project = get_object_or_404(Project.safe_objects, ldt_id=id) |
14 project = get_object_or_404(Project.safe_objects, ldt_id=id) |
14 |
15 |
15 return project_json(request, project, False) |
16 return project_json(request, project, False) |
16 |
17 |
|
18 def project_json_cutting_id(request, id, cutting_id): |
|
19 |
|
20 project = get_object_or_404(Project.safe_objects, ldt_id=id) |
|
21 |
|
22 return project_json(request, project, first_cutting=cutting_id) |
17 |
23 |
18 def project_json_externalid(request, id): |
24 def project_json_externalid(request, id): |
19 |
25 |
20 res_proj = get_list_or_404(Project.safe_objects.order_by('-modification_date'), contents__external_id=id) #@UndefinedVariable |
26 res_proj = get_list_or_404(Project.safe_objects.order_by('-modification_date'), contents__external_id=id) #@UndefinedVariable |
21 |
27 |
22 return project_json(request, res_proj[0], False) |
28 return project_json(request, res_proj[0], False) |
23 |
29 |
24 |
30 |
25 |
31 |
26 def project_json(request, project, serialize_contents=True): # Not checked |
32 def project_json(request, project, serialize_contents=True, first_cutting=None): # Not checked |
27 |
33 |
28 if not ldt_auth.check_access(request.user, project): |
34 if not ldt_auth.check_access(request.user, project): |
29 return HttpResponseForbidden(_("You can not access this project")) |
35 return HttpResponseForbidden(_("You can not access this project")) |
30 |
36 |
31 mimetype = request.REQUEST.get("mimetype") |
37 mimetype = request.REQUEST.get("mimetype") |
49 escape_str = request.REQUEST.get("escape") |
55 escape_str = request.REQUEST.get("escape") |
50 escape_bool = False |
56 escape_bool = False |
51 if escape_str: |
57 if escape_str: |
52 escape_bool = {'true': True, 'false': False, "0": False, "1": True}.get(escape_str.lower()) |
58 escape_bool = {'true': True, 'false': False, "0": False, "1": True}.get(escape_str.lower()) |
53 |
59 |
54 |
60 viewable_contents = get_objects_for_user(request.user, 'ldt_utils.view_content', klass=project.contents.all()) |
55 ps = ProjectSerializer(project, serialize_contents) |
61 viewable_contents = [c.iri_id for c in viewable_contents] |
|
62 ps = ProjectSerializer(project, serialize_contents, viewable_contents=viewable_contents, first_cutting=first_cutting) |
56 project_dict = ps.serialize_to_cinelab() |
63 project_dict = ps.serialize_to_cinelab() |
57 |
64 |
58 json_str = simplejson.dumps(project_dict, ensure_ascii=False, indent=indent) |
65 json_str = simplejson.dumps(project_dict, ensure_ascii=False, indent=indent) |
59 |
66 |
60 if callback is not None: |
67 if callback is not None: |