-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathviews.py
37 lines (31 loc) · 1.06 KB
/
views.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
from django.http import HttpResponse
import json
from . import wikiedits
def edits_list(request, user):
params = request.GET
format = params.get('format', 'human')
limit = params.get('limit')
if limit:
limit = int(limit)
response = HttpResponse(content_type='text/plain; charset=utf-8')
edits = []
for edit in wikiedits.get_edits(user, limit):
if format == 'human':
response.write('{}\t{}\n'.format(edit['timestamp'], edit['title']))
elif format == 'json':
edits.append(edit)
if format == 'json':
json.dump(edits, response)
return response
def edits_per_day(request, user):
date_counts = {}
for date, count in wikiedits.get_edits_per_day(user, time_limit=365):
date_counts[date] = count
response = HttpResponse(content_type='application/json; charset=utf-8')
json.dump(date_counts, response)
return response
def day_edits(request, user, date):
edits = list(wikiedits.get_edits_for_day(user, date))
response = HttpResponse(content_type='application/json; charset=utf-8')
json.dump(edits, response)
return response