def delete_image(request): locstore_key = request.values.get('locstore_key', None) image_key = request.values.get('image_key', None) locstore = None if locstore_key: locstore = memcache.get('get_locstore_%s' % locstore_key) if not locstore: locstore = LocStore.get(locstore_key) if locstore is None: return redirect('/admin/locstore/list/') img = ThumbImage.get(image_key) if img is None: locstore.images.remove(image_key) locstore.put() memcache.set('get_locstore_%s' % locstore.key(), locstore, MEMCACHE_TIMEOUT) return redirect('/admin/locstore/edit/%s/' % locstore.key()) locstore.images.remove(image_key) if locstore.main_image == image_key: if len(locstore.images): locstore.main_image=locstore.images[0] else: locstore.main_image = '' img.delete() if not len(locstore.images): locstore.main_image = '' locstore.put() memcache.set('get_locstore_%s' % locstore.key(), locstore, MEMCACHE_TIMEOUT) return redirect('/admin/locstore/edit/%s/' % locstore.key())
def internal_thumb_image(value, size="700x700"): if value is None: return '' thumb = ThumbImage.get(value) if thumb: try: att = getattr(thumb, "thumb_%s" % size) except AttributeError: return '' return Image.get(att).image return ''
def get_img_url(key): img = ThumbImage.get(key) img_url = '' if img: try: att = getattr(img, "thumb_700x700") i = Image.get(att) img_url = i.get_link() except AttributeError: img_url = '' if img_url: return 'www.5studio.ru%s' % img_url return ''
def get_mini_main_thumb_url(gift): thumb_url = '' if gift.main_thumb: thumb = ThumbImage.get(gift.main_thumb) if thumb: try: att = getattr(thumb, "thumb_100x100") i = Image.get(att) thumb_url = i.get_link() except AttributeError: pass if thumb_url: return 'www.5studio.ru%s' % thumb_url return ''
def get_thumb_url(key, thumb_size = "400x400"): thumb_size_ = "thumb_%s" % thumb_size thumb = ThumbImage.get(key) thumb_url = '' if thumb: try: att = getattr(thumb, thumb_size_) i = Image.get(att) thumb_url = i.get_link() except AttributeError: thumb_url = '' if thumb_url: return 'www.5studio.ru%s' % thumb_url return ''
def get_main_img_url(gift): img_url = '' if gift.main_thumb: img = ThumbImage.get(gift.main_thumb) if img: try: att = getattr(img, "thumb_700x700") i = Image.get(att) img_url = i.get_link() except AttributeError: pass if img_url: return 'www.5studio.ru%s' % img_url return ''
def send_newsletter_task(request, user_key, newsletter_key): newsletter = Newsletter.get(newsletter_key) managers = [] message = mail.EmailMessage(sender=settings.DEFAULT_MAIL_FROM, subject=newsletter.title) user = UserProfile.get(user_key) message.to = user.email if not message.to: return Response("Ok") gifts = [] gifts_images = {} if newsletter.gifts: gifts_split = newsletter.gifts.split(",") for gift in gifts_split: try: gift = gift.strip() obj = Gift.all().filter("uid =", gift).get() if obj: gifts.append(obj) if obj.main_thumb: try: img = ThumbImage.get(obj.main_thumb) img = Image.get(img.thumb_200x200) if img: gifts_images[obj.uid] = base64.b64encode(str(img.image)) except Exception: pass except Exception: pass message_text = render_to_string( "postman/send_newsletter.html", {"newsletter": newsletter, "gifts": gifts, "managers": managers, "gifts_images": gifts_images}, ) message.html = message_text attachments = [] for file_key in newsletter.n_price_list: file_ = File.get(file_key) if file_ and file_.blob_key: bi = blobstore.BlobInfo.get(file_.blob_key) if bi: attachments.append(("%s" % file_.title_filename, bi.open().read())) message.attachments = attachments message.send() return Response("OK")
def url_thumb(environment, value, size="700x700"): if value is None: return '' thumb = memcache.get(value) if thumb is None: thumb = ThumbImage.get(value) if thumb: memcache.add(value, thumb, 7200) if thumb: try: att_name = value + "thumb_%s" % size att = memcache.get(att_name) if att is None: att = getattr(thumb, "thumb_%s" % size) memcache.add(att_name, att, 7200) except AttributeError: return '' return link(environment, att) return ''
def thumb_image(environment, value, size="200x200", prefix=''): if value is None: return '' thumb = memcache.get(value) if thumb is None: thumb = ThumbImage.get(value) if thumb: memcache.add(value, thumb, 7200) if thumb: try: att_name = value + "thumb_%s" % size att = memcache.get(att_name) if att is None: att = getattr(thumb, "thumb_%s" % size) memcache.add(att_name, att, 7200) except AttributeError: return '' return img_tag(environment, att, prefix) return ''
def change_main_thumb(request): gift_key = request.values.get('gift_key') thumb_key = request.values.get('thumb_key') gift = Gift.get(gift_key) if gift is None: return redirect('/') thumb = ThumbImage.get(thumb_key) if thumb is None: gift.thumbs.remove(thumb_key) gift.put() get_gift(gift.uid, True) return redirect('/g/%s' % gift.uid) if gift.main_thumb == thumb_key: return redirect('/g/%s' % gift.uid) else: gift.main_thumb = thumb_key gift.put() get_gift(gift.uid, True) return redirect('/g/%s' % gift.uid)
def delete_thumb(request): gift_key = request.values.get('gift_key') thumb_key = request.values.get('thumb_key') gift = Gift.get(gift_key) if gift is None: return redirect('/') thumb = ThumbImage.get(thumb_key) if thumb is None: gift.thumbs.remove(thumb_key) gift.put() get_gift(gift.uid, True) return redirect('/g/%s' % gift.uid) if gift.main_thumb == thumb_key: gift.main_thumb = None gift.thumbs.remove(thumb_key) thumb.delete() if not len(gift.thumbs): gift.main_thumb = '' gift.put() get_gift(gift.uid, True) return redirect('/g/%s' % gift.uid)
def add_manager_photo(request): if request.method == 'POST': manager_key = request.values.get('manager_key') manager = Manager.get(manager_key) if manager is None: return redirect('/admin/managers') new_th_form = ManagerPhoto() if request.form and new_th_form.validate(request.form, request.files): if manager.photo: thumb = ThumbImage.get(manager.photo) thumb.delete() manager.photo = None thumb = new_th_form['img'] content_type = 'image/jpeg' thumb_img = ThumbImage() thumb_img.add_new_thumb(blob_img=thumb, thumb_size=(200, 200,), content_type=content_type) thumb_img.add_new_thumb(blob_img=thumb, thumb_size=(100, 100,), content_type=content_type) thumb_img.put() manager.photo = str(thumb_img.key()) manager.put() return redirect('/admin/edit_manager/%s' % manager.key()) return redirect('/admin/managers')
def change_main_image(request): locstore_key = request.values.get('locstore_key', None) image_key = request.values.get('image_key', None) locstore = None if locstore_key: locstore = memcache.get('get_locstore_%s' % locstore_key) if not locstore: locstore = LocStore.get(locstore_key) if locstore is None: return redirect('/admin/locstore/list/') thumb = ThumbImage.get(image_key) if thumb is None: locstore.images.remove(image_key) locstore.put() memcache.set('get_locstore_%s' % locstore.key(), locstore, MEMCACHE_TIMEOUT) return redirect('/admin/locstore/edit/%s/' % locstore.key()) if locstore.main_image == image_key: return redirect('/admin/locstore/edit/%s/' % locstore.key()) else: locstore.main_image = image_key locstore.put() memcache.set('get_locstore_%s' % locstore.key(), locstore, MEMCACHE_TIMEOUT) return redirect('/admin/locstore/edit/%s/' % locstore.key())
def write_category(wb, category, all=False): if category.gifts: ws = wb.add_sheet(category.name) if all: gifts = category.gifts else: gifts = category.gifts.filter('in_trash =', False).filter('leftovers >', 0) write_head(ws) for i, g in enumerate(gifts): url = 'http://www.5studio.ru/g/%s/' % g.uid ws.write(i + 1, 0, xlwt.Formula('HYPERLINK("%s")' % url)) if g.main_thumb: img = ThumbImage.get(g.main_thumb) if img and getattr(img, 'thumb_100x100'): img = "http://www.5studio.ru%s" % Image.get(img.thumb_100x100).get_link() ws.write(i + 1, 1, xlwt.Formula('HYPERLINK("%s")' % img)) ws.write(i + 1, 2, g.catalogue_id) ws.write(i + 1, 3, g.barcode) ws.write(i + 1, 4, g.name) ws.write(i + 1, 5, g.category.name) ws.write(i + 1, 6, g.group.name) ws.write(i + 1, 7, g.brand) ws.write(i + 1, 8, g.price) ws.write(i + 1, 9, g.real_price)
def send_newsletter_task2(request, email, newsletter_key_id): newsletter = Newsletter2.get_by_id(newsletter_key_id) managers = [] for mgr_id in newsletter.managers: mgr = Manager.get_by_id(mgr_id) if mgr: managers.append(mgr) message = mail.EmailMessage(sender=settings.DEFAULT_MAIL_FROM, subject=newsletter.title) message.to = email if not message.to: return Response("Ok") mangers_emails = [manager.email for manager in managers] if mangers_emails: message.reply_to = ",".join(mangers_emails) gifts = [] gifts_images = {} if newsletter.gifts: gifts_split = newsletter.gifts.split(",") for gift in gifts_split: try: gift = gift.strip() obj = Gift.all().filter("uid =", gift).get() if obj: gifts.append(obj) if obj.main_thumb: try: img = ThumbImage.get(obj.main_thumb) img = Image.get(img.thumb_200x200) if img: gifts_images[obj.uid] = base64.b64encode(str(img.image)) except Exception: pass except Exception: pass message_text = render_to_string( "postman/send_newsletter2.html", {"newsletter": newsletter, "gifts": gifts, "managers": managers, "gifts_images": gifts_images}, ) message.html = message_text attachments = [] for file_key in newsletter.n_price_list: file_ = File.get(file_key) if file_ and file_.blob_key: bi = blobstore.BlobInfo.get(file_.blob_key) if bi: attachments.append(("%s" % file_.title_filename, bi.open().read())) if attachments: message.attachments = attachments try: message.send() except apiproxy_errors.OverQuotaError: def txn(): taskqueue.add( url=url_for("postman/send_newsletter_task2", email=email, newsletter_key_id=newsletter_key_id), transactional=True, ) db.run_in_transaction(txn) return Response("OK")
def delete(self, **kwargs): if self.photo: thumb = ThumbImage.get(self.photo) if thumb: thumb.delete() super(Manager, self).delete(**kwargs)
def fill_obj(obj, fred_path): if not obj or not obj.catalogue_id: return False title = obj.name.replace('"', '"') cat_path = os.path.join(fred_path, obj.catalogue_id) if not os.path.exists(cat_path): return False file_names = os.listdir(cat_path) if file_names: for i in obj.thumbs: thumb = ThumbImage.get(i) if thumb: thumb.delete() obj.thumbs = [] else: return file_names.sort() first = None for fn in file_names: if fn[0] == '_': first = fn file_names.remove(fn) break if first is not None: try: full_file_name = os.path.join(cat_path, first) img_700 = pilImage.open(full_file_name) content_type = 'image/jpeg' buf = StringIO.StringIO() img_700.save(buf, format=CONVERT_RULES_PIL[content_type][2]) img_700 = buf.getvalue() thumb_img = ThumbImage() thumb_img.add_new_thumb(blob_img=img_700, thumb_size=(700, 700, ), is_using_pil=True, title=title, content_type=content_type) thumb_img.add_new_thumb(blob_img=img_700, thumb_size=(400, 400, ), is_using_pil=True, title=title, content_type=content_type) thumb_img.add_new_thumb(blob_img=img_700, thumb_size=(200, 200, ), is_using_pil=True, title=title, content_type=content_type) thumb_img.add_new_thumb(blob_img=img_700, thumb_size=(100, 100, ), is_using_pil=True, title=title, content_type=content_type) thumb_img.put() obj.thumbs.append(str(thumb_img.key())) obj.main_thumb = str(thumb_img.key()) except Exception, ex: print obj.catalogue_id print ex
def delete(self, **kwargs): for i in self.thumbs: thumb = ThumbImage.get(i) if thumb: thumb.delete() super(Gift, self).delete(**kwargs)