예제 #1
0
파일: user.py 프로젝트: edwargix/mozzarella
 def _lookup(self, uname, *args):
     user = DBSession.query(User) \
                     .filter(User.user_name == uname) \
                     .one_or_none()
     if not user:
         abort(404, "No such user")
     return UserController(user), args
예제 #2
0
def pmsync():
    log.info("Starting mail sync from pipermail")
    global completed_one
    session = requests.Session()
    pmurl = tg.config.get("mailman.pipermail.url")
    r = session.get(pmurl)
    r.raise_for_status()
    for m in archivefiles_p.finditer(r.text):
        name = m.group(1)
        log.info("Syncing archive {}...".format(name))
        ar = session.get(pmurl + "/" + name)
        lines = ar.text.splitlines()
        messages = []
        msglines = []
        for line, nextline in zip(lines, lines[1:] + ['']):
            m1 = fromline_p.match(line)
            m2 = fromline2_p.match(line)
            if line.startswith("From ") and nextline.startswith(
                    "From: ") and msglines:
                messages.append(parse_message('\n'.join(msglines)))
                msglines = []
            elif m1:
                msglines.append('From: "{}" <{}@{}>'.format(
                    m1.group(3), m1.group(1), m1.group(2)))
            elif m2:
                msglines.append('From: {}@{}'.format(m2.group(1), m2.group(2)))
            else:
                msglines.append(line)
        messages.append(parse_message('\n'.join(msglines)))
        for message in messages:
            if DBSession.query(MailMessage).filter(
                    MailMessage.message_id == message.get(
                        'message-id')).count():
                # this is already in our databases
                continue
            m = subject_p.match(message.get('subject', ''))
            subject = m.group(1)
            DBSession.add(
                MailMessage(message_id=message.get('message-id'),
                            from_=message.get('from'),
                            date=email.utils.parsedate_to_datetime(
                                message.get('date',
                                            '1 Jan 1970 00:00:00 -0000')),
                            subject=subject,
                            body=get_plaintext_body(message),
                            parent_message_id=message.get('in-reply-to')))
        DBSession.flush()
        if completed_one:
            transaction.commit()
            log.info(
                "Stopping sync for now as I think I have done everything else recently"
            )
            return
    completed_one = True
    transaction.commit()
    log.info("Complete sync finished")
예제 #3
0
    def attend(self):
        meeting = DBSession.query(Meeting)\
                           .join(Meeting.survey)\
                           .filter(
                               Survey.opens < datetime.datetime.now()
                           ).order_by(Meeting.date.desc()).first()

        if meeting and meeting.survey.active:
            redirect('s/{}/respond'.format(meeting.survey.id))
        else:
            abort(404, 'No active meeting')
예제 #4
0
 def index(self):
     """Handle the 'contact' page."""
     officer_sort = [
         "President", "Vice President", "Secretary", "Treasurer"
     ]
     users = DBSession.query(User)
     officers = []
     general = []
     for user in users:
         if user.officer_title:
             officers.append(user)
     officers.sort(key=lambda u: officer_sort.index(u.officer_title))
     return dict(page='contact', officers=officers, general=general)
예제 #5
0
 def message(self, message_id):
     msg = DBSession.query(MailMessage).filter(MailMessage.message_id == message_id).one_or_none()
     if not msg:
         abort(404, "No message with ID {}".format(message_id))
     return dict(page='mailinglist', message=msg)
예제 #6
0
 def index(self):
     """Handle the 'mailinglist' page."""
     recents = DBSession.query(MailMessage).order_by(MailMessage.date.desc()).limit(5)
     return dict(page='mailinglist', recents=recents)
예제 #7
0
 def index(self):
     """Handle the front-page."""
     meetings = DBSession.query(Meeting).filter(
         Meeting.date > datetime.datetime.now() -
         datetime.timedelta(hours=3)).order_by(Meeting.date).limit(2)
     return dict(page='index', meetings=meetings)
예제 #8
0
파일: wiki.py 프로젝트: edwargix/mozzarella
 def page_by_id(self, id, *args):
     page = DBSession.query(WikiPage).filter(
         WikiPage.id == id).one_or_none()
     if not page:
         abort(404)
     return WikiPageController(page), args
예제 #9
0
파일: wiki.py 프로젝트: edwargix/mozzarella
 def history(self):
     revisions = (DBSession.query(WikiPage).filter(
         WikiPage.slug == self.page.slug).order_by(
             WikiPage.revision.desc()).all())
     return dict(page='wiki', revisions=revisions)
예제 #10
0
 def children(self):
     return DBSession.query(MailMessage).filter(
         MailMessage.parent_message_id == self.message_id).all()
예제 #11
0
 def _lookup(self, mid, *args):
     meeting = DBSession.query(Meeting).filter(Meeting.id == mid).first()
     if not meeting:
         abort(404, "No such meeting")
     return MeetingController(meeting), args
예제 #12
0
 def _lookup(self, sid, *args):
     survey = DBSession.query(Survey).filter(Survey.id == sid).first()
     if not survey:
         abort(404, "No such survey")
     return SurveyController(survey), args
예제 #13
0
 def user(self):
     return DBSession.query(User)\
                     .filter(User.user_name == self.mines_username)\
                     .one_or_none()
예제 #14
0
 def prev_by_date(self):
     return DBSession.query(MailMessage)\
                     .filter(MailMessage.date < self.date)\
                     .order_by(MailMessage.date.desc())\
                     .first()
예제 #15
0
 def next_by_date(self):
     return DBSession.query(MailMessage)\
                     .filter(MailMessage.date > self.date)\
                     .order_by(MailMessage.date)\
                     .first()
예제 #16
0
 def archives(self):
     messages = DBSession.query(MailMessage).order_by(MailMessage.date.desc())
     return dict(page='mailinglist', messages=messages)
예제 #17
0
 def __init__(self):
     self.meetings = DBSession.query(Meeting).order_by(Meeting.date)
예제 #18
0
def latest_revision(slug):
    return (DBSession.query(WikiPage, func.max(
        WikiPage.revision)).filter(WikiPage.slug == slug).scalar())
예제 #19
0
 def parent(self):
     return DBSession.query(MailMessage).filter(
         MailMessage.message_id == self.parent_message_id).one_or_none()