Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Removed django_revisions, fixed empty db bug #1

Open
wants to merge 5 commits into
from
View
@@ -38,23 +38,27 @@ Dependencies
git clone git@github.com:cheeseinvert/geocamMemoWeb.git
2. If you haven't already, you'll need to register your gmail or google apps address here: http://code.google.com/android/c2dm/signup.html
-3. Before running the Django application, rename geocamMemoWeb/geocamMemo/authentication_example.py to geocamMemoWeb/geocamMemo/authentication.py::
+3. CD into you ./geocamMemoWeb/example path and run the following (if there are no errors, continue to step 8)::
+
+ python manage.py googleauth
+
+4. Before running the Django application, rename geocamMemoWeb/geocamMemo/authentication_example.py to geocamMemoWeb/geocamMemo/authentication.py::
mv geocamMemoWeb/geocamMemo/authentication_example.py geocamMemoWeb/geocamMemo/authentication.py
-4. Modify the newly moved file and follow the directions. You'll need to run the following from the console in order to retrieve your authentication token (curl with ssl libraries required: http://curl.haxx.se/)::
+5. Modify the newly moved file and follow the directions. You'll need to run the following from the console in order to retrieve your authentication token (curl with ssl libraries required: http://curl.haxx.se/)::
curl https://www.google.com/accounts/ClientLogin -k --data-urlencode Email=youraccount@gmail.com --data-urlencode Passwd=some_password -d accountType=GOOGLE -d source=com.patrickbaumann.pushprototype -d service=ac2dm
-5. The response will contain an SID, AUTH, and LSID::
+6. The response will contain an SID, AUTH, and LSID::
SID=alsdjfa;ljsdf;lajsdlfj...
AUTH=alsdjkfa;lskjdfl;asjd...
LSID=asl;dfjalskdjflasjdfl...
-6. Paste the AUTH line after the '=' into authentication.py between the quotation marks.
+7. Paste the AUTH line after the '=' into authentication.py between the quotation marks.
-7. CD into your ./geocamMemoWeb/example path and run syncdb, creating an admin user if prompted::
+8. CD into your ./geocamMemoWeb/example path and run syncdb, creating an admin user if prompted::
python manage.py syncdb
View
@@ -70,7 +70,6 @@
MIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
- 'revisions.middleware.VersionedModelRedirectMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
)
@@ -93,6 +92,5 @@
'django.contrib.sessions',
'django.contrib.sites',
'geocamMemo',
- 'geocamTalk',
- 'revisions'
+ 'geocamTalk'
)
View
@@ -5,7 +5,6 @@
# __END_LICENSE__
from django import forms
-from revisions.admin import AutoRevisionForm
from geocamMemo.models import MemoMessage
from datetime import datetime
import re
@@ -29,7 +28,7 @@ def clean(self, value):
except:
raise forms.ValidationError
-class MemoMessageForm(AutoRevisionForm):
+class MemoMessageForm(forms.ModelForm):
position_timestamp = GeolocationTimestampDateTimeFormField()
class Meta:
model = MemoMessage
@@ -0,0 +1,46 @@
+# __BEGIN_LICENSE__
+# Copyright (C) 2008-2010 United States Government as represented by
+# the Administrator of the National Aeronautics and Space Administration.
+# All Rights Reserved.
+# __END_LICENSE__
+
+from django.core.management.base import BaseCommand, CommandError
+from example import settings
+import httplib
+import urllib
+import re
+import os
+
+class Command(BaseCommand):
+ args = 'none'
+ help = 'generate the authentication module needed to push c2dm messages to the google servers'
+
+ def handle(self, *args, **options):
+
+ email = raw_input("Please enter your gmail address: ")
+ password = raw_input("Please enter your gmail password: ")
+
+ params = urllib.urlencode({
+ 'Email': email,
+ 'Passwd': password,
+ 'accountType': 'GOOGLE',
+ 'source':'gov.nasa.arc.geocam.talk',
+ 'service':'ac2dm',
+ })
+
+ # need the following headers set per http://code.google.com/android/c2dm/index.html#push
+ headers = { "Content-Type":"application/x-www-form-urlencoded",
+ "Content-Length":len(params)
+ }
+
+ # NOW SEND THE REQUEST TO GOOGLE SERVERS
+ # first we need an https connection that ignores the certificate (for now)
+ httpsconnection = httplib.HTTPSConnection("www.google.com", 443)
+ httpsconnection.request("POST", "/accounts/ClientLogin", params, headers)
+ response = httpsconnection.getresponse()
+ response_body = response.read()
+ authstring = re.search('(?<=Auth=)[-_a-zA-Z0-9]+$',response_body).group(0)
+
+ authfile = open(settings.APP + os.sep + "geocamMemo" + os.sep + "authentication.py", "w+")
+
+ authfile.write('GOOGLE_TOKEN = "' + authstring + '"')
View
@@ -17,8 +17,6 @@ class Meta:
server_timestamp = models.DateTimeField(auto_now_add = True)
author = models.ForeignKey(User, related_name="%(app_label)s_%(class)s_set")
content = models.TextField(max_length=1024)
- # removed auto_add_now from content_timestamp since revisions are also instances in the
- # same table and we don't overwrite this timestamp on an edit
content_timestamp = models.DateTimeField(blank=True)
latitude = models.FloatField(null=True, blank=True)
longitude = models.FloatField(null=True, blank=True)
@@ -83,7 +81,7 @@ def fromJson(messageDict):
def getMessages(author=None):
""" Message Listing Rules:
- If no author is specified: all messages are displayed (latest revisions)
+ If no author is specified: all messages are displayed
If author is specified: all messages are displayed from author
"""
View
@@ -77,8 +77,6 @@ def create_message(request):
form = MemoMessageForm(request.POST)
if form.is_valid():
msg = form.save(commit=False)
- # Since revisions are now saved to db, this timestamp
- # can't just be auto set since we want to preserve from creation time
msg.content_timestamp = datetime.now()
msg.save()
return HttpResponseRedirect(reverse('memo_message_list_all'))
View
@@ -27,19 +27,8 @@ def getUnreadMessageCount(self):
User.profile = property(lambda u: TalkUserProfile.objects.get_or_create(user=u)[0])
class TalkMessage(GeocamMessage):
- """ This is the data model for Memo application messages
+ """ This is the data model for Memo application messages """
- Some of the Versioned Model API:
- VersionedModel.get_latest_revision()
- VersionedModel.get_revisions()
- VersionedModel.make_current_revision()
- VersionedModel.revert_to(criterion)
- VersionedModel.save(new_revision=True, *vargs, **kwargs)
- VersionedModel.show_diff_to(to, field)
- complete API and docs are here:
- http://stdbrouw.github.com/django-revisions/
-
- """
#TODO - add time to filename location
audio_file = models.FileField(null=True, blank=True, upload_to='geocamTalk/audio/%Y/%m/%d') #"%s-audio" % (GeocamMessage.author))
@@ -87,30 +76,33 @@ def fromJson(messageDict):
def getMessages(recipient=None, author=None):
""" Message Listing Rules:
- If no users are specified: all messages are displayed (latest revisions)
+ If no users are specified: all messages are displayed
If only author is specified: all messages are displayed from author
If only recipient is specified: messages displayed are broadcast + from OR to recipient
If both recipient AND author are specified: messages displayed are braodcast + from author AND to recipient
Note: a broadcast message is a message with no recipients
"""
if (recipient is None and author is None):
- # all messages are displayed (latest revisions)
- messages = TalkMessage.latest.all()
+ # all messages are displayed
+ messages = TalkMessage.objects.all()
elif (recipient is None and author is not None):
# messages displayed are from author:
- messages = TalkMessage.latest.filter(author__username=author.username)
+ messages = TalkMessage.objects.filter(author__username=author.username)
elif (recipient is not None and author is None):
# messages displayed are broadcast + from OR to recipient:
- messages = TalkMessage.latest.annotate(num_recipients=Count('recipients')).filter(Q(num_recipients=0) | Q(recipients__username=recipient.username) | Q(author__username=recipient.username)).distinct()
+ messages = TalkMessage.objects.annotate(num_recipients=Count('recipients')).filter(Q(num_recipients=0) | Q(recipients__username=recipient.username) | Q(author__username=recipient.username)).distinct()
else:
# messages displayed are braodcast + from author AND to recipient
- messages = TalkMessage.latest.annotate(num_recipients=Count('recipients')).filter(Q(num_recipients=0) | Q(recipients__username=recipient.username)).filter(author__username=author.username).distinct()
+ messages = TalkMessage.objects.annotate(num_recipients=Count('recipients')).filter(Q(num_recipients=0) | Q(recipients__username=recipient.username)).filter(author__username=author.username).distinct()
return messages.order_by('-content_timestamp')
@staticmethod
def getLargestMessageId():
- return TalkMessage.objects.all().order_by('-pk')[0].pk
+ try:
+ return TalkMessage.objects.all().order_by('-pk')[0].pk
+ except:
+ return 0
def has_audio(self):
return bool(self.audio_file != '')