Example #1
0
def citymx(req, city_short, city_name, tpl='dtrseo/es_citymx.html'):
    # The old URLs to some Mexican cities, e.g. "/citymxmer/merida.html‎"
    abbr_cities = {
        'aca': 3533462,  # 'Acapulco',
        'cam': 3531732,  # 'Campeche',
        'can': 3531673,  # 'Cancún',
        'chi': 4014338,  # 'Chihuahua',
        'jua': 4013708,  # 'Ciudad Juárez',
        'cue': 3529947,  # 'Cuernavaca',
        'gua': 4005539,  # 'Guadalajara',
        'her': 4004898,  # 'Hermosillo',
        'leo': 3998655,  # 'León',
        'maz': 3996322,  # 'Mazatlán',
        'mer': 3523349,  # 'Mérida',
        'mex': 3996069,  # 'Mexicali',
        'mdf': 3530597,  # 'Mexico D.F.',
        'mty': 3995465,  # 'Monterrey',
        'nog': 4004886,  # 'Nogales',
        'lar': 3522551,  # 'Nuevo Laredo',
        'oax': 3522507,  # 'Oaxaca',
        'pac': 3522210,  # 'Pachuca',
        'pue': 3521081,  # 'Puebla',
        'qro': 3991164,  # 'Querétaro',
        'slp': 3985606,  # 'San Luís Potosí',
        'tam': 3516355,  # 'Tampico',
        'tap': 3516266,  # 'Tapachula',
        'tij': 3981609,  # 'Tijuana',
        'tol': 3515302,  # 'Toluca',
        'tor': 3981254,  # 'Torreón',
        'tux': 3515001,  # 'Tuxtla Gutiérrez',
        'ver': 3514783,  # 'Veracruz',
        'vil': 3514670,  # 'Villahermosa',
        'xal': 3526617,  # 'Xalapa',
        'zac': 3979844,  # 'Zacatecas',
        # 'aaa': 'Otra ciudad mexicana',
        # 'bbb': 'Fuera de México',
    }

    # Find the city id by place name.
    if city_short not in abbr_cities.keys():
        return HttpResponseNotFound()
    city = City.objects.get(pk=abbr_cities[city_short])
    cities = City.get_cities_around_city(city)
    ctx = {
        'userprofiles':
        UserProfile.objects.filter(
            gender__in=[1, 2, 4, 5],
            city__in=cities,
            user__is_active=True,
            pic__isnull=False).order_by('-user__last_login').prefetch_related(
                'user', 'city')[:48],
        'city':
        get_object_or_404(AltName,
                          geoname_id=abbr_cities[city_short],
                          is_main=1,
                          type=3,
                          language=(get_language()
                                    or settings.LANGUAGE_CODE)[:2]),
    }
    return render(req, tpl, ctx)
Example #2
0
File: views.py Project: C14L/anu2
 def get_queryset(self):
     self.city = City.get_by_url(self.kwargs['city'])
     _cities = City.get_cities_around_city(self.city, dist=25)
     _category = self.kwargs['category']
     self.category = get_object_or_404(Category, slug=_category)
     return Post.objects.by_category(self.category).filter(city__in=_cities)