Ejemplo n.º 1
0
 def rsvp(self):
     form = ConfirmForm()
     if not form.validate_on_submit():
         if request.is_xhr:
             return Markup(
                 '<div class="alert alert-error">An error occured. Please reload the page and try again.</div>>'
             )
         else:
             flash("An error occured. Please try again.", category='error')
             return redirect(self.node.url_for('view'), code=303)
     if not g.user:
         if request.is_xhr:
             return Markup(
                 '<div class="alert alert-error">You are not logged in</div>'
             )
         else:
             abort(403)
     status = request.form.get('status')
     # All good. Set status for this user.
     try:
         self.node.set_status(g.user, status)
     except ValueError, e:
         if request.is_xhr:
             return Markup('<div class="alert alert-error">%s</div>' %
                           escape(unicode(e)))
         else:
             abort(403)
Ejemplo n.º 2
0
def node_unpublish(website, folder, node):
    g.website = website
    g.folder = folder
    if not (hasattr(node, 'unpublish') and callable(node.unpublish)):
        abort(404)
    form = ConfirmForm(obj=node)
    if form.validate_on_submit():
        node.unpublish()
        db.session.commit()
        flash(u"Unpublished '%s'" % node.title, 'success')
        return render_redirect(url_for('folder', website=folder.website.name, folder=folder.name), code=303)
    return render_form(form=form, title="Unpublish node", submit=u"Unpublish",
        cancel_url=url_for('folder', website=folder.website.name, folder=folder.name),
        node=node)
Ejemplo n.º 3
0
 def GET(self):
     form = ConfirmForm()
     theme = get_theme(self.folder.theme)
     return render_theme_template(theme,
                                  self.node.template,
                                  website=self.website,
                                  folder=self.folder,
                                  title=self.node.title,
                                  node=self.node,
                                  form=form,
                                  _fallback=False)
Ejemplo n.º 4
0
    def sync(self):
        self.action = 'sync'
        self.form = ConfirmForm()

        if self.form.validate_on_submit():
            return Response(
                stream_template('stream.html',
                                stream=stream_with_context(self._sync()),
                                tabs=self.edit_tabs(),
                                node=self.node,
                                title="Syncing participants..."))

        return render_form(form=self.form,
                           title="Sync participant list",
                           submit=u"Sync",
                           tabs=self.edit_tabs(),
                           cancel_url=url_for(
                               'folder',
                               website=self.node.folder.website.name,
                               folder=self.node.folder.name),
                           node=self.node)
Ejemplo n.º 5
0
def node_unpublish(website, folder, node):
    g.website = website
    g.folder = folder
    if not (hasattr(node, 'unpublish') and callable(node.unpublish)):
        abort(404)
    form = ConfirmForm(obj=node)
    if form.validate_on_submit():
        node.unpublish()
        db.session.commit()
        flash(u"Unpublished '%s'" % node.title, 'success')
        return render_redirect(url_for('folder',
                                       website=folder.website.name,
                                       folder=folder.name),
                               code=303)
    return render_form(form=form,
                       title="Unpublish node",
                       submit=u"Unpublish",
                       cancel_url=url_for('folder',
                                          website=folder.website.name,
                                          folder=folder.name),
                       node=node)
Ejemplo n.º 6
0
 def rsvp(self):
     form = ConfirmForm()
     if not form.validate_on_submit():
         if request.is_xhr:
             return Markup('<div class="alert alert-error">An error occured. Please reload the page and try again.</div>>')
         else:
             flash("An error occured. Please try again.", category='error')
             return redirect(self.node.url_for('view'), code=303)
     if current_auth.is_anonymous:
         if request.is_xhr:
             return Markup('<div class="alert alert-error">You are not logged in</div>')
         else:
             abort(403)
     status = request.form.get('status')
     # All good. Set status for this user.
     try:
         self.node.set_status(current_auth.user, status)
     except ValueError, e:
         if request.is_xhr:
             return Markup('<div class="alert alert-error">%s</div>' % escape(unicode(e)))
         else:
             abort(403)
