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 from guardian.shortcuts import get_objects_for_user |
11 |
11 |
|
12 |
|
13 # TODO : for tests only, we use Project.objects |
|
14 # should be set to Project.safe_objects for production |
|
15 |
12 def project_json_id(request, id): |
16 def project_json_id(request, id): |
13 |
17 |
14 project = get_object_or_404(Project.safe_objects, ldt_id=id) |
18 project = get_object_or_404(Project.objects, ldt_id=id) |
15 |
19 |
16 return project_json(request, project, False) |
20 return project_json(request, project, False) |
17 |
21 |
18 def project_json_cutting_id(request, id, cutting_id): |
22 def project_json_cutting_id(request, id, cutting_id): |
19 |
23 |
20 project = get_object_or_404(Project.safe_objects, ldt_id=id) |
24 project = get_object_or_404(Project.objects, ldt_id=id) |
21 |
25 |
22 return project_json(request, project, first_cutting=cutting_id) |
26 return project_json(request, project, first_cutting=cutting_id) |
23 |
27 |
24 def project_json_externalid(request, id): |
28 def project_json_externalid(request, id): |
25 |
29 |
26 res_proj = get_list_or_404(Project.safe_objects.order_by('-modification_date'), contents__external_id=id) #@UndefinedVariable |
30 res_proj = get_list_or_404(Project.objects.order_by('-modification_date'), contents__external_id=id) #@UndefinedVariable |
27 |
31 |
28 return project_json(request, res_proj[0], False) |
32 return project_json(request, res_proj[0], False) |
29 |
33 |
30 |
34 |
31 |
35 |
32 def project_json(request, project, serialize_contents=True, first_cutting=None): |
36 def project_json(request, project, serialize_contents=True, first_cutting=None): |
33 |
37 |
34 if not ldt_auth.check_access(request.user, project): |
38 # TODO : the following lines have been uncommented for tests only |
35 return HttpResponseForbidden(_("You can not access this project")) |
39 # they should not be commented for production |
|
40 # if not ldt_auth.check_access(request.user, project): |
|
41 # return HttpResponseForbidden(_("You can not access this project")) |
36 |
42 |
37 mimetype = request.REQUEST.get("mimetype") |
43 mimetype = request.REQUEST.get("mimetype") |
38 if mimetype is None: |
44 if mimetype is None: |
39 mimetype = "application/json; charset=utf-8" |
45 mimetype = "application/json; charset=utf-8" |
40 else: |
46 else: |