Esempio n. 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')
Esempio n. 2
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")
Esempio n. 3
0
def list_tempreports(request, page=1):
    """Temporary assessments for connected user

    Paginated list, with order sorting on columns
    """
    ordering = {
        'departure': ['departure_city'],
        '-departure': ['-departure_city'],
        'arrival': ['arrival_city'],
        '-arrival': ['-arrival_city'],
        'date': ['dows', 'date'],
        '-date': ['-dows', '-date'],
        'type': ['type'],
        '-type': ['-type'],
        'user': ['user'],
        '-user': ['-user'],
        'write_date': ['start_date'],
        '-write_date': ['-start_date'],
    }

    pgnum = _RATING_PG[0]
    order = 'write_date'
    if 'pg' in request.GET:
        try:
            if int(request.GET['pg']) in _RATING_PG:
                pgnum = 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' % pgnum
    get_url = '?pg=%d&order=%s' % (pgnum, order)

    oargs = ordering[order]
    
    tr = TempReport.objects.get_user_tempreports(request.user)
    tr = tr.select_related().order_by(*oargs)
        
    paginator = PaginatorRender(
        tr,
        page,
        pgnum,
        allow_empty_first_page=True,
        extra_context = {
            'current_item': 14,
            'current_nav_item': 3,
            'paginations': _RATING_PG,
            'order': order,
            'get_url_pg': get_url_pg,
            'get_url': get_url,
        }
    )
    return paginator.render(request, 'rating/list_tempreports.html')
Esempio n. 4
0
def my_trips(request, page=1):
    """Return a paginated list of trips for the logged user
    
    """
    ordering = {
        "name": ["name"],
        "-name": ["-name"],
        "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"],
        "alert": ["-alert"],
        "-alert": ["alert"],
    }
    pg = _MYTRIP_PG[0]
    order = "date"
    if "pg" in request.GET:
        try:
            if int(request.GET["pg"]) in _MYTRIP_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]

    paginator = PaginatorRender(
        request.user.trip_set.all()
        .extra(select={"type": "CASE WHEN demand_id IS NULL THEN 0 WHEN offer_id IS NULL THEN 1 ELSE 2 END"})
        .order_by(*oargs),
        page,
        pg,
        allow_empty_first_page=True,
        extra_context={
            "current_item": 10,
            "paginations": _MYTRIP_PG,
            "get_url_pg": get_url_pg,
            "get_url": get_url,
            "order": order,
        },
    )
    return paginator.render(request, "carpool/my_trips.html")
Esempio n. 5
0
def list_tempreports(request, page=1):
    """Temporary assessments for connected user

    Paginated list, with order sorting on columns
    """
    ordering = {
        'departure': ['departure_city'],
        '-departure': ['-departure_city'],
        'arrival': ['arrival_city'],
        '-arrival': ['-arrival_city'],
        'date': ['dows', 'date'],
        '-date': ['-dows', '-date'],
        'type': ['type'],
        '-type': ['-type'],
        'user': ['user'],
        '-user': ['-user'],
        'write_date': ['start_date'],
        '-write_date': ['-start_date'],
    }

    pgnum = _RATING_PG[0]
    order = 'write_date'
    if 'pg' in request.GET:
        try:
            if int(request.GET['pg']) in _RATING_PG:
                pgnum = 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' % pgnum
    get_url = '?pg=%d&order=%s' % (pgnum, order)

    oargs = ordering[order]

    tr = TempReport.objects.get_user_tempreports(request.user)
    tr = tr.select_related().order_by(*oargs)

    paginator = PaginatorRender(tr,
                                page,
                                pgnum,
                                allow_empty_first_page=True,
                                extra_context={
                                    'current_item': 14,
                                    'current_nav_item': 3,
                                    'paginations': _RATING_PG,
                                    'order': order,
                                    'get_url_pg': get_url_pg,
                                    'get_url': get_url,
                                })
    return paginator.render(request, 'rating/list_tempreports.html')
Esempio n. 6
0
def my_trips(request, page=1):
    """Return a paginated list of trips for the logged user
    
    """
    ordering = {
        'name': ['name'],
        '-name': ['-name'],
        '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'],
        'alert': ['-alert'],
        '-alert': ['alert'],
    }
    pg = _MYTRIP_PG[0]
    order = 'date'
    if 'pg' in request.GET:
        try:
            if int(request.GET['pg']) in _MYTRIP_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]

    paginator = PaginatorRender(
        request.user.trip_set.all().extra(select={'type': 'CASE WHEN demand_id IS NULL THEN 0 WHEN offer_id IS NULL THEN 1 ELSE 2 END'}).order_by(*oargs),
        page,
        pg,
        allow_empty_first_page=True,
        extra_context = {
            'current_item': 10,
            'paginations': _MYTRIP_PG,
            'get_url_pg': get_url_pg,
            'get_url': get_url,
            'order': order,
        }
    )
    return paginator.render(request, 'carpool/my_trips.html')
