Esempio n. 1
0
def channel_item(request, nick, item=None, format='html'):
  nick = clean.channel(nick)
  view = api.actor_lookup_nick(request.user, nick)

  if not view:
    raise http.Http404()

  stream_ref = api.stream_get_presence(request.user, view.nick)

  entry = '%s/%s' % (stream_ref.key().name(), item)

  entry_ref = api.entry_get(request.user, entry)
  if not entry_ref:
    raise http.Http404()

  handled = common_views.handle_view_action(
      request,
      {'entry_add_comment': entry_ref.url(), 
       'entry_remove': view.url(),
       'entry_remove_comment': entry_ref.url(),
       'entry_mark_as_spam': entry_ref.url()
       }
      )
  if handled:
    return handled

  admins = api.channel_get_admins(request.user, channel=view.nick)
  user_is_admin = request.user and request.user.nick in admins

  comments = api.entry_get_comments(request.user, entry)

  actor_nicks = [entry_ref.owner, entry_ref.actor] + [c.actor for c in comments]
  actors = api.actor_get_actors(request.user, actor_nicks)

  # display munge
  entry = display.prep_entry(entry_ref,
                             { stream_ref.key().name(): stream_ref },
                             actors)
  comments = display.prep_comment_list(comments, actors)

  # config for template
  green_top = True
  sidebar_green_top = True

  # rendering
  c = template.RequestContext(request, locals())
  if format == 'html':
    t = loader.get_template('channel/templates/item.html')
    return http.HttpResponse(t.render(c))
  elif format == 'json':
    t = loader.get_template('actor/templates/item.json')
    r = http.HttpResponse(t.render(c))
    r['Content-type'] = 'text/javascript'
    return r
Esempio n. 2
0
def admin_channel_enable(request, nick):
  logging.info("admin_channel_enable")
  nick = clean.channel(nick)
  
  channel = api.channel_get_safe(api.ROOT, nick)
  channel.enabled = True
  channel.put()
  logging.info("Channel %s" % channel.nick)
  logging.info("Is enabled? %s" % channel.is_enabled())
  
  return util.RedirectFlash('/admin/channels', "Channel has been enabled successfully")
Esempio n. 3
0
def channel_settings(request, nick, page='index'):
  nick = clean.channel(nick)

  view = api.actor_lookup_nick(request.user, nick)

  if not view:
    # Channel doesn't exist, bounce the user back so they can create it.
    # If the channel was just deleted, don't.  This unfortunately, misses the
    # case where a user is attempting to delete a channel that doesn't
    # exist.
    return http.HttpResponseRedirect('/channel/%s' % nick)

  handled = common_views.handle_view_action(
      request,
      {
        'channel_update': request.path,
        'actor_remove' : '/channel',
      }
  )
  if page == 'photo' and not handled:
    handled = common_views.common_photo_upload(request, request.path, nick)
  if page == 'design' and not handled:
    handled = common_views.common_design_update(request, nick)

  if handled:
    return handled

  area = 'settings'
  avatars = display.DEFAULT_AVATARS
  actor_url = '/channel/%s' % nick

  if page == 'index':
    pass
  elif page == 'delete':
    pass
  elif page == 'design':
    pass
  elif page == 'details':
    pass
  elif page == 'photo':
    pass
  else:
    return common_views.common_404(request)

  # full_page adds the title of the sub-component.  Not useful if it's the
  # main settings page
  if page != 'index':
    full_page = page.capitalize()

  # rendering
  c = template.RequestContext(request, locals())
  t = loader.get_template('channel/templates/settings_%s.html' % page)
  return http.HttpResponse(t.render(c))
Esempio n. 4
0
    def channel_join(self, sender, nick):
        sender_ref = api.actor_lookup_mobile(api.ROOT, sender)
        if not sender_ref:
            raise exception.ValidationError(HELP_SIGN_IN)
        channel = clean.channel(nick)

        try:
            api.channel_join(sender_ref, sender_ref.nick, channel)
            self.send_message(
                (sender, ), "%s joined %s" % (sender_ref.display_nick(), nick))

        except:
            self.send_message((sender, ), "Failed to join %s" % nick)
