def add_return_trip(request, trip_id): """Create a new back trip based on information of an existing trip """ trip = get_object_or_404(Trip, pk=trip_id, user=request.user) new_trip = Trip(user=request.user) new_trip.name = _('%(trip_name)s - Return') % {'trip_name': trip.name} new_trip.trip_type = trip.trip_type new_trip.departure_city = trip.arrival_city new_trip.departure_address = trip.arrival_address new_trip.departure_point = trip.arrival_point new_trip.arrival_city = trip.departure_city new_trip.arrival_address = trip.departure_address new_trip.arrival_point = trip.departure_point new_trip.regular = trip.regular if new_trip.regular: new_trip.dows = trip.dows new_offer = None if trip.offer: new_offer = TripOffer() new_offer.checkpointlist = trip.offer.checkpointlist new_offer.checkpointlist.reverse() new_offer.radius = trip.offer.radius new_trip.offer = new_offer new_demand = None if trip.demand: new_demand = TripDemand() new_demand.radius = trip.demand.radius new_trip.demand = new_demand userprofiledata = model_to_dict(request.user.get_profile()) form_trip = EditTripForm(initial=userprofiledata, instance=new_trip) form_offer = EditTripOfferOptionsForm(initial=userprofiledata, instance=new_offer, prefix='offer') form_demand = EditTripDemandOptionsForm(initial=userprofiledata, instance=new_demand, prefix='demand') points = [cp['point'] for cp in trip.offer.checkpointlist] if trip.offer else [] points.append(trip.departure_point) points.append(trip.arrival_point) mpoints = MultiPoint(points) response_dict = { 'form_trip': form_trip, 'form_offer_options': form_offer, 'form_demand_options': form_demand, 'default_center': settings.DEFAULT_MAP_CENTER_POINT, 'default_zoom': settings.DEFAULT_MAP_CENTER_ZOOM, 'return_trip': True, } template = loader.get_template('carpool/add_modify_trip.html') context = RequestContext(request, response_dict) return HttpResponse(template.render(context))
def add_return_trip(request, trip_id): """Create a new back trip based on information of an existing trip """ trip = get_object_or_404(Trip, pk=trip_id, user=request.user) new_trip = Trip(user=request.user) new_trip.name = _("%(trip_name)s - Return") % {"trip_name": trip.name} new_trip.trip_type = trip.trip_type new_trip.departure_city = trip.arrival_city new_trip.departure_address = trip.arrival_address new_trip.departure_point = trip.arrival_point new_trip.arrival_city = trip.departure_city new_trip.arrival_address = trip.departure_address new_trip.arrival_point = trip.departure_point new_trip.regular = trip.regular if new_trip.regular: new_trip.dows = trip.dows new_offer = None if trip.offer: new_offer = TripOffer() new_offer.checkpointlist = trip.offer.checkpointlist new_offer.checkpointlist.reverse() new_offer.radius = trip.offer.radius new_trip.offer = new_offer new_demand = None if trip.demand: new_demand = TripDemand() new_demand.radius = trip.demand.radius new_trip.demand = new_demand userprofiledata = model_to_dict(request.user.get_profile()) form_trip = EditTripForm(initial=userprofiledata, instance=new_trip) form_offer = EditTripOfferOptionsForm(initial=userprofiledata, instance=new_offer, prefix="offer") form_demand = EditTripDemandOptionsForm(initial=userprofiledata, instance=new_demand, prefix="demand") points = [cp["point"] for cp in trip.offer.checkpointlist] if trip.offer else [] points.append(trip.departure_point) points.append(trip.arrival_point) mpoints = MultiPoint(points) response_dict = { "form_trip": form_trip, "form_offer_options": form_offer, "form_demand_options": form_demand, "default_center": settings.DEFAULT_MAP_CENTER_POINT, "default_zoom": settings.DEFAULT_MAP_CENTER_ZOOM, "return_trip": True, } template = loader.get_template("carpool/add_modify_trip.html") context = RequestContext(request, response_dict) return HttpResponse(template.render(context))
arrival_city=arrival_city, arrival_point=GEOSGeometry(json.get('arrival_point')[0]), regular=regular, ) if not regular: trip.date = today trip.interval_min = random.randint(0, 6) trip.interval_max = random.randint(0, 6) else: trip.dows = [ dow for dow in range(0, 7) if random.random() < 0.5 ] if not trip.dows: trip.dows = [1] if trip_type != Trip.OFFER: demand = TripDemand(radius=random.choice(DEMAND_RADIUS_CHOICE)) demand.save() trip.demand = demand if trip_type != Trip.DEMAND: offer = TripOffer(radius=random.choice(OFFER_RADIUS_CHOICE), route=MultiLineString( [GEOSGeometry(json.get('geometry')[0])])) offer.save() trip.offer = offer trip.save() except Exception, e: print "!!!!!!!!!!!!!!!!!!!!!", e #if index > 10: # break finally: route_file.close()
departure_point=GEOSGeometry(json.get('departure_point')[0]), arrival_city=arrival_city, arrival_point=GEOSGeometry(json.get('arrival_point')[0]), regular=regular, ) if not regular: trip.date = today trip.interval_min = random.randint(0, 6) trip.interval_max = random.randint(0, 6) else: trip.dows = [dow for dow in range(0, 7) if random.random() < 0.5] if not trip.dows: trip.dows = [1] if trip_type != Trip.OFFER: demand = TripDemand( radius=random.choice(DEMAND_RADIUS_CHOICE) ) demand.save() trip.demand = demand if trip_type != Trip.DEMAND: offer = TripOffer( radius=random.choice(OFFER_RADIUS_CHOICE), route=MultiLineString([GEOSGeometry(json.get('geometry')[0])]) ) offer.save() trip.offer = offer trip.save() except Exception, e: print "!!!!!!!!!!!!!!!!!!!!!", e #if index > 10: # break