コード例 #1
0
 def take(self, iplace, vd):
     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)
     return uplace
コード例 #2
0
    def test_image_by_url(self):
        '''
        pb = PostBase('{"urls": [{"content": "http://map.naver.com/local/siteview.nhn?code=31130096"}]}')
        pb.load_additional_info()
        print(pb.images[0].content)
        self.assertIn(pb.images[0].content, [
            unquote_plus('https://ssl.map.naver.com/staticmap/image?version=1.1&crs=EPSG%3A4326&caller=og_map&center=127.0584149%2C37.3916387&level=11&scale=2&w=500&h=500&markers=type%2Cdefault2%2C127.0584149%2C37.3916387&baselayer=default'),
            'http://ldb.phinf.naver.net/20150902_90/1441122604108F2r99_JPEG/SUBMIT_1353817968111_31130096.jpg',
        ])
        '''

        pb = PostBase(
            '{"urls": [{"content": "http://place.kakao.com/places/14720610"}]}'
        )
        pb.load_additional_info()
        self.assertEqual(
            pb.images[0].content,
            unquote_plus(
                'http://img1.daumcdn.net/thumb/C300x300/?fname=http%3A%2F%2Fdn-rp-place.kakao.co.kr%2Fplace%2FoWaiTZmpy7%2FviOeK5KRQK7mEsAHlckFgK%2FapreqCwxgnM_l.jpg'
            ))

        pb = PostBase(
            '{"urls": [{"content": "http://m.blog.naver.com/mardukas/220671562152"}]}'
        )
        pb.load_additional_info()
        self.assertEqual(
            pb.images[0].content,
            'http://blogthumb2.naver.net/20160401_292/mardukas_1459496453119PGXjg_JPEG/DSC03071.JPG?type=w2'
        )
コード例 #3
0
    def test_placed(self):
        vd = VD()
        vd.save()
        pb_add = PostBase('{"urls": [{"content": "http://www.naver.com/"}]}')
        pb_place1 = PostBase(
            '{"urls": [{"content": "http://place.kakao.com/places/15738374"}]}'
        )
        pb_place2 = PostBase(
            '{"urls": [{"content": "http://place.kakao.com/places/26455534"}]}'
        )

        uplace, is_created = UserPlace.get_or_create_smart(pb_add, vd)
        self.assertEqual(uplace.place, None)

        pb_place1.uplace_uuid = uplace.uuid
        uplace, is_created = UserPlace.get_or_create_smart(
            pb_place1.pb_MAMMA, vd)
        self.assertNotEqual(uplace.place, None)
        self.assertEqual(uplace.lonLat, uplace.place.lonLat)
        place1 = uplace.place

        pb_place2.uplace_uuid = uplace.uuid
        pb_place2.place_id = place1.id
        uplace, is_created = UserPlace.get_or_create_smart(
            pb_place2.pb_MAMMA, vd)
        self.assertNotEqual(uplace.place, None)
        self.assertEqual(uplace.lonLat, uplace.place.lonLat)
        place2 = uplace.place

        self.assertNotEqual(place1, place2)
        self.assertNotEqual(place1.lonLat, place2.lonLat)
コード例 #4
0
 def test_get_from_post(self):
     vd_other = VD.objects.create()
     place_other = Place.objects.create()
     uplace1 = UserPlace.objects.create(vd=vd_other, place=self.place)
     uplace2 = UserPlace.objects.create(vd=self.vd, place=place_other)
     uplace3 = UserPlace.objects.create(vd=self.vd, place=self.place)
     pb = PostBase()
     pb.place_id = self.place.id
     ru = RealUser.objects.create(email='*****@*****.**')
     self.vd.realOwner = ru
     self.vd.save()
     vd_mine = VD.objects.create(realOwner=ru)
     uplace_check, is_created = UserPlace.get_or_create_smart(pb, vd_mine)
     self.assertNotEqual(uplace1, uplace_check)
     self.assertNotEqual(uplace2, uplace_check)
     self.assertEqual(uplace3, uplace_check)
コード例 #5
0
    def test_data_property(self):
        # TODO : json 에 대한 query 테스트 추가
        uplace = UserPlace.objects.create()
        pp = PostPiece(uplace=uplace)
        json_add = json_loads('''
            {
                "lonLat": {"lon": 127.1037430, "lat": 37.3997320},
                "images": [{"content": "http://blogthumb2.naver.net/20160302_285/mardukas_1456922688406bYGAH_JPEG/DSC07301.jpg"}],
                "addr1": {"content": "경기도 성남시 분당구 판교로 256번길 25"},
                "addr2": {"content": "경기도 성남시 분당구 삼평동 631"},
                "addr3": {"content": "경기도 성남시 분당구 삼평동"},
                "urls": [{"content": "http://place.kakao.com/places/15738374"}]
            }
        ''')
        pp.data = json_add
        pp.vd = self.vd
        pp.save()
        saved = PostPiece.objects.first()
        self.assertEqual(json_add, pp.data)
        self.assertEqual(json_add, saved.data)
        self.assertEqual(pp.pb.image.vd, pp.vd)
        self.assertEqual(pp.pb.url.vd, pp.vd)

        pp2 = PostPiece()
        pb = PostBase(json_add)
        pp2.pb = pb
        pp2.save()
        saved = PostPiece.objects.order_by('-id').first()
        self.assertEqual(pp2, saved)
        self.assertDictEqual(pp2.pb.json, saved.pb.json)
        self.assertDictEqual(pp2.pb.cjson, saved.pb.cjson)
        self.assertDictEqual(pb.json, saved.pb.json)
        self.assertDictEqual(pb.cjson, saved.pb.cjson)
        self.assertEqual(pp2.pb.image.vd, pp2.vd)
        self.assertEqual(pp2.pb.url.vd, pp2.vd)