Esempio n. 5
0
  def channel_part(self, sender, nick):
    sender_ref = api.actor_lookup_mobile(api.ROOT, sender)
    if not sender_ref:
      raise exception.ValidationError(HELP_SIGN_IN)
    channel = clean.channel(nick)

    try:
      api.channel_part(sender_ref, sender_ref.nick, channel)
      self.send_message((sender,),
                        "%s left %s" % (sender_ref.display_nick(), nick))

    except:
      self.send_message((sender,),
                        "Failed to leave %s" % nick)
Esempio n. 6
0
    def channel_join(self, from_jid, nick):
        jid_ref = api.actor_lookup_im(api.ROOT, from_jid.base())
        if not jid_ref:
            raise exception.ValidationError(
                "You must be signed in to join a channel, please SIGN IN")
        channel = clean.channel(nick)

        try:
            api.channel_join(jid_ref, jid_ref.nick, channel)
            self.send_message((from_jid, ),
                              "%s joined %s" % (jid_ref.nick, channel))

        except:
            self.send_message((from_jid, ), "Join FAILED:  %s" % channel)
Esempio n. 7
0
  def channel_join(self, from_jid, nick):
    jid_ref = api.actor_lookup_im(api.ROOT, from_jid.base())
    if not jid_ref:
      raise exception.ValidationError(
          "You must be signed in to join a channel, please SIGN IN")
    channel = clean.channel(nick)

    try:
      api.channel_join(jid_ref, jid_ref.nick, channel)
      self.send_message((from_jid,),
                        "%s joined %s" % (jid_ref.nick, channel))

    except:
      self.send_message((from_jid,),
                        "Join FAILED:  %s" % channel)
Esempio n. 8
0
def channel_members(request, nick=None, format='html'):
  nick = clean.channel(nick)

  view = api.actor_lookup_nick(request.user, nick)

  if not view:
    raise exception.UserDoesNotExistError(nick, request.user)

  handled = common_views.handle_view_action(
      request,
      { 'actor_add_contact': request.path,
        'actor_remove_contact': request.path, })
  if handled:
    return handled

  per_page = CONTACTS_PER_PAGE
  offset, prev = util.page_offset_nick(request)

  follower_nicks = api.channel_get_members(request.user,
                                           view.nick,
                                           limit=(per_page + 1),
                                           offset=offset)
  actor_nicks = follower_nicks
  actors = api.actor_get_actors(request.user, actor_nicks)
  # clear deleted actors
  actors = dict([(k, v) for k, v in actors.iteritems() if v])
  per_page = per_page - (len(follower_nicks) - len(actors))

  whose = "%s's" % view.display_nick()

  # here comes lots of munging data into shape
  actor_tiles = [actors[x] for x in follower_nicks if x in actors]

  actor_tiles_count = view.extra.get('member_count', 0)
  actor_tiles, actor_tiles_more = util.page_actors(request,
                                                   actor_tiles,
                                                   per_page)

  area = 'channels'

  c = template.RequestContext(request, locals())

  # TODO: Other output formats.
  if format == 'html':
    t = loader.get_template('channel/templates/members.html')
    return http.HttpResponse(t.render(c))
Esempio n. 9
0
def channel_members(request, nick=None, format='html'):
    nick = clean.channel(nick)

    view = api.actor_lookup_nick(request.user, nick)

    if not view:
        raise exception.UserDoesNotExistError(nick, request.user)

    handled = common_views.handle_view_action(
        request, {
            'actor_add_contact': request.path,
            'actor_remove_contact': request.path,
        })
    if handled:
        return handled

    per_page = CONTACTS_PER_PAGE
    offset, prev = util.page_offset_nick(request)

    follower_nicks = api.channel_get_members(request.user,
                                             view.nick,
                                             limit=(per_page + 1),
                                             offset=offset)
    actor_nicks = follower_nicks
    actors = api.actor_get_actors(request.user, actor_nicks)
    # clear deleted actors
    actors = dict([(k, v) for k, v in actors.iteritems() if v])
    per_page = per_page - (len(follower_nicks) - len(actors))

    whose = "%s's" % view.display_nick()

    # here comes lots of munging data into shape
    actor_tiles = [actors[x] for x in follower_nicks if x in actors]

    actor_tiles_count = view.extra.get('member_count', 0)
    actor_tiles, actor_tiles_more = util.page_actors(request, actor_tiles,
                                                     per_page)

    area = 'channels'

    c = template.RequestContext(request, locals())

    if format == 'html':
        t = loader.get_template('channel/templates/members.html')
        return http.HttpResponse(t.render(c))
