Example #1
0
def depart_from_arrival_to(request, city_slug, city_zip, is_depart, page):
    """Displays the list of trip offers with a departure or an arrival from or to
    the given city
    
    """
    ordering = {
        'departure': ['departure_city'],
        '-departure': ['-departure_city'],
        'arrival': ['arrival_city'],
        '-arrival': ['-arrival_city'],
        'date': ['dows', 'date'],
        '-date': ['-dows', '-date'],
        'time': ['time'],
        '-time': ['-time'],
        'type': ['type'],
        '-type': ['-type'],
    }
    pg = _TRIP_PG[0]
    order = 'date'
    if 'pg' in request.GET:
        try:
            if int(request.GET['pg']) in _TRIP_PG:
                pg = int(request.GET['pg'])
        except ValueError:
            pass
    if 'order' in request.GET and request.GET['order'] in ordering:
        order = request.GET['order']
    get_url_pg = '?pg=%d' % pg
    get_url = '?pg=%d&order=%s' % (pg, order)

    oargs = ordering[order]
    
    radius = 10000
    int_city_zip = int(city_zip)
    city = get_object_or_404(
            City, slug=str_slugify(city_slug),
            zipcode__gte=int_city_zip*1000,
            zipcode__lte=(int_city_zip+1)*1000
    )

    if is_depart:
        trips = Trip.objects.get_trip_from_city(city.point, radius).exclude_outdated().order_by(*oargs)
    else:
        trips = Trip.objects.get_trip_to_city(city.point, radius).exclude_outdated().order_by(*oargs)

    paginator = PaginatorRender(
        trips,
        page,
        pg,
        allow_empty_first_page=True,
        extra_context = {
            'city': city,
            'is_depart': is_depart,
            'paginations': _TRIP_PG,
            'get_url_pg': get_url_pg,
            'get_url': get_url,
            'order': order,
        }
    )
    return paginator.render(request, 'carpool/depart_from_arrival_to.html')
Example #2
0
 def get_city(cls, value):
     """Return a city from a value"""
     if not value:
         return None
     match_address = R_CITY_ZIP.match(str_slugify(value))
     try:
         if match_address:
             return cls.objects.get_from_slug(
                     match_address.group(1),
                     int(match_address.group(2)),
             )
         else:
             return cls.objects.filter(
                 slug__startswith=str_slugify(value)
             ).order_by('-population', 'slug', 'zipcode')[0]
     except (ValueError, cls.DoesNotExist, IndexError):
         return None
Example #3
0
 def get_city(cls, value):
     """Return a city from a value"""
     if not value:
         return None
     match_address = R_CITY_ZIP.match(str_slugify(value))
     try:
         if match_address:
             return cls.objects.get_from_slug(
                 match_address.group(1),
                 int(match_address.group(2)),
             )
         else:
             return cls.objects.filter(
                 slug__startswith=str_slugify(value)).order_by(
                     '-population', 'slug', 'zipcode')[0]
     except (ValueError, cls.DoesNotExist, IndexError):
         return None
Example #4
0
def depart_from_arrival_to(request, city_slug, city_zip, is_depart, page):
    """Displays the list of trip offers with a departure or an arrival from or to
    the given city
    
    """
    ordering = {
        "departure": ["departure_city"],
        "-departure": ["-departure_city"],
        "arrival": ["arrival_city"],
        "-arrival": ["-arrival_city"],
        "date": ["dows", "date"],
        "-date": ["-dows", "-date"],
        "time": ["time"],
        "-time": ["-time"],
        "type": ["type"],
        "-type": ["-type"],
    }
    pg = _TRIP_PG[0]
    order = "date"
    if "pg" in request.GET:
        try:
            if int(request.GET["pg"]) in _TRIP_PG:
                pg = int(request.GET["pg"])
        except ValueError:
            pass
    if "order" in request.GET and request.GET["order"] in ordering:
        order = request.GET["order"]
    get_url_pg = "?pg=%d" % pg
    get_url = "?pg=%d&order=%s" % (pg, order)

    oargs = ordering[order]

    radius = 10000
    int_city_zip = int(city_zip)
    city = get_object_or_404(
        City, slug=str_slugify(city_slug), zipcode__gte=int_city_zip * 1000, zipcode__lte=(int_city_zip + 1) * 1000
    )

    if is_depart:
        trips = Trip.objects.get_trip_from_city(city.point, radius).exclude_outdated().order_by(*oargs)
    else:
        trips = Trip.objects.get_trip_to_city(city.point, radius).exclude_outdated().order_by(*oargs)

    paginator = PaginatorRender(
        trips,
        page,
        pg,
        allow_empty_first_page=True,
        extra_context={
            "city": city,
            "is_depart": is_depart,
            "paginations": _TRIP_PG,
            "get_url_pg": get_url_pg,
            "get_url": get_url,
            "order": order,
        },
    )
    return paginator.render(request, "carpool/depart_from_arrival_to.html")