コード例 #6
0
 def test_setUp_with_str(self):
     json_add = '''
         {
             "lonLat": {"lon": 127.1037430, "lat": 37.3997320},
             "images": [{"content": "http://blogthumb2.naver.net/20160302_285/mardukas_1456922688406bYGAH_JPEG/DSC07301.jpg"}],
             "addr1": {"content": "경기도 성남시 분당구 판교로 256번길 25"},
             "addr2": {"content": "경기도 성남시 분당구 삼평동 631"},
             "urls": [{"content": "http://place.kakao.com/places/15738374"}]
         }
     '''
     pb = PostBase(json_add)
     json = pb.json
     pb2 = PostBase(json)
     self.assertDictEqual(json, pb2.json)
     self.assertIsSubsetOf(json_loads(json_add), json)
     self.printJson(pb.pb_MAMMA)
コード例 #7
0
 def setUp(self):
     super(ImportedPlaceViewSetTest, self).setUp()
     self.vd_subscriber = VD.objects.get(id=self.vd_id)
     self.vd_publisher = VD.objects.create()
     self.proxy = Proxy.objects.create(vd=self.vd_publisher)
     self.vd_publisher2 = VD.objects.create()
     self.proxy2 = Proxy.objects.create(vd=self.vd_publisher2)
     self.imp = Importer.objects.create(publisher=self.proxy,
                                        subscriber=self.vd_subscriber)
     self.imp2 = Importer.objects.create(publisher=self.proxy2,
                                         subscriber=self.vd_subscriber)
     self.place = Place.objects.create()
     self.place2 = Place.objects.create()
     self.iplace = ImportedPlace.objects.create(vd=self.vd_publisher,
                                                place=self.place)
     self.pb = PostBase('{"notes": [{"content": "test note"}]}')
     self.pp = PostPiece.create_smart(self.iplace, self.pb)
     self.iplace2 = ImportedPlace.objects.create(vd=self.vd_publisher,
                                                 place=self.place2)
     self.iplace3 = ImportedPlace.objects.create(vd=self.vd_publisher,
                                                 place=None)
     self.uplace = UserPlace.objects.create(vd=self.vd_subscriber,
                                            place=self.place2)
     self.vd_other = VD.objects.create()
     self.uplace_other = UserPlace.objects.create(vd=self.vd_other,
                                                  place=self.place)
     self.place3 = Place.objects.create()
     self.iplace4 = ImportedPlace.objects.create(vd=self.vd_publisher2,
                                                 place=self.place3)
コード例 #8
0
    def summarize_force(self, accessed=None):
        # TODO : 각종 URL 패턴들에 대해 정보 수집하여 요약
        if not accessed:
            accessed = self.content_accessed

        json = None
        if accessed:
            if self.contentType == 'naver':
                #json = self.summarize_force_naver(accessed)
                raise NotImplementedError
            elif self.contentType == 'kakao':
                json = self.summarize_force_kakao(accessed)
            elif self.contentType == '4square':
                json = self.summarize_force_4square(accessed)
            elif self.contentType == 'mango':
                json = self.summarize_force_mango(accessed)
            elif self.contentType == 'google':
                json = self.summarize_force_google(accessed)
            else:
                raise NotImplementedError

        if json:
            from place.post import PostBase
            pb = PostBase(json)
            for img in pb.images:
                img.summarize()
            f = Path(self.path_summarized)
            f.write_text(json_dumps(pb.json).decode('utf-8'))
コード例 #9
0
    def test_placed_by_name2(self):
        vd = VD()
        vd.save()
        pb_add = PostBase('''{
            "urls": [{"content": "http://www.naver.com/"}]
        }''')
        pb_name = PostBase('{"name": {"content": "바이키 문정점"}}')
        pb_place2 = PostBase(
            '{"urls": [{"content": "http://place.kakao.com/places/26455534"}]}'
        )

        self.assertEqual(Place.objects.count(), 0)
        self.assertEqual(PostPiece.objects.count(), 0)
        uplace, is_created = UserPlace.get_or_create_smart(pb_add, vd)
        self.assertEqual(uplace.place, None)
        self.assertEqual(Place.objects.count(), 0)
        self.assertEqual(PostPiece.objects.count(), 0)

        pb_place2.uplace_uuid = uplace.uuid
        uplace, is_created = UserPlace.get_or_create_smart(
            pb_place2.pb_MAMMA, vd)
        self.assertNotEqual(uplace.place, None)
        place2 = uplace.place
        self.assertEqual(Place.objects.count(), 1)
        self.assertNotEqual(place2.placePost.addr1, None)
        self.assertEqual(PostPiece.objects.count(), 1)

        pb_name.uplace_uuid = uplace.uuid
        uplace, is_created = UserPlace.get_or_create_smart(pb_name, vd)
        self.assertNotEqual(uplace.place, None)
        self.assertEqual(Place.objects.count(), 1)
        self.assertEqual(PostPiece.objects.count(), 1)
        place1 = uplace.place
        self.assertEqual(place1, place2)
        self.assertNotEqual(place1.placePost.addr1, None)
コード例 #10
0
 def _totalPost(self):
     pb = PostBase()
     for pp in self.pps.all().order_by('id'):
         pb.update(pp.pb, pp.is_add)
     pb.place_id = self.id
     pb.normalize()
     return pb
