예제 #1
0
    def save(self):
        _image = self.cleaned_data.get('image')
        _image_link = self.cleaned_data.get('image_link')
        _is_chief = self.cleaned_data.get('is_chief')

        if _image:
            entity_image = HandleImage(_image)
        else:
            import urllib2
            f = urllib2.urlopen(_image_link)
            entity_image = HandleImage(f)
            # fetch_image.delay(entity.images, entity.id)

        image_name = image_path + "%s.jpg" % entity_image.name

        if default_storage.exists(image_name):
            image_name = image_host + image_name
        else:
            image_name = image_host + default_storage.save(
                image_name, ContentFile(entity_image.image_data))
        images = self.entity.images

        if _is_chief:
            images.insert(0, image_name)
        else:
            images.append(image_name)
        self.entity.images = images
        self.entity.save()
예제 #2
0
    def save(self):
        link = self.cleaned_data.get('link')
        editor_recommend_image = self.cleaned_data.get(
            'editor_recommend_image')
        link = self.cleaned_data.get('link')
        position = self.clean_position()
        section = self.cleaned_data.get('section')
        event = self.cleaned_data.get('event')

        # log.info(position)

        if editor_recommend_image:
            _image = HandleImage(editor_recommend_image)
            # file_path = "%s%s.jpg" % (image_path, _image.name)
            # filename = default_storage.save(file_path, ContentFile(_image.image_data))
            self.recommendation.image = _image.save()

        self.recommendation.link = link
        self.recommendation.save()

        if event:
            try:
                show = Show_Editor_Recommendation.objects.get(
                    recommendation=self.recommendation)
                show.event_id = event
                show.section = section
                show.save()
            except Show_Editor_Recommendation.DoesNotExist, e:
                Show_Editor_Recommendation.objects.create(
                    recommendation=self.recommendation,
                    event_id=event,
                )
예제 #3
0
    def save(self):
        _image = self.cleaned_data.get('image')
        _nickname = self.cleaned_data.get('nickname')
        _bio = self.cleaned_data.get('bio')
        _gender = self.cleaned_data.get('gender')
        _location = self.cleaned_data.get('location')
        # print _nickname
        if _image:
            avatar_file = HandleImage(_image)

            self.user_cache.profile.avatar = avatar_file.avatar_save()

        if _nickname:
            self.user_cache.profile.nickname = _nickname

        if _gender:
            self.user_cache.profile.gender = _gender

        if _location:
            self.user_cache.profile.location = _location
        # if _email:
        #     self.user_cache.email = _email
        #     self.user_cache.save()
        #
        # if _password:
        #     self.user_cache.set_password(_password)
        #     self.user_cache.save()

        if _bio:
            self.user_cache.profile.bio = _bio

        self.user_cache.profile.save()
        return self.user_cache.v3_toDict()
예제 #4
0
    def save(self):
        _cover = self.cleaned_data.get('cover_file')

        _image = HandleImage(_cover)
        filename = _image.save()
        self.article_cache.cover = filename
        self.article_cache.save()

        return self.article_cache.cover_url
예제 #5
0
    def save(self):
        # self.user = user
        _avatar_file = self.cleaned_data.get('avatar_file')
        # log.info(_avatar_file)
        _image = HandleImage(image_file= _avatar_file)

        avatar_path_name = _image.avatar_save()

        self.user.profile.avatar = avatar_path_name

        self.user.profile.save()
예제 #6
0
    def save(self):
        self.api_key = self.cleaned_data.get('api_key')
        self.user_cache = super(MobileUserSignUpForm, self).save()

        _avatar_file = self.cleaned_data.get('image')
        if _avatar_file:
            _image = HandleImage(image_file=_avatar_file)
            avatar_path_name = _image.avatar_save()

            self.user_cache.profile.avatar = avatar_path_name

            self.user_cache.profile.save()

        return self.user_cache
예제 #7
0
    def save(self):
        _title = self.cleaned_data.get('name')
        _description = self.cleaned_data.get('description')
        if 'image' in self.changed_data:
            new_image = self.cleaned_data.get('image')
            _image = HandleImage(new_image)
            filename = _image.save()
            self.tag_cache.image = filename
        # print _title
        self.tag_cache.name = _title
        self.tag_cache.hash = md5(_title.encode('utf-8')).hexdigest()
        self.tag_cache.description = _description

        return self.tag_cache.save()
