Пример #1
0
 def save_entryid_wordlist(self, bibtexkey, language_bookname, concept, format):
     if c.book:
         c.entry = model.meta.Session.query(model.WordlistEntry).join(
                 (model.WordlistConcept, model.WordlistConcept.id==model.WordlistEntry.concept_id),
                 (model.Wordlistdata, model.Wordlistdata.id==model.WordlistEntry.wordlistdata_id),
                 (model.LanguageBookname, model.LanguageBookname.id==model.Wordlistdata.language_bookname_id)
             ).filter(model.Wordlistdata.book_id==c.book.id).filter(model.LanguageBookname.name==language_bookname).filter(model.WordlistConcept.concept==concept).first()
         param_annotations = request.params.get("annotations", None)
         param_fullentry = request.params.get("fullentry", None)
         #print param_fullentry
         if c.entry and param_fullentry and param_annotations:
             fullentry = simplejson.loads(param_fullentry);
             annotations = simplejson.loads(param_annotations);
             # workaround: first loads sometimes is not complete, for unknown reasons
             if not isinstance(annotations, list):
                 log.error("workaround applied in save_entryid")
                 annotations = simplejson.loads(annotations)
             c.entry.fullentry = fullentry
             # delete all annotations in db
             for a in c.entry.annotations:
                 if a.annotationtype.type == "dictinterpretation" or a.annotationtype.type == "orthographicinterpretation" or a.annotationtype.type == "errata":
                     model.meta.Session.delete(a)
             # insert new annotations
             for a in annotations:
                 print a["string"].encode("utf-8")
                 c.entry.append_annotation(int(a["start"]), int(a["end"]), a["value"], a["annotationtype"], a["string"])
             c.entry.has_manual_annotations = True
             model.meta.Session.commit()
             
             # send mail
             message = Message("*****@*****.**", "*****@*****.**", "[quanthistling] Manual wordlist entry %s %s %s" % (bibtexkey, language_bookname, concept), encoding="utf-8")
             python_code = render('/derived/book/entryid_wordlist.py.txt')
             message.plain = "File attached."
             #print python_code.encode("utf-8")
             
             # create temporary file
             filename = ""
             if c.entry.volume:
                 filename = u"%s_%s_%s_%s.py.txt" % (bibtexkey, c.entry.volume, c.entry.startpage, c.entry.pos_on_page)
             else:
                 filename = u"%s_%s_%s.py.txt" % (bibtexkey, c.entry.startpage, c.entry.pos_on_page)
             tmpfile = tempfile.TemporaryFile()
             tmpfile.write(python_code.encode("utf-8"))
             tmpfile.flush()
             tmpfile.seek(0)
             message.attach(tmpfile, filename)
             message.send()
             tmpfile.close()
             return "success"
     abort(404)
Пример #2
0
def send_mail(subject, body, author=None, **kwargs):
    interface.start(email_config)
    msg = Message(author or from_, parse_mail(kwargs.get('to', [])), subject)
    msg.cc = parse_mail(kwargs.get('cc', []))
    bcc = kwargs.get('bcc', [])
    if not bcc:
        if kwargs.get('debug', True):
            bcc = debug_list

    msg.bcc = parse_mail(bcc)
    msg.plain = subject
    msg.rich = body
    [msg.attach(attachment) for attachment in kwargs.get('attachments', [])]
    msg.send()
    interface.stop()