def flag(self, request, pk): try: placename = PlaceName.objects.get(pk=int(pk)) if placename.status == PlaceName.VERIFIED: return Response( {"message": "PlaceName has already been verified"}) else: if 'status_reason' in request.data.keys(): PlaceName.flag(int(pk), request.data["status_reason"]) #Notifying Administrators try: inform_placename_to_be_verified(int(pk)) except Exception as e: pass #Notifying the creator try: inform_placename_rejected_or_flagged( int(pk), request.data["status_reason"], PlaceName.FLAGGED) except Exception as e: pass return Response({"message": "Flagged!"}) else: return Response({"message": "Reason must be provided"}) except PlaceName.DoesNotExist: return Response( {"message": "No PlaceName with the given id was found"})
def reject(self, request, pk): if request and hasattr(request, "user"): if request.user.is_authenticated: try: if 'status_reason' in request.data.keys(): PlaceName.reject(int(pk), request.data["status_reason"]) #Notifying the creator try: inform_placename_rejected_or_flagged( int(pk), request.data["status_reason"], PlaceName.REJECTED) except Exception as e: pass return Response({"message": "Rejected!"}) else: return Response({"message": "Reason must be provided"}) except PlaceName.DoesNotExist: return Response({ "message": "No PlaceName with the given id was found" }) return Response( {"message", "Only Administrators can reject contributions"})
def handle(self, *args, **options): for rec in json.loads( open('./fixtures/pois.json').read())['markers']['marker']: n = PlaceName(point=Point(float(rec['_loc_x']), float(rec['_loc_y'])), name=rec['_name'], kind='poi') n.save()
def test_placename_reject(self): # Must be logged in to submit a place. self.assertTrue( self.client.login(username="******", password="******")) # Check we're logged in response = self.client.get("/api/user/auth/") self.assertEqual(response.json()["is_authenticated"], True) placename = PlaceName() placename.name = "test place" placename.creator = self.user placename.community = self.community placename.language = self.language1 placename.save() created_id = placename.id # now update it. response = self.client.patch( "/api/placename/{}/reject/".format(created_id), {"status_reason": "test reason status"}, format="json", ) self.assertEqual(response.status_code, status.HTTP_200_OK) place = PlaceName.objects.get(pk=created_id) self.assertEqual(place.status, PlaceName.REJECTED)
def verify(self, request, pk): if request and hasattr(request, "user"): if request.user.is_authenticated: try: PlaceName.verify(int(pk)) return Response({"message": "Verified!"}) except PlaceName.DoesNotExist: return Response({ "message": "No PlaceName with the given id was found" }) return Response( {"message", "Only Administrators can verify contributions"})
def flag(self, request, pk): try: placename = PlaceName.objects.get(pk=int(pk)) if placename.status == PlaceName.VERIFIED: return Response( {"message": "PlaceName has already been verified"}) else: if 'status_reason' in request.data.keys(): PlaceName.flag(int(pk), request.data["status_reason"]) return Response({"message": "Flagged!"}) else: return Response({"message": "Reason must be provided"}) except PlaceName.DoesNotExist: return Response( {"message": "No PlaceName with the given id was found"})
def reject(self, request, pk): if request and hasattr(request, "user"): if request.user.is_authenticated: try: if 'status_reason' in request.data.keys(): PlaceName.reject(int(pk), request.data["status_reason"]) return Response({"message": "Rejected!"}) else: return Response({"message": "Reason must be provided"}) except PlaceName.DoesNotExist: return Response({ "message": "No PlaceName with the given id was found" }) return Response( {"message", "Only Administrators can reject contributions"})
def test_placename_flag(self): placename = PlaceName() placename.name = "test place" placename.creator = self.user placename.community = self.community placename.language = self.language1 placename.save() created_id = placename.id # now update it. response = self.client.patch( "/api/placename/{}/flag/".format(created_id), {"status_reason": "test reason status"}, format="json", ) self.assertEqual(response.status_code, status.HTTP_200_OK) place = PlaceName.objects.get(pk=created_id) self.assertEqual(place.status, PlaceName.FLAGGED)
def create_placename(self, rec): # avoid duplicates on remote data source. try: node_placename = PlaceName.objects.get( name=rec["properties"]["name"]) # print('Updating %s' % rec["properties"]["name"]) except PlaceName.DoesNotExist: node_placename = PlaceName(name=rec["properties"]["name"]) print('Creating %s' % rec["properties"]["name"]) # Geometry map point with latitude and longitude node_placename.geom = Point( float(rec["geometry"]["coordinates"][0]), # latitude float(rec["geometry"]["coordinates"][1]), ) if rec["geometry"] else None node_placename.description = rec["properties"]["details"] node_placename.kind = rec["properties"]["type"] node_placename.save() return node_placename
def test_media_post_with_placename(self): """ Ensure media API POST method API works """ # Must be logged in to submit a place. self.assertTrue( self.client.login(username="******", password="******")) # Check we're logged in response = self.client.get("/api/user/auth/") self.assertEqual(response.json()["is_authenticated"], True) placename = PlaceName() placename.name = "test place" placename.other_names = "string" placename.common_name = "string" placename.community_only = True placename.description = "string" placename.community = self.community1 placename.language = self.language1 placename.save() response = self.client.post( "/api/media/", { "name": "Test media 001", "file_type": "image", "url": "https://google.com", "status": Media.UNVERIFIED, "placename": placename.id, "community_only": True, }, format="json", ) self.assertEqual(response.status_code, status.HTTP_201_CREATED) created_id = response.json()["id"] media = Media.objects.get(pk=created_id) self.assertEqual(media.name, "Test media 001") self.assertEqual(media.file_type, "image") self.assertEqual(media.url, "https://google.com") self.assertEqual(media.status, Media.UNVERIFIED) self.assertEqual(media.placename.id, placename.id)