Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Restructured.

  • Loading branch information...
commit 1bfd1baa48bb78cb2a363d54d57e6ef8adb3f485 1 parent 00509b1
Johan authored
Showing with 641 additions and 2 deletions.
  1. +5 −2 .gitignore
  2. 0  __init__.py
  3. 0  apps/log/__init__.py
  4. +8 −0 apps/log/admin.py
  5. +108 −0 apps/log/migrations/0001_initial.py
  6. +89 −0 apps/log/migrations/0002_auto__chg_field_entry_longitude__chg_field_entry_latitude__chg_field_e.py
  7. +88 −0 apps/log/migrations/0003_auto__add_field_entry_member.py
  8. 0  apps/log/migrations/__init__.py
  9. +26 −0 apps/log/models.py
  10. +16 −0 apps/log/tests.py
  11. +10 −0 apps/log/urls.py
  12. +37 −0 apps/log/views.py
  13. 0  apps/sync/__init__.py
  14. 0  apps/sync/migrations/__init__.py
  15. +11 −0 apps/sync/models.py
  16. +60 −0 apps/sync/sync.py
  17. +16 −0 apps/sync/tests.py
  18. +1 −0  apps/sync/views.py
  19. +14 −0 manage.py
  20. +130 −0 settings.py
  21. +9 −0 settings_local.py
  22. 0  {html → static}/coffee/main.coffee
  23. 0  {html → static}/config.rb
  24. 0  {html → static}/images/bg.jpg
  25. 0  {html → static}/javascripts/main.js
  26. 0  {html → static}/sass/ie.scss
  27. 0  {html → static}/sass/partials/_base.sass
  28. 0  {html → static}/sass/print.scss
  29. 0  {html → static}/sass/screen.sass
  30. 0  {html → static}/stylesheets/ie.css
  31. 0  {html → static}/stylesheets/print.css
  32. 0  {html → static}/stylesheets/screen.css
  33. 0  {html → static}/vendor/backbone-min.js
  34. 0  {html → static}/vendor/jquery-1.6.4.js
  35. 0  {html → static}/vendor/jquery-1.6.4.min.js
  36. 0  {html → static}/vendor/json/README
  37. 0  {html → static}/vendor/json/cycle.js
  38. 0  {html → static}/vendor/json/json.js
  39. 0  {html → static}/vendor/json/json2.js
  40. 0  {html → static}/vendor/json/json_parse.js
  41. 0  {html → static}/vendor/json/json_parse_state.js
  42. 0  {html → static}/vendor/underscore-min.js
  43. 0  {html → static}/vendor/underscore.js
  44. 0  {html → templates}/index.html
  45. BIN  test.db
  46. +13 −0 urls.py
