Exemplo n.º 1
0
 def test_bogus_longitude(self):
     data = {
         "name": "My bar",
         "website": "https://www.example.com",
         "instagram_handle": "example",
         "time_zone": "America/New_York",
         "tap_list_provider": "untappd",
         "slug": "my-bar",
         "latitude": 34.8,
         "longitude": 180.00001,
     }
     serializer = VenueSerializer(data=data)
     self.assertFalse(serializer.is_valid(raise_exception=False))
Exemplo n.º 2
0
 def test_bogus_longitude(self):
     data = {
         'name': 'My bar',
         'website': 'https://www.example.com',
         'instagram_handle': 'example',
         'time_zone': 'America/New_York',
         'tap_list_provider': 'untappd',
         'slug': 'my-bar',
         'latitude': 34.8,
         'longitude': 180.00001,
     }
     serializer = VenueSerializer(data=data)
     self.assertFalse(serializer.is_valid(raise_exception=False))
Exemplo n.º 3
0
    def placesavailable(self, request, pk):
        """Get all the venues at which the given beer is on tap"""
        queryset = Venue.objects.filter(taps__beer__id=pk).distinct().order_by(
            'name', )
        # let the user use all the venue filters just for kicks
        queryset = VenueFilterSet(request.query_params, queryset=queryset).qs

        page = self.paginate_queryset(queryset)
        if page is not None:
            serializer = VenueSerializer(page, many=True)
            return self.get_paginated_response(serializer.data)

        serializer = VenueSerializer(queryset, many=True)
        return Response(serializer.data)
Exemplo n.º 4
0
class EventSerializer(serializers.ModelSerializer):
    venue = VenueSerializer(read_only=True)
    venue_id = serializers.PrimaryKeyRelatedField(
        write_only=True, required=True, allow_null=False,
        queryset=Venue.objects.all(),
    )

    def validate(self, data):
        try:
            start = data['startDate']
            end = data['endDate']
        except KeyError:
            # must be in a patch; don't care
            pass
        else:
            if start >= end:
                raise serializers.ValidationError({
                    'startDate': [
                        'This must be before endDate',
                    ],
                    'endDate': [
                        'This must be after startDate',
                    ]
                })
        try:
            data['venue'] = data.pop('venue_id')
        except KeyError:
            # must be in a patch; don't care
            pass
        return data

    class Meta:
        model = models.Event
        fields = '__all__'
Exemplo n.º 5
0
    def post(self, request, format=None):
        user = request.user
        cohort = request.user.cohort_set.all().first()

        lat = self.request.data.get('lat', None)
        lng = self.request.data.get('lng', None)

        if lat and lng:
            geo_lookup_results = geo_search(lat, lng)

            if geo_lookup_results:
                print geo_lookup_results

                venue, created = Venue.objects.get_or_create(
                    foursquare_id = geo_lookup_results['foursquare_id']
                )

                venue.name = geo_lookup_results['name']
                venue.category = geo_lookup_results['category']
                venue.lat = geo_lookup_results['lat']
                venue.lng = geo_lookup_results['lng']
                venue.save()

                venue_serializer = VenueSerializer(venue)

                return Response(venue_serializer.data, status=status.HTTP_200_OK)
                
            else:
                # no valid venue found

                return Response(status=status.HTTP_404_NOT_FOUND)

        else:
            # we need lat/lng
            return Response(status=status.HTTP_400_BAD_REQUEST)
Exemplo n.º 6
0
 def test_create(self):
     data = {
         'name': 'My bar',
         'website': 'https://www.example.com',
         'instagram_handle': 'example',
         'time_zone': 'America/New_York',
     }
     serializer = VenueSerializer(data=data)
     serializer.is_valid(raise_exception=True)
     instance = serializer.save()
     self.assertIsInstance(instance, Venue)
     for field, value in data.items():
         with self.subTest(field=field):
             if field != 'time_zone':
                 self.assertEqual(getattr(instance, field), value)
             else:
                 self.assertEqual(instance.time_zone.zone, value)
Exemplo n.º 7
0
 def test_create(self):
     data = {
         "name": "My bar",
         "website": "https://www.example.com",
         "instagram_handle": "example",
         "time_zone": "America/New_York",
         "slug": "my-bar",
     }
     serializer = VenueSerializer(data=data)
     serializer.is_valid(raise_exception=True)
     instance = serializer.save()
     self.assertIsInstance(instance, Venue)
     for field, value in data.items():
         with self.subTest(field=field):
             if field != "time_zone":
                 self.assertEqual(getattr(instance, field), value)
             else:
                 self.assertEqual(instance.time_zone.zone, value)
Exemplo n.º 8
0
 def get_venues(self, obj):
     from venues.serializers import VenueSerializer
     taps = list(obj.taps.all())
     if not taps:
         return []
     venues = {i.venue for i in taps}
     return VenueSerializer(
         instance=list(sorted(venues, key=lambda v: v.name)),
         many=True,
     ).data
Exemplo n.º 9
0
def venue_nearby(request, lat, lon):

    venues = Venue.objects.all()
    venues = [
        v for v in venues
        if haversine(float(lon), float(lat), float(v.longitude),
                     float(v.latitude)) < 0.5
    ]

    serializer = VenueSerializer(venues, many=True)
    response = JSONResponse(serializer.data)
    return response