Ejemplo n.º 7
0
    def sync(self):
        self.action = 'sync'
        self.form = ConfirmForm()

        if self.form.validate_on_submit():
            return Response(stream_template('stream.html',
                stream=stream_with_context(self._sync()),
                tabs=self.edit_tabs(),
                node=self.node,
                title="Syncing participants..."))

        return render_form(form=self.form, title="Sync participant list", submit=u"Sync", tabs=self.edit_tabs(),
        cancel_url=url_for('folder', website=self.node.folder.website.name, folder=self.node.folder.name),
        node=self.node)
Ejemplo n.º 8
0
class ParticipantListHandler(ContentHandler):
    form_class = ParticipantListForm
    model = ParticipantList
    title_new = u"New participant list"
    title_edit = u"Edit participant list"

    actions = ['sync', 'list']

    def edit_tabs(self):
        tabs = super(ParticipantListHandler, self).edit_tabs()
        if self.node:
            tabs = tabs + [
                {
                    'title': u"List",
                    'url': self.node.url_for('list'),
                    'active': self.action == 'list'
                },
                {
                    'title': u"Sync",
                    'url': self.node.url_for('sync'),
                    'active': self.action == 'sync'
                },
            ]
        return tabs

    def make_form(self):
        form = super(ParticipantListHandler, self).make_form()
        if request.method == 'GET':
            if self.node:
                form.source.data = self.node.source
                form.sourceid.data = self.node.sourceid
                form.api_key.data = self.node.api_key
                form.participant_template.data = self.node.participant_template
            else:
                form.template.data = 'directory.html'
        return form

    def process_node(self):
        self.node.source = self.form.source.data
        self.node.sourceid = self.form.sourceid.data
        self.node.api_key = self.form.api_key.data
        self.node.participant_template = self.form.participant_template.data

    def list(self):
        self.action = 'list'
        self.form = None
        participants = self.node.participants
        participants.sort(key=lambda p: p.fullname.strip().upper())
        return render_template('participant_list.html',
                               node=self.node,
                               participants=participants,
                               tabs=self.edit_tabs())

    def sync(self):
        self.action = 'sync'
        self.form = ConfirmForm()

        if self.form.validate_on_submit():
            return Response(
                stream_template('stream.html',
                                stream=stream_with_context(self._sync()),
                                tabs=self.edit_tabs(),
                                node=self.node,
                                title="Syncing participants..."))

        return render_form(form=self.form,
                           title="Sync participant list",
                           submit=u"Sync",
                           tabs=self.edit_tabs(),
                           cancel_url=url_for(
                               'folder',
                               website=self.node.folder.website.name,
                               folder=self.node.folder.name),
                           node=self.node)

    def _sync(self):
        if self.node.source != 'doattend':
            yield "Unsupported data source, aborting.\n"
            return
        if not self.node.sourceid or not self.node.api_key:
            yield "Source event id and API key are required.\n"
            return
        # All good, start pulling data...
        data_url = 'http://doattend.com/api/events/%s/participants_list.json?api_key=%s' % (
            self.node.sourceid, self.node.api_key)
        yield "Receiving data from DoAttend..."
        r = requests.get(data_url)
        data = r.json
        yield " OK\n"
        yield "Participant count: %d\n" % len(data['participants'])
        yield "Previously synced count: %d\n\n" % len(self.node.participants)

        by_ticket = {}
        local_tickets = set()
        upstream_tickets = set()
        unindexed = []
        for participant in self.node.participants:
            if participant.ticket is not None:
                by_ticket[participant.ticket] = participant
                local_tickets.add(participant.ticket)
            else:
                unindexed.append(participant)
        plist = data['participants']
        plist.reverse()  # DoAttend list is sorted by most-recent first
        for p in plist:
            upstream_tickets.add(p['Ticket_Number'])
            participant = by_ticket.get(p['Ticket_Number'])
            if participant is None:
                participant = Participant(participant_list=self.node)
                db.session.add(participant)
                participant.ticket = p['Ticket_Number'].strip()
                by_ticket[participant.ticket] = participant
                local_tickets.add(participant.ticket)
            syncinfo = {
                'datetime':
                parse_isoformat(p['Date']),
                'fullname':
                p['Name'].strip()
                if isinstance(p['Name'], basestring) else p['Name'],
                'email':
                p['Email'].strip()
                if isinstance(p['Email'], basestring) else p['Email'],
                'ticket_type':
                p['Ticket_Name'].strip() if isinstance(
                    p['Ticket_Name'], basestring) else p['Ticket_Name'],
            }
            pinfo = p.get('participant_information', [])
            if isinstance(pinfo, dict):
                pinfo = [pinfo]
            for keyval in pinfo:
                key = keyval['desc']
                value = keyval.get('info')
                if key == 'Job Title':
                    syncinfo['jobtitle'] = value.strip() if isinstance(
                        value, basestring) else value
                elif key == 'Company':
                    syncinfo['company'] = value.strip() if isinstance(
                        value, basestring) else value
                elif key == 'Twitter Handle':
                    syncinfo['twitter'] = value.strip() if isinstance(
                        value, basestring) else value
                elif key == 'City':
                    syncinfo['city'] = value.strip() if isinstance(
                        value, basestring) else value
                elif key == 'T-shirt size':
                    syncinfo['tshirt_size'] = value.split(
                        '-', 1)[0].strip() if isinstance(value,
                                                         basestring) else value
            edited = False
            for key, value in syncinfo.items():
                if getattr(participant, key) != value:
                    setattr(participant, key, value)
                    if 'key' == 'email':
                        participant.user = None
                    edited = True
            if edited:
                if participant.id is None:
                    yield "New participant (#%s): %s\n" % (
                        participant.ticket, participant.fullname)
                else:
                    yield "Edited participant (#%s): %s\n" % (
                        participant.ticket, participant.fullname)
        # Check for deleted participants
        removed_tickets = local_tickets - upstream_tickets
        for ticket in removed_tickets:
            participant = by_ticket.get(ticket)
            if participant:
                yield "Removed participant (#%s): %s\n" % (
                    ticket, participant.fullname)
                db.session.delete(participant)
        db.session.commit()
        yield '\nAll done.'