コード例 #11
0
    def test_placed_by_url0_2(self):
        url, is_created = Url.get_or_create_smart('http://www.naver.com/')
        json_add = '''{"urls": [{"content": "%s"}]}''' % (url.content, )
        place1 = Place.objects.create()
        place2 = Place.objects.create()
        place3 = Place.objects.create()
        self.assertEqual(UserPlace.objects.count(), 0)

        pb = PostBase(json_add)
        uplace = UserPlace.objects.create(vd=self.vd)
        PostPiece.create_smart(uplace, pb)

        url.add_place(place1)
        self.assertEqual(UserPlace.objects.count(), 1)
        '''
        pb = PostBase(json_add)
        uplace, is_created = UserPlace.get_or_create_smart(pb, self.vd)
        PostPiece.create_smart(uplace, pb)
        print(is_created)
        #'''
        #UserPlace.dump_all()
        #'''
        response = self.client.post('/uplaces/', dict(add=json_add, ))
        self.assertEqual(response.status_code, status.HTTP_201_CREATED)
        uplace = UserPlace.get_from_uuid(
            json_loads(response.content)['uplace_uuid'])
        uplace.place = None
        uplace.save()
        #'''
        self.assertEqual(UserPlace.objects.count(), 1 + 1)
        #UserPlace.dump_all()

        url.add_place(place2)
        self.assertEqual(UserPlace.objects.count(), 2 + 2)
        pb = PostBase(json_add)
        uplace = UserPlace.objects.create(vd=self.vd)
        PostPiece.create_smart(uplace, pb)
        self.assertEqual(UserPlace.objects.count(), 4 + 1)

        url.add_place(place3)
        self.assertEqual(UserPlace.objects.count(), 5 + 1)
        pb = PostBase(json_add)
        uplace = UserPlace.objects.create(vd=self.vd)
        PostPiece.create_smart(uplace, pb)
        self.assertEqual(UserPlace.objects.count(), 6 + 1)
コード例 #12
0
 def test_get_or_create_smart(self):
     vd = VD.objects.create()
     test_data = 'http://place.kakao.com/places/15738374'
     lp, is_created = LegacyPlace.get_or_create_smart(test_data)
     pb = PostBase()
     pb.lps.append(lp)
     place, is_created = Place.get_or_create_smart(pb.pb_MAMMA, vd)
     placePost = place.placePost
     self.assertDictEqual(pb.pb_MAMMA.json, placePost.json)
     self.assertEqual(unicode(place), '방아깐')
コード例 #13
0
    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)
コード例 #14
0
 def helper(self):
     pb = PostBase()
     for pp in self.pps.all().filter(uplace=None).order_by('id'):
         if pp.is_bounded:
             continue
         pb_new = pp.pb
         pb.update(pb_new, pp.is_add)
     pb.place_id = self.id
     pb.normalize()
     return pb
コード例 #15
0
    def get_or_create_child(self, place=None):
        if self.parent:
            print('[Child cannot created from other Child]')
            print('[Child info]')
            self.dump()
            print('[Parent info]')
            self.parent.dump()
            print('------------------------------')
            raise NotImplementedError
        self.is_parent = True
        self.place = None
        self.save()

        pb = PostBase()
        pb.place_id = place and place.id or None
        child, is_created = UserPlace.get_or_create_smart(pb, self.vd)
        # 하기 is_created 에 의한 if 처리는 반드시 해야 함
        # 이를 하지 않으면 생성(U1) --> URL장소화(P1) --> 생성(U2) --> URL장소(P2) 에서 문제 발생
        # 위 문제가 아니더라도 성능상 유리
        if is_created:
            child.parent = self
            child.save()
        return child, is_created
コード例 #16
0
    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)
コード例 #17
0
    def drop(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)
        if is_created:
            # 매칭되는 UserPlace 가 없었다면 drop 처리
            pp = PostPiece.create_smart(uplace, pb, is_drop=True)
            uplace.is_drop = True
            uplace.save()
            serializer = UserPlaceSerializer(uplace)
            return Response(serializer.data, status=status.HTTP_204_NO_CONTENT)
        else:
            # 매칭되는 UserPlace 가 있었다면 무시
            # 이를 drop 처리하려면 delete /uplaces/detail/
            serializer = UserPlaceSerializer(uplace)
            return Response(serializer.data, status=status.HTTP_200_OK)
コード例 #18
0
 def setUp(self):
     from account.models import VD
     from place.models import Place, PostPiece
     from importer.models import Proxy, Importer, ImportedPlace
     from place.post import PostBase
     super(ImportedPlaceScenarioTest, self).setUp()
     self.vd_publisher = VD.objects.create()
     self.proxy = Proxy.objects.create(vd=self.vd_publisher)
     self.vd_subscriber = VD.objects.get(id=self.vd_id)
     self.imp = Importer.objects.create(publisher=self.proxy, subscriber=self.vd_subscriber)
     self.place = Place.objects.create()
     self.place2 = Place.objects.create()
     self.iplace = ImportedPlace.objects.create(vd=self.vd_publisher, place=self.place)
     pb = PostBase('{"notes": [{"content": "test note"}]}')
     self.pp = PostPiece.create_smart(self.iplace, pb)
     self.iplace2 = ImportedPlace.objects.create(vd=self.vd_publisher, place=self.place2)
コード例 #19
0
 def pb(self):
     vd = None
     if self.uplace:
         vd = self.vd
     pb1 = PostBase(self.data, self.timestamp, vd)
     '''
     if pb1.iplace_uuid and self.uplace:
         from importer.models import ImportedPlace
         iplace = ImportedPlace.get_from_uuid(pb1.iplace_uuid)
         if iplace.id == self.uplace.id:
             return pb1
         if iplace and iplace.vd and not iplace.vd.is_private:
             iplace.subscriber = self.vd
             iplace.is_bounded = True
             post = iplace.userPost
             pb1.update(post)
     '''
     return pb1
コード例 #20
0
    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)
