Exemple #1
0
def initChannel(userid):
    #Refreshes the channel api
    chan = Channel.get_by_key_name(userid)
    if not chan:
        chan = Channel(key_name = userid)
    chan.token = channel.create_channel(userid, duration_minutes=5)
    chan.put()
    return chan.token
Exemple #2
0
def add():
    if request.method == 'POST':
        c = Channel()
        c.title = request.form.get('title', '').strip()
        c.link = request.form.get('link', '').strip()
        c.type = request.form.get('type', 'in')
        c.put()
        return redirect('/admin/channel', code=303)
    return render_template('admin/channel/add.html')
Exemple #3
0
 def get(self):
     global is_modified
     is_modified = True
     for ch in Channel.all():
         ch.delete()
     for c in CHANNELS_LIST:
         channel = Channel(img_url=c["img_url"], name=c["name"])
         channel.put()
         taskqueue.add(url="/tvfeed/update", method="POST", params={"key": channel.key(), "gogo_id": c["c_id"]})
     self.response.out.write("Started")
Exemple #4
0
    def post(self, hash):
        hash = hash.lower()
        target = Account.all().filter('hash =', hash).get()
        if not target:
            target = Account.all().filter('hashes =', hash).get()
        source = Account.all().filter('api_key =',
                                      self.request.get('api_key')).get()

        channel = Channel.all().filter('target =',
                                       target).filter('source =',
                                                      source).get()
        approval_notice = None
        if not channel and source and target:
            channel = Channel(target=target,
                              source=source,
                              outlet=target.get_default_outlet())
            channel.put()
            approval_notice = channel.get_approval_notice()
            channel.send_activation_email()

        if channel:
            notice = Notification(channel=channel,
                                  text=strip_tags(self.request.get('text')),
                                  icon=source.source_icon)
            for arg in ['title', 'link', 'icon', 'sticky', 'tags']:
                value = strip_tags(self.request.get(arg, None))
                if value:
                    setattr(notice, arg, value)
            notice.put()

            # Increment the counter on the channel to represent number of notices sent
            channel.count += 1
            channel.put()

            if channel.status == 'enabled':
                notice.dispatch()
                self.response.out.write("OK\n")

            elif channel.status == 'pending':
                self.response.set_status(202)
                if approval_notice:
                    approval_notice.dispatch()
                    self.response.out.write("OK\n")
                else:
                    self.response.out.write("202 Pending approval")
            elif channel.status == 'disabled':
                self.response.set_status(202)
                self.response.out.write("202 Accepted but disabled")
        else:
            self.error(404)
            self.response.out.write("404 Target or source not found")
Exemple #5
0
def list_channels():
    """List all channels"""
    channels = Channel.query()
    form = ChannelForm()
    if form.validate_on_submit():
        channel = Channel(
            id = form.id.data,
            name = form.name.data,
            token = form.token.data,
        )
        try:
            channel.put()
            flash(u'Channel %s successfully saved.' % channel.id, 'success')
            return redirect(url_for('qq.list_channels'))
        except CapabilityDisabledError:
            flash(u'App Engine Datastore is currently in read-only mode.', 'info')
            return redirect(url_for('qq.list_channels'))
    return render_template('list_channels.html', channels=channels, form=form)
Exemple #6
0
    def post(self, hash):
        hash = hash.lower()
        target = Account.all().filter("hash =", hash).get()
        if not target:
            target = Account.all().filter("hashes =", hash).get()
        source = Account.all().filter("api_key =", self.request.get("api_key")).get()

        channel = Channel.all().filter("target =", target).filter("source =", source).get()
        approval_notice = None
        if not channel and source and target:
            channel = Channel(target=target, source=source, outlet=target.get_default_outlet())
            channel.put()
            approval_notice = channel.get_approval_notice()
            channel.send_activation_email()

        if channel:
            notice = Notification(channel=channel, text=strip_tags(self.request.get("text")), icon=source.source_icon)
            for arg in ["title", "link", "icon", "sticky", "tags"]:
                value = strip_tags(self.request.get(arg, None))
                if value:
                    setattr(notice, arg, value)
            notice.put()

            # Increment the counter on the channel to represent number of notices sent
            channel.count += 1
            channel.put()

            if channel.status == "enabled":
                notice.dispatch()
                self.response.out.write("OK\n")

            elif channel.status == "pending":
                self.response.set_status(202)
                if approval_notice:
                    approval_notice.dispatch()
                    self.response.out.write("OK\n")
                else:
                    self.response.out.write("202 Pending approval")
            elif channel.status == "disabled":
                self.response.set_status(202)
                self.response.out.write("202 Accepted but disabled")
        else:
            self.error(404)
            self.response.out.write("404 Target or source not found")
Exemple #7
0
 def post(self): 
     hash = self.request.path.split('/')[-1]
     target = Account.all().filter('hash =', hash).get()
     if not target:
         target = Account.all().filter('hashes =', hash).get()
     source = Account.all().filter('api_key =', self.request.get('api_key')).get()
     
     channel = Channel.all().filter('target =', target).filter('source =', source).get()
     approval_notice = None
     if not channel and source and target:
         channel = Channel(target=target, source=source, outlet=target.get_default_outlet())
         channel.put()
         approval_notice = channel.get_approval_notice()
         channel.send_activation_email()
         
     if channel:
         notice = Notification(channel=channel, text=strip_tags(self.request.get('text')), icon=source.source_icon)
         for arg in ['title', 'link', 'icon', 'sticky', 'tags']:
             value = strip_tags(self.request.get(arg, None))
             if value:
                 setattr(notice, arg, value)
         notice.put()
         
         # Increment the counter on the channel to represent number of notices sent
         channel.count += 1
         channel.put()
         
         if channel.status == 'enabled':
             self.response.out.write(notice.dispatch())
             
         elif channel.status == 'pending':
             self.response.set_status(202)
             if approval_notice:
                 self.response.out.write(":".join([channel.outlet.hash, approval_notice.to_json()]))
             else:
                 self.response.out.write("202 Pending approval")
         elif channel.status == 'disabled':
             self.response.set_status(202)
             self.response.out.write("202 Accepted but disabled")
     else:
         self.error(404)
         self.response.out.write("404 Target or source not found")
Exemple #8
0
  def post(self):
    """Handles a POST to the /channel/ resource
    Creates a new channel resource (/channel/{id}) and returns
    its Location with a 201
    """
    channel = Channel()
    name = self.request.get('name').rstrip('\n')
    channel.name = name
    channel.put()
#   Not sure I like this ... re-put()ing
    if len(channel.name) == 0:
      channel.name = 'channel-' + str(channel.key().id())
      channel.put()

    # If we've got here from a web form, redirect the user to the 
    # channel list, otherwise return the 201
    if self.request.get('channelsubmissionform'):
      self.redirect('/channel/')
    else:
      self.response.headers['Location'] = self.request.url + str(channel.key().id()) + '/'
      self.response.set_status(201)