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, )
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()
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
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
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()
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
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)
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
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