コード例 #21
0
def url_placed(request):
    url = None
    places = None
    vd_id = request.session[VD_SESSION_KEY]
    vd = VD.objects.get(id=vd_id)
    if not vd:
        raise ValueError('Admin Login Required')

    if request.method == 'POST':
        raw_url = request.POST['url']
        url, is_created = Url.get_or_create_smart(raw_url)
        if not url:
            raise ValueError('Invalid URL')
        raw_places = request.POST['places']

        for raw_place in raw_places.split('\n'):
            raw_place = raw_place.strip()
            is_remove = False
            if raw_place.startswith('-'):
                is_remove = True
                raw_place = raw_place[1:]
            if not raw_place:
                continue
            lp_content = LegacyPlace.normalize_content(raw_place)
            if lp_content:
                lp, is_created = LegacyPlace.get_or_create_smart(lp_content)
                pb = PostBase()
                pb.lps.append(lp)
                place, is_created = Place.get_or_create_smart(pb.pb_MAMMA, vd)
                if is_remove:
                    url.remove_place(place)
                else:
                    url.add_place(place)
            else:
                raise NotImplementedError
        places = [place for place in url.places.all()]

    return render(request, 'admin2/url_placed.html',
                  dict(url=url, places=places))
コード例 #22
0
    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)
コード例 #23
0
    def test_uplaces_total(self):
        iplace32_album = self.take(self.uplace32_album, self.vd32)

        iplace22_album = self.take(self.uplace22_album, self.vd22)
        iplace31 = self.take(self.uplace31, self.vd22)
        iplace32 = self.take(self.uplace32, self.vd22)
        iiplace32_album = self.take(iplace32_album, self.vd22)

        iplace12_album = self.take(self.uplace12_album, self.vd12)
        iplace21 = self.take(self.uplace21, self.vd11)
        iplace22 = self.take(self.uplace22, self.vd11)
        iiplace22_album = self.take(iplace22_album, self.vd11)
        iiplace31 = self.take(iplace31, self.vd11)
        iiplace32 = self.take(iplace32, self.vd11)
        iiiplace32_album = self.take(iiplace32_album, self.vd11)

        response = self.client.get('/uplaces/')
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        results = json_loads(response.content)['results']
        self.assertEqual(len(results), 9)
        self.assertMembersIn([
            self.url11, self.url12, self.url12_album, self.url31, self.url32,
            self.url21, self.url22
        ], response.content)
        self.assertMembersNotIn([
            self.url22_album,
            self.url32_album,
        ], response.content)

        # add image
        url22_album_2 = 'http://www.maukistudio.com/img22_album_2.jpg'
        img22_album_2 = Image.objects.create(content=url22_album_2)
        pb22_album_2 = PostBase()
        pb22_album_2.images.append(img22_album_2)
        uplace = iplace22_album
        pb = pb22_album_2
        pp22_album_2 = PostPiece.objects.create(uplace=uplace,
                                                pb=pb,
                                                place=uplace.place,
                                                vd=uplace.vd)

        url32_album_2 = 'http://www.maukistudio.com/img32_album_2.jpg'
        img32_album_2 = Image.objects.create(content=url32_album_2)
        pb32_album_2 = PostBase()
        pb32_album_2.images.append(img32_album_2)
        uplace = iiplace32_album
        pb = pb32_album_2
        pp32_album_2 = PostPiece.objects.create(uplace=uplace,
                                                pb=pb,
                                                place=uplace.place,
                                                vd=uplace.vd)

        self.reset_cache()
        response = self.client.get('/uplaces/')
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        results = json_loads(response.content)['results']
        self.assertEqual(len(results), 9)
        self.assertMembersIn([
            self.url11, self.url12, self.url12_album, self.url31, self.url32,
            self.url21, self.url22, url22_album_2, url32_album_2
        ], response.content)
        self.assertMembersNotIn([
            self.url22_album,
            self.url32_album,
        ], response.content)

        # ru1 imports ru3
        self.importer_ru1_ru3 = Importer.objects.create(
            publisher=self.proxy_ru3, subscriber=self.vd11)

        self.reset_cache()
        response = self.client.get('/uplaces/')
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        results = json_loads(response.content)['results']
        self.assertEqual(len(results), 9)
        self.assertMembersIn([
            self.url11, self.url12, self.url12_album, self.url21, self.url22,
            url22_album_2, url32_album_2, self.url31, self.url32
        ], response.content)
        self.assertMembersNotIn([
            self.url22_album,
            self.url32_album,
        ], response.content)
コード例 #24
0
 def base_post(self):
     base_post = self.parent and self.parent.userPost or PostBase()
     # TODO : 아래 코드가 기억나지 않음 ㅠ_ㅜ 정체 파악 후 다시 부활
     #base_post.reset_except_region_property()
     base_post = base_post.copy()
     return base_post