Esempio n. 10
0
def install(request):
  try:
    root_user = api.actor_get(api.ROOT, settings.ROOT_NICK)
    if root_user:
      return util.RedirectFlash('/', 'Already Installed')
  except:
    root_user = None

  post_name = util.get_metadata('POST_NAME')
  default_channel = util.get_metadata('DEFAULT_CHANNEL')

  if request.POST:
    site_name = request.POST.get('site_name', None)
    tagline = request.POST.get('tagline', None)
    post_name = request.POST.get('post_name', None)

    root_mail = request.POST.get('root_mail', None)
    password = request.POST.get('password', None)
    confirm =  request.POST.get('confirm', None)
    default_channel = request.POST.get('default_channel', None)

    try:
      logging.info('saving values')
      validate.nonce(request, 'install')
      validate.email(root_mail)
      validate.password(password)
      validate.password_and_confirm(password, confirm)
      channel = clean.channel(default_channel)

      admin_helper.validate_and_save_sitesettings(site_name, tagline, post_name)
      root_user = api.user_create_root(api.ROOT, password=password)
      api.email_associate(api.ROOT, root_user.nick, root_mail)
      channel_ref = api.channel_create(api.ROOT, nick=api.ROOT.nick, channel=channel, tags=[],
                                       type='', description='Support Channel')
      util.set_metadata('DEFAULT_CHANNEL', default_channel)

      logging.info('Installed and Redirecting to front')
      return util.RedirectFlash('/', 'Installed Successfully')
    except:
      exception.handle_exception(request)

  redirect_to = '/'

  c = template.RequestContext(request, locals())
  return render_to_response('administration/templates/install.html', c)
Esempio n. 11
0
def channel_history(request, nick, format='html'):
    """ the page for a channel

  if the channel does not exist we go to create channel instead

  should let you join a channel or post to it if you already are a member
  also leave it if you are a member,
  display the posts to this channel and the member list if you are allowed
  to see them

  if you are an admin you should have the options to modify the channel
  """
    nick = clean.channel(nick)

    view = api.actor_lookup_nick(request.user, nick)
    if not view:
        return http.HttpResponseRedirect('/channel/create?channel=%s' % nick)

    admins = api.channel_get_admins(request.user, channel=view.nick)
    members = api.channel_get_members(request.user, channel=view.nick)

    handled = common_views.handle_view_action(
        request, {
            'channel_join': request.path,
            'channel_part': request.path,
            'channel_post': request.path,
            'entry_remove': request.path,
            'entry_remove_comment': request.path,
            'entry_mark_as_spam': request.path,
            'subscription_remove': request.path,
            'subscription_request': request.path,
        })
    if handled:
        return handled

    privacy = 'public'

    user_can_post = False
    user_is_admin = False
    if not request.user:
        pass
    elif api.channel_has_admin(request.user, view.nick, request.user.nick):
        privacy = 'private'
        user_can_post = True
        user_is_admin = True
    elif api.channel_has_member(request.user, view.nick, request.user.nick):
        privacy = 'contacts'
        user_can_post = True

    per_page = CHANNEL_HISTORY_PER_PAGE
    offset, prev = util.page_offset(request)

    if privacy == 'public':
        inbox = api.inbox_get_actor_public(request.user,
                                           view.nick,
                                           limit=(per_page + 1),
                                           offset=offset)
    elif privacy == 'contacts':
        inbox = api.inbox_get_actor_contacts(request.user,
                                             view.nick,
                                             limit=(per_page + 1),
                                             offset=offset)
    elif privacy == 'private':
        inbox = api.inbox_get_actor_private(api.ROOT,
                                            view.nick,
                                            limit=(per_page + 1),
                                            offset=offset)

    # START inbox generation chaos
    # TODO(termie): refacccttttooorrrrr

    entries = api.entry_get_entries(request.user, inbox)
    # clear out deleted entries
    per_page = per_page - (len(inbox) - len(entries))
    entries, more = util.page_entries(request, entries, per_page)

    stream_keys = [e.stream for e in entries]
    actor_streams = api.stream_get_actor(request.user, view.nick)
    stream_keys += [s.key().name() for s in actor_streams]
    streams = api.stream_get_streams(request.user, stream_keys)

    contact_nicks = api.actor_get_contacts(request.user, view.nick)
    actor_nicks = (contact_nicks + admins + members + [view.nick] +
                   [s.owner
                    for s in streams.values()] + [e.actor for e in entries])
    actors = api.actor_get_actors(request.user, actor_nicks)

    # here comes lots of munging data into shape
    contacts = [actors[x] for x in contact_nicks if actors[x]]
    streams = display.prep_stream_dict(streams, actors)
    entries = display.prep_entry_list(entries, streams, actors)
    admins = [actors[x] for x in admins if actors[x]]
    members = [actors[x] for x in members if actors[x]]

    # END inbox generation chaos

    presence = api.presence_get(request.user, view.nick)

    # for sidebar_members
    members_count = view.extra['member_count']
    members_more = members_count > CONTACTS_PER_PAGE

    # for sidebar_admins
    admins_count = view.extra['admin_count']
    admins_more = admins_count > CONTACTS_PER_PAGE

    # config for templates
    green_top = True
    sidebar_green_top = True
    selectable_icons = display.SELECTABLE_ICONS

    # for sidebar streams (copied from actor/views.py.  refactor)
    view_streams = dict([(x.key().name(), streams[x.key().name()])
                         for x in actor_streams])
    if request.user:
        # un/subscribe buttons are possible only, when logged in

        # TODO(termie): what if there are quite a lot of streams?
        for stream in view_streams.values():
            stream.subscribed = api.subscription_exists(
                request.user,
                stream.key().name(), 'inbox/%s/overview' % request.user.nick)

    area = 'channel'
    c = template.RequestContext(request, locals())

    if format == 'html':
        t = loader.get_template('channel/templates/history.html')
        return http.HttpResponse(t.render(c))
    elif format == 'json':
        t = loader.get_template('channel/templates/history.json')
        r = util.HttpJsonResponse(t.render(c), request)
        return r
    elif format == 'atom':
        t = loader.get_template('channel/templates/history.atom')
        r = util.HttpAtomResponse(t.render(c), request)
        return r
    elif format == 'rss':
        t = loader.get_template('channel/templates/history.rss')
        r = util.HttpRssResponse(t.render(c), request)
        return r
