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}
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 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)