Example #5
0
 def get_absolute_url(self):
     """Build the announce URL."""
     if self.regular:
         return ('carpool:ajax_get_trip_details_regular', [
             '-'.join([value
                 for (key, value) in self.DOWS
                 if key in self.dows]),
             str_slugify(self.departure_city),
             str_slugify(self.arrival_city),
             str(self.id)
         ])
     else:
         return ('carpool:ajax_get_trip_details_punctual', [
             self.date.strftime("%d-%m-%Y"),
             str_slugify(self.departure_city),
             str_slugify(self.arrival_city),
             str(self.id)
         ])
Example #6
0
 def get_city(self, slug, zipcode):
     """Return a city object from slug and zipcode informations
     
     Raises a CityNotfound exception if the city doenst exists        
     """
     slug = unicode(slug)
     try:
         zipcode = int(zipcode)
         return City.objects.get(slug=str_slugify(slug), zipcode__gte=zipcode*1000, zipcode__lte=(zipcode+1)*1000)
     except City.DoesNotExist:
         raise CityDoesNotExist()
Example #7
0
def get_city(request):
    """Return a list of cities begining with the given value."""
    if request.method != "POST":
        raise Http404

    query = request.POST.get("value", None)
    if query:
        cities = City.objects.filter(slug__startswith=str_slugify(query)).order_by("-population", "slug")[:15]
    else:
        cities = []

    return HttpResponse("<ul>%s</ul>" % "".join(["<li>%s</li>" % city for city in cities]))
Example #8
0
 def get_city(self, slug, zipcode):
     """Return a city object from slug and zipcode informations
     
     Raises a CityNotfound exception if the city doenst exists        
     """
     slug = unicode(slug)
     try:
         zipcode = int(zipcode)
         return City.objects.get(slug=str_slugify(slug),
                                 zipcode__gte=zipcode * 1000,
                                 zipcode__lte=(zipcode + 1) * 1000)
     except City.DoesNotExist:
         raise CityDoesNotExist()
Example #9
0
def robots_search_trip(request, departure_slug, departure_zip, arrival_slug, arrival_zip, trip_type):
    """Search for a trip, and put information in session
    
    Then, call and return the response of the "search_trip" view
    
    """
    try:
        int_departure_zip = int(departure_zip)
        int_arrival_zip = int(arrival_zip)
        departure_city = City.objects.get(
            slug=str_slugify(departure_slug),
            zipcode__gte=int_departure_zip * 1000,
            zipcode__lte=(int_departure_zip + 1) * 1000,
        )
        arrival_city = City.objects.get(
            slug=str_slugify(arrival_slug),
            zipcode__gte=int_arrival_zip * 1000,
            zipcode__lte=(int_arrival_zip + 1) * 1000,
        )
        search_trip_details = {
            "departure": {
                "name": smart_unicode(departure_city),
                "point": departure_city.point.wkt,
                "favoriteplace": None,
            },
            "arrival": {"name": smart_unicode(arrival_city), "point": arrival_city.point.wkt, "favoriteplace": None},
        }
        if request.session.get("search_trip_details"):
            if (
                smart_unicode(departure_city) != request.session["search_trip_details"]["departure"]["name"]
                or smart_unicode(arrival_city) != request.session["search_trip_details"]["arrival"]["name"]
            ):
                request.session["search_trip_details"].update(search_trip_details)
        else:
            request.session["search_trip_details"] = search_trip_details
            request.session["search_trip_details"].update({"date": datetime.date.today().strftime("%d/%m/%Y")})
    except City.DoesNotExist:
        pass
    return search_trip(request, trip_type)