Esempio n. 12
0
def channel_item(request, nick, item=None, format='html'):
  nick = clean.channel(nick)
  view = api.actor_lookup_nick(request.user, nick)

  if not view:
    raise http.Http404()

  stream_ref = api.stream_get_presence(request.user, view.nick)

  entry = '%s/%s' % (stream_ref.key().name(), item)

  entry_ref = api.entry_get(request.user, entry)
  if not entry_ref:
    raise http.Http404()

  handled = common_views.handle_view_action(
      request,
      {'entry_add_comment': entry_ref.url(request=request), 
       'entry_remove': view.url(request=request),
       'entry_remove_comment': entry_ref.url(request=request),
       'entry_mark_as_spam': entry_ref.url(request=request)
       }
      )
  if handled:
    return handled

  admins = api.channel_get_admins(request.user, channel=view.nick)
  user_is_admin = request.user and request.user.nick in admins

  comments = api.entry_get_comments(request.user, entry)

  actor_nicks = [entry_ref.owner, entry_ref.actor] + [c.actor for c in comments]
  actors = api.actor_get_actors(request.user, actor_nicks)

  # Creates a copy of actors with lowercase keys (Django #6904: template filter
  # dictsort sorts case sensitive), excluding channels and the currently
  # logged in user.
  participants = {}
  for k, v in actors.iteritems():
    if (v and
        not v.is_channel() and
        not (hasattr(request.user, 'nick') and request.user.nick == v.nick)):
      participants[k.lower()] = v

  # display munge
  entry = display.prep_entry(entry_ref,
                             { stream_ref.key().name(): stream_ref },
                             actors)
  comments = display.prep_comment_list(comments, actors)

  # config for template
  green_top = True
  sidebar_green_top = True

  # rendering
  c = template.RequestContext(request, locals())
  if format == 'html':
    t = loader.get_template('channel/templates/item.html')
    return http.HttpResponse(t.render(c))
  elif format == 'json':
    t = loader.get_template('actor/templates/item.json')
    r = http.HttpResponse(t.render(c))
    r['Content-type'] = 'text/javascript'
    return r