예제 #8
0
def fetch_avatar(avatar_url, user_id, *args, **kwargs):

    try:
        profile = User_Profile.objects.get(user_id = user_id)
    except User_Profile.DoesNotExist:
        return

    f = urllib2.urlopen(avatar_url)
    # return

    image = HandleImage(f)
    avatar_file = image.avatar_save(resize=False)
    profile.avatar = avatar_file
    profile.save()
예제 #9
0
    def save(self):
        _image = self.cleaned_data.get('launchImage', None)
        _title = self.cleaned_data.get('title')
        _description = self.cleaned_data.get('description')
        _device = self.cleaned_data.get('device')
        _version = self.cleaned_data.get('version')
        _action_title = self.cleaned_data.get('action_title')
        _action = self.cleaned_data.get('action')
        _status = self.cleaned_data.get('status')

        if _image:
            launch_image = HandleImage(_image)
            image_name = image_path + "%s.jpg" % launch_image.name
            default_storage.save(image_name,
                                 ContentFile(launch_image.image_data))
            self.launch.launchImage = image_name

        if _status:
            LaunchBoard.objects.filter(status=True).update(status=False)

        self.launch.title = _title
        self.launch.description = _description
        self.launch.action_title = _action_title
        self.launch.device = _device
        self.version = _version
        self.launch.action = _action
        self.launch.status = _status
        self.launch.save()
예제 #10
0
    def save(self):
        _name = self.cleaned_data.get('name')
        _alias = self.cleaned_data.get('alias')
        _national = self.cleaned_data.get('national')
        _company = self.cleaned_data.get('company')
        _website = self.cleaned_data.get('website')
        _tmall_link = self.cleaned_data.get('tmall_link')
        _intro = self.cleaned_data.get('intro')
        _icon_file = self.cleaned_data.get('icon')
        _status = self.cleaned_data.get('status')
        _score = self.cleaned_data.get('score')

        brand = Brand()
        brand.name = _name
        brand.alias = _alias
        brand.national = _national
        brand.company = _company
        brand.website = _website
        brand.tmall_link = _tmall_link
        brand.score = _score

        if _intro:
            brand.intro = _intro

        if _icon_file:
            _image = HandleImage(_icon_file)
            file_path = "%s%s.jpg" % (image_path, _image.name)
            default_storage.save(file_path, ContentFile(_image.image_data))
            # self.banner.image = file_path
            brand.icon = file_path
        # brand.intro = _intro

        brand.status = _status
        brand.save()
        return brand
예제 #11
0
    def save(self):
        content_type = self.cleaned_data.get('content_type')
        key = self.cleaned_data.get('key')
        banner_image = self.cleaned_data.get('banner_image')
        position = self.clean_position()

        # log.info(banner_image)
        _image = HandleImage(banner_image)
        file_path = "%s%s.jpg" % (image_path, _image.name)
        default_storage.save(file_path, ContentFile(_image.image_data))

        banner = Banner.objects.create(
            content_type=content_type,
            image=file_path,
            key=key,
            position=position,
        )

        if position > 0:
            try:
                show = Show_Banner.objects.get(pk=position)
                show.banner = banner
                show.save()
            except Show_Banner.DoesNotExist:
                Show_Banner.objects.create(
                    id=position,
                    banner=banner,
                )

        return banner
예제 #12
0
    def save(self):
        _name = self.cleaned_data.get('name')
        _alias = self.cleaned_data.get('alias')
        _national = self.cleaned_data.get('national')
        _company = self.cleaned_data.get('company')
        _website = self.cleaned_data.get('website')
        _tmall_link = self.cleaned_data.get('tmall_link')
        _intro = self.cleaned_data.get('intro')
        _icon_file = self.cleaned_data.get('icon')
        _status = self.cleaned_data.get('status')
        _score = self.cleaned_data.get('score')

        self.brand_cache.name = _name
        self.brand_cache.alias = _alias
        self.brand_cache.national = _national
        self.brand_cache.company = _company
        self.brand_cache.website = _website
        self.brand_cache.tmall_link = _tmall_link
        self.brand_cache.status = _status
        self.brand_cache.score = _score

        if _intro:
            self.brand_cache.intro = _intro

        if _icon_file:
            _image = HandleImage(_icon_file)
            file_path = "%s%s.jpg" % (image_path, _image.name)
            default_storage.save(file_path, ContentFile(_image.image_data))
            # self.banner.image = file_path
            self.brand_cache.icon = file_path

        self.brand_cache.save()

        return self.brand_cache
