Esempio n. 1
0
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))
Esempio n. 2
0
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))