Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Changed api structure.

  • Loading branch information...
commit 173272f9a037c9b415c9c6cd166653f01f7ca84a 1 parent 316ff77
Johan authored
Showing with 60 additions and 42 deletions.
  1. +0 −1  apache/django.wsgi
  2. +10 −3 apps/log/urls.py
  3. +50 −38 apps/log/views.py
View
1  apache/django.wsgi
@@ -10,5 +10,4 @@ sys.path.append('/home/illutron/srv/IllutronDashboard/')
os.environ['DJANGO_SETTINGS_MODULE'] = 'IllutronDashboard.settings'
import django.core.handlers.wsgi
-
application = django.core.handlers.wsgi.WSGIHandler()
View
13 apps/log/urls.py
@@ -2,9 +2,16 @@
urlpatterns = patterns('log.views',
- url(r'^latest/$',
- 'latest',
- name='api_latest'
+ url(r'^members/(?P<id>\d+)/$',
+ 'member',
+ name='api_member'
),
+ url(r'^members/$',
+ 'member_list',
+ name='api_member_list'
+ ),
+
+
+
)
View
88 apps/log/views.py
@@ -1,46 +1,58 @@
+from pprint import pprint
+from django.core import serializers
from django.utils import simplejson
from django.http import HttpResponse
from django.contrib.auth.models import User
-def latest(request):
- """
- Return a list of the latest entries for all members.
- """
-
- users = User.objects.all()
- data = []
-
- for user in users:
- try:
- entry = user.log_entries.all()[0]
-
- try:
- latest_checkin_entry = user.log_entries.filter(on_illutron=True)[0].time.isoformat()
- except:
- latest_checkin_entry = False
-
- if user.first_name and user.last_name:
- name = user.first_name + " " + user.last_name
- else:
- name = user.username
- try:
- image = user.get_profile().image.url
- except:
- image = False
+def member(request, id):
+
+ user = User.objects.get(id=id)
+
+ try:
+ log_entries = user.log_entries.all()[:10]
+ except:
+ return HttpResponse("No activity yet.")
+
+ if user.first_name and user.last_name:
+ name = user.first_name + " " + user.last_name
+ else:
+ name = user.username
+
+ try:
+ latest_checkin_entry = user.log_entries.filter(on_illutron=True)[0].time.isoformat()
+ except:
+ latest_checkin_entry = None
+
+ try:
+ image = user.get_profile().image.url
+ except:
+ image = False
+
+ log_list = []
+ for log in log_entries:
+ log_list.append({
+ 'latitude': log.latitude,
+ 'longitude': log.longitude,
+ 'on_illutron': log.on_illutron,
+ 'time': log.time.isoformat(),
+ 'description': log.description
+ })
+
+ data = {
+ 'name': name,
+ 'on_illutron': log_entries[0].on_illutron,
+ 'latest_checkin_time': latest_checkin_entry,
+ 'image': image,
+ 'log': log_list
+ }
- data.append({
- 'member': name,
- 'on_illutron': entry.on_illutron,
- 'latest_checkin_time': latest_checkin_entry,
- 'image': image
- #'last_log_entry': entry.time.isoformat(),
- #'latitude': entry.latitude,
- #'longitude': entry.longitude,
- })
-
- except:
- pass
+ return HttpResponse(simplejson.dumps(data), mimetype='application/json')
+def member_list(request):
+ """
+ Return a list of all members.
+ """
- return HttpResponse(simplejson.dumps(data), mimetype='application/json')
+ data = simplejson.dumps(list(User.objects.all().values('id', 'username', 'first_name', 'last_name')))
+ return HttpResponse(data, mimetype='application/json')
Please sign in to comment.
Something went wrong with that request. Please try again.