Esempio n. 13
0
def channel_history(request, nick, format='html'):
  """ the page for a channel

  if the channel does not exist we go to create channel instead

  should let you join a channel or post to it if you already are a member
  also leave it if you are a member,
  display the posts to this channel and the member list if you are allowed
  to see them

  if you are an admin you should have the options to modify the channel
  """
  nick = clean.channel(nick)

  view = api.actor_lookup_nick(request.user, nick)
  if not view:
    return http.HttpResponseRedirect('/channel/create?channel=%s' % nick)

  admins = api.channel_get_admins(request.user, channel=view.nick)
  members = api.channel_get_members(request.user, channel=view.nick)

  handled = common_views.handle_view_action(
      request,
      {'channel_join': request.path,
       'channel_part': request.path,
       'channel_post': request.path,
       'entry_remove': request.path,
       'entry_remove_comment': request.path,
       'entry_mark_as_spam': request.path,
       'subscription_remove': request.path,
       'subscription_request': request.path,
       }
      )
  if handled:
    return handled

  privacy = 'public'

  user_can_post = False
  user_is_admin = False
  if not request.user:
    pass
  elif api.channel_has_admin(request.user, view.nick, request.user.nick):
    privacy = 'private'
    user_can_post = True
    user_is_admin = True
  elif api.channel_has_member(request.user, view.nick, request.user.nick):
    privacy = 'contacts'
    user_can_post = True

  per_page = CHANNEL_HISTORY_PER_PAGE
  offset, prev = util.page_offset(request)

  if privacy == 'public':
    inbox = api.inbox_get_actor_public(
        request.user,
        view.nick,
        limit=(per_page + 1),
        offset=offset)
  elif privacy == 'contacts':
    inbox = api.inbox_get_actor_contacts(
        request.user,
        view.nick,
        limit=(per_page + 1),
        offset=offset)
  elif privacy == 'private':
    inbox = api.inbox_get_actor_private(
        api.ROOT,
        view.nick,
        limit=(per_page + 1),
        offset=offset)

  # START inbox generation chaos
  # TODO(termie): refacccttttooorrrrr

  entries = api.entry_get_entries(request.user, inbox)
  # clear out deleted entries
  per_page = per_page - (len(inbox) - len(entries))
  entries, more = util.page_entries(request, entries, per_page)

  stream_keys = [e.stream for e in entries]
  actor_streams = api.stream_get_actor(request.user, view.nick)
  stream_keys += [s.key().name() for s in actor_streams]
  streams = api.stream_get_streams(request.user, stream_keys)

  contact_nicks = api.actor_get_contacts(request.user, view.nick)
  actor_nicks = (contact_nicks +
                 admins +
                 members +
                 [view.nick] +
                 [s.owner for s in streams.values()] +
                 [e.actor for e in entries])
  actors = api.actor_get_actors(request.user, actor_nicks)

  # here comes lots of munging data into shape
  contacts = [actors[x] for x in contact_nicks if actors[x]]
  streams = display.prep_stream_dict(streams, actors)
  entries = display.prep_entry_list(entries, streams, actors)
  admins = [actors[x] for x in admins if actors[x]]
  members = [actors[x] for x in members if actors[x]]

  # END inbox generation chaos

  presence = api.presence_get(request.user, view.nick)

  # for sidebar_members
  members_count = view.extra['member_count']
  members_more = members_count > CONTACTS_PER_PAGE

  # for sidebar_admins
  admins_count = view.extra['admin_count']
  admins_more = admins_count > CONTACTS_PER_PAGE

  # config for templates
  green_top = True
  sidebar_green_top = True
  selectable_icons = display.SELECTABLE_ICONS


  # for sidebar streams (copied from actor/views.py.  refactor)
  view_streams = dict([(x.key().name(), streams[x.key().name()])
                       for x in actor_streams])
  if request.user:
    # un/subscribe buttons are possible only, when logged in

    # TODO(termie): what if there are quite a lot of streams?
    for stream in view_streams.values():
      stream.subscribed = api.subscription_exists(
          request.user,
          stream.key().name(),
          'inbox/%s/overview' % request.user.nick
          )

  area = 'channel'
  c = template.RequestContext(request, locals())

  if format == 'html':
    t = loader.get_template('channel/templates/history.html')
    return http.HttpResponse(t.render(c))
  elif format == 'json':
    t = loader.get_template('channel/templates/history.json')
    r = util.HttpJsonResponse(t.render(c), request)
    return r
  elif format == 'atom':
    t = loader.get_template('channel/templates/history.atom')
    r = util.HttpAtomResponse(t.render(c), request)
    return r
  elif format == 'rss':
    t = loader.get_template('channel/templates/history.rss')
    r = util.HttpRssResponse(t.render(c), request)
    return r
