Permalink
Browse files

removed obsolete references to django-revisions; added kml feed

  • Loading branch information...
1 parent c552172 commit 29b5da0a87481102b195017c7af05a20b45f4ffa @trey0 trey0 committed Oct 11, 2011
View
@@ -102,7 +102,10 @@ def getMessages(author=None):
def get_user_string(user):
if user.first_name and user.last_name:
- return (user.first_name + " " + user.last_name)
+ if user.last_name in ('group', 'Group'):
+ return user.first_name
+ else:
+ return (user.first_name + " " + user.last_name)
else:
return (user.username)
@@ -38,13 +38,13 @@ def testMessageListSizeAndOrder(self):
self.assertEqual(displayed_message_ids, message_ids, "Order should be the same")
def testMessageListDateFormat(self):
- messages = MemoMessage.latest.all()
+ messages = MemoMessage.objects.all()
response = self.get_messages_response()
for m in messages:
self.assertContains(response, m.content_timestamp.strftime("%m/%d/%y %H:%M:%S"), None, 200)
def testMessageListAuthorFormat(self):
- messages = MemoMessage.latest.all()
+ messages = MemoMessage.objects.all()
response = self.get_messages_response()
for m in messages:
@@ -55,7 +55,7 @@ def testMessageListAuthorFormat(self):
def testMessageListContentFormat(self):
- messages = MemoMessage.latest.all()
+ messages = MemoMessage.objects.all()
response = self.get_messages_response()
for m in messages:
self.assertContains(response, m.content)
@@ -65,7 +65,7 @@ def testMessageListGeoLocationPresent(self):
response = self.get_messages_response()
# act
- geocount = MemoMessage.latest.exclude(latitude=None, longitude=None).count()
+ geocount = MemoMessage.objects.exclude(latitude=None, longitude=None).count()
# assert
self.assertContains(response, "data-icon=\"geoCam-map\"", geocount)
@@ -108,7 +108,7 @@ def testEnsureFilteredMessageListSizeAndOrder(self):
def testEnsureMessageListAuthorLinksPresent(self):
#arrange
- messages = MemoMessage.latest.all()
+ messages = MemoMessage.objects.all()
#act
response = self.get_messages_response()
@@ -211,7 +211,7 @@ class GeocamMemoSingleMessageViewTest(TestCase):
def testEnsureProperFieldsAreDisplayed(self):
# arrange
- m = MemoMessage.latest.all()[0]
+ m = MemoMessage.objects.all()[0]
u = User.objects.all()[0]
self.client.login(username=u.username, password='geocam')
View
@@ -35,7 +35,7 @@ def testMessagesJsonListUrl(self):
def testMessageJsonListUrl(self):
#arrange
- pk = str(MemoMessage.latest.all()[0].pk)
+ pk = str(MemoMessage.objects.all()[0].pk)
path = "/memo/messages/details/" + pk + ".json"
#act
@@ -46,7 +46,7 @@ def testMessageJsonListUrl(self):
def testMessageDetailsUrl(self):
#arrange
- message = MemoMessage.latest.all()[0]
+ message = MemoMessage.objects.all()[0]
path = "/memo/messages/details/" + str(message.pk)
template = "geocamMemo/details.html"
@@ -55,7 +55,7 @@ def testMessageDetailsUrl(self):
def testMessageEditUrl(self):
#arrange
- message = MemoMessage.latest.all()[0]
+ message = MemoMessage.objects.all()[0]
path = "/memo/messages/edit/" + str(message.pk)
template = "geocamMemo/edit_message_form.html"
@@ -90,7 +90,7 @@ def testMessageListFilteredByUserUrl(self):
def testMessageDeleteUrl(self):
#arrange
- message = MemoMessage.latest.all()[0]
+ message = MemoMessage.objects.all()[0]
path = "/memo/messages/delete/" + str(message.pk)
#act
View
@@ -33,7 +33,7 @@ def tearDown(self):
def test_createMessage(self):
""" Create Geocam Message """
- msgCnt = MemoMessage.latest.all().count()
+ msgCnt = MemoMessage.objects.all().count()
content = "This is a message"
author = User.objects.get(username="rhornsby")
@@ -49,11 +49,11 @@ def test_createMessage(self):
def test_deleteMessage(self):
""" Delete Geocam Message """
- msgCnt = MemoMessage.latest.all().count()
- msg = MemoMessage.latest.all()[1]
+ msgCnt = MemoMessage.objects.all().count()
+ msg = MemoMessage.objects.all()[1]
# delete the first message and all it's revisions:
msg.delete()
- newMsgCnt = MemoMessage.latest.all().count()
+ newMsgCnt = MemoMessage.objects.all().count()
self.assertEqual(newMsgCnt + 1, msgCnt, "Deleting a Message Failed.")
def test_submitFormToCreateMessage(self):
@@ -69,7 +69,7 @@ def test_submitFormToCreateMessage(self):
self.assertEqual(response.status_code, 200, "submitFormToCreateMessage Failed")
def test_submitFormToCreateMessageJSON(self):
- msgCnt = MemoMessage.latest.all().count()
+ msgCnt = MemoMessage.objects.all().count()
content = "Whoa man, that burning building almost collapsed on me!"
timestamp = self.now
author = User.objects.get(username="rhornsby")
@@ -80,7 +80,7 @@ def test_submitFormToCreateMessageJSON(self):
"contentTimestamp": time.mktime(timestamp.timetuple()),
"latitude": GeocamMemoMessageSaveTest.cmusv_lat,
"longitude": GeocamMemoMessageSaveTest.cmusv_lon})})
- newMsgCnt = MemoMessage.latest.all().count()
+ newMsgCnt = MemoMessage.objects.all().count()
self.assertEqual(response.status_code, 200, "submitFormToCreateMessageJSON Failed")
self.assertEqual(newMsgCnt, msgCnt + 1)
@@ -97,7 +97,7 @@ def test_MessagesJsonFeed(self):
def test_MessageJsonFeed(self):
# arrange
- msg = MemoMessage.latest.all().reverse()[0]
+ msg = MemoMessage.objects.all().reverse()[0]
stringified_msg = json.dumps(msg.getJson())
#self.client.login(username="root", password='geocam')
@@ -175,24 +175,24 @@ def test_submitFormToEditMessage(self):
self.assertEqual(new_msg.longitude, original_msg.longitude, "submitFormToEditMessage Failed")
def test_ensureDeleteByNonAuthorForbidden(self):
- m = MemoMessage.latest.all()[0]
- msgCnt = MemoMessage.latest.all().count()
+ m = MemoMessage.objects.all()[0]
+ msgCnt = MemoMessage.objects.all().count()
for user in User.objects.all():
if user.pk != m.author.pk and not user.is_superuser:
self.loginUser(user.pk)
break
response = self.client.post("/memo/messages/delete/%s" % m.pk)
self.assertEqual(response.status_code, 302, "ensureDeleteByNonAuthorForbidden Failed")
- newMsgCnt = MemoMessage.latest.all().count()
+ newMsgCnt = MemoMessage.objects.all().count()
self.assertEqual(msgCnt, newMsgCnt, "ensureDeleteByNonAuthorForbidden Failed")
def test_deleteMessage(self):
"Delete the Memo Message"
- m = MemoMessage.latest.all()[0]
- msgCnt = MemoMessage.latest.all().count()
+ m = MemoMessage.objects.all()[0]
+ msgCnt = MemoMessage.objects.all().count()
self.loginUser(m.author.pk)
response = self.client.post("/memo/messages/delete/%s" % m.pk)
self.assertEqual(response.status_code, 302, "deleteMessage Failed")
- newMsgCnt = MemoMessage.latest.all().count()
+ newMsgCnt = MemoMessage.objects.all().count()
self.assertEqual(msgCnt - 1, newMsgCnt, "deleteMessage Failed")
View
@@ -16,7 +16,7 @@
from django.contrib.auth.models import User
from django.db.models import Q, Count
-from geocamMemo.models import GeocamMessage
+from geocamMemo.models import GeocamMessage, get_user_string
from geocamMemo import settings
@@ -58,6 +58,34 @@ def __unicode__(self):
recipients = models.ManyToManyField(User, null=True, blank=True, related_name="received_messages")
+ def getKml(self):
+ if not self.has_geolocation():
+ return ''
+ fields = vars(self).copy()
+ fields['authorFullname'] = self.get_author_string()
+ fields['recipients'] = ', '.join([get_user_string(r) for r in self.recipients.all()])
+ if self.content:
+ fields['name'] = '<name>' + self.content[:10] + '...</name>'
+ else:
+ fields['name'] = ''
+ return ("""
+<Placemark>
+ <Point>
+ <coordinates>%(longitude).6f,%(latitude).6f</coordinates>
+ </Point>
+ %(name)s
+ <description>
+ <![CDATA[
+ <div><span style="color: #888;">Author:</span> %(authorFullname)s</div>
+ <div><span style="color: #888;">Recipients:</span> %(recipients)s</div>
+ <div><span style="color: #888;">Date:</span> %(content_timestamp)s</div>
+ <div><span style="color: #888;">Position:</span> %(latitude).6f, %(longitude).6f</div>
+ <div style="margin: 20px;">%(content)s</div>
+ ]]>
+ </description>
+</Placemark>
+""" % fields)
+
def getJson(self):
return dict(messageId=self.pk,
userId=self.author.pk,
@@ -102,16 +130,16 @@ def getMessages(recipient=None, author=None):
"""
if (recipient is None and author is None):
# all messages are displayed (latest revisions)
- messages = TalkMessage.latest.all()
+ 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
View
@@ -45,7 +45,7 @@ def testMessageCreateJSONFeed(self):
def testMessageJsonUrl(self):
#arrange
- pk = str(TalkMessage.latest.all()[0].pk)
+ pk = str(TalkMessage.objects.all()[0].pk)
path = "/talk/messages/details/" + pk + ".json"
self.login()
View
@@ -40,7 +40,7 @@ def tearDown(self):
def test_createTalkMessage(self):
""" Create Geocam Talk Message """
- msgCnt = TalkMessage.latest.all().count()
+ msgCnt = TalkMessage.objects.all().count()
content = "This is a message"
author = User.objects.get(username="rhornsby")
@@ -50,23 +50,23 @@ def test_createTalkMessage(self):
longitude=GeocamTalkMessageSaveTest.cmusv_lon,
author=author,
content_timestamp=self.now)
- newMsgCnt = TalkMessage.latest.all().count()
+ newMsgCnt = TalkMessage.objects.all().count()
self.assertEqual(msgCnt + 1, newMsgCnt, "Creating a Talk Message Failed.")
def test_deleteTalkMessage(self):
""" Delete Geocam Talk Message """
- msgCnt = TalkMessage.latest.all().count()
+ msgCnt = TalkMessage.objects.all().count()
# delete the first message:
- msg = TalkMessage.latest.all()[1]
+ msg = TalkMessage.objects.all()[1]
msg.delete()
- newMsgCnt = TalkMessage.latest.all().count()
+ newMsgCnt = TalkMessage.objects.all().count()
self.assertEqual(newMsgCnt + 1, msgCnt, "Deleting a Talk Message Failed.")
def test_submitFormToCreateMessage(self):
""" submit the Talk Message through the form """
- msgCnt = TalkMessage.latest.all().count()
+ msgCnt = TalkMessage.objects.all().count()
content = "Whoa man, that burning building almost collapsed on me!"
author = User.objects.get(username="rhornsby")
self.client.login(username=author.username, password='geocam')
@@ -78,13 +78,13 @@ def test_submitFormToCreateMessage(self):
"author": author.pk})
# should be redirected when form post is successful:
self.assertEqual(response.status_code, 302, "submitFormToCreateMessage Failed")
- newMsgCnt = TalkMessage.latest.all().count()
+ newMsgCnt = TalkMessage.objects.all().count()
self.assertEqual(msgCnt + 1, newMsgCnt, "Creating a Talk Message through view Failed.")
def test_submitFormToCreateMessageWithRecipients(self):
""" submit the Talk Message through the form """
- msgCnt = TalkMessage.latest.all().count()
+ msgCnt = TalkMessage.objects.all().count()
content = "Whoa man, that burning building almost collapsed on me!"
author = User.objects.get(username="rhornsby")
self.client.login(username=author.username, password='geocam')
@@ -101,13 +101,13 @@ def test_submitFormToCreateMessageWithRecipients(self):
# should be redirected when form post is successful:
self.assertEqual(response.status_code, 302, "submitFormToCreateMessage Failed")
- newMsgCnt = TalkMessage.latest.all().count()
+ newMsgCnt = TalkMessage.objects.all().count()
self.assertEqual(msgCnt + 1, newMsgCnt, "Creating a Talk Message through view Failed.")
newMsg = TalkMessage.getMessages()[0]
self.assertEqual(newMsg.recipients.all().count(), 2, "Different number of recipients than expected")
def test_submitFormToCreateMessageJSON(self):
- msgCnt = TalkMessage.latest.all().count()
+ msgCnt = TalkMessage.objects.all().count()
content = "Whoa man, that burning building almost collapsed on me!"
timestamp = self.now
author = User.objects.get(username="rhornsby")
@@ -118,14 +118,14 @@ def test_submitFormToCreateMessageJSON(self):
"contentTimestamp": time.mktime(timestamp.timetuple()),
"latitude": GeocamTalkMessageSaveTest.cmusv_lat,
"longitude": GeocamTalkMessageSaveTest.cmusv_lon})})
- newMsgCnt = TalkMessage.latest.all().count()
+ newMsgCnt = TalkMessage.objects.all().count()
self.assertEqual(response.status_code, 200, "submitFormToCreateMessageJSON Failed")
self.assertContains(response, "messageId")
self.assertContains(response, "authorFullname")
self.assertEqual(newMsgCnt, msgCnt + 1)
def testAudioMsgCreate(self):
- _msgCnt = TalkMessage.latest.all().count()
+ _msgCnt = TalkMessage.objects.all().count()
content = "Whoa man, that burning building almost collapsed on me!"
timestamp = self.now
author = User.objects.get(username="rhornsby")
@@ -147,7 +147,7 @@ def testAudioMsgCreate(self):
f.close()
self.assertEqual(response.status_code, 200, "Failed to move message from phone to web app")
# get the message we just created:
- postedFile = TalkMessage.latest.get(content=content).audio_file.name
+ postedFile = TalkMessage.objects.get(content=content).audio_file.name
self._clean_test_files(testAudioFile, postedFile)
def _createFile(self, filename, filesize=5 * 1024 * 1024):
@@ -194,7 +194,7 @@ def _clean_test_files(self, test_file_path, postedFile):
def test_submitFormWithoutContentTalkMessage(self):
""" submit the Talk Message without content through the form """
- msgCnt = TalkMessage.latest.all().count()
+ msgCnt = TalkMessage.objects.all().count()
author = User.objects.get(username="rhornsby")
self.client.login(username=author.username, password='geocam')
@@ -204,12 +204,12 @@ def test_submitFormWithoutContentTalkMessage(self):
"author": author.pk})
# should get 200 on render_to_response when is_valid fails (which should occur)
self.assertEqual(response.status_code, 200, "test_submitFormWithoutContentTalkMessage Failed")
- newMsgCnt = TalkMessage.latest.all().count()
+ newMsgCnt = TalkMessage.objects.all().count()
self.assertEqual(msgCnt, newMsgCnt, "Creating a Talk Message through view Succeeded with no content.")
def test_MessageJsonFeed(self):
# arrange
- msg = TalkMessage.latest.all()[0]
+ msg = TalkMessage.objects.all()[0]
stringified_msg = json.dumps(msg.getJson())
self.client.login(username=msg.author.username, password='geocam')
@@ -228,7 +228,7 @@ def test_login(self):
def test_MessageContentOrdering(self):
- ordered_messages = TalkMessage.latest.all().order_by('-content_timestamp')
+ ordered_messages = TalkMessage.objects.all().order_by('-content_timestamp')
response = self._get_messages_response()
response_ordered_messages = response.context["gc_msg"]
self.assertEqual(ordered_messages[0], response_ordered_messages[0], 'Ordering of the message in the message list is not right')
Oops, something went wrong.

0 comments on commit 29b5da0

Please sign in to comment.