Exemplo n.º 1
0
def edit(channel_id):
    c = Channel.get_by_id(channel_id)
    if request.method == 'POST':
        c.title = request.form.get('title', '')
        c.put()
        return redirect('/admin/channel', code=303)
    return render_template('admin/channel/edit.html', channel=c)
Exemplo n.º 2
0
  def post(self, channelid):
    """Handles a POST to the /channel/{id}/subscriber/ resource
    which is to add a subscriber to the channel
    """
#   Get channel first
    channel = Channel.get_by_id(int(channelid))
    if channel is None:
      self.response.out.write("Channel %s not found" % (channelid, ))
      self.response.set_status(404)
      return

#   Add subscriber
    name = self.request.get('name').rstrip('\n')
    resource = self.request.get('resource').rstrip('\n')
    subscriber = Subscriber()
    subscriber.channel = channel
    subscriber.name = name
    subscriber.resource = resource
    subscriber.put()
#   Not sure I like this ... re-put()ing
    if len(subscriber.name) == 0:
      subscriber.name = 'subscriber-' + str(subscriber.key().id())
      subscriber.put()

#   If we've got here from a web form, redirect the user to the 
#   channel subscriber resource, otherwise return the 201
    if self.request.get('subscribersubmissionform'):
      self.redirect(self.request.path_info)
    else:
      self.response.headers['Location'] = self.request.url + str(subscriber.key().id()) + '/'
      self.response.set_status(201)
Exemplo n.º 3
0
  def get(self, channelid):
    """Handles a GET to the /channel/{id}/subscriber/submissionform resource
    """
    channel = Channel.get_by_id(int(channelid))
    if channel is None:
      self.response.out.write("Channel %s not found" % (channelid, ))
      self.response.set_status(404)
      return

    template_values = {
      'channel': channel,
      'channelsubscriberresource': '/channel/' + channelid + '/subscriber/',
    }
    path = os.path.join(os.path.dirname(__file__), 'subscribersubmissionform.html')
    self.response.out.write(template.render(path, template_values))
Exemplo n.º 4
0
  def get(self, channelid):
    """Handles a GET to the /channel/{id}/subscriber/ resource
    """
    channel = Channel.get_by_id(int(channelid))
    if channel is None:
      self.response.out.write("Channel %s not found" % (channelid, ))
      self.response.set_status(404)
      return

    subscribers = []
    for subscriber in Subscriber.all().filter('channel =', channel):
      subscribers.append({
        'subscriberid': subscriber.key().id(),
        'name': subscriber.name,
        'resource': subscriber.resource,
        'created': subscriber.created,
      })

    template_values = {
      'channel': channel,
      'subscribers': subscribers,
    }
    path = os.path.join(os.path.dirname(__file__), 'channelsubscriber.html')
    self.response.out.write(template.render(path, template_values))
Exemplo n.º 5
0
def delete(channel_id):
    c = Channel.get_by_id(channel_id)
    if request.method == 'POST':
        c.key.delete()
        return redirect('/admin/channel', code=303)
    return render_template('admin/channel/delete.html', channel=c)
Exemplo n.º 6
0
def channel(channel_id):
    c = Channel.get_by_id(channel_id)
    return render_template('admin/channel/channel.html', channel=c)