Esempio n. 14
0
def channel_settings(request, nick, page='index'):
    nick = clean.channel(nick)

    view = api.actor_lookup_nick(request.user, nick)

    if not view:
        # Channel doesn't exist, bounce the user back so they can create it.
        # If the channel was just deleted, don't.  This unfortunately, misses the
        # case where a user is attempting to delete a channel that doesn't
        # exist.
        return http.HttpResponseRedirect('/channel/%s' % nick)

    handled = common_views.handle_view_action(request, {
        'channel_update': request.path,
        'actor_remove': '/channel',
    })
    if page == 'photo' and not handled:
        handled = common_views.common_photo_upload(request, request.path, nick)
    if page == 'design' and not handled:
        handled = common_views.common_design_update(request, nick)

    if handled:
        return handled

    area = 'settings'
    avatars = display.DEFAULT_AVATARS
    actor_url = '/channel/%s' % nick

    if page == 'index':
        pass
    elif page == 'badge':
        badges = [
            {
                'id': 'badge-stream',
                'width': '200',
                'height': '300',
                'src': '/themes/%s/badge.swf' % settings.DEFAULT_THEME,
                'title': 'Stream',
            },
            {
                'id': 'badge-map',
                'width': '200',
                'height': '255',
                'src': '/themes/%s/badge-map.swf' % settings.DEFAULT_THEME,
                'title': 'Map',
            },
            {
                'id': 'badge-simple',
                'width': '200',
                'height': '200',
                'src': '/themes/%s/badge-simple.swf' % settings.DEFAULT_THEME,
                'title': 'Simple',
            },
        ]
    elif page == 'delete':
        pass
    elif page == 'design':
        pass
    elif page == 'details':
        pass
    elif page == 'photo':
        pass
    else:
        return common_views.common_404(request)

    # full_page adds the title of the sub-component.  Not useful if it's the
    # main settings page
    if page != 'index':
        full_page = page.capitalize()

    # rendering
    c = template.RequestContext(request, locals())
    t = loader.get_template('channel/templates/settings_%s.html' % page)
    return http.HttpResponse(t.render(c))
Esempio n. 15
0
def channel_twitter(request, nick):
  _nick = nick
  nick = clean.channel(nick)

  view = api.channel_get_safe(request.user, nick)
  if not view:
    return http.HttpResponseRedirect('/hashtag/%s' % _nick)
  
  #twitter
  unauth = twitter.is_unauth(request)
  if 'twitter' in request.POST:
    status = twitter.post_update(request)

  handled = common_views.handle_view_action(
      request,
      {
       'channel_join': request.path,
       'channel_part': request.path,
       'channel_post': request.path,
       }
      )

  if handled:
    return handled

  page = util.paging_get_page(request)
  more = page+1

  try:
    entries = twitter.twitter_search(request, '#%s' % _nick, page)
    twitter_error = False
  except:
    entries = []
    twitter_error = True

  if not twitter_error:
    size_entries = len(entries)

  user_can_post, user_is_admin = _user_permissions(request, view)
  
  for entry in entries:
    entry['source'] =util.htmlentities_decode(entry.get('source'))

  # for sidebar_members
  members_count = view.extra['member_count']
  members_more = members_count > CONTACTS_PER_PAGE
  
  members = api.channel_get_members(request.user, channel=view.nick)
  actors = api.actor_get_actors(request.user, members)
  members = [actors[x] for x in members if actors[x]]

  if(request.user):
    channels = api.actor_get_channels_member(request.user, request.user.nick,
                              limit=(CHANNELS_SIDEBAR + 1))
  else:
    channels = []

  childs = api.channel_get_related(request.user, view)
  
  area = 'channel'
  tab = 'channel-twitter'

  green_top = True
  sidebar_green_top = True

  c = template.RequestContext(request, locals())
  t = loader.get_template('channel/templates/twitter.html')
  return http.HttpResponse(t.render(c))
