Project for the UPV to develop an app like BlaBlaCar but only for UPV people.
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

added cancel event

+20 -5
+2 -1
upvcarshare/journeys/models.py
··· 19 19 from journeys.exceptions import NoFreePlaces, NotAPassenger, AlreadyAPassenger 20 20 from journeys.helpers import make_point_wgs84 21 21 from journeys.managers import JourneyManager, ResidenceManager 22 - from notifications import JOIN, LEAVE 22 + from notifications import JOIN, LEAVE, CANCEL 23 23 from notifications.decorators import dispatch 24 24 25 25 ··· 236 236 """Gets the journey distance.""" 237 237 return self.residence.position.distance(self.campus.position) / 1000 238 238 239 + @dispatch(CANCEL) 239 240 def cancel(self): 240 241 """Cancels a journey.""" 241 242 self.disabled = True
+1 -1
upvcarshare/notifications/__init__.py
··· 2 2 from __future__ import unicode_literals, print_function, absolute_import 3 3 4 4 # Notification verbs 5 - JOIN, LEAVE = "join", "leave" 5 + JOIN, LEAVE, CANCEL = "join", "leave", "cancel"
+11 -2
upvcarshare/notifications/manager.py
··· 5 5 from django.db import models 6 6 from django.utils.functional import SimpleLazyObject 7 7 8 - from notifications import LEAVE, JOIN 8 + from notifications import LEAVE, JOIN, CANCEL 9 9 10 10 11 11 def extract(classes, iterable): ··· 43 43 notification.target = journey 44 44 notification.save() 45 45 return notification 46 - 46 + elif verb == CANCEL: 47 + notifications = [] 48 + journey = extract(Journey, objects)[0] 49 + for passenger in journey.passengers.all(): 50 + notification = self.model(verb=verb) 51 + notification.actor = journey 52 + notification.user = passenger.user 53 + notification.save() 54 + notifications.append(notification) 55 + return notifications 47 56 return None
+6 -1
upvcarshare/notifications/models.py
··· 13 13 from django.utils.translation import ugettext_lazy as _ 14 14 from django_extensions.db.models import TimeStampedModel 15 15 16 - from notifications import JOIN, LEAVE 16 + from notifications import JOIN, LEAVE, CANCEL 17 17 from notifications.manager import NotificationManager 18 18 19 19 ··· 70 70 "user": six.text_type(self.actor), 71 71 "journey": six.text_type(self.target).lower(), 72 72 "date": localize(self.target.departure), 73 + } 74 + elif self.verb == CANCEL: 75 + value = _("El trayecto <strong>%(journey)s</strong> del %(date)s ha sido <strong>cancelado</strong>") % { 76 + "journey": six.text_type(self.actor).lower(), 77 + "date": localize(self.actor.departure), 73 78 } 74 79 if strip_html: 75 80 value = strip_tags(value)