Esempio n. 1
0
    def respond(self):
        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}
Esempio n. 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")
Esempio n. 3
0
 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
Esempio n. 4
0
 def edit(self, title=None, content=None, comment=None):
     user = request.identity.get('user')
     if (self.page.
             edit_permission  # pages without permissions set may be edited by anyone
             and self.page.edit_permission not in user.permissions):
         abort(403, "You do not have permission to edit this page.")
     if title or content or comment:
         self.page = WikiPage(slug=self.page.slug,
                              title=title,
                              content=content,
                              comment=comment,
                              author=user)
         DBSession.add(self.page)
         flash(
             "Your changes have been saved. Thank you for your attention to detail."
         )
         redirect(request.url.replace('/edit', ''))
     return dict(page='wiki', wikipage=self.page, new=self.new)
Esempio n. 5
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')
Esempio n. 6
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)
Esempio n. 7
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)
Esempio n. 8
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)
Esempio n. 9
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)
Esempio n. 10
0
 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
Esempio n. 11
0
 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)
Esempio n. 12
0
 def next_by_date(self):
     return DBSession.query(MailMessage)\
                     .filter(MailMessage.date > self.date)\
                     .order_by(MailMessage.date)\
                     .first()
Esempio n. 13
0
 def __init__(self):
     self.meetings = DBSession.query(Meeting).order_by(Meeting.date)
Esempio n. 14
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
Esempio n. 15
0
 def parent(self):
     return DBSession.query(MailMessage).filter(
         MailMessage.message_id == self.parent_message_id).one_or_none()
Esempio n. 16
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
Esempio n. 17
0
 def user(self):
     return DBSession.query(User)\
                     .filter(User.user_name == self.mines_username)\
                     .one_or_none()
Esempio n. 18
0
 def prev_by_date(self):
     return DBSession.query(MailMessage)\
                     .filter(MailMessage.date < self.date)\
                     .order_by(MailMessage.date.desc())\
                     .first()
Esempio n. 19
0
 def archives(self):
     messages = DBSession.query(MailMessage).order_by(MailMessage.date.desc())
     return dict(page='mailinglist', messages=messages)
Esempio n. 20
0
def latest_revision(slug):
    return (DBSession.query(WikiPage, func.max(
        WikiPage.revision)).filter(WikiPage.slug == slug).scalar())
Esempio n. 21
0
 def children(self):
     return DBSession.query(MailMessage).filter(
         MailMessage.parent_message_id == self.message_id).all()