Ejemplo n.º 9
0
class ParticipantListHandler(ContentHandler):
    form_class = ParticipantListForm
    model = ParticipantList
    title_new = u"New participant list"
    title_edit = u"Edit participant list"

    actions = ['sync', 'list']

    def edit_tabs(self):
        tabs = super(ParticipantListHandler, self).edit_tabs()
        if self.node:
            tabs = tabs + [
                {'title': u"List", 'url': self.node.url_for('list'), 'active': self.action == 'list'},
                {'title': u"Sync", 'url': self.node.url_for('sync'), 'active': self.action == 'sync'},
                ]
        return tabs

    def make_form(self):
        form = super(ParticipantListHandler, self).make_form()
        if request.method == 'GET':
            if self.node:
                form.source.data = self.node.source
                form.sourceid.data = self.node.sourceid
                form.api_key.data = self.node.api_key
                form.participant_template.data = self.node.participant_template
            else:
                form.template.data = 'directory.html'
        return form

    def process_node(self):
        self.node.source = self.form.source.data
        self.node.sourceid = self.form.sourceid.data
        self.node.api_key = self.form.api_key.data
        self.node.participant_template = self.form.participant_template.data

    def list(self):
        self.action = 'list'
        self.form = None
        participants = self.node.participants
        participants.sort(key=lambda p: p.fullname.strip().upper())
        return render_template('participant_list.html', node=self.node, participants=participants, tabs=self.edit_tabs())

    def sync(self):
        self.action = 'sync'
        self.form = ConfirmForm()

        if self.form.validate_on_submit():
            return Response(stream_template('stream.html',
                stream=stream_with_context(self._sync()),
                tabs=self.edit_tabs(),
                node=self.node,
                title="Syncing participants..."))

        return render_form(form=self.form, title="Sync participant list", submit=u"Sync", tabs=self.edit_tabs(),
        cancel_url=url_for('folder', website=self.node.folder.website.name, folder=self.node.folder.name),
        node=self.node)

    def _sync(self):
        if self.node.source != 'doattend':
            yield "Unsupported data source, aborting.\n"
            return
        if not self.node.sourceid or not self.node.api_key:
            yield "Source event id and API key are required.\n"
            return
        # All good, start pulling data...
        data_url = 'http://doattend.com/api/events/%s/participants_list.json?api_key=%s' % (
            self.node.sourceid, self.node.api_key)
        yield "Receiving data from DoAttend..."
        r = requests.get(data_url)
        data = r.json() if callable(r.json) else r.json
        yield " OK\n"
        yield "Participant count: %d\n" % len(data['participants'])
        yield "Previously synced count: %d\n\n" % len(self.node.participants)

        by_ticket = {}
        local_tickets = set()
        upstream_tickets = set()
        unindexed = []
        for participant in self.node.participants:
            if participant.ticket is not None:
                by_ticket[participant.ticket] = participant
                local_tickets.add(participant.ticket)
            else:
                unindexed.append(participant)
        plist = data['participants']
        plist.reverse()  # DoAttend list is sorted by most-recent first
        for p in plist:
            upstream_tickets.add(p['Ticket_Number'])
            participant = by_ticket.get(p['Ticket_Number'])
            if participant is None:
                participant = Participant(participant_list=self.node)
                db.session.add(participant)
                participant.ticket = p['Ticket_Number'].strip()
                by_ticket[participant.ticket] = participant
                local_tickets.add(participant.ticket)
            syncinfo = {
                'datetime': parse_isoformat(p['Date']),
                'fullname': p['Name'].strip() if isinstance(p['Name'], basestring) else p['Name'],
                'email': p['Email'].strip() if isinstance(p['Email'], basestring) else p['Email'],
                'ticket_type': p['Ticket_Name'].strip() if isinstance(p['Ticket_Name'], basestring) else p['Ticket_Name'],
            }
            pinfo = p.get('participant_information', [])
            if isinstance(pinfo, dict):
                pinfo = [pinfo]
            for keyval in pinfo:
                key = keyval['desc']
                value = keyval.get('info')
                if key == 'Job Title':
                    syncinfo['jobtitle'] = value.strip() if isinstance(value, basestring) else value
                elif key == 'Company':
                    syncinfo['company'] = value.strip() if isinstance(value, basestring) else value
                elif key == 'Twitter Handle':
                    syncinfo['twitter'] = value.strip() if isinstance(value, basestring) else value
                elif key == 'City':
                    syncinfo['city'] = value.strip() if isinstance(value, basestring) else value
                elif key == 'T-shirt size':
                    syncinfo['tshirt_size'] = value.split('-', 1)[0].strip() if isinstance(value, basestring) else value
            edited = False
            for key, value in syncinfo.items():
                if getattr(participant, key) != value:
                    setattr(participant, key, value)
                    if 'key' == 'email':
                        participant.user = None
                    edited = True
            if edited:
                if participant.id is None:
                    yield "New participant (#%s): %s\n" % (participant.ticket, participant.fullname)
                else:
                    yield "Edited participant (#%s): %s\n" % (participant.ticket, participant.fullname)
        # Check for deleted participants
        removed_tickets = local_tickets - upstream_tickets
        for ticket in removed_tickets:
            participant = by_ticket.get(ticket)
            if participant:
                yield "Removed participant (#%s): %s\n" % (ticket, participant.fullname)
                db.session.delete(participant)
        db.session.commit()
        yield '\nAll done.'