def get(self): counter = 0 letter_bag = Letter.gql("limit 10") if letter_bag.count(1): for letter in letter_bag: rcp = letter.to sender_email = DBCustomField().getByName('email') # нужен такой цикл, тк фор тупит при добавлении элементов while len(rcp) > 0: #for r in rcp: self.send_letter( DBUser.get(rcp[0]).email, letter.subject, letter.body, sender_email) # rcp.remove(r) rcp.pop(0) counter += 1 print counter if counter == self._step: break if len(rcp) > 0: letter.to = rcp letter.put() else: db.delete(letter)
def __send_mail(self, recipient_login, recipient_email, owner_login, owner_name, content = ""): #try: urls = DBCustomField.gql("where type=3") our_url = urls[0].value.encode("utf8") emails = DBCustomField.gql("where type=2") our_email = emails[0].value.encode("utf8") subject = "[" + DBCustomField().getByName("name") + "] Личное сообщение" body = """Здравствуйте, """+str(recipient_login)+"""! \nВам личное сообщение! Прочитать можно на странице личных сообщений по адресу """+our_url+"""/msg/ \n""" + self._del_tags(content).encode("utf8") # if DBCustomField().getByName("mail_type") == "html": ## html = content + unicode("""<p>_______<br/>От: <a href='http://www.runiver.net/users/""", 'utf_8') + str(owner_login) + "'>" + owner_name.encode("utf8") + unicode("""</a></p><p>не отвечайте на это сообщение<br/>ответить можно на сервере: """, "utf_8") + our_url + "/msg/</p>" # mail.send_mail(sender=our_email, to=str(recipient_email), subject = subject, body = body)#, html = html) # else: #mail.send_mail(sender=our_email, to=str(recipient_email), subject = subject, body = body) po = PostOffice() po.append_to_queue(recipient_email, subject, body) return True
def __init__(self, *args, **kwargs): self._child_get = self.get self.get = self._get_request_time self._child_post = self.post self.post = self._post try: tpls = DBCustomField.gql("where type=4") self.__TemplatePath = tpls[0].value.encode("utf8") except: self.__TemplatePath = 'templates/'
def get(self): if not super(Customizer, self).get(): return param_set = self.param_set for param in param_set.values(): try: rows = DBCustomField.gql("where type=:type", type=param["type"]) param["value"] = (rows[0].value).encode("utf-8") except: #self.insertContent("<br/>type: " + param["type"]) pass tpl_cust = template.Template(""" <form method="post" action=""> <table> {% for param in params %} <tr> <td> {{param.caption}} </td> <td> {% if param.txt_long %} <textarea name="{{param.name}}">{{param.value}}</textarea> {% else %} <input type="text" name="{{param.name}}" size="40" value='{{param.value}}'> {% endif %} </td> </tr> {% endfor %} <tr> <td> </td> <td> <input type="submit" value='Сохранить'> </td> </tr> </table> <form> """) for param in param_set.values(): if "txt_long" not in param: param["txt_long"] = True if len( param["value"]) > 100 else False out = tpl_cust.render(template.Context({"params": param_set.values()})) self.insertContent(out) self.drawPage()
def get(self): if not super(Customizer, self).get(): return param_set = self.param_set for param in param_set.values(): try: rows = DBCustomField.gql("where type=:type", type = param["type"]) param["value"] = (rows[0].value).encode("utf-8") except: #self.insertContent("<br/>type: " + param["type"]) pass tpl_cust = template.Template (""" <form method="post" action=""> <table> {% for param in params %} <tr> <td> {{param.caption}} </td> <td> {% if param.txt_long %} <textarea name="{{param.name}}">{{param.value}}</textarea> {% else %} <input type="text" name="{{param.name}}" size="40" value='{{param.value}}'> {% endif %} </td> </tr> {% endfor %} <tr> <td> </td> <td> <input type="submit" value='Сохранить'> </td> </tr> </table> <form> """) for param in param_set.values(): if "txt_long" not in param: param["txt_long"] = True if len(param["value"]) > 100 else False out = tpl_cust.render(template.Context({"params":param_set.values()})) self.insertContent(out) self.drawPage()
def post(self): if not super(Customizer, self).get(): return for param in self.param_set.values(): param["value"] = self.request.get(param["name"]) try: rows = DBCustomField.gql("where type=:type", type=param["type"]) row = rows[0] row.value = param["value"] row.name = param["name"] row.put() except: row = DBCustomField() row.type = param["type"] row.value = param["value"] row.name = param["name"] row.put() self.insertContent("Сохранено") self.drawPage()
class WaterMark(): __watermark_addr = DBCustomField().getByName("url_watermark") #"http://7.latest.ru-dev.appspot.com/images/watermark.png" def insert(self, image_data): """Stable on appspot, not local""" """Hm, unstable everywhere""" image = images.Image(image_data) result = urlfetch.Fetch(self.__watermark_addr) watermark = images.Image(result.content) if watermark.width > image.width: watermark.resize(image.width) watermark.execute_transforms(images.JPEG) watermarked_image = images.composite( [ (image_data, 0, 0, 1.0, images.TOP_LEFT), (watermark._image_data, 0, 0, 0.5, images.BOTTOM_CENTER) ], image.width, image.height, 0, images.JPEG) return watermarked_image
def post(self): if super(CommentHandler, self).get(): if not self.request.get("content"): self.showMessage("""Введите текст комментария! <br><a href='""" + self.request.headers.get("Referer") + """'>Вернуться в тему</a>""") return comment = DBComments() user = DBUser.get_by_id(self.Session['userid']) comment.user = user if user.comments_count: user.comments_count = user.comments_count + 1 user.put() comment.obj = db.Key(str(self.request.get('entity'))) content = self.request.get("content") comment.content = cgi.escape(content).replace("\n", "<br />") comment.parent_comment = DBComments().get(self.request.get('parent_comment')) if \ self.request.get('parent_comment') else None # Old part with id #DBComments().get_by_id(int(self.request.get('parent_comment'))) if \ # self.request.get('parent_comment') else None key_ = comment.put() comment = db.get(key_) try: comment.obj.increase_comments_count(comment) except: pass #Отсылаем владельцу топика if self.Session['user_key'] != comment.obj.author.key(): body = template.render( "comments/comment_notification.html", { 'user': self.Session, 'comment': comment, 'referer': self.request.headers.get("Referer"), 'site_url': DBCustomField().getByName('url') }) PostOffice().append_to_queue( comment.obj.author.key(), """Новый комментарий на портале Архимир""".decode("utf-8"), body.decode("utf-8")) #Отсылаем владельцу коммента-предка: if comment.parent_comment and \ (self.Session['user_key'] != comment.parent_comment.user.key()) and \ (comment.obj.author.key() != comment.parent_comment.user.key()): body = template.render( "comments/comment_notification.html", { 'to_parent': True, 'user': self.Session, 'comment': comment, 'referer': self.request.headers.get("Referer"), 'site_url': DBCustomField().getByName('url') }) PostOffice().append_to_queue( comment.parent_comment.user.key(), """Новый комментарий на портале Архимир""".decode("utf-8"), body.decode("utf-8")) self.redirect(self.request.headers.get("Referer"))
class Customizer(OutputClass): """ this allows to customize site """ url_handler = '/customize/?' access = 10 param_set = DBCustomField().param_set def get(self): if not super(Customizer, self).get(): return param_set = self.param_set for param in param_set.values(): try: rows = DBCustomField.gql("where type=:type", type=param["type"]) param["value"] = (rows[0].value).encode("utf-8") except: #self.insertContent("<br/>type: " + param["type"]) pass tpl_cust = template.Template(""" <form method="post" action=""> <table> {% for param in params %} <tr> <td> {{param.caption}} </td> <td> {% if param.txt_long %} <textarea name="{{param.name}}">{{param.value}}</textarea> {% else %} <input type="text" name="{{param.name}}" size="40" value='{{param.value}}'> {% endif %} </td> </tr> {% endfor %} <tr> <td> </td> <td> <input type="submit" value='Сохранить'> </td> </tr> </table> <form> """) for param in param_set.values(): if "txt_long" not in param: param["txt_long"] = True if len( param["value"]) > 100 else False out = tpl_cust.render(template.Context({"params": param_set.values()})) self.insertContent(out) self.drawPage() def post(self): if not super(Customizer, self).get(): return for param in self.param_set.values(): param["value"] = self.request.get(param["name"]) try: rows = DBCustomField.gql("where type=:type", type=param["type"]) row = rows[0] row.value = param["value"] row.name = param["name"] row.put() except: row = DBCustomField() row.type = param["type"] row.value = param["value"] row.name = param["name"] row.put() self.insertContent("Сохранено") self.drawPage()
def paramByName(self, name): return DBCustomField().getByName(name)