Example #10
0
def robots_search_trip(request, departure_slug, departure_zip, arrival_slug, arrival_zip, trip_type):
    """Search for a trip, and put information in session
    
    Then, call and return the response of the "search_trip" view
    
    """
    try:
        int_departure_zip = int(departure_zip)
        int_arrival_zip = int(arrival_zip)
        departure_city = City.objects.get(slug=str_slugify(departure_slug), zipcode__gte=int_departure_zip*1000, zipcode__lte=(int_departure_zip+1)*1000)
        arrival_city = City.objects.get(slug=str_slugify(arrival_slug), zipcode__gte=int_arrival_zip*1000, zipcode__lte=(int_arrival_zip+1)*1000)
        search_trip_details = {
            'departure': {'name': smart_unicode(departure_city), 'point': departure_city.point.wkt, 'favoriteplace': None},
            'arrival': {'name': smart_unicode(arrival_city), 'point': arrival_city.point.wkt, 'favoriteplace': None},
        }
        if request.session.get('search_trip_details'):
            if smart_unicode(departure_city) != request.session['search_trip_details']['departure']['name'] or smart_unicode(arrival_city) != request.session['search_trip_details']['arrival']['name']:
                request.session['search_trip_details'].update(search_trip_details)
        else:
            request.session['search_trip_details'] = search_trip_details
            request.session['search_trip_details'].update({'date': datetime.date.today().strftime("%d/%m/%Y")})
    except City.DoesNotExist:
        pass
    return search_trip(request, trip_type)
Example #11
0
def get_city(request):
    """Return a list of cities begining with the given value."""
    if request.method != 'POST':
        raise Http404

    query = request.POST.get('value', None)
    if query:
        cities = City.objects.filter(
            slug__startswith=str_slugify(query)).order_by(
                '-population', 'slug')[:15]
    else:
        cities = []

    return HttpResponse('<ul>%s</ul>' %
                        ''.join(['<li>%s</li>' % city for city in cities]))
Example #12
0
        try:
            if re.search("^#", line):
                # next
                continue

            data = [d.strip() for d in line.split(";")]
            # print data

            lat = data[DATA["LAT"]] if data[DATA["LAT"]] != "-" else "0"
            lng = data[DATA["LNG"]] if data[DATA["LNG"]] != "-" else "0"
            lat = re.sub(",", ".", lat)
            lng = re.sub(",", ".", lng)

            name = smart_unicode(data[DATA["NAME"]])
            city = City(
                name=name,
                slug=str_slugify(name),
                zipcode=int(data[DATA["ZIPCODE"]]),
                point=GEOSGeometry("POINT( %s %s )" % (lng, lat), srid=SRID_DEFAULT),
                insee_code=int(data[DATA["INSEECODE"]]),
                population=0,
            )
            print city, city.slug
            city.save()
        except Exception, e:
            print "!!!!!!!!!!!!!!!!!!!!!", line, e
finally:
    input_file.close()

print "OK\n"
Example #13
0
    for line in input_file:
        try:
            if re.search('^#', line):
                # next
                continue

            data = [d.strip() for d in line.split(';')]
            #print data

            lat = data[DATA['LAT']] if data[DATA['LAT']] != '-' else "0"
            lng = data[DATA['LNG']] if data[DATA['LNG']] != '-' else "0"
            lat = re.sub(',', '.', lat)
            lng = re.sub(',', '.', lng)

            name = smart_unicode(data[DATA['NAME']])
            city = City(name=name,
                        slug=str_slugify(name),
                        zipcode=int(data[DATA['ZIPCODE']]),
                        point=GEOSGeometry('POINT( %s %s )' % (lng, lat),
                                           srid=SRID_DEFAULT),
                        insee_code=int(data[DATA['INSEECODE']]),
                        population=0)
            print city, city.slug
            city.save()
        except Exception, e:
            print "!!!!!!!!!!!!!!!!!!!!!", line, e