예제 #13
0
    def save(self):
        _title = self.cleaned_data.get('title')
        _status = self.cleaned_data.get('status')
        _cover = self.cleaned_data.get('cover')
        # _status = int(_status)
        category = Category(
            title = _title,
            status = _status,
        )

        if _cover:
            # log.info("icon %s" % _cover)
            image_file = HandleImage(_cover)
            cover_file = image_file.save(path=image_path)
            category.cover = cover_file
        category.save()
        return category
예제 #14
0
    def save(self):
        _title = self.cleaned_data.get('title')
        _category = self.cleaned_data.get('category')
        _icon = self.cleaned_data.get('icon')

        _status = self.cleaned_data.get('status')
        _status = int(_status)

        if _icon:
            log.info("icon %s" % _icon)
            image_file = HandleImage(_icon)
            icon_file = image_file.icon_save(path=image_path)
            self.sub_category.icon = icon_file

        self.sub_category.title = _title
        self.sub_category.group_id = _category
        self.sub_category.status = _status
        self.sub_category.save()
예제 #15
0
    def save(self):
        link = self.cleaned_data.get('link')
        editor_recommend_image = self.cleaned_data.get(
            'editor_recommend_image')
        event = self.cleaned_data.get('event')
        section = self.cleaned_data.get('section')
        # position = self.clean_position()
        # log.info(event_banner_image)
        _image = HandleImage(editor_recommend_image)
        filename = _image.save()
        # file_path = "%s%s.jpg" % (image_path, _image.name)
        # default_storage.save(file_path, ContentFile(_image.image_data))
        # log.info(f)
        #
        _recommendation = Editor_Recommendation.objects.create(
            link=link,
            image=filename,
        )

        #
        # if position > 0:
        #     show_list = Show_Editor_Recommendation.objects.filter(event_id = event, position = position)
        #
        #     show_list.update(position = 0)
        #     try:
        #         show = Show_Editor_Recommendation.objects.get(position = position)
        #         show.recommendation = _recommendation
        #         show.save()
        #     except Show_Editor_Recommendation.DoesNotExist:
        #         Show_Editor_Recommendation.objects.create(
        #             recommendation =_recommendation
        #         )

        if event:
            try:
                show = Show_Editor_Recommendation.objects.get(
                    recommendation=_recommendation)
                show.event_id = event
                show.save()
            except Show_Editor_Recommendation.DoesNotExist, e:
                Show_Editor_Recommendation.objects.create(
                    recommendation=_recommendation,
                    event_id=event,
                    section=section)
예제 #16
0
def fetch_image(images, entity_id, *args, **kwargs):
    image_list = list()
    for image_url in images:
        if 'http' not in image_url:
            image_url = 'http:' + image_url
        if image_host in image_url:
            image_list.append(image_url)
            continue

        r = requests.get(image_url, stream=True)
        image = HandleImage(r.raw)
        image_name = image.save()
        image_list.append("%s%s" % (image_host, image_name))
    try:
        entity = Entity.objects.get(pk=entity_id)
        entity.images = image_list
        entity.save()
    except Entity.DoesNotExist, e:
        pass
예제 #17
0
 def save(self, commit=True):
     cover_image = self.cleaned_data.get('cover_image')
     if self.instance.pk is None or self.instance.cover_image != cover_image:
         _image = HandleImage(cover_image)
         file_path = "%s%s.jpg" % (image_path, _image.name)
         self.instance.cover_image = file_path
         default_storage.save(file_path, ContentFile(_image.image_data))
     if self.has_changed():
         self.instance.status = EDM.waiting_for_sd_verify
     return super(EDMDetailForm, self).save()
예제 #18
0
    def save(self, user):
        _avatar_file = self.cleaned_data.get('avatar')
        _bio = self.cleaned_data.get('bio')
        _bio = clean_user_text(_bio)
        _gender = self.cleaned_data.get('gender')
        _location = self.cleaned_data.get('location')
        _city = self.cleaned_data.get('city')

        self.user = user
        if _avatar_file:
            _image = HandleImage(image_file=_avatar_file)
            _image.crop_square()
            avatar = _image.avatar_save(resize=True)
            self.user.profile.avatar = avatar

        self.user.profile.bio = _bio
        self.user.profile.gender = _gender
        self.user.profile.location = _location
        self.user.profile.city = _city
        self.user.profile.save()
