def save(self, *args, **kwargs): if not self.publisher or not self.subscriber: raise IntegrityError( 'Importer.publisher and subscriber must not be None') if self.subscriber: cache_expire_ru(self.subscriber, 'realOwner_publisher_ids') super(Importer, self).save(*args, **kwargs)
def save(self, *args, **kwargs): if not self.mask: self.mask = 0 self.data = convert_to_json(self.data) self.accessHistory = convert_to_json(self.accessHistory) cache_expire_ru(self, 'realOwner_vd_ids') super(VD, self).save(*args, **kwargs)
def create_bounded(self, request, pk=None): # vd 조회 vd = self.vd if not vd: return Response(status=status.HTTP_401_UNAUTHORIZED) uplace = self.get_object() pb = PostBase(request.data['add']) uplace_temp = UserPlace.objects.create(vd=vd, is_bounded=True, place=uplace.place, lonLat=uplace.lonLat) pp = PostPiece.create_smart(uplace_temp, pb) serializer = self.get_serializer(uplace_temp) cache_expire_ru(vd, 'uplaces') return Response(serializer.data, status=status.HTTP_201_CREATED)
def take(self, request, pk=None): # vd 조회 vd = self.vd if not vd: return Response(status=status.HTTP_401_UNAUTHORIZED) iplace = self.get_object() pb = PostBase() pb.iplace_uuid = iplace.uuid pb.place_id = iplace.place_id pb.uplace_uuid = None uplace, is_created = UserPlace.get_or_create_smart(pb, vd) pp = PostPiece.create_smart(uplace, pb) serializer = UserPlaceSerializer(uplace) # for make taken place hidden from base.cache import cache_expire, cache_expire_ru cache_expire(vd, 'realOwner_place_ids') cache_expire_ru(vd, 'uplaces') return Response(serializer.data, status=status.HTTP_201_CREATED)
def perform_destroy(self, instance): # vd 조회 vd = self.vd if not vd: raise NotImplementedError # remove cache cache_expire_ru(vd, 'uplaces') cache_expire_ru(vd, instance.post_cache_name) # 장소화 안된 경우 완전 삭제 if not instance.place: super(UserPlaceViewset, self).perform_destroy(instance) # 장소화된 경우 drop 처리 else: instance.is_drop = True instance.save() pb = PostBase('{"notes": [{"content": "delete"}]}') pp = PostPiece.create_smart(instance, pb, is_drop=True)
def create(self, request, *args, **kwargs): # vd 조회 vd = self.vd if not vd: return Response(status=status.HTTP_401_UNAUTHORIZED) # 결과 처리를 위한 변수 선언 uplace = None ####################################### # 삭제 포스트 처리 ####################################### if 'remove' in request.data and request.data['remove']: # PostBase instance 생성 pb = PostBase(request.data['remove']) if 'place_id' in request.data and request.data['place_id']: pb.place_id = request.data['place_id'] if 'uplace_uuid' in request.data and request.data['uplace_uuid']: pb.uplace_uuid = request.data['uplace_uuid'] # 삭제 포스트는 반드시 uplace_uuid 가 지정되어야 한다. uplace = UserPlace.get_from_uuid(pb.uplace_uuid) if not uplace: raise ValueError('삭제 포스트 처리 시에는 반드시 uplace_uuid 가 지정되어야 함') # 삭제 PostPiece 생성 pp = PostPiece.create_smart(uplace, pb, is_remove=True) ####################################### # 추가 포스트 처리 ####################################### if 'add' in request.data and request.data['add']: # PostBase instance 생성 pb = PostBase(request.data['add']) if 'place_id' in request.data and request.data['place_id']: pb.place_id = request.data['place_id'] if 'uplace_uuid' in request.data and request.data['uplace_uuid']: pb.uplace_uuid = request.data['uplace_uuid'] # 추가 정보 가져오기 : 유저가 직접 입력했다고 봐도 무방한 사항만 pb.load_additional_info() # UserPlace/Place 찾기 uplace, is_created = UserPlace.get_or_create_smart(pb, vd) # valid check if not pb.is_valid(uplace): raise ValueError('PostPiece 생성을 위한 최소한의 정보도 없음') # PostPiece 생성 pp = PostPiece.create_smart(uplace, pb) # 임시적인 어드민 구현을 위해, MAMMA 가 추가로 뽑아준 post 가 있으면 추가로 포스팅 pb_MAMMA = pb.pb_MAMMA if pb_MAMMA: # 아래 호출에서 Place 가 생성되고, 필요시 Place PostPiece 도 생성됨 # TODO : 좀 더 Readability 가 높은 형태로 리팩토링 uplace, is_created = UserPlace.get_or_create_smart( pb_MAMMA, vd) # Place.lonLat 관련 예외 처리 lonLat = (pb_MAMMA and pb_MAMMA.lonLat) or pb.lonLat if lonLat and uplace.place and (not uplace.place.lonLat or (pb_MAMMA and pb_MAMMA.lonLat)): uplace.place.lonLat = lonLat uplace.place.save() # 현재 위치 저장인 경우 이미지에 추가 정보 붙이기 if is_created and lonLat and pb.images and len( pb.images) == 1 and pb.images[0]: img = pb.images[0] img.lonLat = lonLat img.timestamp = uplace.created - 1000 img.save() # 빠른 장소화를 위한 flag 세팅 if is_created and not uplace.place: uplace.is_hurry2placed = True # 최종 저장 uplace.lonLat = (uplace.place and uplace.place.lonLat) or lonLat or uplace.lonLat uplace.modified = get_timestamp() # TODO : 아래 코드가 테스트되는 테스트 추가 uplace.is_drop = False uplace.save() # Placed by Contents if pb.urls: placesets = [ set(url.places.all()) for url in pb.urls if url.places ] if placesets: places = list(reduce(lambda a, b: a & b, placesets)) for place in places: uplace.process_child(place) ####################################### # 결과 처리 ####################################### serializer = self.get_serializer(uplace) cache_expire_ru(vd, 'uplaces') cache_expire_ru(vd, uplace.post_cache_name) return Response(serializer.data, status=status.HTTP_201_CREATED)