def channel_index(request, format='html'): """ the index page for channels, /channel should list the channels you administer, the channels you belong to and let you create new channels if you are not logged in, it should suggest that you log in to create or join channels and give a list of public channels """ if not request.user: return channel_index_signedout(request, format='html') owned_nicks = api.actor_get_channels_admin( request.user, request.user.nick, limit=(CHANNELS_PER_INDEX_PAGE + 1)) owned_more = len(owned_nicks) > CHANNELS_PER_INDEX_PAGE followed_nicks = api.actor_get_channels_member( request.user, request.user.nick, limit=(CHANNELS_PER_INDEX_PAGE + 1)) followed_more = len(owned_nicks) > CHANNELS_PER_INDEX_PAGE channel_nicks = owned_nicks + followed_nicks channels = api.channel_get_channels(request.user, channel_nicks) owned_channels = [channels[x] for x in owned_nicks if channels[x]] for c in owned_channels: c.i_am_admin = True followed_channels = [ channels[x] for x in followed_nicks if channels[x] and x not in owned_nicks ] for c in followed_channels: c.i_am_member = True try: # for the Our Picks section of the sidebar ourpicks_channels = api.actor_get_channels_member(request.user, api.ROOT.nick) ourpicks_channels = api.channel_get_channels(request.user, ourpicks_channels) ourpicks_channels = [x for x in ourpicks_channels.values() if x] except exception.ApiNotFound: pass related_tags = api.channel_get_children_tags(request.user) is_admin_user = request.user.nick in settings.ADMINS_POBOX area = 'channel' c = template.RequestContext(request, locals()) if format == 'html': t = loader.get_template('channel/templates/index.html') return http.HttpResponse(t.render(c))
def channel_browse(request, format='html', tagkey=None): per_page = CHANNELS_PER_PAGE page = util.paging_get_page(request) filter = util.paging_filter(request) type = util.paging_type(request) if request.user: view = request.user owner = api.actor_lookup_nick(view, util.get_owner(request)) else: view = api.ROOT owner = api.actor_lookup_nick(view, view.nick) nick = view.nick if filter == 'member': actors, size = api.channel_browse_tagkey(view, per_page, page, tagkey, type, nick) else: actors, size = api.channel_browse_tagkey(view, per_page, page, tagkey, type) start, end, next, prev, first, last = util.paging(page, per_page, size) for c in actors: if request.user: c.i_am_member = api.actor_is_a_member(request.user, request.user.nick, c.nick) else: c.i_am_member = False c.tags_ref = api.channel_get_tags(view, c.tags) if tagkey is not None: base_url = '/channel/browse%s?' % tagkey breadcrumb = channel_helper.get_breadcrumb(view, tagkey) else: base_url = '/channel?' filter_url = util.paging_url(filter, nick, owner.nick) type_url = '' if type is not None: type_url = '&type=%s' % type countries = api.tags_get_countries(view, util.get_metadata('DEFAULT_TAG')) if request.user: country_tag = request.user.extra.get('country_tag', '/tag_geo/North America/United States') else: country_tag = '/tag_geo/North America/United States' channel_nicks, other = api.channel_browse_tagkey(view, 5, 1, country_tag) related_tags = api.channel_get_children_tags(view, tagkey) related_tags = api.channel_get_tags(view, related_tags) show_tags_url = True channel_types = util.get_metadata('CHANNEL_TYPES') area = 'channel' c = template.RequestContext(request, locals()) # TODO(tyler): Other output formats. if format == 'html': t = loader.get_template('channel/templates/browse_tag.html') return http.HttpResponse(t.render(c))