コード例 #25
0
def placed_detail(request, uplace_id):
    if request.method == 'POST':
        vd = VD.objects.get(id=request.session[VD_SESSION_KEY])

        # LegacyPlace URL 로 장소화
        if 'url' in request.POST and request.POST['url']:
            url = request.POST['url']

            # 삭제
            if url in ('삭제', '제거', 'delete', 'remove'):
                uplace = UserPlace.objects.get(id=uplace_id)
                uplace.delete()
                return redirect('/admin2/placed/%s.uplace/' % uplace_id)

            # 나중에
            if url in ('나중에', '나중', 'later', 'delay'):
                uplace = UserPlace.objects.get(id=uplace_id)
                uplace.is_hard2placed = True
                uplace.save()
                return redirect('/admin2/placed/%s.uplace/' % uplace_id)

            # PostBase instance 생성
            json_add = '{"urls": [{"content": "%s"}]}' % url
            pb = PostBase(json_add)
            pb.uplace_uuid = '%s.uplace' % uplace_id

            # UserPlace/Place 찾기
            uplace, is_created = UserPlace.get_or_create_smart(pb, vd)
            pb.uplace_uuid = uplace.uuid

            # valid check
            if not pb.is_valid(uplace):
                raise ValueError('PostPiece 생성을 위한 최소한의 정보도 없음')

            pb_MAMMA = pb.pb_MAMMA
            if pb_MAMMA:
                uplace, is_created = UserPlace.get_or_create_smart(
                    pb_MAMMA, vd)

            # redirect
            return redirect('/admin2/placed/%s.uplace/' % uplace_id)

        # placeName/lonLat 로 장소화
        elif 'placeName' in request.POST and request.POST['placeName']:
            placeName = request.POST['placeName']
            lon = None
            lat = None
            if 'lonLat' in request.POST and request.POST['lonLat']:
                raw_lonLat = request.POST['lonLat']
                regexs = [
                    re_compile(
                        r'^.*[&\?]?lat=(?P<lat>-?[0-9\.]+)&lng=(?P<lon>-?[0-9\.]+)&?.*$'
                    ),
                    re_compile(
                        r'^.*[&\?]?lng=(?P<lon>-?[0-9\.]+)&lat=(?P<lat>-?[0-9\.]+)&?.*$'
                    ),
                    re_compile(
                        r'^.*[&\?]?lat=(?P<lat>-?[0-9\.]+)&lon=(?P<lon>-?[0-9\.]+)&?.*$'
                    ),
                    re_compile(
                        r'^.*[&\?]?lon=(?P<lon>-?[0-9\.]+)&lat=(?P<lat>-?[0-9\.]+)&?.*$'
                    ),
                    re_compile(
                        r'^.*[&\?]?x=(?P<lon>-?[0-9\.]+)&y=(?P<lat>-?[0-9\.]+)&?.*$'
                    ),
                    re_compile(
                        r'^.*/data=.*!3d(?P<lat>-?[0-9\.]+)!4d(?P<lon>-?[0-9\.]+).*$'
                    ),
                    re_compile(
                        r'^.*/@(?P<lat>-?[0-9\.]+),(?P<lon>-?[0-9\.]+).*$'),
                ]
                for regex in regexs:
                    searcher = regex.search(raw_lonLat)
                    if searcher:
                        lon = float(searcher.group('lon'))
                        lat = float(searcher.group('lat'))
                        print('lon', searcher.group('lon'))
                        print('lat', searcher.group('lat'))
                        break
            if not lon or not lat:
                _uplace = UserPlace.objects.get(id=uplace_id)
                if _uplace and _uplace.lonLat:
                    lon = _uplace.lonLat.x
                    lat = _uplace.lonLat.y
            if not lon or not lat:
                # 현재는 이름과 함께 좌표(위도경도)를 넣어줘야 장소화가 됨 (향후 좌표 대신 주소도 가능)
                raise NotImplementedError

            # PostBase instance 생성
            json_add = '{"lonLat": {"lon": %f, "lat": %f}, "name": {"content": "%s"}}' % (
                lon,
                lat,
                placeName,
            )
            pb = PostBase(json_add)
            pb.uplace_uuid = '%s.uplace' % uplace_id

            # 장소화
            uplace, is_created = UserPlace.get_or_create_smart(pb, vd)

            # redirect
            return redirect('/admin2/placed/%s.uplace/' % uplace_id)

    try:
        uplace = UserPlace.objects.get(id=uplace_id)
    except UserPlace.DoesNotExist:
        return HttpResponse('삭제되었습니다')

    default_lonLat = 'LonLat Required'
    if uplace.lonLat:
        default_lonLat = 'lon=%f&lat=%f' % (uplace.lonLat.x, uplace.lonLat.y)
    #uplace.userPost.map_url = get_map_url(uplace.lonLat)
    uplace.userPost.map_url_daum = get_map_url_daum(uplace.lonLat)
    uplace.userPost.map_url_google = get_map_url_google(uplace.lonLat)
    if uplace.placePost:
        #uplace.placePost.map_url = get_map_url(uplace.placePost.lonLat)
        uplace.placePost.map_url_daum = get_map_url_daum(
            uplace.placePost.lonLat)
        uplace.placePost.map_url_google = get_map_url_google(
            uplace.placePost.lonLat)
    context = dict(userPost=uplace.userPost,
                   placePost=uplace.placePost,
                   default_lonLat=default_lonLat)
    return render(request, 'admin2/placed_detail.html', context)
コード例 #26
0
 def test_setUp_with_None(self):
     pb = PostBase()
     json = pb.json
     pb2 = PostBase(json)
     self.assertDictEqual(json, pb2.json)
コード例 #27
0
 def content_summarized(self):
     from place.post import PostBase
     file = Path(self.path_summarized)
     json_str = file.read_text()
     return PostBase(json_str)