finally:
    input_file.close()

print "OK\n"
Example #14
0
def home(request):
    response_dict = {
        'current_item': 1,
        'gmapkey': settings.GOOGLE_MAPS_API_KEY,
        'places': FavoritePlace.objects.all().order_by('name'),
    }

    today = datetime.date.today()

    search_trip_details = request.session.get('search_trip_details', None)
    if search_trip_details:
        date = get_date(search_trip_details['date'], FRENCH_DATE_INPUT_FORMATS)
        if date < today:
            date = today
        data = {
            'departure':
            search_trip_details['departure']['name'],
            'departure_point':
            search_trip_details['departure']['point'],
            'departure_favoriteplace':
            search_trip_details['departure']['favoriteplace']
            if 'favoriteplace' in search_trip_details['departure'] else None,
            'arrival':
            search_trip_details['arrival']['name'],
            'arrival_point':
            search_trip_details['arrival']['point'],
            'arrival_favoriteplace':
            search_trip_details['arrival']['favoriteplace']
            if 'favoriteplace' in search_trip_details['arrival'] else None,
            'date':
            date,
            'type':
            Trip.OFFER
        }
    else:
        data = None

    dates_concert = get_dates_concert()

    if request.method == 'POST':
        if dates_concert:
            form = SearchTripRmll2009Form(request.POST)
        else:
            form = SearchTripForm(request.POST)
        if form.is_valid():
            try:
                trip_type = int(form.cleaned_data['type'])
            except:
                trip_type = Trip.OFFER
            search_trip_details = {
                'departure': {
                    'name': form.cleaned_data['departure'],
                    'point': form.cleaned_data['departure_point'],
                    'favoriteplace':
                    form.cleaned_data['departure_favoriteplace']
                },
                'arrival': {
                    'name': form.cleaned_data['arrival'],
                    'point': form.cleaned_data['arrival_point'],
                    'favoriteplace': form.cleaned_data['arrival_favoriteplace']
                },
                'date':
                form.cleaned_data['date'].strftime("%d/%m/%Y")
                if form.cleaned_data['date'] else
                date_default.strftime("%d/%m/%Y")
            }
            request.session['search_trip_details'] = search_trip_details
            match_departure = R_CITY_ZIP.match(
                str_slugify(form.cleaned_data['departure']))
            match_arrival = R_CITY_ZIP.match(
                str_slugify(form.cleaned_data['arrival']))
            args = None
            if match_departure and match_arrival:
                args = [
                    match_departure.group(1),
                    match_departure.group(2),
                    match_arrival.group(1),
                    match_arrival.group(2)
                ]

            if trip_type == Trip.OFFER:
                if args:
                    return HttpResponseRedirect(
                        reverse('carpool:robots_search_offer_trip', args=args))
                else:
                    return HttpResponseRedirect(
                        reverse('carpool:search_offer_trip'))
            else:
                if args:
                    return HttpResponseRedirect(
                        reverse('carpool:robots_search_demand_trip',
                                args=args))
                else:
                    return HttpResponseRedirect(
                        reverse('carpool:search_demand_trip'))
    else:
        if dates_concert:
            form = SearchTripRmll2009Form(data)
        else:
            initial_data = {'date': today}
            form = SearchTripForm(data, initial=initial_data)
    response_dict.update({
        'form': form,
        'date_uptodate': dates_concert,
        'cities_concert': _CITIES_CONCERT,
    })

    template = loader.get_template('carpool/home_rmll2009.html')
    context = RequestContext(request, response_dict)
    return HttpResponse(template.render(context))