Esempio n. 16
0
def channel_settings(request, nick, page='index'):
  nick = clean.channel(nick)

  view = api.actor_lookup_nick(request.user, nick)

  if not view:
    # Channel doesn't exist, bounce the user back so they can create it.
    # If the channel was just deleted, don't.  This unfortunately, misses the
    # case where a user is attempting to delete a channel that doesn't
    # exist.
    return http.HttpResponseRedirect('/channel/%s' % nick)

  handled = common_views.handle_view_action(
      request,
      {
        'channel_update': request.path,
        'actor_remove' : '/channel',
      }
  )
  if page == 'photo' and not handled:
    handled = common_views.common_photo_upload(request, request.path, nick)
  if page == 'design' and not handled:
    handled = common_views.common_design_update(request, nick)

  if handled:
    return handled

  area = 'settings'
  avatars = display.DEFAULT_AVATARS
  actor_url = '/channel/%s' % nick

  if page == 'index':
    pass
  elif page == 'badge':
    badges = [{'id': 'badge-stream',
               'width': '200',
               'height': '300',
               'src': '%sglobal/themes/%s/badge.swf' % (settings.MEDIA_URL, settings.DEFAULT_THEME),
               'title': 'Stream',
               },
              {'id': 'badge-map',
               'width': '200',
               'height': '255',
               'src': '%sglobal/themes/%s/badge-map.swf' % (settings.MEDIA_URL, settings.DEFAULT_THEME),
               'title': 'Map',
               },
              {'id': 'badge-simple',
               'width': '200',
               'height': '200',
               'src': '%sglobal/themes/%s/badge-simple.swf' % (settings.MEDIA_URL, settings.DEFAULT_THEME),
               'title': 'Simple',
               },
              ]
  elif page == 'delete':
    pass
  elif page == 'design':
    pass
  elif page == 'details':
    pass
  elif page == 'photo':
    pass
  else:
    return common_views.common_404(request)

  # full_page adds the title of the sub-component.  Not useful if it's the
  # main settings page
  if page != 'index':
    full_page = page.capitalize()
    
  # rendering
  c = template.RequestContext(request, locals())
  t = loader.get_template('channel/settings_%s.html' % page)
  
  import logging
  logging.debug(page)
  import logging
  logging.debug(t)
  return http.HttpResponse(t.render(c))
Esempio n. 17
0
def channel_item(request, nick, item=None, format='html'):
    nick = clean.channel(nick)
    view = api.actor_lookup_nick(request.user, nick)

    if not view:
        raise http.Http404()

    stream_ref = api.stream_get_presence(request.user, view.nick)

    entry = '%s/%s' % (stream_ref.key().name(), item)

    entry_ref = api.entry_get(request.user, entry)
    if not entry_ref:
        raise http.Http404()

    handled = common_views.handle_view_action(
        request, {
            'entry_add_comment': entry_ref.url(request=request),
            'entry_remove': view.url(request=request),
            'entry_remove_comment': entry_ref.url(request=request),
            'entry_mark_as_spam': entry_ref.url(request=request)
        })
    if handled:
        return handled

    admins = api.channel_get_admins(request.user, channel=view.nick)
    user_is_admin = request.user and request.user.nick in admins

    comments = api.entry_get_comments(request.user, entry)

    actor_nicks = [entry_ref.owner, entry_ref.actor
                   ] + [c.actor for c in comments]
    actors = api.actor_get_actors(request.user, actor_nicks)

    # Creates a copy of actors with lowercase keys (Django #6904: template filter
    # dictsort sorts case sensitive), excluding channels and the currently
    # logged in user.
    participants = {}
    for k, v in actors.iteritems():
        if (v and not v.is_channel()
                and not (hasattr(request.user, 'nick')
                         and request.user.nick == v.nick)):
            participants[k.lower()] = v

    # display munge
    entry = display.prep_entry(entry_ref,
                               {stream_ref.key().name(): stream_ref}, actors)
    comments = display.prep_comment_list(comments, actors)

    # config for template
    green_top = True
    sidebar_green_top = True

    # rendering
    c = template.RequestContext(request, locals())
    if format == 'html':
        t = loader.get_template('channel/templates/item.html')
        return http.HttpResponse(t.render(c))
    elif format == 'json':
        t = loader.get_template('actor/templates/item.json')
        r = http.HttpResponse(t.render(c))
        r['Content-type'] = 'text/javascript'
        return r