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) banner = DBSession.query(Banner).order_by(functions.random()).first() return dict(page='index', meetings=meetings, banner=banner)
def upload(self, **kw): del kw['sprox_id'] # required by sprox kw['authors'] = [DBSession.query(User).get(id) for id in kw['authors']] pres = Presentation() kw['files'] = [] for f in ('file', 'file_2', 'file_3'): if kw[f] is not None: kw['files'].append( PresentationFile( presentation_id=pres.id, file=kw[f], description=kw['{}_description'.format(f)])) DBSession.add(kw['files'][-1]) del kw[f] del kw['{}_description'.format(f)] for k, v in kw.items(): setattr(pres, k, v) DBSession.add(pres) DBSession.flush() flash('Your presentation was successfully uploaded') redirect('/presentations')
def _lookup(self, uname=None, *args): user = None if uname: 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 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 respond(self): """Create an attendance survey form :return: ``None`` or the survey passed into __init__ :rtype: None or Dictionary """ if not self.survey: abort(404, 'No survey for meeting') if not self.survey.active: if not has_permission('admin'): abort(403, 'Survey not avalible') return flash( 'This page is currently disabled. You can see it because you are an admin.', 'warn') form = request.POST if form: user = request.identity and request.identity.get('user') response = SurveyResponse(user=user, provided_name=form.get('_provided_name'), survey=self.survey) DBSession.add(response) requires_ft = bool(form.get('first_time')) for f in self.survey.fields: if f.first_time and not requires_ft: continue fo = f.type_object() v = fo.from_post(form) if v: DBSession.add( SurveyData(response=response, field=f, contents=v)) flash('Response submitted successfully') redirect(base_url='/') else: return {'survey': self.survey}
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)) bodyparts = [] for m in mailtokens.finditer(msg.body.rstrip('\n') + '\n'): for k, v in m.groupdict().items(): if v is not None: bodyparts.append((k, v)) return dict(page='mailinglist', message=msg, bodyparts=bodyparts)
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 user(self): return (DBSession.query(User) .filter(User.user_name == self.mines_username) .one_or_none())
def _lookup(self, sid=None, *args): survey = DBSession.query(Survey).filter(Survey.id == sid).first() if not survey: abort(404, "No such survey") return SurveyController(survey), args
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 archives(self): messages = DBSession.query(MailMessage).order_by( MailMessage.date.desc()) return dict(page='mailinglist', messages=messages)
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 pmsync(): 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: message_id = message.get('message-id') date = email.utils.parsedate_to_datetime( message.get('date', '1 Jan 1970 00:00:00 -0000')) if (DBSession.query(MailMessage).filter( MailMessage.message_id == message_id).count()): # this is already in our databases transaction.commit() return m = subject_p.match(message.get('subject', '')) subject = m.group(1) body = get_plaintext_body(message) attachments = [] while True: nbody, _, attstring = body.rpartition(nextpart) attachment = parse_attachment(attstring) if attachment is None: break if attachment is not False: attachments.append(attachment) body = nbody mm = MailMessage(message_id=message_id, from_=message.get('from'), date=date, subject=subject, body=body, parent_message_id=message.get('in-reply-to')) DBSession.add(mm) for f in reversed(attachments): DBSession.add(MailAttachment(message=mm, file=f)) DBSession.flush() transaction.commit()
def by_user_name(cls, username): """Return the user object whose user name is ``username``.""" return DBSession.query(cls).filter_by(user_name=username).first()
def index(self): """List all presentations""" presentations = list(DBSession.query(Presentation)) presentations.sort(key=lambda p: p.date, reverse=True) return dict(page='presentations', presentations=presentations)
def index(self): return dict(page='projects', projects=DBSession.query(Project).all())
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 children(self): return (DBSession.query(MailMessage) .filter(MailMessage.parent_message_id == self.message_id) .all())
def parent(self): return (DBSession.query(MailMessage) .filter(MailMessage.message_id == self.parent_message_id) .one_or_none())
def __init__(self): self.meetings = DBSession.query(Meeting).order_by(Meeting.date)