Exemplo n.º 10
0
    def get_context_data(self, **kwargs):
        venues = []
        for venue in self.tournament.relevant_venues.select_related('checkin_identifier').prefetch_related('venuecategory_set').all():
            item = VenueSerializer(venue).data
            item['locked'] = False
            try:
                item['identifier'] = [venue.checkin_identifier.barcode]
            except ObjectDoesNotExist:
                item['identifier'] = [None]
            venues.append(item)
        kwargs["venues"] = json.dumps(venues)
        kwargs["team_codes"] = json.dumps(False)

        return super().get_context_data(**kwargs)
Exemplo n.º 11
0
def category_venues(request, pk):
    """
    Retrieve venues catering to requested category.
    """
    try:
        print('finding ' + pk)
        category = Category.objects.get(pk=pk)
    except Category.DoesNotExist:
        return HttpResponse(status=404)

    venues = Venue.objects.filter(categories__pk=pk)

    if request.method == 'GET':
        serializer = VenueSerializer(venues, many=True)
        return JSONResponse(serializer.data)

    return JSONResponse(status=403)
Exemplo n.º 12
0
 def test_display_tap_list_provider(self):
     data = {
         'name': 'My bar',
         'website': 'https://www.example.com',
         'instagram_handle': 'example',
         'time_zone': 'America/New_York',
         'tap_list_provider': 'untappd',
     }
     serializer = VenueSerializer(data=data)
     serializer.is_valid(raise_exception=True)
     instance = serializer.save()
     self.assertIsInstance(instance, Venue)
     serializer = VenueSerializer(instance=instance)
     self.assertEqual(
         serializer.data['tap_list_provider_display'],
         'Untappd',
     )
Exemplo n.º 13
0
 def test_display_tap_list_provider(self):
     data = {
         "name": "My bar",
         "website": "https://www.example.com",
         "instagram_handle": "example",
         "time_zone": "America/New_York",
         "tap_list_provider": "untappd",
         "slug": "my-bar",
     }
     serializer = VenueSerializer(data=data)
     serializer.is_valid(raise_exception=True)
     instance = serializer.save()
     self.assertIsInstance(instance, Venue)
     serializer = VenueSerializer(instance=instance)
     self.assertEqual(
         serializer.data["tap_list_provider_display"],
         "Untappd",
     )
Exemplo n.º 14
0
    def construct_info(self, venue, source, source_p, target, target_p):
        if hasattr(source, 'name'):
            source_n = source.name
        elif use_team_code_names(self.tournament, False):
            source_n = source.code_name
        else:
            source_n = source.short_name

        return {
            'venue':
            VenueSerializer(venue).data if venue else '',
            'authorInstitution':
            source.institution.code
            if source.institution else _("Unaffiliated"),
            'author':
            source_n,
            'authorPosition':
            source_p,
            'target':
            target.name,
            'targetPosition':
            target_p,
        }
Exemplo n.º 15
0
class TapSerializer(serializers.ModelSerializer):
    venue_id = serializers.PrimaryKeyRelatedField(
        write_only=True,
        allow_null=False,
        required=True,
        queryset=Venue.objects.all(),
    )
    estimated_percent_remaining = serializers.FloatField(
        min_value=0,
        max_value=100,
        allow_null=True,
        required=False,
    )
    venue = VenueSerializer(read_only=True)
    time_added = serializers.DateTimeField(read_only=True)
    time_updated = serializers.DateTimeField(read_only=True)

    def update(self, instance, validated_data):
        instance.time_updated = timezone.now()
        return super().update(instance, validated_data)

    def validate(self, data):
        try:
            data['venue'] = data.pop('venue_id')
        except KeyError:
            pass
        return data

    class Meta:
        fields = '__all__'
        model = models.Tap
        validators = [
            UniqueTogetherValidator(
                queryset=models.Tap.objects.all(),
                fields=('tap_number', 'venue_id'),
            ),
        ]
Exemplo n.º 16
0
 def test_display(self):
     instance = Event.objects.create(
         title='test',
         venue=self.venue,
         start_time=UTC.localize(datetime.datetime(2018, 11, 20, 12)),
         end_time=UTC.localize(datetime.datetime(2018, 11, 20, 16)),
     )
     serializer = EventSerializer(instance=instance)
     for field, value in serializer.data.items():
         if field == 'venue':
             self.assertEqual(
                 value,
                 VenueSerializer(self.venue).data,
                 field,
             )
         elif field.endswith('_time'):
             self.assertEqual(
                 value,
                 DateTimeField().to_representation(getattr(instance,
                                                           field), ),
                 field,
             )
         else:
             self.assertEqual(value, getattr(instance, field), field)
Exemplo n.º 17
0
class EventSerializer(serializers.ModelSerializer):
    venue = VenueSerializer(read_only=True)
    venue_id = serializers.PrimaryKeyRelatedField(
        write_only=True,
        required=True,
        allow_null=False,
        queryset=Venue.objects.all(),
    )

    def validate(self, data):
        try:
            start = data["start_time"]
            end = data["end_time"]
        except KeyError:
            # must be in a patch; don't care
            pass
        else:
            if start >= end:
                raise serializers.ValidationError({
                    "start_time": [
                        "This must be before end_time",
                    ],
                    "end_time": [
                        "This must be after start_time",
                    ],
                })
        try:
            data["venue"] = data.pop("venue_id")
        except KeyError:
            # must be in a patch; don't care
            pass
        return data

    class Meta:
        model = models.Event
        fields = "__all__"