| author | veltr |
| Fri, 27 Jan 2012 15:57:14 +0100 | |
| changeset 477 | 1c4894a4de72 |
| parent 467 | a1e9f5e91791 |
| child 534 | e2d15b14ce56 |
| permissions | -rw-r--r-- |
| 63 | 1 |
from django.conf.urls.defaults import patterns, url |
| 0 | 2 |
from django.contrib import admin |
3 |
from django.shortcuts import render_to_response |
|
4 |
from django.template import RequestContext |
|
| 77 | 5 |
from ldt.ldt_utils.contentindexer import ContentIndexer, ProjectIndexer |
| 63 | 6 |
from ldt.ldt_utils.fileimport import FileImport, FileImportError |
|
340
5f919a978f50
Stats for annotations volume can be computed using ./manage.py statannotation [-c content_id] or in the admin pages of module ldt_utils.
verrierj
parents:
249
diff
changeset
|
7 |
from ldt.ldt_utils.forms import LdtImportForm, ReindexForm, StatAnnotationForm |
|
467
a1e9f5e91791
Removed object AnnotationStat + stats are computed when projects are published/unpublished
verrierj
parents:
393
diff
changeset
|
8 |
from ldt.ldt_utils.models import Content, Project, Media, Author |
| 77 | 9 |
import ldt.indexation |
|
230
39d97d561c60
Add admin panel to manage permissions for Content and Project
verrierj
parents:
167
diff
changeset
|
10 |
from guardian.admin import GuardedModelAdmin |
| 0 | 11 |
|
|
393
fa07a599883c
GroupProfile and AnnotationStat are editable in admin pages
verrierj
parents:
343
diff
changeset
|
12 |
|
|
230
39d97d561c60
Add admin panel to manage permissions for Content and Project
verrierj
parents:
167
diff
changeset
|
13 |
class ProjectAdmin(GuardedModelAdmin): |
|
467
a1e9f5e91791
Removed object AnnotationStat + stats are computed when projects are published/unpublished
verrierj
parents:
393
diff
changeset
|
14 |
pass |
| 0 | 15 |
|
|
249
5c5fab6d8ae8
Add admin permission panel to Group, Media, Author
verrierj
parents:
230
diff
changeset
|
16 |
class AuthorAdmin(GuardedModelAdmin): |
|
5c5fab6d8ae8
Add admin permission panel to Group, Media, Author
verrierj
parents:
230
diff
changeset
|
17 |
pass |
|
5c5fab6d8ae8
Add admin permission panel to Group, Media, Author
verrierj
parents:
230
diff
changeset
|
18 |
|
|
5c5fab6d8ae8
Add admin permission panel to Group, Media, Author
verrierj
parents:
230
diff
changeset
|
19 |
class MediaAdmin(GuardedModelAdmin): |
|
5c5fab6d8ae8
Add admin permission panel to Group, Media, Author
verrierj
parents:
230
diff
changeset
|
20 |
pass |
|
230
39d97d561c60
Add admin panel to manage permissions for Content and Project
verrierj
parents:
167
diff
changeset
|
21 |
|
|
39d97d561c60
Add admin panel to manage permissions for Content and Project
verrierj
parents:
167
diff
changeset
|
22 |
class ContentAdmin(GuardedModelAdmin): |
| 0 | 23 |
|
24 |
def import_file(self, request): |
|
|
13
97ab7b3191cf
add api to update project, uses psiton
ymh <ymh.work@gmail.com>
parents:
0
diff
changeset
|
25 |
if request.method == 'POST': |
| 0 | 26 |
form = LdtImportForm(request.POST, request.FILES) |
27 |
if form.is_valid(): |
|
|
13
97ab7b3191cf
add api to update project, uses psiton
ymh <ymh.work@gmail.com>
parents:
0
diff
changeset
|
28 |
filetoprocess = form.cleaned_data['importFile'] |
| 0 | 29 |
flatten = form.cleaned_data['flatten'] |
30 |
videoPath = form.cleaned_data['videoPath'] |
|
31 |
# fi = None |
|
32 |
fi = FileImport(filetoprocess, videoPath, flatten) |
|
33 |
try: |
|
|
167
fe00e7302efe
Change class and functions names to follow PEP8 formatting standards
verrierj
parents:
142
diff
changeset
|
34 |
fi.process_file() |
| 0 | 35 |
args = {'message': "File imported"} |
36 |
except FileImportError: |
|
37 |
non_field_errors = form.non_field_errors() |
|
38 |
non_field_errors.append("Error when importing : unknown file type") |
|
39 |
form._errors["__all__"] = non_field_errors |
|
40 |
args = {'message': "Can not import file, unknown file type", 'form': form} |
|
41 |
||
42 |
else: |
|
43 |
non_field_errors = form.non_field_errors() |
|
44 |
non_field_errors.append("Error when importing : invalid form") |
|
45 |
form._errors["__all__"] = non_field_errors |
|
46 |
args = {'message': "Error when importing : invalid form", 'form': form} |
|
47 |
else: |
|
48 |
form = LdtImportForm() |
|
49 |
args = {'form': form, 'current_app': self.admin_site.name, 'current_action' : 'import_file'} |
|
50 |
return render_to_response('admin/ldt_utils/content/upload_form.html', args, context_instance=RequestContext(request)) |
|
51 |
||
52 |
def reindex(self, request): |
|
53 |
message = None |
|
54 |
if request.method == "POST": |
|
55 |
form = ReindexForm(request.POST) |
|
56 |
if form.is_valid(): |
|
57 |
# try: |
|
| 142 | 58 |
writer = ldt.indexation.get_writer(True) |
|
111
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
78
diff
changeset
|
59 |
try: |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
78
diff
changeset
|
60 |
contentList = form.cleaned_data["contents"] |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
78
diff
changeset
|
61 |
indexer = ContentIndexer(contentList, writer) |
| 77 | 62 |
indexer.index_all() |
|
111
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
78
diff
changeset
|
63 |
|
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
78
diff
changeset
|
64 |
index_projects = form.cleaned_data["index_projects"] |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
78
diff
changeset
|
65 |
if index_projects: |
|
119
07c64d93dce5
correct resource path and document indexation
ymh <ymh.work@gmail.com>
parents:
111
diff
changeset
|
66 |
projectList = Project.objects.filter(contents__in=contentList, state=2).distinct() #filter(contents__in=contentList) @UndefinedVariable |
|
111
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
78
diff
changeset
|
67 |
indexer = ProjectIndexer(projectList, writer) |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
78
diff
changeset
|
68 |
indexer.index_all() |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
78
diff
changeset
|
69 |
finally: |
|
4535dafa6007
improve releasing of resources when indexing + convert line endings to unix
ymh <ymh.work@gmail.com>
parents:
78
diff
changeset
|
70 |
writer.close() |
| 0 | 71 |
message = "Indexation ok : " + repr(form.cleaned_data["contents"]) |
72 |
form = ReindexForm() |
|
73 |
# except Exception, inst: |
|
74 |
# non_field_errors = form.non_field_errors() |
|
75 |
# non_field_errors.append("Error when reindexing : " + cgi.escape(repr(inst))) |
|
76 |
# form._errors["__all__"] = non_field_errors |
|
77 |
#message = "ERROR : " + repr(non_field_errors) |
|
78 |
else: |
|
79 |
form = ReindexForm() |
|
80 |
||
81 |
return render_to_response('admin/ldt_utils/content/reindex_form.html', {'form': form, 'message':message, 'current_app': self.admin_site.name, 'current_action' : 'reindex' }, context_instance=RequestContext(request)) |
|
82 |
||
|
340
5f919a978f50
Stats for annotations volume can be computed using ./manage.py statannotation [-c content_id] or in the admin pages of module ldt_utils.
verrierj
parents:
249
diff
changeset
|
83 |
def stats_annotations(self, request): |
|
5f919a978f50
Stats for annotations volume can be computed using ./manage.py statannotation [-c content_id] or in the admin pages of module ldt_utils.
verrierj
parents:
249
diff
changeset
|
84 |
|
|
5f919a978f50
Stats for annotations volume can be computed using ./manage.py statannotation [-c content_id] or in the admin pages of module ldt_utils.
verrierj
parents:
249
diff
changeset
|
85 |
message = None |
|
5f919a978f50
Stats for annotations volume can be computed using ./manage.py statannotation [-c content_id] or in the admin pages of module ldt_utils.
verrierj
parents:
249
diff
changeset
|
86 |
if request.method == "POST": |
|
343
1b9b509013a7
Stats are recomputed without parsing extra xml file when projects are saved from ligne de temps.
verrierj
parents:
340
diff
changeset
|
87 |
form = StatAnnotationForm(request.POST) |
|
340
5f919a978f50
Stats for annotations volume can be computed using ./manage.py statannotation [-c content_id] or in the admin pages of module ldt_utils.
verrierj
parents:
249
diff
changeset
|
88 |
|
|
343
1b9b509013a7
Stats are recomputed without parsing extra xml file when projects are saved from ligne de temps.
verrierj
parents:
340
diff
changeset
|
89 |
if form.is_valid(): |
|
340
5f919a978f50
Stats for annotations volume can be computed using ./manage.py statannotation [-c content_id] or in the admin pages of module ldt_utils.
verrierj
parents:
249
diff
changeset
|
90 |
|
|
343
1b9b509013a7
Stats are recomputed without parsing extra xml file when projects are saved from ligne de temps.
verrierj
parents:
340
diff
changeset
|
91 |
if form.cleaned_data['choose_all']: |
|
1b9b509013a7
Stats are recomputed without parsing extra xml file when projects are saved from ligne de temps.
verrierj
parents:
340
diff
changeset
|
92 |
projects = Content.objects.all() |
|
340
5f919a978f50
Stats for annotations volume can be computed using ./manage.py statannotation [-c content_id] or in the admin pages of module ldt_utils.
verrierj
parents:
249
diff
changeset
|
93 |
else: |
|
343
1b9b509013a7
Stats are recomputed without parsing extra xml file when projects are saved from ligne de temps.
verrierj
parents:
340
diff
changeset
|
94 |
projects = form.cleaned_data['projects'] |
|
340
5f919a978f50
Stats for annotations volume can be computed using ./manage.py statannotation [-c content_id] or in the admin pages of module ldt_utils.
verrierj
parents:
249
diff
changeset
|
95 |
|
|
343
1b9b509013a7
Stats are recomputed without parsing extra xml file when projects are saved from ligne de temps.
verrierj
parents:
340
diff
changeset
|
96 |
# for content in contents: |
|
1b9b509013a7
Stats are recomputed without parsing extra xml file when projects are saved from ligne de temps.
verrierj
parents:
340
diff
changeset
|
97 |
# compute_stats_for(content) |
|
1b9b509013a7
Stats are recomputed without parsing extra xml file when projects are saved from ligne de temps.
verrierj
parents:
340
diff
changeset
|
98 |
message = "Stats computed for :" + repr(projects) |
|
340
5f919a978f50
Stats for annotations volume can be computed using ./manage.py statannotation [-c content_id] or in the admin pages of module ldt_utils.
verrierj
parents:
249
diff
changeset
|
99 |
else: |
|
343
1b9b509013a7
Stats are recomputed without parsing extra xml file when projects are saved from ligne de temps.
verrierj
parents:
340
diff
changeset
|
100 |
form = StatAnnotationForm() |
|
340
5f919a978f50
Stats for annotations volume can be computed using ./manage.py statannotation [-c content_id] or in the admin pages of module ldt_utils.
verrierj
parents:
249
diff
changeset
|
101 |
|
|
343
1b9b509013a7
Stats are recomputed without parsing extra xml file when projects are saved from ligne de temps.
verrierj
parents:
340
diff
changeset
|
102 |
return render_to_response('admin/ldt_utils/content/stats_form.html', {'form': form, 'message':message, 'current_app': self.admin_site.name, 'current_action' : 'stats' }, context_instance=RequestContext(request)) |
|
340
5f919a978f50
Stats for annotations volume can be computed using ./manage.py statannotation [-c content_id] or in the admin pages of module ldt_utils.
verrierj
parents:
249
diff
changeset
|
103 |
|
|
5f919a978f50
Stats for annotations volume can be computed using ./manage.py statannotation [-c content_id] or in the admin pages of module ldt_utils.
verrierj
parents:
249
diff
changeset
|
104 |
|
| 0 | 105 |
def get_urls(self): |
106 |
urls = super(ContentAdmin, self).get_urls() |
|
107 |
content_urls = patterns('', |
|
108 |
url(r'^reindex/$', self.admin_site.admin_view(self.reindex), name="ldt_content_reindex"), |
|
109 |
# (r'^admin/ldt/content/import/upload/$', 'ldt.ldt_utils.views.uploadFile'), |
|
|
340
5f919a978f50
Stats for annotations volume can be computed using ./manage.py statannotation [-c content_id] or in the admin pages of module ldt_utils.
verrierj
parents:
249
diff
changeset
|
110 |
url(r'^import/$', self.admin_site.admin_view(self.import_file), name="ldt_content_import_file"), |
|
343
1b9b509013a7
Stats are recomputed without parsing extra xml file when projects are saved from ligne de temps.
verrierj
parents:
340
diff
changeset
|
111 |
url(r'^stats/$', self.admin_site.admin_view(self.stats_annotations), name="ldt_project_compute_stats") |
|
340
5f919a978f50
Stats for annotations volume can be computed using ./manage.py statannotation [-c content_id] or in the admin pages of module ldt_utils.
verrierj
parents:
249
diff
changeset
|
112 |
|
| 0 | 113 |
) |
|
340
5f919a978f50
Stats for annotations volume can be computed using ./manage.py statannotation [-c content_id] or in the admin pages of module ldt_utils.
verrierj
parents:
249
diff
changeset
|
114 |
|
| 0 | 115 |
return content_urls + urls |
116 |
||
117 |
||
|
249
5c5fab6d8ae8
Add admin permission panel to Group, Media, Author
verrierj
parents:
230
diff
changeset
|
118 |
admin.site.register(Project, ProjectAdmin) |
| 0 | 119 |
admin.site.register(Content, ContentAdmin) |
|
249
5c5fab6d8ae8
Add admin permission panel to Group, Media, Author
verrierj
parents:
230
diff
changeset
|
120 |
admin.site.register(Media, MediaAdmin) |
|
5c5fab6d8ae8
Add admin permission panel to Group, Media, Author
verrierj
parents:
230
diff
changeset
|
121 |
admin.site.register(Author, AuthorAdmin) |