Esempio n. 7
0
    def get_trip_list_paginator_with_departure_or_arrival(
            self,
            city,
            is_departure,
            ordered_by,
            page,
            pagination,
            available_paginations,
            url_pagination=None,
            url_pagination_order=None):
        """Return a paginator for the list of trips matching given city as an 
        arrival or a departure point.

        """
        if (not pagination):
            url_pagination = self._get_pagination_url(pagination)
        if (not url_pagination_order):
            url_pagination_order = self._get_pagination_url_with_order(
                pagination, ordered_by)

        trips = self.list_trips_with_departure_or_arrival(
            city, is_departure, ordered_by)
        return PaginatorRender(trips,
                               page,
                               pagination,
                               allow_empty_first_page=True,
                               extra_context={
                                   'city': city,
                                   'is_depart': is_departure,
                                   'paginations': available_paginations,
                                   'get_url_pg': url_pagination,
                                   'get_url': url_pagination_order,
                                   'order': ordered_by,
                               })
Esempio n. 8
0
def list_other_reports(request, page=1):
    """List all assessments by connected user.

    Paginated list, with order sorting on columns
    """
    ordering = {
        'date': ['creation_date'],
        '-date': ['-creation_date'],
        'user': ['auth_user.username'],
        '-user': ['-auth_user.username'],
        'mark': ['mark'],
        '-mark': ['-mark'],
        'comment': ['comment'],
        '-comment': ['-comment'],
    }

    pgnum = _RATING_PG[0]
    order = 'date'
    if 'pg' in request.GET:
        try:
            if int(request.GET['pg']) in _RATING_PG:
                pgnum = 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' % pgnum
    get_url = '?pg=%d&order=%s' % (pgnum, order)

    oargs = ordering[order]

    paginator = PaginatorRender(
        Report.objects.select_related().filter(from_user=request.user)\
                .order_by(*oargs),
        page,
        pgnum,
        allow_empty_first_page=True,
        extra_context = {
            'current_item': 14,
            'current_nav_item': 2,
            'paginations': _RATING_PG,
            'order': order,
            'get_url_pg': get_url_pg,
            'get_url': get_url,
        }
    )
    return paginator.render(request, 'rating/list_other_reports.html')
Esempio n. 9
0
def list_other_reports(request, page=1):
    """List all assessments by connected user.

    Paginated list, with order sorting on columns
    """
    ordering = {
        'date': ['creation_date'],
        '-date': ['-creation_date'],
        'user': ['auth_user.username'],
        '-user': ['-auth_user.username'],
        'mark': ['mark'],
        '-mark': ['-mark'],
        'comment': ['comment'],
        '-comment': ['-comment'],
    }

    pgnum = _RATING_PG[0]
    order = 'date'
    if 'pg' in request.GET:
        try:
            if int(request.GET['pg']) in _RATING_PG:
                pgnum = 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' % pgnum
    get_url = '?pg=%d&order=%s' % (pgnum, order)

    oargs = ordering[order]

    paginator = PaginatorRender(
        Report.objects.select_related().filter(from_user=request.user)\
                .order_by(*oargs),
        page,
        pgnum,
        allow_empty_first_page=True,
        extra_context = {
            'current_item': 14,
            'current_nav_item': 2,
            'paginations': _RATING_PG,
            'order': order,
            'get_url_pg': get_url_pg,
            'get_url': get_url,
        }
    )
    return paginator.render(request, 'rating/list_other_reports.html')
Esempio n. 10
0
def trip_list(request, page):
    """Return a paginated list of all requested trips

    """
    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]

    paginator = PaginatorRender(
        Trip.objects.exclude_outdated().extra(select={'type': 'CASE WHEN demand_id IS NULL THEN 0 WHEN offer_id IS NULL THEN 1 ELSE 2 END'}).order_by(*oargs),
        page,
        pg,
        allow_empty_first_page=True,
        extra_context = {
            'paginations': _TRIP_PG,
            'get_url_pg': get_url_pg,
            'get_url': get_url,
            'order': order,
        }
    )
    return paginator.render(request, 'carpool/trip_list.html')
Esempio n. 11
0
def trip_list(request, page):
    """Return a paginated list of all requested trips

    """
    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]

    paginator = PaginatorRender(
        Trip.objects.exclude_outdated()
        .extra(select={"type": "CASE WHEN demand_id IS NULL THEN 0 WHEN offer_id IS NULL THEN 1 ELSE 2 END"})
        .order_by(*oargs),
        page,
        pg,
        allow_empty_first_page=True,
        extra_context={"paginations": _TRIP_PG, "get_url_pg": get_url_pg, "get_url": get_url, "order": order},
    )
    return paginator.render(request, "carpool/trip_list.html")
Esempio n. 12
0
 def get_trip_list_paginator(self, page, pagination, available_paginations,
                             ordered_by, url_pagination, url):
     """Return a paginator for the list of trips.
     
     Uses the list_trips method
     
     """
     trips = list_trips_by_user(ordered_by)
     return PaginatorRender(trips,
                            page,
                            pagination,
                            allow_empty_first_page=True,
                            extra_context={
                                'paginations': available_paginations,
                                'get_url_pg': url_pagination,
                                'get_url': url,
                                'order': ordered_by,
                            })
Esempio n. 13
0
    def get_list_by_user_paginator(self, user, page, pagination,
                                   available_paginations, ordered_by,
                                   url_pagination, url):
        """Return a paginator of the list of trips for a given user

        """

        trips = self.get_user_trips(user, ordered_by)
        return PaginatorRender(trips,
                               page,
                               pagination,
                               allow_empty_first_page=True,
                               extra_context={
                                   'current_item': 10,
                                   'paginations': available_paginations,
                                   'get_url_pg': url_pagination,
                                   'get_url': url,
                                   'order': ordered_by,
                               })