Example #15
0
def home(
    request,
    layout=None,
    theme_id=None,
    theme_dict=None,
    format_id=None,
    format_dict=None,
    media_specific=None,
    date=None,
    departure=None,
    arrival=None,
):
    """Home.
    
    This view is acessible via GET and POST.
    
    
    On GET, it displays a form for selecting a trip
    On POST, check if the form is valid, and redirect to other views
    """

    def get_dates_available(dates):
        """Filter dates from a set of given dates
        
        filter dates in past
        
        """
        today = datetime.date.today()
        return [date for date in dates if date[0] >= today]

    if media_specific is None:
        media_specific = ""

    response_dict = {
        "current_item": 1,
        "gmapkey": settings.GOOGLE_MAPS_API_KEY,
        "theme_id": theme_id,
        "theme_dict": theme_dict,
        "format_id": format_id,
        "format_dict": format_dict,
        "departure": departure,
        "arrival": arrival,
    }

    today = datetime.date.today()
    dates_available = ()

    search_trip_details = request.session.get("search_trip_details", None)
    if search_trip_details and not theme_id:
        date = get_date(search_trip_details["date"], FRENCH_DATE_INPUT_FORMATS)
        if date is not None and dates_available:
            # check if date in session is in dates_available, else it would print an error
            if date not in dates_available:
                date = None
        initial = {
            "departure": search_trip_details["departure"]["name"],
            "departure_point": search_trip_details["departure"]["point"],
            "departure_favoriteplace": search_trip_details["departure"]["favoriteplace"]
            if "favoriteplace" in search_trip_details["departure"]
            else None,
            "arrival": search_trip_details["arrival"]["name"],
            "arrival_point": search_trip_details["arrival"]["point"],
            "arrival_favoriteplace": search_trip_details["arrival"]["favoriteplace"]
            if "favoriteplace" in search_trip_details["arrival"]
            else None,
            "date": date,
            "type": Trip.OFFER,
        }
    elif theme_id:
        initial = {"date": date, "departure": departure, "arrival": arrival}
    else:
        initial = {"date": today}

    if request.method == "POST":
        if dates_available:
            form = SearchTripWithDatesForm(dates_available, data=request.POST)
        else:
            form = SearchTripForm(data=request.POST)
        if form.is_valid():
            try:
                trip_type = int(form.cleaned_data["type"])
            except:
                trip_type = Trip.OFFER
            search_trip_details = {
                "departure": {
                    "name": form.cleaned_data["departure"],
                    "point": form.cleaned_data["departure_point"],
                    "favoriteplace": form.cleaned_data["departure_favoriteplace"],
                },
                "arrival": {
                    "name": form.cleaned_data["arrival"],
                    "point": form.cleaned_data["arrival_point"],
                    "favoriteplace": form.cleaned_data["arrival_favoriteplace"],
                },
                "date": form.cleaned_data["date"].strftime("%d/%m/%Y")
                if form.cleaned_data["date"]
                else today.strftime("%d/%m/%Y"),
            }
            request.session["search_trip_details"] = search_trip_details
            match_departure = R_CITY_ZIP.match(str_slugify(form.cleaned_data["departure"]))
            match_arrival = R_CITY_ZIP.match(str_slugify(form.cleaned_data["arrival"]))
            args = None
            if match_departure and match_arrival:
                args = [
                    match_departure.group(1),
                    match_departure.group(2),
                    match_arrival.group(1),
                    match_arrival.group(2),
                ]

            if trip_type == Trip.OFFER:
                if args:
                    return HttpResponseRedirect(reverse("carpool:robots_search_offer_trip", args=args))
                else:
                    return HttpResponseRedirect(reverse("carpool:search_offer_trip"))
            else:
                if args:
                    return HttpResponseRedirect(reverse("carpool:robots_search_demand_trip", args=args))
                else:
                    return HttpResponseRedirect(reverse("carpool:search_demand_trip"))

    elif request.method == "GET":
        if dates_available:
            form = SearchTripWithDatesForm(dates_available, initial=data)
        else:
            initial_data = {"date": today}
            form = SearchTripForm(initial=initial_data)

    response_dict.update({"form": form, "date_uptodate": dates_available})

    # theming
    if layout in _LAYOUTS:
        template = loader.get_template("carpool/tools/%s_form.html" % layout)
    else:
        template = loader.get_template("carpool/home.html")
    context = RequestContext(request, response_dict)
    return HttpResponse(template.render(context))
