예제 #1
0
 def map(self, api, data):
     self.api = api
     dict_to_object_value('username', self, data)
     dict_to_object_value('display_name', self, data)
     dict_to_object_value('id', self, data)
     dict_to_object_value('follower_count', self, data, type='int')
     dict_to_object_value('following_count', self, data, type='int')
     try:
         self.pics = {}
         __has_more_pics__ = False
         __last_pic_id__ = False
         icon_data = data['icon']
         pic_files_dict = {}
         pic_files_dict['name'] = 'icon'
         pic_files_dict['img_url'] = icon_data['url']
         pic_files_dict['height'] = icon_data['height']
         pic_files_dict['width'] = icon_data['width']
         self.icon = PicplzImageFile.from_dict(api, pic_files_dict)
     except:
         pass
     try:
         pics_data = data['pics']
         for pic_data in pics_data:
             next_pic = Pic()
             next_pic = Pic.from_dict(self.api, pic_data)
             self.pics[next_pic.id] = next_pic
     except:
         ## no pics :(
         pass
예제 #2
0
    def map(self, api, data):
        """map a dict object into a model instance."""
        self.api = api
        dict_to_object_value('name', self, data)
        dict_to_object_value('img_url', self, data, object_field_name='url')
        dict_to_object_value('width', self, data, type='int')
        dict_to_object_value('height', self, data, type='int')

        self.name = data['name']
        self.url = data['img_url']
        self.width = int(data['width'])
        self.height = int(data['height'])
예제 #3
0
 def map(self, api, data):
     dict_to_object_value('id', self, data)
     dict_to_object_value('content', self, data)
     dict_to_object_value('date', self, data, type='datetime')
     try:
         user_data = data['user']
         self.creator = PicplzUser.from_dict(api, user_data)
     except:
         pass
예제 #4
0
 def map(self, api, data):
     dict_to_object_value('id', self, data)
     dict_to_object_value('url', self, data)
     dict_to_object_value('name', self, data)
     try:
         pics_data = data['pics']
         self.pics = {}
         for pic_data in pics_data:
             next_pic = Pic()
             next_pic = Pic.from_dict(self.api, pic_data)
             self.pics[next_pic.id] = next_pic
     except:
         ## no pics :(
         pass
예제 #5
0
 def map(self, api, data):
     dict_to_object_value('id', self, data)
     dict_to_object_value('description', self, data)
예제 #6
0
 def map(self, api, data):
     dict_to_object_value('id', self, data)
     dict_to_object_value('date', self, data, type='datetime')
     self.user = PicplzUser.from_dict(api, data['user'])
예제 #7
0
    def map(self, api, data):
        self.api = api
        """map a JSON object into a model instance."""
        dict_to_object_value('view_count', self, data, type='int')
        dict_to_object_value('url', self, data)
        dict_to_object_value('caption', self, data)
        dict_to_object_value('comment_count', self, data, type='int')
        dict_to_object_value('like_count', self, data, type='int')
        dict_to_object_value('id', self, data, type='int')
        dict_to_object_value('date', self, data, type='datetime')

        ## this is confusing, just go with it
        pic_files = {}
        pic_files_dict = {}
        for key in data['pic_files'].keys():
            pic_dict = data['pic_files'][key]
            pic_files_dict['name'] = key
            pic_files_dict['img_url'] = pic_dict['img_url']
            pic_files_dict['height'] = pic_dict['height']
            pic_files_dict['width'] = pic_dict['width']
            pic_files[pic_files_dict['name']] = PicplzImageFile().from_dict(
                api, pic_files_dict)
        self.pic_files = pic_files

        try:
            creator_data = data['creator']
            self.creator = PicplzUser.from_dict(api, creator_data)
        except:
            pass
        try:
            city_data = data['city']
            self.city = PicplzCity.from_dict(api, city_data)
        except:
            ## no city, no biggie
            pass

        if data.has_key('location'):
            self.location = Location()
            dict_to_object_value('lat',
                                 self.location,
                                 data['location'],
                                 object_field_name='latitude')
            dict_to_object_value('lon',
                                 self.location,
                                 data['location'],
                                 object_field_name='longitude')

        try:
            place_data = data['place']
            self.place = PicplzPlace.from_dict(api, place_data)
        except:
            ## no place, no biggie
            pass
        try:
            comment_string = data['items']
            for item in comment_string:
                comment = PicplzComment.from_dict(api, item)
                self.comments.append(comment)
        except:
            pass