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
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")
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')
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)
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)
def index(self): """Handle the 'mailinglist' page.""" recents = DBSession.query(MailMessage).order_by(MailMessage.date.desc()).limit(5) return dict(page='mailinglist', recents=recents)
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)
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
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)
def children(self): return DBSession.query(MailMessage).filter( MailMessage.parent_message_id == self.message_id).all()
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
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
def user(self): return DBSession.query(User)\ .filter(User.user_name == self.mines_username)\ .one_or_none()
def prev_by_date(self): return DBSession.query(MailMessage)\ .filter(MailMessage.date < self.date)\ .order_by(MailMessage.date.desc())\ .first()
def next_by_date(self): return DBSession.query(MailMessage)\ .filter(MailMessage.date > self.date)\ .order_by(MailMessage.date)\ .first()
def archives(self): messages = DBSession.query(MailMessage).order_by(MailMessage.date.desc()) return dict(page='mailinglist', messages=messages)
def __init__(self): self.meetings = DBSession.query(Meeting).order_by(Meeting.date)
def latest_revision(slug): return (DBSession.query(WikiPage, func.max( WikiPage.revision)).filter(WikiPage.slug == slug).scalar())
def parent(self): return DBSession.query(MailMessage).filter( MailMessage.message_id == self.parent_message_id).one_or_none()