Example #16
0
def home(request, layout=None, theme_id=None, theme_dict=None, format_id=None, \
        format_dict=None, media_specific=None, date=None, departure=None, \
        arrival=None):
    """Home.
    
    This view is acessible via GET and POST.
    
    
    On GET, it displays a form for selecting a trip
    On POST, check if the form is valid, and redirect to other views
    """
    
    def get_dates_available(dates):
        """Filter dates from a set of given dates
        
        filter dates in past
        
        """
        today = datetime.date.today()
        return [date for date in dates if date[0] >= today]

    if media_specific is None:
        media_specific = ''

    response_dict = {
        'current_item': 1,
        'gmapkey': settings.GOOGLE_MAPS_API_KEY,
        'theme_id': theme_id,
        'theme_dict': theme_dict,
        'format_id': format_id,
        'format_dict': format_dict,
        'departure': departure,
        'arrival': arrival,
    }

    today = datetime.date.today()
    dates_available = () 

    search_trip_details = request.session.get('search_trip_details', None)
    if search_trip_details and not theme_id:
        date = get_date(search_trip_details['date'], FRENCH_DATE_INPUT_FORMATS)
        if date is not None and dates_available:
            # check if date in session is in dates_available, else it would print an error
            if date not in dates_available:
                date = None
        initial = {
            'departure': search_trip_details['departure']['name'],
            'departure_point': search_trip_details['departure']['point'],
            'departure_favoriteplace': search_trip_details['departure']['favoriteplace'] if 'favoriteplace' in search_trip_details['departure'] else None,
            'arrival': search_trip_details['arrival']['name'],
            'arrival_point': search_trip_details['arrival']['point'],
            'arrival_favoriteplace': search_trip_details['arrival']['favoriteplace'] if 'favoriteplace' in search_trip_details['arrival'] else None,
            'date': date,
            'type': Trip.OFFER,
        }
    elif theme_id:
        initial = {
            'date': date,
            'departure': departure,
            'arrival': arrival,
        }
    else:
        initial = {'date': today}

    if request.method == 'POST':
        if dates_available:
            form = SearchTripWithDatesForm(dates_available, data=request.POST)
        else:
            form = SearchTripForm(data=request.POST)
        if form.is_valid():
            try:
                trip_type = int(form.cleaned_data['type'])
            except:
                trip_type = Trip.OFFER
            search_trip_details = {
                'departure': {'name': form.cleaned_data['departure'], 'point': form.cleaned_data['departure_point'], 'favoriteplace': form.cleaned_data['departure_favoriteplace']},
                'arrival': {'name': form.cleaned_data['arrival'], 'point': form.cleaned_data['arrival_point'], 'favoriteplace': form.cleaned_data['arrival_favoriteplace']},
                'date': form.cleaned_data['date'].strftime("%d/%m/%Y") if form.cleaned_data['date'] else today.strftime("%d/%m/%Y")
            }
            request.session['search_trip_details'] = search_trip_details
            match_departure = R_CITY_ZIP.match(str_slugify(form.cleaned_data['departure']))
            match_arrival = R_CITY_ZIP.match(str_slugify(form.cleaned_data['arrival']))
            args = None
            if match_departure and match_arrival:
                args = [match_departure.group(1), match_departure.group(2), match_arrival.group(1), match_arrival.group(2)]

            if trip_type == Trip.OFFER:
                if args:
                    return HttpResponseRedirect(reverse('carpool:robots_search_offer_trip', args=args))
                else:
                    return HttpResponseRedirect(reverse('carpool:search_offer_trip'))
            else:
                if args:
                    return HttpResponseRedirect(reverse('carpool:robots_search_demand_trip', args=args))
                else:
                    return HttpResponseRedirect(reverse('carpool:search_demand_trip'))

    elif request.method == "GET":
        if dates_available:
            form = SearchTripWithDatesForm(dates_available, initial=data)
        else:
            initial_data = {'date': today}
            form = SearchTripForm(initial=initial_data)
            
    response_dict.update({
        'form': form,
        'date_uptodate': dates_available,
    })
    
    # theming
    if layout in _LAYOUTS:
        template = loader.get_template('carpool/tools/%s_form.html' % layout)
    else:
        template = loader.get_template('carpool/home.html')
    context = RequestContext(request, response_dict)
    return HttpResponse(template.render(context))