예제 #19
0
    def save(self):

        _title = self.cleaned_data.get('title')
        _status = self.cleaned_data.get('status')
        _cover = self.cleaned_data.get('cover')
        # _status = int(_status)
        # print _status

        self.category_cache.title = _title
        self.category_cache.status = _status

        if _cover:
            log.info("icon %s" % _cover)
            image_file = HandleImage(_cover)
            cover_file = image_file.save(path=image_path)
            self.category_cache.cover = cover_file

        self.category_cache.save()

        return self.category_cache
예제 #20
0
    def save(self):
        _title = self.cleaned_data.get('title')
        _category = self.cleaned_data.get('category')
        _icon = self.cleaned_data.get('icon')

        _status = self.cleaned_data.get('status')
        _status = int(_status)

        sub_category = Sub_Category(
            title = _title,
            group_id = _category,
            status = _status,
        )

        if _icon:
            image_file = HandleImage(_icon)
            icon_file = image_file.icon_save(path=image_path)
            sub_category.icon = icon_file

        sub_category.save()
        return sub_category
예제 #21
0
    def save(self):
        self.api_key = self.cleaned_data.get('api_key')
        _nickname = self.cleaned_data.get('nickname')
        _email = self.cleaned_data.get('email')
        _password = self.cleaned_data.get('password')

        _taobao_id = self.cleaned_data.get('taobao_id')
        _taobao_token = self.cleaned_data.get('taobao_token')
        _screen_name = self.cleaned_data.get('screen_name')
        # _api_key = self.cleaned_data.get('api_key')

        self.user_cache = GKUser.objects.create_user(
            email=_email,
            password=_password,
            is_active=GKUser.active,
        )

        User_Profile.objects.create(
            user=self.user_cache,
            nickname=_nickname,
        )

        _avatar_file = self.cleaned_data.get('image')
        if _avatar_file:
            _image = HandleImage(image_file=_avatar_file)
            avatar_path_name = _image.avatar_save()

            self.user_cache.profile.avatar = avatar_path_name

            self.user_cache.profile.save()
        update_token.delay(user_id=self.user_cache.id,
                           taobao_id=_taobao_id,
                           screen_name=_screen_name,
                           access_token=_taobao_token,
                           expires_in=7200)

        return self.user_cache
예제 #22
0
    def save(self):
        _image = self.cleaned_data.get('image')
        _nickname = self.cleaned_data.get('nickname')
        _email = self.cleaned_data.get('email')
        _password = self.cleaned_data.get('password')
        # print _nickname
        if _image:
            avatar_file = HandleImage(_image)

            self.user_cache.profile.avatar = avatar_file.avatar_save()

        if _nickname:
            self.user_cache.profile.nickname = _nickname

        if _email:
            self.user_cache.email = _email
            self.user_cache.save()

        if _password:
            self.user_cache.set_password(_password)
            self.user_cache.save()

        self.user_cache.profile.save()
        return self.user_cache.v3_toDict()
예제 #23
0
def resize(image_name, size=None, **kwargs):
    # print image_name
    url = intranet_image_server + image_name
    r = requests.get(url)
    if r.status_code == 404:
        return None
    # f = default_storage.open(image_name)
    f = StringIO(r.content)

    try:
        if size is not None:
            image = HandleImage(f)
            _size = float(size)
            # logger.info(image.content_type)
            # print image
            image.resize(_size, _size)
            image_data = image.image_data
        else:
            image_data = f.read()
    except AttributeError:
        logger.error("Error: %s" % image_name)
        return None

    return image_data
예제 #24
0
    def save(self):
        event_banner_image = self.cleaned_data.get('event_banner_image')
        link = self.cleaned_data.get('link')
        user_id = self.cleaned_data.get('user_id')
        banner_type = self.cleaned_data.get('banner_type')
        position = self.clean_position()
        event = self.cleaned_data.get('event')
        event_banner_background_image = self.cleaned_data.get('event_banner_background_image')
        event_banner_background_color = self.cleaned_data.get('event_banner_background_color')


        # log.info(position)
        self.banner.link = link
        # self.banner.position = position
        self.banner.user_id = user_id
        self.banner.banner_type = banner_type

        if event_banner_background_image:
            _background_image = HandleImage(event_banner_background_image)
            self.banner.background_image = _background_image.save()

        self.banner.background_color = event_banner_background_color

        if event_banner_image:
            _image = HandleImage(event_banner_image)
            # file_path = "%s%s.jpg" % (image_path, _image.name)
            # filename = default_storage.save(file_path, ContentFile(_image.image_data))
            self.banner.image = _image.save()

        self.banner.save()

        if event:
            try:
                show = Show_Event_Banner.objects.get(banner = self.banner)
                show.event_id = event
                show.save()
            except Show_Event_Banner.DoesNotExist:
                Show_Event_Banner.objects.create(
                    banner = self.banner,
                    event_id = event,
                )

        if position > 0 and self.banner.position == 0:
            show = Show_Event_Banner.objects.get(banner= self.banner)
            # show.banner = self.banner
            show.position = position
            show.save()
