Ejemplo n.º 1
0
def get_venue_from_google(data):
    name = data.get("geo_venue")
    street = data.get("geo_street")
    street_number = data.get("geo_street_number")
    city = City.objects.filter(
        Q(name_std=data.get("geo_city").encode('utf8')) |
        Q(name=data.get("geo_city"))
    )
    country = Country.objects.get(name='Canada')
    location = Point((
        float(data.get("geo_longtitude")),
        float(data.get("geo_latitude"))
    ))

    if city.count() > 1:
        city = find_nearest_city(location, city)
    elif not city.count():
        city = City.objects.distance(location).order_by('distance')[0]
    else:
        city = city[0]

    try:
        venue = Venue.objects.get(name=name, street=street, city=city, country=country, suggested=False)
    except:
        venue = Venue(name=name, street=street, city=city, country=country, location=location, suggested=False)
    

    venue.street_number = street_number
    venue.save()

    return venue
Ejemplo n.º 2
0
def get_venue_suggested_by_user(data, user=None):
    name = data.get("venue_name")
    street = data.get("street")
    city = City.objects.get(id=int(data.get("city_identifier")))
    country = Country.objects.get(name="Canada")
    location = Point((float(data.get("location_lng")), float(data.get("location_lat"))))

    venue = Venue(name=name, street=street, city=city, country=country, location=location, suggested=True, user=user)
    venue.save()

    return venue
Ejemplo n.º 3
0
    def test_account_should_be_informed_about_tag_in_region_he_interested_in(self):
        """
        User should be informed about event that appeared in region that he is interested in
        """

        user = User.objects.create_user(username='******', email="*****@*****.**",  password="******")
        account = Account(
            user=user,
            all_of_canada=False,
            regions=[Region.objects.filter(name="Alberta"), Region.objects.filter(name="Saskatchewan")],
            tags=["boo"]
        )

        venue = Venue(
            name="Test venue",
            city=City.objects.filter(name="Saskatoon"),
            country=Country.objects.filter(name="Canada")
        )

        event = Event(
            name="Test event",
            venue=venue,
            tags=["boo"]
        )

        self.assertIn(
            event,
            InTheLoopSchedule.unprocessed_for_account(account)
        )        
Ejemplo n.º 4
0
def get_venue_suggested_by_user(data, user=None):
    name = data.get("venue_name")
    street = data.get("street")
    city = City.objects.get(id=int(data.get("city_identifier")))
    country = Country.objects.get(name='Canada')
    location = Point(
        (float(data.get("location_lng")), float(data.get("location_lat"))))

    venue = Venue(name=name,
                  street=street,
                  city=city,
                  country=country,
                  location=location,
                  suggested=True,
                  user=user)
    venue.save()

    return venue
Ejemplo n.º 5
0
def get_venue_from_google(data):
    name = data.get("geo_venue")
    street = data.get("geo_street")
    street_number = data.get("geo_street_number")
    city = City.objects.filter(
        Q(name_std=data.get("geo_city").encode('utf8'))
        | Q(name=data.get("geo_city")))
    country = Country.objects.get(name='Canada')
    location = Point(
        (float(data.get("geo_longtitude")), float(data.get("geo_latitude"))))

    if city.count() > 1:
        city = find_nearest_city(location, city)
    elif not city.count():
        city = City.objects.distance(location).order_by('distance')[0]
    else:
        city = city[0]

    try:
        venue = Venue.objects.get(name=name,
                                  street=street,
                                  city=city,
                                  country=country,
                                  suggested=False)
    except:
        venue = Venue(name=name,
                      street=street,
                      city=city,
                      country=country,
                      location=location,
                      suggested=False)

    venue.street_number = street_number
    venue.save()

    return venue
Ejemplo n.º 6
0
def nearest_venues(request):
    if request.method == 'GET':
        search = request.GET.get("search", "")

        venues = Venue.with_active_events()
        if search:
            venues = venues.filter(Q(name__icontains=search) | Q(city__name__icontains=search))
        if request.location:
            venues = venues.distance(Point(request.location)).order_by('distance')[:10]

        return HttpResponse(json.dumps({
            "venues": [{
                "id": venue.id,
                "name": venue.name,
                "city": venue.city.name_std
            } for venue in venues.select_related("city")]
        }), mimetype="application/json")
Ejemplo n.º 7
0
def nearest_venues(request):
    if request.method == 'GET':
        search = request.GET.get("search", "")

        venues = Venue.with_active_events()
        if search:
            venues = venues.filter(
                Q(name__icontains=search) | Q(city__name__icontains=search))
        if request.location:
            venues = venues.distance(Point(
                request.location)).order_by('distance')[:10]

        return HttpResponse(json.dumps({
            "venues": [{
                "id": venue.id,
                "name": venue.name,
                "city": venue.city.name_std
            } for venue in venues.select_related("city")]
        }),
                            mimetype="application/json")