Ejemplo n.º 1
0
def channel_search(request, format='html'):
  q = request.GET.get('q', None)
  page   = util.paging_get_page(request)
  type = request.GET.get('type', None)

  if q is not None:
    actors, size = api.channel_search(request.user, q, page, CHANNELS_PER_PAGE, type)
  else:
    actors, size = [], 0


  for c in actors:
    c.i_am_member = api.actor_is_a_member(request.user, request.user.nick, c.nick)
    c.tags_ref = api.channel_get_tags(request.user, c.tags)
    
  start, end, next, prev, first, last = util.paging(page, CHANNELS_PER_PAGE, size)

  offset_text = 'More'
  area = 'channel'

  base_url = '/channel/search/?q=%s' % q
  
  type_url = ''
  if type is not None:
    type_url = '&type=%s' % type

  channels_member = api.actor_get_channels_member(request.user, request.user.nick,
                                                  limit=(CHANNELS_PER_PAGE + 1))

  c = template.RequestContext(request, locals())
  # TODO(tyler): Other output formats.
  if format == 'html':
    t = loader.get_template('channel/templates/search.html')
    return http.HttpResponse(t.render(c))
Ejemplo n.º 2
0
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))