def test_activity_item_tag(self): lyr = Layer.objects.create(owner=self.bobby, name='layer1', typename='layer1', title='example') lyr.publish.status = 'Public' lyr.publish.save() comment_on(lyr, self.bobby, 'a comment') expected = ( "http://localhost:8000/mapstory/storyteller/bobby/ (bobby)" " commented on http://localhost:8000/data/layer1 (the StoryLayer 'example')" " [ 0 minutes ago ]") actual = mapstory_tags.activity_item(self.bobby.actor_actions.all()[0], plain_text=True) self.assertEqual(expected, actual) rate(lyr, self.bobby, 4) expected = ( "http://localhost:8000/mapstory/storyteller/bobby/ (bobby)" " gave http://localhost:8000/data/layer1 (the StoryLayer 'example')" " a rating of 4 [ 0 minutes ago ]") actual = mapstory_tags.activity_item(self.bobby.actor_actions.all()[0], plain_text=True) self.assertEqual(expected, actual) lyr.delete() # it seems like comment objects are not deleted when the commented-on object # is deleted - test that the tag doesn't blow up # @todo is this somehow related to mptt in threaded comments? self.assertEqual(1, len(self.bobby.actor_actions.all())) for a in self.bobby.actor_actions.all(): self.assertEqual('', mapstory_tags.activity_item(a))
def test_activity_item_tag(self): lyr = Layer.objects.create(owner=self.bobby, name='layer1',typename='layer1', title='example') lyr.publish.status = 'Public' lyr.publish.save() comment_on(lyr, self.bobby, 'a comment') expected = ("http://localhost:8000/mapstory/storyteller/bobby/ (bobby)" " commented on http://localhost:8000/data/layer1 (the StoryLayer 'example')" " [ 0 minutes ago ]") actual = mapstory_tags.activity_item(self.bobby.actor_actions.all()[0], plain_text=True) self.assertEqual(expected, actual) rate(lyr, self.bobby, 4) expected = ("http://localhost:8000/mapstory/storyteller/bobby/ (bobby)" " gave http://localhost:8000/data/layer1 (the StoryLayer 'example')" " a rating of 4 [ 0 minutes ago ]") actual = mapstory_tags.activity_item(self.bobby.actor_actions.all()[0], plain_text=True) self.assertEqual(expected, actual) lyr.delete() # it seems like comment objects are not deleted when the commented-on object # is deleted - test that the tag doesn't blow up # @todo is this somehow related to mptt in threaded comments? self.assertEqual(1, len(self.bobby.actor_actions.all())) for a in self.bobby.actor_actions.all(): self.assertEqual('', mapstory_tags.activity_item(a))
def notify_handler(sender, instance, action, model, pk_set, **kwargs): if action != 'post_add': return if instance.notification_preference != 'E': return assert len(pk_set) == 1 real_action = getattr(model,'objects').get(id=iter(pk_set).next()) send_html_mail("[MapStory] Notification", message=mapstory_tags.activity_item(real_action, plain_text=True), message_html=mapstory_tags.activity_item(real_action), from_email="*****@*****.**", recipient_list=[instance.user.email])
def storyteller_activity_pager(req, username, what='actions'): user = get_object_or_404(User, username=username) from mapstory.templatetags.mapstory_tags import activity_item pager = _storyteller_activity_pager(user, what) page_num = int(req.REQUEST.get('page',1)) if req else 1 page = None try: page = pager.page(page_num) except EmptyPage: pass link = tiles = '' if page: show_link = what != 'actions' tiles = ''.join([activity_item(i, show_link) for i in page]) link = "<a href='%s?page=%s' class='next'></a>" % (req.path, page.next_page_number()) if page.has_next() else '' return HttpResponse('<div>%s%s</div>' % (tiles,link))
def storyteller_activity_pager(req, username, what='actions'): user = get_object_or_404(User, username=username) from mapstory.templatetags.mapstory_tags import activity_item pager = _storyteller_activity_pager(user, what) page_num = _get_requested_page(req) page = None try: page = pager.page(page_num) except EmptyPage: raise Http404() link = tiles = '' if page: show_link = what != 'actions' tiles = ''.join([activity_item(i, show_link) for i in page]) link = "<a href='%s?page=%s' class='next'></a>" % ( req.path, page.next_page_number()) if page.has_next() else '' return HttpResponse('<div>%s%s</div>' % (tiles, link))
def activity_summary(actions, plain_text=False): sep = "\n" if plain_text else "<br/>" return sep.join( [mapstory_tags.activity_item(a, plain_text) for a in actions])
def activity_summary(actions, plain_text=False): sep = "\n" if plain_text else "<br/>" return sep.join([mapstory_tags.activity_item(a, plain_text) for a in actions])