Example #17
0
def home(request):
    response_dict = {
        "current_item": 1,
        "gmapkey": settings.GOOGLE_MAPS_API_KEY,
        "places": FavoritePlace.objects.all().order_by("name"),
    }

    today = datetime.date.today()

    search_trip_details = request.session.get("search_trip_details", None)
    if search_trip_details:
        date = get_date(search_trip_details["date"], FRENCH_DATE_INPUT_FORMATS)
        if date < today:
            date = today
        data = {
            "departure": search_trip_details["departure"]["name"],
            "departure_point": search_trip_details["departure"]["point"],
            "departure_favoriteplace": search_trip_details["departure"]["favoriteplace"]
            if "favoriteplace" in search_trip_details["departure"]
            else None,
            "arrival": search_trip_details["arrival"]["name"],
            "arrival_point": search_trip_details["arrival"]["point"],
            "arrival_favoriteplace": search_trip_details["arrival"]["favoriteplace"]
            if "favoriteplace" in search_trip_details["arrival"]
            else None,
            "date": date,
            "type": Trip.OFFER,
        }
    else:
        data = None

    dates_concert = get_dates_concert()

    if request.method == "POST":
        if dates_concert:
            form = SearchTripRmll2009Form(request.POST)
        else:
            form = SearchTripForm(request.POST)
        if form.is_valid():
            try:
                trip_type = int(form.cleaned_data["type"])
            except:
                trip_type = Trip.OFFER
            search_trip_details = {
                "departure": {
                    "name": form.cleaned_data["departure"],
                    "point": form.cleaned_data["departure_point"],
                    "favoriteplace": form.cleaned_data["departure_favoriteplace"],
                },
                "arrival": {
                    "name": form.cleaned_data["arrival"],
                    "point": form.cleaned_data["arrival_point"],
                    "favoriteplace": form.cleaned_data["arrival_favoriteplace"],
                },
                "date": form.cleaned_data["date"].strftime("%d/%m/%Y")
                if form.cleaned_data["date"]
                else date_default.strftime("%d/%m/%Y"),
            }
            request.session["search_trip_details"] = search_trip_details
            match_departure = R_CITY_ZIP.match(str_slugify(form.cleaned_data["departure"]))
            match_arrival = R_CITY_ZIP.match(str_slugify(form.cleaned_data["arrival"]))
            args = None
            if match_departure and match_arrival:
                args = [
                    match_departure.group(1),
                    match_departure.group(2),
                    match_arrival.group(1),
                    match_arrival.group(2),
                ]

            if trip_type == Trip.OFFER:
                if args:
                    return HttpResponseRedirect(reverse("carpool:robots_search_offer_trip", args=args))
                else:
                    return HttpResponseRedirect(reverse("carpool:search_offer_trip"))
            else:
                if args:
                    return HttpResponseRedirect(reverse("carpool:robots_search_demand_trip", args=args))
                else:
                    return HttpResponseRedirect(reverse("carpool:search_demand_trip"))
    else:
        if dates_concert:
            form = SearchTripRmll2009Form(data)
        else:
            initial_data = {"date": today}
            form = SearchTripForm(data, initial=initial_data)
    response_dict.update({"form": form, "date_uptodate": dates_concert, "cities_concert": _CITIES_CONCERT})

    template = loader.get_template("carpool/home_rmll2009.html")
    context = RequestContext(request, response_dict)
    return HttpResponse(template.render(context))