View
7 .gitignore
@@ -1,2 +1,5 @@
-/html/.sass-cache/
-.DS_Store
+/static/.sass-cache/
+.DS_Store
+.idea
+*pyc
+*~
View
0  __init__.py
No changes.
View
0  apps/log/__init__.py
No changes.
View
8 apps/log/admin.py
@@ -0,0 +1,8 @@
+# -*- coding: utf-8 -*-
+
+from django.contrib import admin
+from models import Entry, Provider
+
+
+admin.site.register(Entry, admin.ModelAdmin)
+admin.site.register(Provider, admin.ModelAdmin)
View
108 apps/log/migrations/0001_initial.py
@@ -0,0 +1,108 @@
+# encoding: utf-8
+import datetime
+from south.db import db
+from south.v2 import SchemaMigration
+from django.db import models
+
+class Migration(SchemaMigration):
+
+ def forwards(self, orm):
+
+ # Adding model 'Provider'
+ db.create_table('log_provider', (
+ ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
+ ('name', self.gf('django.db.models.fields.CharField')(max_length=40)),
+ ))
+ db.send_create_signal('log', ['Provider'])
+
+ # Adding model 'Entry'
+ db.create_table('log_entry', (
+ ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
+ ('description', self.gf('django.db.models.fields.TextField')(blank=True)),
+ ('time', self.gf('django.db.models.fields.DateTimeField')(default=datetime.datetime.now)),
+ ('on_illutron', self.gf('django.db.models.fields.BooleanField')(default=False)),
+ ('latitude', self.gf('django.db.models.fields.DecimalField')(max_digits=8, decimal_places=6, blank=True)),
+ ('longitude', self.gf('django.db.models.fields.DecimalField')(max_digits=8, decimal_places=6, blank=True)),
+ ('accuracy', self.gf('django.db.models.fields.IntegerField')(blank=True)),
+ ('provider', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['log.Provider'])),
+ ))
+ db.send_create_signal('log', ['Entry'])
+
+ # Adding M2M table for field member on 'Entry'
+ db.create_table('log_entry_member', (
+ ('id', models.AutoField(verbose_name='ID', primary_key=True, auto_created=True)),
+ ('entry', models.ForeignKey(orm['log.entry'], null=False)),
+ ('user', models.ForeignKey(orm['auth.user'], null=False))
+ ))
+ db.create_unique('log_entry_member', ['entry_id', 'user_id'])
+
+
+ def backwards(self, orm):
+
+ # Deleting model 'Provider'
+ db.delete_table('log_provider')
+
+ # Deleting model 'Entry'
+ db.delete_table('log_entry')
+
+ # Removing M2M table for field member on 'Entry'
+ db.delete_table('log_entry_member')
+
+
+ models = {
+ 'auth.group': {
+ 'Meta': {'object_name': 'Group'},
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '80'}),
+ 'permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'})
+ },
+ 'auth.permission': {
+ 'Meta': {'ordering': "('content_type__app_label', 'content_type__model', 'codename')", 'unique_together': "(('content_type', 'codename'),)", 'object_name': 'Permission'},
+ 'codename': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+ 'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['contenttypes.ContentType']"}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '50'})
+ },
+ 'auth.user': {
+ 'Meta': {'object_name': 'User'},
+ 'date_joined': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
+ 'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'blank': 'True'}),
+ 'first_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
+ 'groups': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Group']", 'symmetrical': 'False', 'blank': 'True'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'is_active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
+ 'is_staff': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+ 'is_superuser': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+ 'last_login': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
+ 'last_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
+ 'password': ('django.db.models.fields.CharField', [], {'max_length': '128'}),
+ 'user_permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}),
+ 'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '30'})
+ },
+ 'contenttypes.contenttype': {
+ 'Meta': {'ordering': "('name',)", 'unique_together': "(('app_label', 'model'),)", 'object_name': 'ContentType', 'db_table': "'django_content_type'"},
+ 'app_label': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'model': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '100'})
+ },
+ 'log.entry': {
+ 'Meta': {'object_name': 'Entry'},
+ 'accuracy': ('django.db.models.fields.IntegerField', [], {'blank': 'True'}),
+ 'description': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'latitude': ('django.db.models.fields.DecimalField', [], {'max_digits': '8', 'decimal_places': '6', 'blank': 'True'}),
+ 'longitude': ('django.db.models.fields.DecimalField', [], {'max_digits': '8', 'decimal_places': '6', 'blank': 'True'}),
+ 'member': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.User']", 'symmetrical': 'False'}),
+ 'on_illutron': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+ 'provider': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['log.Provider']"}),
+ 'time': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'})
+ },
+ 'log.provider': {
+ 'Meta': {'object_name': 'Provider'},
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '40'})
+ }
+ }
+
+ complete_apps = ['log']
View
89 apps/log/migrations/0002_auto__chg_field_entry_longitude__chg_field_entry_latitude__chg_field_e.py
@@ -0,0 +1,89 @@
+# encoding: utf-8
+import datetime
+from south.db import db
+from south.v2 import SchemaMigration
+from django.db import models
+
+class Migration(SchemaMigration):
+
+ def forwards(self, orm):
+
+ # Changing field 'Entry.longitude'
+ db.alter_column('log_entry', 'longitude', self.gf('django.db.models.fields.DecimalField')(null=True, max_digits=8, decimal_places=6))
+
+ # Changing field 'Entry.latitude'
+ db.alter_column('log_entry', 'latitude', self.gf('django.db.models.fields.DecimalField')(null=True, max_digits=8, decimal_places=6))
+
+ # Changing field 'Entry.accuracy'
+ db.alter_column('log_entry', 'accuracy', self.gf('django.db.models.fields.IntegerField')(null=True))
+
+
+ def backwards(self, orm):
+
+ # User chose to not deal with backwards NULL issues for 'Entry.longitude'
+ raise RuntimeError("Cannot reverse this migration. 'Entry.longitude' and its values cannot be restored.")
+
+ # User chose to not deal with backwards NULL issues for 'Entry.latitude'
+ raise RuntimeError("Cannot reverse this migration. 'Entry.latitude' and its values cannot be restored.")
+
+ # User chose to not deal with backwards NULL issues for 'Entry.accuracy'
+ raise RuntimeError("Cannot reverse this migration. 'Entry.accuracy' and its values cannot be restored.")
+
+
+ models = {
+ 'auth.group': {
+ 'Meta': {'object_name': 'Group'},
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '80'}),
+ 'permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'})
+ },
+ 'auth.permission': {
+ 'Meta': {'ordering': "('content_type__app_label', 'content_type__model', 'codename')", 'unique_together': "(('content_type', 'codename'),)", 'object_name': 'Permission'},
+ 'codename': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+ 'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['contenttypes.ContentType']"}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '50'})
+ },
+ 'auth.user': {
+ 'Meta': {'object_name': 'User'},
+ 'date_joined': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
+ 'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'blank': 'True'}),
+ 'first_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
+ 'groups': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Group']", 'symmetrical': 'False', 'blank': 'True'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'is_active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
+ 'is_staff': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+ 'is_superuser': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+ 'last_login': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
+ 'last_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
+ 'password': ('django.db.models.fields.CharField', [], {'max_length': '128'}),
+ 'user_permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}),
+ 'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '30'})
+ },
+ 'contenttypes.contenttype': {
+ 'Meta': {'ordering': "('name',)", 'unique_together': "(('app_label', 'model'),)", 'object_name': 'ContentType', 'db_table': "'django_content_type'"},
+ 'app_label': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'model': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '100'})
+ },
+ 'log.entry': {
+ 'Meta': {'object_name': 'Entry'},
+ 'accuracy': ('django.db.models.fields.IntegerField', [], {'null': 'True', 'blank': 'True'}),
+ 'description': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'latitude': ('django.db.models.fields.DecimalField', [], {'null': 'True', 'max_digits': '8', 'decimal_places': '6', 'blank': 'True'}),
+ 'longitude': ('django.db.models.fields.DecimalField', [], {'null': 'True', 'max_digits': '8', 'decimal_places': '6', 'blank': 'True'}),
+ 'member': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.User']", 'symmetrical': 'False'}),
+ 'on_illutron': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+ 'provider': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['log.Provider']"}),
+ 'time': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'})
+ },
+ 'log.provider': {
+ 'Meta': {'object_name': 'Provider'},
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '40'})
+ }
+ }
+
+ complete_apps = ['log']
View
88 apps/log/migrations/0003_auto__add_field_entry_member.py
@@ -0,0 +1,88 @@
+# encoding: utf-8
+import datetime
+from south.db import db
+from south.v2 import SchemaMigration
+from django.db import models
+
+class Migration(SchemaMigration):
+
+ def forwards(self, orm):
+
+ # Adding field 'Entry.member'
+ db.add_column('log_entry', 'member', self.gf('django.db.models.fields.related.ForeignKey')(default=1, to=orm['auth.User']), keep_default=False)
+
+ # Removing M2M table for field member on 'Entry'
+ db.delete_table('log_entry_member')
+
+
+ def backwards(self, orm):
+
+ # Deleting field 'Entry.member'
+ db.delete_column('log_entry', 'member_id')
+
+ # Adding M2M table for field member on 'Entry'
+ db.create_table('log_entry_member', (
+ ('id', models.AutoField(verbose_name='ID', primary_key=True, auto_created=True)),
+ ('entry', models.ForeignKey(orm['log.entry'], null=False)),
+ ('user', models.ForeignKey(orm['auth.user'], null=False))
+ ))
+ db.create_unique('log_entry_member', ['entry_id', 'user_id'])
+
+
+ models = {
+ 'auth.group': {
+ 'Meta': {'object_name': 'Group'},
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '80'}),
+ 'permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'})
+ },
+ 'auth.permission': {
+ 'Meta': {'ordering': "('content_type__app_label', 'content_type__model', 'codename')", 'unique_together': "(('content_type', 'codename'),)", 'object_name': 'Permission'},
+ 'codename': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+ 'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['contenttypes.ContentType']"}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '50'})
+ },
+ 'auth.user': {
+ 'Meta': {'object_name': 'User'},
+ 'date_joined': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
+ 'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'blank': 'True'}),
+ 'first_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
+ 'groups': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Group']", 'symmetrical': 'False', 'blank': 'True'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'is_active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
+ 'is_staff': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+ 'is_superuser': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+ 'last_login': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
+ 'last_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
+ 'password': ('django.db.models.fields.CharField', [], {'max_length': '128'}),
+ 'user_permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}),
+ 'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '30'})
+ },
+ 'contenttypes.contenttype': {
+ 'Meta': {'ordering': "('name',)", 'unique_together': "(('app_label', 'model'),)", 'object_name': 'ContentType', 'db_table': "'django_content_type'"},
+ 'app_label': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'model': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '100'})
+ },
+ 'log.entry': {
+ 'Meta': {'object_name': 'Entry'},
+ 'accuracy': ('django.db.models.fields.IntegerField', [], {'null': 'True', 'blank': 'True'}),
+ 'description': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'latitude': ('django.db.models.fields.DecimalField', [], {'null': 'True', 'max_digits': '8', 'decimal_places': '6', 'blank': 'True'}),
+ 'longitude': ('django.db.models.fields.DecimalField', [], {'null': 'True', 'max_digits': '8', 'decimal_places': '6', 'blank': 'True'}),
+ 'member': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['auth.User']"}),
+ 'on_illutron': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+ 'provider': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['log.Provider']"}),
+ 'time': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'})
+ },
+ 'log.provider': {
+ 'Meta': {'object_name': 'Provider'},
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '40'})
+ }
+ }
+
+ complete_apps = ['log']
View
0  apps/log/migrations/__init__.py
No changes.
View
26 apps/log/models.py
@@ -0,0 +1,26 @@
+from django.db import models
+from django.contrib.auth.models import User
+import datetime
+
+class Provider(models.Model):
+ name = models.CharField(max_length=40)
+
+ def __unicode__(self):
+ return self.name
+
+class Entry(models.Model):
+ member = models.ForeignKey(User, related_name='log_entries')
+ description = models.TextField(blank=True)
+ time = models.DateTimeField(default=datetime.datetime.now)
+ on_illutron = models.BooleanField(default=False)
+ latitude = models.DecimalField(max_digits=8, decimal_places=6, blank=True, null=True)
+ longitude = models.DecimalField(max_digits=8, decimal_places=6, blank=True, null=True)
+ accuracy = models.IntegerField(blank=True, help_text="accuracy in meters.", null=True)
+ provider = models.ForeignKey(Provider)
+
+ def __unicode__(self):
+ s = ""
+ if not self.on_illutron:
+ s = " not"
+ return "{} is{} on Illutron".format(self.member.username, s)
+
View
16 apps/log/tests.py
@@ -0,0 +1,16 @@
+"""
+This file demonstrates writing tests using the unittest module. These will pass
+when you run "manage.py test".
+
+Replace this with more appropriate tests for your application.
+"""
+
+from django.test import TestCase
+
+
+class SimpleTest(TestCase):
+ def test_basic_addition(self):
+ """
+ Tests that 1 + 1 always equals 2.
+ """
+ self.assertEqual(1 + 1, 2)
View
10 apps/log/urls.py
@@ -0,0 +1,10 @@
+from django.conf.urls.defaults import patterns, url
+
+urlpatterns = patterns('log.views',
+
+ url(r'^latest/$',
+ 'latest',
+ name='api_latest'
+ ),
+
+)
View
37 apps/log/views.py
@@ -0,0 +1,37 @@
+from django.core import serializers
+
+from django.utils import simplejson
+
+from django.http import HttpResponse
+from models import Entry
+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:
+ entry = user.log_entries.all()[0]
+ latest_checkin_entry = user.log_entries.filter(on_illutron=True)[0]
+
+ if user.first_name and user.last_name:
+ name = user.first_name + user.last_name
+ else:
+ name = user.username
+
+ data.append({
+ 'member': name,
+ 'on_illutron': entry.on_illutron,
+ 'latest_checkin_time': latest_checkin_entry.time.isoformat(),
+ #'last_log_entry': entry.time.isoformat(),
+ #'latitude': entry.latitude,
+ #'longitude': entry.longitude,
+
+ })
+
+ return HttpResponse(simplejson.dumps(data))
+
View
0  apps/sync/__init__.py
No changes.
View
0  apps/sync/migrations/__init__.py
No changes.
View
11 apps/sync/models.py
@@ -0,0 +1,11 @@
+from django.contrib.auth.models import User
+from django.db import models
+from apiclient.ext.django_orm import OAuthCredentialsField
+
+class LatitudeCredential(models.Model):
+ """
+ Model for storing oauth2 token user credentials
+ to access private information through latitude api.
+ """
+ id = models.ForeignKey(User, primary_key=True)
+ credential = OAuthCredentialsField()
View
60 apps/sync/sync.py
@@ -0,0 +1,60 @@
+import os
+import logging
+import httplib2
+
+from django.http import HttpResponse
+from django.core.urlresolvers import reverse
+from django.contrib.auth.decorators import login_required
+
+from oauth2client.django_orm import Storage
+from oauth2client.client import OAuth2WebServerFlow
+from django_sample.buzz.models import CredentialsModel
+from django_sample.buzz.models import FlowModel
+from apiclient.discovery import build
+
+from django.http import HttpResponseRedirect
+from django.shortcuts import render_to_response
+
+STEP2_URI = 'http://localhost:8000/auth_return'
+FLOW = OAuth2WebServerFlow(
+ client_id='837647042410.apps.googleusercontent.com',
+ client_secret='+SWwMCL9d8gWtzPRa1lXw5R8',
+ scope='https://www.googleapis.com/auth/buzz',
+ user_agent='buzz-django-sample/1.0',
+ )
+
+@login_required
+def index(request):
+ storage = Storage(CredentialsModel, 'id', request.user, 'credential')
+ credential = storage.get()
+ if credential is None or credential.invalid == True:
+
+ authorize_url = FLOW.step1_get_authorize_url(STEP2_URI)
+ f = FlowModel(id=request.user, flow=FLOW)
+ f.save()
+ return HttpResponseRedirect(authorize_url)
+ else:
+ http = httplib2.Http()
+ http = credential.authorize(http)
+ service = build("buzz", "v1", http=http)
+ activities = service.activities()
+ activitylist = activities.list(scope='@consumption',
+ userId='@me').execute()
+ logging.info(activitylist)
+
+ return render_to_response('buzz/welcome.html', {
+ 'activitylist': activitylist,
+ })
+
+
+@login_required
+def auth_return(request):
+ try:
+ f = FlowModel.objects.get(id=request.user)
+ credential = f.flow.step2_exchange(request.REQUEST)
+ storage = Storage(CredentialsModel, 'id', request.user, 'credential')
+ storage.put(credential)
+ f.delete()
+ return HttpResponseRedirect("/")
+ except FlowModel.DoesNotExist:
+ pass
View
16 apps/sync/tests.py
@@ -0,0 +1,16 @@
+"""
+This file demonstrates writing tests using the unittest module. These will pass
+when you run "manage.py test".
+
+Replace this with more appropriate tests for your application.
+"""
+
+from django.test import TestCase
+
+
+class SimpleTest(TestCase):
+ def test_basic_addition(self):
+ """
+ Tests that 1 + 1 always equals 2.
+ """
+ self.assertEqual(1 + 1, 2)
View
1  apps/sync/views.py
@@ -0,0 +1 @@
+# Create your views here.
View
14 manage.py
@@ -0,0 +1,14 @@
+#!/usr/bin/env python
+from django.core.management import execute_manager
+import imp
+try:
+ imp.find_module('settings') # Assumed to be in the same directory.
+except ImportError:
+ import sys
+ sys.stderr.write("Error: Can't find the file 'settings.py' in the directory containing %r. It appears you've customized things.\nYou'll have to run django-admin.py, passing it your settings module.\n" % __file__)
+ sys.exit(1)
+
+import settings
+
+if __name__ == "__main__":
+ execute_manager(settings)
View
130 settings.py
@@ -0,0 +1,130 @@
+# coding=utf-8
+import os.path
+import sys
+import platform
+
+PRODUCTION_HOSTNAME = "tango"
+
+BASE_PATH = os.path.dirname(os.path.abspath(__file__))
+
+ROOT_URLCONF = 'urls'
+
+sys.path.append(BASE_PATH + '/apps')
+
+ADMINS = (
+ ('Johan Bichel Lindegaard', 'sysadmin@tango.johan.cc'),
+)
+MANAGERS = ADMINS
+
+DEVELOPMENT_MODE = (platform.node() != PRODUCTION_HOSTNAME)
+if DEVELOPMENT_MODE:
+ DEBUG = True
+ MEDIA_URL = '/media/'
+ STATIC_URL = '/static/'
+else:
+ DEBUG = False
+ MEDIA_URL = 'http://media.illutronlog.johan.cc/'
+ STATIC_URL = 'http://static.illutronlog.johan.cc/'
+ ADMIN_MEDIA_PREFIX = STATIC_URL + 'admin/'
+ CACHES = {
+ 'default': {
+ 'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache',
+ 'LOCATION': '127.0.0.1:11211',
+ }
+ }
+
+TEMPLATE_DEBUG = DEBUG
+
+# Static files
+MEDIA_ROOT = BASE_PATH + '/media'
+STATICFILES_DIRS = (
+ BASE_PATH + '/static',
+)
+
+TIME_ZONE = 'Europe/Copenhagen'
+LANGUAGE_CODE = 'en'
+SITE_ID = 1
+USE_I18N = False
+USE_L10N = True
+
+# List of finder classes that know how to find static files in
+# various locations.
+STATICFILES_FINDERS = (
+ 'django.contrib.staticfiles.finders.FileSystemFinder',
+ 'django.contrib.staticfiles.finders.AppDirectoriesFinder',
+# 'django.contrib.staticfiles.finders.DefaultStorageFinder',
+)
+
+# List of callables that know how to import templates from various sources.
+TEMPLATE_LOADERS = (
+ 'django.template.loaders.filesystem.Loader',
+ 'django.template.loaders.app_directories.Loader',
+# 'django.template.loaders.eggs.Loader',
+)
+
+MIDDLEWARE_CLASSES = (
+ 'django.middleware.common.CommonMiddleware',
+ 'django.contrib.sessions.middleware.SessionMiddleware',
+ 'django.middleware.csrf.CsrfViewMiddleware',
+ 'django.contrib.auth.middleware.AuthenticationMiddleware',
+ 'django.contrib.messages.middleware.MessageMiddleware',
+)
+
+TEMPLATE_DIRS = (
+ BASE_PATH + '/templates/'
+)
+
+INSTALLED_APPS = (
+ # Apps
+ 'log',
+ 'sync',
+ #'import',
+
+ # Third-party
+ 'south',
+
+ # Django
+ 'django.contrib.auth',
+ 'django.contrib.contenttypes',
+ 'django.contrib.sessions',
+ 'django.contrib.sites',
+ 'django.contrib.messages',
+ 'django.contrib.staticfiles',
+ 'django.contrib.admin',
+ 'django.contrib.admindocs',
+ 'django.contrib.markup',
+)
+
+DATE_FORMAT = "j N Y"
+TIME_FORMAT = "H:i"
+DATETIME_FORMAT = "j N Y H:i"
+PAGINATE_BY = 12
+
+# A sample logging configuration. The only tangible logging
+# performed by this configuration is to send an email to
+# the site admins on every HTTP 500 error.
+# See http://docs.djangoproject.com/en/dev/topics/logging for
+# more details on how to customize your logging configuration.
+LOGGING = {
+ 'version': 1,
+ 'disable_existing_loggers': False,
+ 'handlers': {
+ 'mail_admins': {
+ 'level': 'ERROR',
+ 'class': 'django.utils.log.AdminEmailHandler'
+ }
+ },
+ 'loggers': {
+ 'django.request': {
+ 'handlers': ['mail_admins'],
+ 'level': 'ERROR',
+ 'propagate': True,
+ },
+ }
+}
+
+try:
+ execfile(BASE_PATH + '/settings_local.py')
+except IOError:
+ sys.stderr.write("\nYou need to copy settings_local.example to settings_local.py and customize it.\n")
+ sys.exit(1)
View
9 settings_local.py
@@ -0,0 +1,9 @@
+# Make this unique, and don't share it with anybody.
+SECRET_KEY = 'b-6!khjsadlgfiiawer3bv%4kcv-^h1tag6e_!2_iw'
+
+DATABASES = {
+ 'default': {
+ 'ENGINE': 'django.db.backends.sqlite3', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
+ 'NAME': 'test.db', # Or path to database file if using sqlite3.
+ }
+}
View
0  html/coffee/main.coffee → static/coffee/main.coffee
File renamed without changes
View
0  html/config.rb → static/config.rb
File renamed without changes
View
0  html/images/bg.jpg → static/images/bg.jpg
File renamed without changes
View
0  html/javascripts/main.js → static/javascripts/main.js
File renamed without changes
View
0  html/sass/ie.scss → static/sass/ie.scss
File renamed without changes
View
0  html/sass/partials/_base.sass → static/sass/partials/_base.sass
File renamed without changes
View
0  html/sass/print.scss → static/sass/print.scss
File renamed without changes
View
0  html/sass/screen.sass → static/sass/screen.sass
File renamed without changes
View
0  html/stylesheets/ie.css → static/stylesheets/ie.css
File renamed without changes
View
0  html/stylesheets/print.css → static/stylesheets/print.css
File renamed without changes
View
0  html/stylesheets/screen.css → static/stylesheets/screen.css
File renamed without changes
View
0  html/vendor/backbone-min.js → static/vendor/backbone-min.js
File renamed without changes
View
0  html/vendor/jquery-1.6.4.js → static/vendor/jquery-1.6.4.js
File renamed without changes
View
0  html/vendor/jquery-1.6.4.min.js → static/vendor/jquery-1.6.4.min.js
File renamed without changes
View
0  html/vendor/json/README → static/vendor/json/README
File renamed without changes
View
0  html/vendor/json/cycle.js → static/vendor/json/cycle.js
File renamed without changes
View
0  html/vendor/json/json.js → static/vendor/json/json.js
File renamed without changes
View
0  html/vendor/json/json2.js → static/vendor/json/json2.js
File renamed without changes
View
0  html/vendor/json/json_parse.js → static/vendor/json/json_parse.js
File renamed without changes
View
0  html/vendor/json/json_parse_state.js → static/vendor/json/json_parse_state.js
File renamed without changes
View
0  html/vendor/underscore-min.js → static/vendor/underscore-min.js
File renamed without changes
View
0  html/vendor/underscore.js → static/vendor/underscore.js
File renamed without changes
View
0  html/index.html → templates/index.html
File renamed without changes
View
BIN  test.db
Binary file not shown
View
13 urls.py
@@ -0,0 +1,13 @@
+from django.conf.urls.defaults import patterns, include, url
+
+from django.contrib import admin
+admin.autodiscover()
+
+urlpatterns = patterns('',
+ url(r'^api/', include('log.urls')),
+
+ # Uncomment the admin/doc line below to enable admin documentation:
+ # url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
+
+ url(r'^admin/', include(admin.site.urls)),
+)
Please sign in to comment.
Something went wrong with that request. Please try again.