コード例 #28
0
    def setUp(self):
        super(ImportedPlaceViewSetTest, self).setUp()

        # ru1 : myself
        self.ru1 = self.vd.realOwner
        self.vd11 = self.vd
        self.vd12 = VD.objects.create(realOwner=self.ru1)
        self.vd12_album = VD.objects.create(parent=self.vd12,
                                            is_private=True,
                                            is_public=False)
        self.proxy_vd12_album = Proxy.objects.create(vd=self.vd12_album,
                                                     guide={
                                                         'type': 'images',
                                                         'vd': self.vd12.id
                                                     })
        self.importer_vd12_album = Importer.objects.create(
            publisher=self.proxy_vd12_album, subscriber=self.vd12)

        # ru2 : ru1 --> ru2
        self.ru2_email = '*****@*****.**'
        self.ru2 = RealUser.objects.create(email=self.ru2_email)
        self.vd21 = VD.objects.create(realOwner=self.ru2)
        self.vd22 = VD.objects.create(realOwner=self.ru2)
        self.vd22_album = VD.objects.create(parent=self.vd22,
                                            is_private=True,
                                            is_public=False)
        self.proxy_vd22_album = Proxy.objects.create(vd=self.vd22_album,
                                                     guide={
                                                         'type': 'images',
                                                         'vd': self.vd22.id
                                                     })
        self.importer_vd22_album = Importer.objects.create(
            publisher=self.proxy_vd22_album, subscriber=self.vd22)

        # ru3 : ru2 --> ru3
        self.ru3_email = '*****@*****.**'
        self.ru3 = RealUser.objects.create(email=self.ru3_email)
        self.vd31 = VD.objects.create(realOwner=self.ru3)
        self.vd32 = VD.objects.create(realOwner=self.ru3)
        self.vd32_album = VD.objects.create(parent=self.vd32,
                                            is_private=True,
                                            is_public=False)
        self.proxy_vd32_album = Proxy.objects.create(vd=self.vd32_album,
                                                     guide={
                                                         'type': 'images',
                                                         'vd': self.vd32.id
                                                     })
        self.importer_vd32_album = Importer.objects.create(
            publisher=self.proxy_vd32_album, subscriber=self.vd32)

        # make user importers
        self.vd2_virtual = VD.objects.create()
        self.proxy_ru2 = Proxy.objects.create(vd=self.vd2_virtual,
                                              guide={
                                                  'type': 'user',
                                                  'email': self.ru2_email
                                              })
        self.importer_ru1_ru2 = Importer.objects.create(
            publisher=self.proxy_ru2, subscriber=self.vd11)
        self.vd3_virtual = VD.objects.create()
        self.proxy_ru3 = Proxy.objects.create(vd=self.vd3_virtual,
                                              guide={
                                                  'type': 'user',
                                                  'email': self.ru3_email
                                              })
        self.importer_ru2_ru3 = Importer.objects.create(
            publisher=self.proxy_ru3, subscriber=self.vd21)

        # make images
        self.url11 = 'http://www.maukistudio.com/img11.jpg'
        self.img11 = Image.objects.create(content=self.url11)
        self.url12 = 'http://www.maukistudio.com/img12.jpg'
        self.img12 = Image.objects.create(content=self.url12)
        self.url12_album = 'http://www.maukistudio.com/img12_album.jpg'
        self.img12_album = Image.objects.create(content=self.url12_album)
        self.url21 = 'http://www.maukistudio.com/img21.jpg'
        self.img21 = Image.objects.create(content=self.url21)
        self.url22 = 'http://www.maukistudio.com/img22.jpg'
        self.img22 = Image.objects.create(content=self.url22)
        self.url22_album = 'http://www.maukistudio.com/img22_album.jpg'
        self.img22_album = Image.objects.create(content=self.url22_album)
        self.url31 = 'http://www.maukistudio.com/img31.jpg'
        self.img31 = Image.objects.create(content=self.url31)
        self.url32 = 'http://www.maukistudio.com/img32.jpg'
        self.img32 = Image.objects.create(content=self.url32)
        self.url32_album = 'http://www.maukistudio.com/img32_album.jpg'
        self.img32_album = Image.objects.create(content=self.url32_album)

        # make places
        self.place11 = Place.objects.create()
        self.place12 = Place.objects.create()
        self.place12_album = Place.objects.create()
        self.place21 = Place.objects.create()
        self.place22 = Place.objects.create()
        self.place22_album = Place.objects.create()
        self.place31 = Place.objects.create()
        self.place32 = Place.objects.create()
        self.place32_album = Place.objects.create()

        # make uplaces
        self.uplace11 = UserPlace.objects.create(vd=self.vd11,
                                                 place=self.place11)
        self.uplace12 = UserPlace.objects.create(vd=self.vd12,
                                                 place=self.place12)
        self.uplace12_album = UserPlace.objects.create(
            vd=self.vd12_album, place=self.place12_album)
        self.uplace21 = UserPlace.objects.create(vd=self.vd21,
                                                 place=self.place21)
        self.uplace22 = UserPlace.objects.create(vd=self.vd22,
                                                 place=self.place22)
        self.uplace22_album = UserPlace.objects.create(
            vd=self.vd22_album, place=self.place22_album)
        self.uplace31 = UserPlace.objects.create(vd=self.vd31,
                                                 place=self.place31)
        self.uplace32 = UserPlace.objects.create(vd=self.vd32,
                                                 place=self.place32)
        self.uplace32_album = UserPlace.objects.create(
            vd=self.vd32_album, place=self.place32_album)

        # make postbase
        self.pb11 = PostBase()
        self.pb11.images.append(self.img11)
        self.pb12 = PostBase()
        self.pb12.images.append(self.img12)
        self.pb12_album = PostBase()
        self.pb12_album.images.append(self.img12_album)
        self.pb21 = PostBase()
        self.pb21.images.append(self.img21)
        self.pb22 = PostBase()
        self.pb22.images.append(self.img22)
        self.pb22_album = PostBase()
        self.pb22_album.images.append(self.img22_album)
        self.pb31 = PostBase()
        self.pb31.images.append(self.img31)
        self.pb32 = PostBase()
        self.pb32.images.append(self.img32)
        self.pb32_album = PostBase()
        self.pb32_album.images.append(self.img32_album)

        # make postpiece
        uplace = self.uplace11
        pb = self.pb11
        self.pp11 = PostPiece.objects.create(uplace=uplace,
                                             pb=pb,
                                             place=uplace.place,
                                             vd=uplace.vd)
        uplace = self.uplace12
        pb = self.pb12
        self.pp12 = PostPiece.objects.create(uplace=uplace,
                                             pb=pb,
                                             place=uplace.place,
                                             vd=uplace.vd)
        uplace = self.uplace12_album
        pb = self.pb12_album
        self.pp12_album = PostPiece.objects.create(uplace=uplace,
                                                   pb=pb,
                                                   place=uplace.place,
                                                   vd=uplace.vd)
        uplace = self.uplace21
        pb = self.pb21
        self.pp21 = PostPiece.objects.create(uplace=uplace,
                                             pb=pb,
                                             place=uplace.place,
                                             vd=uplace.vd)
        uplace = self.uplace22
        pb = self.pb22
        self.pp22 = PostPiece.objects.create(uplace=uplace,
                                             pb=pb,
                                             place=uplace.place,
                                             vd=uplace.vd)
        uplace = self.uplace22_album
        pb = self.pb22_album
        self.pp22_album = PostPiece.objects.create(uplace=uplace,
                                                   pb=pb,
                                                   place=uplace.place,
                                                   vd=uplace.vd)
        uplace = self.uplace31
        pb = self.pb31
        self.pp31 = PostPiece.objects.create(uplace=uplace,
                                             pb=pb,
                                             place=uplace.place,
                                             vd=uplace.vd)
        uplace = self.uplace32
        pb = self.pb32
        self.pp32 = PostPiece.objects.create(uplace=uplace,
                                             pb=pb,
                                             place=uplace.place,
                                             vd=uplace.vd)
        uplace = self.uplace32_album
        pb = self.pb32_album
        self.pp32_album = PostPiece.objects.create(uplace=uplace,
                                                   pb=pb,
                                                   place=uplace.place,
                                                   vd=uplace.vd)
