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")
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))
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 """ tag = nick nick = clean.channel(nick) view = api.channel_get_safe(request.user, nick) if not view: return http.HttpResponseRedirect('/hashtag/%s' % tag) if not view.is_enabled(): return http.HttpResponseRedirect('/hashtag/%s' % tag) admins = api.channel_get_admins(request.user, channel=view.nick) members = api.channel_get_members(request.user, channel=view.nick) unauth = twitter.is_unauth(request) if 'twitter' in request.POST: if unauth: return http.HttpResponseRedirect('/twitter/auth?redirect_to=/channel/%s/twitter/' % _nick) success = twitter.post_update(request) 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, user_is_admin = _user_permissions(request, view) if user_can_post: privacy = 'contacts' if user_is_admin: privacy = 'private' 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 # for sidebar My Group POBoxes if(request.user): channels = api.actor_get_channels_member(request.user, request.user.nick, limit=(CHANNELS_SIDEBAR + 1)) else: channels = [] channels_count = view.extra.get('channel_count', 0) channels_more = channels_count > CHANNELS_PER_PAGE childs = api.channel_get_related(request.user, view) # config for templates green_top = True sidebar_green_top = True selectable_icons = display.SELECTABLE_ICONS actor_link = True # 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' tab = 'local' 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