Beispiel #1
0
 def patch(self, request, *args, **kwargs):
     meetup = self.get_object(kwargs["uri"])
     serializer = MeetupSerializer(meetup, data=request.data, partial=True)
     if serializer.is_valid():
         serializer.save()
         return Response(serializer.data)
     return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
Beispiel #2
0
def sync_meetup(request: Request) -> Response:
    """Sync an individual meetup."""

    serializer = SyncMeetupPayloadSerializer(data=request.data)
    serializer.is_valid(raise_exception=True)

    try:
        meetup_id = serializer.validated_data.get("meetup_id", None)
        meetup = Meetup.objects.get(pk=meetup_id)
    except Meetup.DoesNotExist:
        raise serializers.ValidationError(
            {"non_field_errors": [f"invalid meetup_id '{meetup_id}'"]}
        )

    tasks.sync_meetup.send(name=meetup.name)
    serializer = MeetupSerializer(instance=meetup)
    return Response(serializer.data)
Beispiel #3
0
    def test_MeetupListView_GET_private_meetups(self):
        response = client.get(
            "/api/meetups/", {
                "type": "private",
                "startDate": yesterday,
                "endDate": tomorrow,
                "latitude": 34.228754,
                "longitude": -118.2351192
            })
        meetups = self.user.meetups
        meetups_json = {}

        for meetup in meetups.all():
            serializer = MeetupSerializer(meetup.meetup)
            meetups_json[meetup.meetup.uri] = serializer.data
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(response.data["meetups"], meetups_json)
Beispiel #4
0
    def post(self, request, *args, **kwargs):
        """
        Add member to meetup
        """
        email = request.data["email"]
        uri = kwargs["uri"]

        try:
            meetup = Meetup.objects.get(uri=uri)
        except ObjectDoesNotExist:
            return Response({"error": "Meetup does not exist"},
                            status=status.HTTP_400_BAD_REQUEST)

        try:
            member = User.objects.get(email=email)
        except ObjectDoesNotExist:
            return Response({"error": "User does not exist"},
                            status=status.HTTP_400_BAD_REQUEST)

        meetup.members.get_or_create(meetup=meetup, user=member)

        return Response(MeetupSerializer(meetup).data)
Beispiel #5
0
 def post(self, request, *args, **kwargs):
     try:
         user, date, name, location = (
             request.user,
             request.data["date"],
             request.data["name"],
             request.data["location"],
         )
         public, latitude, longitude = (
             request.data["public"],
             request.data["latitude"],
             request.data["longitude"],
         )
         meetup = Meetup.objects.create(
             date=date,
             location=location,
             name=name,
             creator=user,
             public=public,
             latitude=latitude,
             longitude=longitude,
         )
         member = MeetupMember.objects.create(user=user,
                                              meetup=meetup,
                                              admin=True)
         return Response({
             "status":
             "Success",
             "meetup":
             MeetupSerializer(meetup, context={
                 "user": user
             }).data,
             "message":
             "new meetup created",
         })
     except:
         return Response(status=status.HTTP_400_BAD_REQUEST)
Beispiel #6
0
    def get(self, request, *args, **kwargs):
        user, categories = request.user, request.GET.get("categories", [])
        coords = [
            request.GET.get('latitude'),
            request.GET.get('longitude'),
            request.GET.get("radius", 25)
        ]
        today = date.today()
        start, end = request.GET.get("startDate", str(today)), request.GET.get(
            "endDate", str(today + timedelta(days=7)))
        meetup_type = request.GET.get('type', 'public')
        latitude, longitude, radius = get_user_coordinates(coords, request)

        if meetup_type == "public":
            meetups = Meetup.get_public(categories, coords, request, start,
                                        end)
        elif meetup_type == "private":
            meetups = Meetup.get_private(categories, coords, request, user,
                                         start, end)
        else:
            return Response(status=status.HTTP_400_BAD_REQUEST)

        meetups_json = {}

        if meetups:
            for meetup in meetups.all():
                serializer = MeetupSerializer(meetup, context={"user": user})
                meetups_json[meetup.uri] = serializer.data

        return Response({
            "meetups": meetups_json,
            'count': len(meetups_json),
            "coords": {
                "latitude": float(latitude),
                "longitude": float(longitude)
            }
        })
Beispiel #7
0
 def get(self, request, *args, **kwargs):
     user = request.user
     meetup = self.get_object(kwargs["uri"])
     serializer = MeetupSerializer(meetup, context={"user": user})
     return Response(serializer.data)
Beispiel #8
0
 def test_MeetupView_GET_valid(self):
     response = client.get("/api/meetups/" + self.private.uri + "/")
     self.assertEqual(response.status_code, status.HTTP_200_OK)
     serializer = MeetupSerializer(self.private,
                                   context={"user": self.user})
     self.assertEqual(response.data, serializer.data)