コード例 #29
0
    def test_post(self):
        place = Place()
        place.save()
        vd1 = VD()
        vd1.save()
        uplace1 = UserPlace(vd=vd1, place=place)
        uplace1.save()
        point1 = GEOSGeometry('POINT(127 37)', srid=4326)
        name1, is_created = PlaceName.get_or_create_smart('능라')
        addr1, is_created = Address.get_or_create_smart(
            '경기도 성남시 분당구 운중동 883-3')
        note11, is_created = PlaceNote.get_or_create_smart('분당 냉면 최고')
        note12, is_created = PlaceNote.get_or_create_smart('만두도 괜찮음')
        imgNote1, is_created = ImageNote.get_or_create_smart('냉면 사진')
        img1_content = 'http://blogthumb2.naver.net/20160302_285/mardukas_1456922688406bYGAH_JPEG/DSC07301.jpg'
        img1, is_created = Image.get_or_create_smart(img1_content)
        phone1, is_created = PhoneNumber.get_or_create_smart('010-5686-1613')

        vd2 = VD()
        vd2.save()
        uplace2 = UserPlace(vd=vd2, place=place)
        uplace2.save()
        point2 = GEOSGeometry('POINT(127.1037430 37.3997320)', srid=4326)
        name2, is_created = PlaceName.get_or_create_smart('능라도')
        addr2, is_created = Address.get_or_create_smart(
            '경기도 성남시 분당구 산운로32번길 12')
        note21, is_created = PlaceNote.get_or_create_smart('여기 가게 바로 옆으로 이전')
        note22, is_created = PlaceNote.get_or_create_smart('평양냉면 맛집')
        img21_content = 'http://blogpfthumb.phinf.naver.net/20100110_16/mardukas_1263055491560_VI01Ic_JPG/DSCN1968.JPG'
        img22_content = 'http://mblogthumb3.phinf.naver.net/20160807_298/mardukas_14705287064440EYVC_JPEG/DSC03530.JPG?type=w800'
        img21, is_created = Image.get_or_create_smart(img21_content)
        img22, is_created = Image.get_or_create_smart(img22_content)
        imgNote2, is_created = ImageNote.get_or_create_smart('만두 사진')
        url2, is_created = Url.get_or_create_smart('http://www.naver.com/')
        lp, is_created = LegacyPlace.get_or_create_smart(
            '4ccffc63f6378cfaace1b1d6.4square')
        phone2, is_created = PhoneNumber.get_or_create_smart('010-5597-9245')

        json_userPost = '''
            {
                "lonLat": {"lon": %f, "lat": %f},
                "name": {"uuid": "%s", "content": "%s"},
                "addr2": {"uuid": "%s", "content": "%s"},
                "notes": [{"uuid": "%s", "content": "%s"}, {"uuid": "%s", "content": "%s"}],
                "images": [{"uuid": "%s", "content": "%s", "note": {"uuid": "%s", "content": "%s"}}],
                "urls": [],
                "lps": [],
                "phone": {"uuid": "%s", "content": "%s"}
            }
        ''' % (
            point1.x,
            point1.y,
            name1.uuid,
            name1.content,
            addr1.uuid,
            addr1.content,
            note12.uuid,
            note12.content,
            note11.uuid,
            note11.content,
            img1.uuid,
            img1.content,
            imgNote1.uuid,
            imgNote1.content,
            phone1.uuid,
            phone1.content,
        )
        json_placePost = '''
            {
                "lonLat": {"lon": %f, "lat": %f},
                "name": {"uuid": "%s", "content": "%s"},
                "addr1": {"uuid": "%s", "content": "%s"},
                "addr2": {"uuid": "%s", "content": "%s"},
                "notes": [
                    {"uuid": "%s", "content": "%s"},
                    {"uuid": "%s", "content": "%s"},
                    {"uuid": "%s", "content": "%s"},
                    {"uuid": "%s", "content": "%s"}
                ],
                "images": [
                    {"uuid": "%s", "content": "%s", "note": null},
                    {"uuid": "%s", "content": "%s", "note": {"uuid": "%s", "content": "%s"}},
                    {"uuid": "%s", "content": "%s", "note": {"uuid": "%s", "content": "%s"}}
                ],
                "urls": [{"uuid": "%s", "content": "%s"}],
                "lps": [{"uuid": "%s", "content": "%s"}],
                "phone": {"uuid": "%s", "content": "%s"}
            }
        ''' % (
            point2.x,
            point2.y,
            name2.uuid,
            name2.content,
            addr2.uuid,
            addr2.content,
            addr1.uuid,
            addr1.content,
            note22.uuid,
            note22.content,
            note21.uuid,
            note21.content,
            note12.uuid,
            note12.content,
            note11.uuid,
            note11.content,
            img22.uuid,
            img22.content,
            img21.uuid,
            img21.content,
            imgNote2.uuid,
            imgNote2.content,
            img1.uuid,
            img1.content,
            imgNote1.uuid,
            imgNote1.content,
            url2.uuid,
            url2.content,
            lp.uuid,
            lp.content,
            phone2.uuid,
            phone2.content,
        )
        pb1 = PostBase(json_userPost)
        pb2 = PostBase(json_placePost)
        self.assertEqual(PostPiece.objects.count(), 0)
        pp1 = PostPiece.create_smart(uplace1, pb1)
        self.assertEqual(PostPiece.objects.count(), 1)
        pp2 = PostPiece.create_smart(uplace2, pb2)
        pp3 = PostPiece.create_smart_4place(place, vd1, pb2, by_MAMMA=True)
        self.assertEqual(PostPiece.objects.count(), 3)

        want_userPost = json_loads(json_userPost)
        want_placePost = json_loads(json_placePost)

        self.assertNotIn('timestamp', uplace1.userPost.json['lonLat'])
        self.assertNotIn('timestamp', uplace1.userPost.json['name'])
        self.assertIn('timestamp', uplace1.userPost.json['notes'][0])
        self.assertNotIn('timestamp', uplace1.userPost.json['images'][0])
        self.assertIn('timestamp', uplace1.userPost.json['images'][0]['note'])

        self.assertNotIn('timestamp', uplace2.userPost.json['urls'][0])
        self.assertNotIn('timestamp', uplace2.userPost.json['lps'][0])
        timestamp = uplace1.userPost.json['notes'][0]['timestamp']
        self.assertAlmostEqual(get_timestamp(), timestamp, delta=1000)
        self.assertIn('summary', uplace1.userPost.json['images'][0])
        self.assertIn('phone', uplace1.userPost.json)
        self.assertNotEqual(uplace1.userPost.json['images'][0]['content'],
                            None)

        self.assertIsSubsetOf(want_userPost, uplace1.userPost)
        self.assertIsNotSubsetOf(uplace1.userPost, want_userPost)

        self.assertIsSubsetOf(want_placePost, uplace1.place.placePost)
        self.assertIsNotSubsetOf(uplace1.place.placePost, want_placePost)
        uplace1._clearCache()
        p1 = uplace1.place.placePost
        uplace2._clearCache()
        p2 = uplace2.place.placePost
        place._clearCache()
        p3 = place.placePost
        self.assertDictEqual(p1.json, p3.json)
        self.assertDictEqual(p2.json, p3.json)

        pb12 = PostBase(json_userPost)
        pb12.update(pb1)
        self.assertNotEqual(pb12.json, pb1.json)
        pb12.normalize()
        self.assertEqual(pb12.json, pb1.json)

        pb13 = PostBase(json_userPost)
        pb13.update(pb1)
        pb13.update(pb1, add=False)
        pb_null = PostBase()
        self.assertEqual(pb13.json, pb_null.json)

        totalPost = place._totalPost
        self.assertIsSubsetOf(uplace1.place.placePost, totalPost)
        #self.assertIsSubsetOf(uplace1.userPost, totalPost)     # Note 에서 timestamp 를 제거해야...
        #self.assertIsSubsetOf(uplace2.userPost, totalPost)     # 상동
        #self.assertIsNotSubsetOf(totalPost, uplace1.place.placePost)   # userPost 를 하나 더 생성해야...

        # child/parent test
        uplace3 = UserPlace.objects.create(parent=uplace1)
        self.assertEqual(uplace3.parent, uplace1)
        self.assertNotEqual(uplace3.userPost, uplace1.userPost)
        self.printJson(uplace3.userPost.json)
        self.printJson(uplace1.userPost.json)
        self.assertEqual(uplace3.userPost.json, uplace1.userPost.json)
        uplace1._clearCache()
        uplace3._clearCache()
        pb3 = PostBase('{"notes": [{"content": "child"}]}')
        pp3 = PostPiece.create_smart(uplace3, pb3)
        self.assertNotEqual(uplace3.userPost, uplace1.userPost)
        self.assertNotEqual(uplace3.userPost.json, uplace1.userPost.json)

        place4 = Place.objects.create()
        uplace4 = UserPlace.objects.create(parent=uplace1,
                                           vd=vd1,
                                           place=place4)
        self.assertEqual(uplace4.parent, uplace1)
        self.assertNotEqual(uplace4.userPost, uplace1.userPost)
        self.assertEqual(uplace4.userPost.json, uplace1.userPost.json)
        uplace1._clearCache()
        uplace4._clearCache()
        pb3 = PostBase('{"notes": [{"content": "child"}]}')
        pp3 = PostPiece.create_smart(uplace4, pb3)
        self.assertNotEqual(uplace4.userPost, uplace1.userPost)
        self.assertNotEqual(uplace4.userPost.json, uplace1.userPost.json)