Index: trunk/tools/editor_trends/wikilytics/api/views.py |
— | — | @@ -4,12 +4,13 @@ |
5 | 5 | |
6 | 6 | from django.shortcuts import render_to_response |
7 | 7 | from django.http import HttpResponseRedirect, HttpResponse |
| 8 | +from django.core.context_processors import csrf |
8 | 9 | from django.core.urlresolvers import reverse |
9 | 10 | from django.conf import settings |
10 | 11 | from django.core import serializers |
11 | 12 | |
12 | 13 | |
13 | | -from wikilytics.api.forms import SearchForm |
| 14 | +from wikilytics.api.forms import SearchForm, AnalysisForm |
14 | 15 | from wikilytics.api.models import Editor, Dataset, Job, Dump |
15 | 16 | import wikilytics.api.helpers as helpers |
16 | 17 | |
— | — | @@ -31,38 +32,59 @@ |
32 | 33 | |
33 | 34 | |
34 | 35 | def dataset_dispatcher(request, project, language): |
35 | | - dbname = '%s%s' % (language, project) |
36 | | - editors = Editor.objects.count() |
37 | | - if editors == 0: |
| 36 | + #dbname = '%s%s' % (language, project) |
| 37 | + print request |
38 | 38 | #Dataset has not yet been made, put job in queue to create the dataset |
39 | | - hash = helpers.create_hash(project, language) |
40 | | - job, created = Job.objects.get_or_create(hash=hash, defaults={'project':project, 'language_code': language, 'hash':hash}) |
41 | | - print job.hash |
42 | | - if created: |
43 | | - job.save() |
44 | | - jobs = Job.objects.filter(jobtype='dataset', finished=False, in_progress=True) |
45 | | - return render_to_response('queue.html', {'jobs': jobs}) |
46 | | - else: |
47 | | - ds = Dataset.objects.filter(project=project, language_code=language) |
48 | | - print ds |
49 | | - return render_to_response('datasets_available.html', {'datasets': ds}) |
| 39 | + hash = helpers.create_hash(project, language) |
| 40 | + job, created = Job.objects.get_or_create(hash=hash, defaults={'project':project, 'language_code': language, 'hash':hash}) |
| 41 | + print job.hash |
| 42 | + if created: |
| 43 | + job.save() |
| 44 | + jobs = Job.objects.filter(jobtype='dataset', finished=False, in_progress=False) |
| 45 | + ds = Dataset.objects.filter(project=project, language_code=language) |
| 46 | + print ds |
| 47 | + return render_to_response('datasets.html', {'datasets': ds, 'jobs': jobs}) |
50 | 48 | |
51 | 49 | |
52 | 50 | def chart_dispatcher(request, project, language): |
53 | 51 | #project = '%s%s' % (project, language) |
54 | | - analyses = Job.objects.filter(jobtype='chart') |
| 52 | + analyses = Job.objects.exclude(jobtype='dataset').filter(finished=True, project=project, language_code=language) |
55 | 53 | print analyses |
56 | | - return render_to_response('analyses_available.html', {'analyses': analyses}) |
| 54 | + return render_to_response('analyses.html', {'analyses': analyses}) |
57 | 55 | |
58 | 56 | |
59 | 57 | def chart_generator(request, project, language, chart): |
60 | 58 | xhr = request.GET.has_key('json') |
61 | | - print xhr |
62 | | - ds = Dataset.objects.using('enwiki').get(project=project, language_code=language, name=chart) |
63 | | - if xhr: |
| 59 | + c = {} |
| 60 | + print project, language, chart |
| 61 | + try: |
| 62 | + ds = Dataset.objects.using('enwiki').get(project=project, language_code=language, name=chart) |
| 63 | + except: |
| 64 | + hash = helpers.create_hash(project, language) |
| 65 | + job = Job() |
| 66 | + job.jobtype = chart |
| 67 | + job.project = project |
| 68 | + job.language_code = language |
| 69 | + job.hash = hash |
| 70 | + job.save() |
| 71 | + c['queue'] = True |
| 72 | + |
| 73 | + if request.POST: |
| 74 | + print request.POST |
| 75 | + chart = request.POST.get('analysis') |
| 76 | + return HttpResponseRedirect(reverse('chart_generator', args=[project, language, chart])) |
| 77 | + elif xhr: |
64 | 78 | dthandler = lambda obj:'new Date("%s")' % datetime.date.ctime(obj) if isinstance(obj, datetime.datetime) else obj |
65 | 79 | data = helpers.transform_to_stacked_bar_json(ds) |
66 | 80 | return HttpResponse(json.dumps(data, default=dthandler), mimetype='application/json') |
67 | 81 | else: |
68 | | - url = ds.get_absolute_url() |
69 | | - return render_to_response('chart.html', {'url': url}) |
| 82 | + |
| 83 | + c.update(csrf(request)) |
| 84 | + analysis = AnalysisForm() |
| 85 | + url = reverse('chart_generator', args=[project, language, chart]) |
| 86 | + #url = ds.get_absolute_url() |
| 87 | + |
| 88 | + c['url'] = url |
| 89 | + c['analysis'] = analysis |
| 90 | + c['chart'] = chart |
| 91 | + return render_to_response('chart.html', c) |
Index: trunk/tools/editor_trends/wikilytics/api/models.py |
— | — | @@ -63,6 +63,7 @@ |
64 | 64 | created = models.DateField(auto_now_add=True) |
65 | 65 | finished = models.BooleanField(default=False) |
66 | 66 | in_progress = models.BooleanField(default=False) |
| 67 | + error = models.BooleanField(default=False) |
67 | 68 | jobtype = models.CharField(max_length=15, default='dataset') |
68 | 69 | |
69 | 70 | def __unicode__(self): |
— | — | @@ -71,13 +72,13 @@ |
72 | 73 | |
73 | 74 | @permalink |
74 | 75 | def get_absolute_url(self): |
75 | | - if self.jobtype == 'chart': |
76 | | - print reverse('chart_generator', args=[self.project, self.language_code, self.hash]) |
| 76 | + if self.jobtype != 'dataset': |
| 77 | + print reverse('chart_generator', args=[self.project, self.language_code, self.jobtype]) |
77 | 78 | return ('chart_generator', (), |
78 | 79 | {'project': self.project, |
79 | 80 | 'language': self.language_code, |
80 | | - 'chart': self.hash}) |
81 | | - elif self.jobtype == 'dataset': |
| 81 | + 'chart': self.jobtype}) |
| 82 | + else: |
82 | 83 | return ('dataset_dispatcher', (), |
83 | 84 | {'project': self.project, |
84 | 85 | 'language': self.language_code, |
Index: trunk/tools/editor_trends/wikilytics/api/forms.py |
— | — | @@ -3,8 +3,8 @@ |
4 | 4 | |
5 | 5 | from wikilytics.api.widgets import MonthYearWidget |
6 | 6 | from editor_trends.classes import wikiprojects |
| 7 | +from editor_trends.analyses.analyzer import available_analyses |
7 | 8 | |
8 | | - |
9 | 9 | wiki = wikiprojects.Wiki('settings') |
10 | 10 | |
11 | 11 | |
— | — | @@ -21,3 +21,6 @@ |
22 | 22 | #print 'Project: %s' % language |
23 | 23 | #date = forms.DateField(widget=MonthYearWidget(years=years)) |
24 | 24 | |
| 25 | +class AnalysisForm(forms.Form): |
| 26 | + analysis = forms.CharField(widget=forms.Select(choices=available_analyses('django'))) |
| 27 | + |
Index: trunk/tools/editor_trends/wikilytics/urls.py |
— | — | @@ -16,7 +16,7 @@ |
17 | 17 | #url(r'^search/(?P<project>[\w]*)/available_dumps/json/$', 'api.views.available_dumps', name='available_dumps'), |
18 | 18 | url(r'^(?P<project>[\w]*)/(?P<language>\w{2})/datasets/$', 'api.views.dataset_dispatcher', name='dataset_dispatcher'), |
19 | 19 | url(r'^(?P<project>[\w]*)/(?P<language>\w{2})/analyses/$', 'api.views.chart_dispatcher', name='chart_dispatcher'), |
20 | | - url(r'^(?P<project>[\w]*)/(?P<language>\w{2})/chart/(?P<chart>[\w]*)/$', 'api.views.chart_generator', name='chart_generator'), |
| 20 | + url(r'^(?P<project>[\w]*)/(?P<language>\w{2})/analyses/(?P<chart>[\w]*)/$', 'api.views.chart_generator', name='chart_generator'), |
21 | 21 | url(r'^static/js/(?P<path>.*)$', 'django.views.static.serve', {'document_root': settings.MEDIA_JS}), |
22 | 22 | url(r'^static/css/(?P<path>.*)$', 'django.views.static.serve', {'document_root': settings.MEDIA_CSS}), |
23 | 23 | |