예제 #25
0
 def save(self):
     _image = self.cleaned_data.get('launchImage')
     _title = self.cleaned_data.get('title')
     _description = self.cleaned_data.get('description')
     _device = self.cleaned_data.get('device')
     _version = self.cleaned_data.get('version')
     _action_title = self.cleaned_data.get('action_title')
     _action = self.cleaned_data.get('action')
     _status = self.cleaned_data.get('status')
     # print _image
     launch_image = HandleImage(_image)
     image_name = image_path + "%s.jpg" % launch_image.name
     default_storage.save(image_name, ContentFile(launch_image.image_data))
     launch = LaunchBoard()
     launch.launchImage = image_name
     launch.title = _title
     launch.description = _description
     launch.device = _device
     launch.version = _version
     launch.action_title = _action_title
     launch.action = _action
     launch.status = _status
     launch.save()
예제 #26
0
    def save(self):
        banner_image = self.cleaned_data.get('banner_image')
        position = self.clean_position()
        content_type = self.cleaned_data.get('content_type')
        key = self.cleaned_data.get('key')

        self.banner.key = key
        self.banner.content_type = content_type
        # self.banner.save()

        if banner_image:
            _image = HandleImage(banner_image)
            file_path = "%s%s.jpg" % (image_path, _image.name)
            default_storage.save(file_path, ContentFile(_image.image_data))
            self.banner.image = file_path
        self.banner.save()

        if position > 0 and self.banner.position == 0:
            try:
                show = Show_Banner.objects.get(pk=position)
                show.banner = self.banner
                show.save()
            except Show_Banner.DoesNotExist:
                Show_Banner.objects.create(
                    id=position,
                    banner=self.banner,
                )
        elif self.banner.position != position:
            show = Show_Banner.objects.get(pk=position)
            tmp_show = Show_Banner.objects.get(pk=self.banner.position)
            tmp_banner = show.banner
            show.banner = self.banner
            tmp_show.banner = tmp_banner
            show.save()
            tmp_show.save()

        return self.banner
예제 #27
0
    def save(self):
        link = self.cleaned_data.get('link')
        event_banner_image = self.cleaned_data.get('event_banner_image')
        event_banner_background_image = self.cleaned_data.get('event_banner_background_image',None)
        event_banner_background_color = self.cleaned_data.get('event_banner_background_color','fff')
        position = self.cleaned_data.get('position')
        banner_type = self.cleaned_data.get('banner_type')
        user_id = self.cleaned_data.get('user_id')


        # log.info(event_banner_image)
        _image = HandleImage(event_banner_image)
        # file_path = "%s%s.jpg" % (image_path, _image.name)
        # default_storage.save(file_path, ContentFile(_image.image_data))
        # log.info(f)
        #
        filename = _image.save()
        _background_image_file_name = None
        if event_banner_background_image:
            _background_image = HandleImage(event_banner_background_image)
            _background_image_file_name = _background_image.save()


        _event_banner = Event_Banner.objects.create(
            link = link,
            image = filename,
            banner_type = banner_type,
            user_id = user_id,
            background_image = _background_image_file_name,
            background_color = event_banner_background_color
        )
        #
        # if position > 0:
        #     try:
        #         show = Show_Event_Banner.objects.get(pk = position)
        #         show.banner = _event_banner
        #         show.save()
        #     except Show_Event_Banner.DoesNotExist:
        #         Show_Event_Banner.objects.create(
        #             banner = _event_banner
        #         )
        return _event_banner
예제 #28
0
 def handle_post_image_by_name(self, image_name):
     _image = HandleImage(image_file=self.cleaned_data.get(image_name))
     _image_path = _image.icon_save()
     return _image_path
예제 #29
0
 def _handle_post_image(self, form_field_name):
     _image = HandleImage(image_file=self.cleaned_data.get(form_field_name))
     _image_path = _image.icon_save()
     return _image_path