def actor_settings(request, nick, page='index'): """ just a static page that links to the rest""" nick = clean.nick(nick) view = api.actor_lookup_nick(api.ROOT, nick) if not api.actor_owns_actor(request.user, view): raise exception.ApiException(exception.PRIVACY_ERROR, 'Operation not allowed') logging.info('Actor settings') handled = common_views.handle_view_action( request, { 'activation_activate_mobile': view.url('/settings/mobile'), 'activation_request_email': view.url('/settings/email'), 'activation_request_mobile': view.url('/settings/mobile'), 'settings_change_notify': view.url('/settings/notifications'), 'settings_change_privacy': request.path, 'settings_update_account': view.url('/settings/profile'), 'actor_remove': '/logout', #'oauth_remove_consumer': request.path, #'oauth_remove_access_token': request.path } ) if handled: return handled # TODO(tyler/termie): This conflicts with the global settings import. # Also, this seems fishy. Do none of the settings.* items work in templates? import settings is_admin_user = request.user.nick in settings.ADMINS_POBOX # TODO(tyler): Merge this into handle_view_action, if possible if 'password' in request.POST: try: validate.nonce(request, 'change_password') password = request.POST.get('password', '') confirm = request.POST.get('confirm', '') validate.password_and_confirm(password, confirm, field = 'password') api.settings_change_password(request.user, view.nick, password) response = util.RedirectFlash(view.url() + '/settings/password', 'Password updated') request.user.password = util.hash_password(request.user.nick, password) # TODO(mikie): change when cookie-auth is changed user.set_user_cookie(response, request.user) return response except: exception.handle_exception(request) if page == 'feeds': try: if not settings.FEEDS_ENABLED: raise exception.DisabledFeatureError('Feeds are currently disabled') except: exception.handle_exception(request) if page == 'photo': redirect_to = view.url() + '/settings/photo' handled = common_views.common_photo_upload(request, redirect_to) if handled: return handled area = 'settings' full_page = page.capitalize() if page == 'mobile': full_page = 'Mobile Number' mobile = api.mobile_get_actor(request.user, view.nick) sms_notify = view.extra.get('sms_notify', False) elif page == 'im': full_page = 'IM Address' im_address = api.im_get_actor(request.user, view.nick) im_notify = view.extra.get('im_notify', False) elif page == 'index': email = api.email_get_actor(request.user, view.nick) email_notify = view.extra.get('email_notify', False) im_address = api.im_get_actor(request.user, view.nick) im_notify = view.extra.get('im_notify', False) elif page == 'feeds': full_page = 'Web Feeds' elif page == 'email': full_page = 'Email Address' email_notify = view.extra.get('email_notify', False) # check if we already have an email email = api.email_get_actor(request.user, view.nick) # otherwise look for an unconfirmed one if not email: unconfirmeds = api.activation_get_actor_email(api.ROOT, view.nick) if unconfirmeds: unconfirmed_email = unconfirmeds[0].content elif page == 'design': handled = common_views.common_design_update(request, view.nick) if handled: return handled full_page = 'Look and Feel' elif page == 'notifications': email = api.email_get_actor(request.user, view.nick) email_notify = view.extra.get('email_notify', False) im_address = api.im_get_actor(request.user, view.nick) im_notify = view.extra.get('im_notify', False) mobile = api.mobile_get_actor(request.user, request.user.nick) sms_notify = view.extra.get('sms_notify', False) sms_confirm = sms_notify and not view.extra.get('sms_confirmed', False) # TODO(termie): remove this once we can actually receive sms sms_confirm = False bio = view.extra.get('bio', False) elif page == 'twitter': unauth = twitter.is_unauth(request) if not unauth: if request.POST: cc_twitter = request.POST.get('cc_twitter', False) and True api.settings_twitter_settings(request.user, view.nick, cc_twitter=cc_twitter) response = util.RedirectFlash(view.url() + '/settings/twitter', 'Twitter options updated') return response else: post = False twitter_options = view.extra.get('twitter_settings', {'cc_twitter':True}) elif page == 'profile': # check if we already have an email email = api.email_get_actor(request.user, view.nick) # otherwise look for an unconfirmed one if not email: unconfirmeds = api.activation_get_actor_email(api.ROOT, view.nick) if unconfirmeds: unconfirmed_email = unconfirmeds[0].content elif page == 'photo': avatars = display.DEFAULT_AVATARS small_photos = api.image_get_all_keys(request.user, view.nick, size='f') # TODO(tyler): Fix this avatar nonsense! own_photos = [{ 'path' : small_photo.key().name(), 'name' : small_photo.key().name()[len('image/'):-len('_f.jpg')], } for small_photo in small_photos ] elif page == 'privacy': PRIVACY_PUBLIC = api.PRIVACY_PUBLIC PRIVACY_CONTACTS = api.PRIVACY_CONTACTS elif page == 'jsbadge': full_page = 'Javascript Badges' 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 in ['password', 'delete']: # Catch for remaining pages before we generate a 404. pass elif page == 'tags_rel': if request.method == 'GET' and 'new' in request.GET: form = request.GET['new'] if form == 'newtag' or form == 'modtag': tags = api.site_get_tags(request.user) elif request.method == 'POST': back_page = request.POST['backpage'] if back_page == 'newtag': parent = request.POST['parent'] sons = request.POST['sons'].strip() sons = sons.split() api.new_tags_relation(parent, sons) elif back_page == 'modtag': parent_old = request.POST['parent_old'] parent_new = request.POST['parent_new'] son = request.POST['son'] api.mod_tags_relation(parent_old, parent_new, son) else: return common_views.common_404(request) # rendering c = template.RequestContext(request, locals()) t = loader.get_template('actor/templates/settings_%s.html' % page) return http.HttpResponse(t.render(c))
def explore_recent(request, format="html"): if request.user: view = request.user logging.info("entering here") #twitter unauth = twitter.is_unauth(request) if 'twitter' in request.POST: if unauth: return http.HttpResponseRedirect('/twitter/auth?redirect_to=/') status = twitter.post_update(request) if status: flasherror = ["We have experimented some problems trying to post a cc in twitter"] handled = common_views.handle_view_action( request, { 'entry_remove': request.path, 'entry_remove_comment': request.path, 'entry_mark_as_spam': request.path, 'actor_add_contact': request.path, 'actor_remove_contact': request.path, 'post': request.path, 'presence_set': request.path, } ) if handled: return handled subtab = 'explore' per_page = ENTRIES_PER_PAGE offset, prev = util.page_offset(request) inbox = api.inbox_get_explore(request, limit=(per_page + 1), offset=offset) entries, more = helper.get_inbox_entries(request, inbox) stream_keys = [e.stream for e in entries] streams = api.stream_get_streams(request.user, stream_keys) actor_nicks = [e.owner for e in entries] + [e.actor for e in entries] actors = api.actor_get_actors(request.user, actor_nicks) # here comes lots of munging data into shape entries = prep_entry_list(entries, streams, actors) if request.user: channels_count = view.extra.get('channel_count', 0) channels_more = channels_count > CHANNELS_PER_PAGE followers_count = view.extra.get('follower_count', 0) contacts_count = view.extra.get('contact_count', 0) contacts_more = contacts_count > CONTACTS_PER_PAGE contact_nicks = api.actor_get_contacts_safe(request.user, view.nick, limit=CONTACTS_PER_PAGE) contacts = api.actor_get_actors(request.user, contact_nicks) contacts = [contacts[x] for x in contact_nicks if contacts[x]] green_top = True sidebar_green_top = True # END inbox generation chaos area = 'explore' actor_link = True c = template.RequestContext(request, locals()) if format == 'html': t = loader.get_template('explore/templates/recent.html') return http.HttpResponse(t.render(c)); elif format == 'json': t = loader.get_template('explore/templates/recent.json') r = util.HttpJsonResponse(t.render(c), request) return r elif format == 'atom': t = loader.get_template('explore/templates/recent.atom') r = util.HttpAtomResponse(t.render(c), request) return r elif format == 'rss': t = loader.get_template('explore/templates/recent.rss') r = util.HttpRssResponse(t.render(c), request) return r
def actor_mentions(request, nick, format='html'): nick = clean.nick(nick) view = api.actor_lookup_nick(request.user, nick) if not view: raise exception.UserDoesNotExistError(nick, request.user) if not request.user or view.nick != request.user.nick: return http.HttpResponseRedirect(view.url()) unauth = twitter.is_unauth(request) twitter_options = twitter.twitter_options(request) if 'twitter' in request.POST: if unauth: return http.HttpResponseRedirect('/twitter/auth?redirect_to=/%s/mentions' % view.display_nick()) status = twitter.post_update(request) if status: flasherror = ["We have experimented some problems trying to post a cc in twitter"] handled = common_views.handle_view_action( request, { 'entry_remove': request.path, 'entry_remove_comment': request.path, 'entry_mark_as_spam': request.path, 'presence_set': request.path, 'settings_hide_comments': request.path, 'post': request.path, } ) if handled: return handled per_page = ENTRIES_PER_PAGE offset, prev = util.page_offset(request) inbox = api.inbox_get_actor_mentions(request.user, view.nick, limit=(per_page + 1), offset=offset) # START inbox generation chaos # TODO(termie): refacccttttooorrrrr entries = api.entry_get_entries(request.user, inbox) #begin @zero code #if view.extra.get('comments_hide', 0): # TODO(tyler): This is certainly not the most eloquent way to filter # through entries to remove comments. # entries = [x for x in entries if not x.stream.endswith('comments')] entries = api.filter_entries_mentions(request.user, entries, view.nick) 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, limit=CONTACTS_PER_PAGE) actor_nicks = (contact_nicks + [view.nick] + [s.owner for s in streams.values()] + [e.owner for e in entries] + [e.actor for e in entries]) actors = api.actor_get_actors(request.user, actor_nicks) channels = api.actor_get_channels_member(request.user, view.nick, limit=(CHANNELS_PER_PAGE + 1)) # here comes lots of munging data into shape # clear deleted contacts 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) # END inbox generation chaos # Check for unconfirmed emails unconfirmeds = api.activation_get_actor_email(request.user, view.nick) if unconfirmeds: unconfirmed_email = unconfirmeds[0].content # If not logged in, cannot write is_owner = False try: is_owner = view.nick == request.user.nick except: pass presence = api.presence_get(request.user, view.nick) # for sidebar streams view_streams = dict([(x.key().name(), streams[x.key().name()]) for x in actor_streams]) channels_count = view.extra.get('channel_count', 0) channels_more = channels_count > CHANNELS_PER_PAGE followers_count = view.extra.get('follower_count', 0) # for sidebar_contacts contacts_count = view.extra.get('contact_count', 0) contacts_more = contacts_count > CONTACTS_PER_PAGE # Config for the template green_top = True sidebar_green_top = True selectable_icons = display.SELECTABLE_ICONS area = 'mentions' subtab = 'mentions' # TODO(tyler/termie): This conflicts with the global settings import. # Also, this seems fishy. Do none of the settings.* items work in templates? import settings c = template.RequestContext(request, locals()) if format == 'html': t = loader.get_template('actor/templates/mentions.html') return http.HttpResponse(t.render(c))
def actor_twitter(request, nick, format='html'): nick = clean.nick(nick) view = api.actor_lookup_nick(request.user, nick) if not view: raise exception.UserDoesNotExistError(nick, request.user) if not request.user or view.nick != request.user.nick: # Instead of displaying the twitter tab, redirect to the public-facing page return http.HttpResponseRedirect(view.url()) unauth = twitter.is_unauth(request) if unauth: return http.HttpResponseRedirect('/twitter/auth?redirect_to=/%s/twitter' % view.display_nick()) unauth = twitter.is_unauth(request) twitter_options = twitter.twitter_options(request) if 'twitter' in request.POST: if unauth: return http.HttpResponseRedirect('/twitter/auth?redirect_to=/%s/mentions' % view.display_nick()) status = twitter.post_update(request) if status: flasherror = ["We have experimented some problems trying to post a cc in twitter"] logging.info('Twitter request.path: %s' % request.path) handled = common_views.handle_view_action( request, { 'post': request.path, } ) logging.info('handled: %s' % handled) if handled: return handled more = False page = util.paging_get_page(request) size_entries = ENTRIES_PER_PAGE+ENTRIES_PER_PAGE*(page-1) #Getting Entries twitter_error = False try: user_info, streams = twitter.twitter_get_entries(request, size_entries+1) except: twitter_error = True if not twitter_error: if len(streams) > ENTRIES_PER_PAGE: streams = streams[0:-1] entry_id = streams[size_entries-1].id more = page+1 size_stream = len(streams) green_top = True sidebar_green_top = True area = 'actor-twitter' subtab = 'twitter' c = template.RequestContext(request, locals()) if format == 'html': t = loader.get_template('actor/templates/twitter_tab.html') return http.HttpResponse(t.render(c))
def actor_overview(request, nick, format='html'): nick = clean.nick(nick) view = api.actor_lookup_nick(request.user, nick) if not view: raise exception.UserDoesNotExistError(nick, request.user) if not request.user or view.nick != request.user.nick: # Instead of displaying the overview, redirect to the public-facing page return http.HttpResponseRedirect(view.url()) unauth = twitter.is_unauth(request) twitter_options = twitter.twitter_options(request) if 'twitter' in request.POST: if unauth: return http.HttpResponseRedirect('/twitter/auth?redirect_to=/%s/overview' % view.display_nick()) status = twitter.post_update(request) if status: flasherror = ["We have experimented some problems trying to post a cc in twitter"] logging.info('Overview request.path: %s' % request.path) handled = common_views.handle_view_action( request, { 'entry_remove': request.path, 'entry_remove_comment': request.path, 'entry_mark_as_spam': request.path, 'presence_set': request.path, 'settings_hide_comments': request.path, 'post': request.path, } ) logging.info('handled: %s' % handled) if handled: return handled per_page = ENTRIES_PER_PAGE offset, prev = util.page_offset(request) inbox = api.inbox_get_actor_overview(request.user, view.nick, limit=(per_page + 1), offset=offset) actor_streams = api.stream_get_actor(request.user, view.nick) entries, more = helper.get_inbox_entries(request, inbox, False, per_page, True, view) contacts, channels, streams, entries = helper.assemble_inbox_data(request, entries, actor_streams, view) latest = api.inbox_get_actor_private(request.user, view.nick, per_page) latest = api.entry_get_entries(request.user, latest) if len(latest) > 0: latest = latest[0] # Check for unconfirmed emails unconfirmeds = api.activation_get_actor_email(request.user, view.nick) if unconfirmeds: unconfirmed_email = unconfirmeds[0].content first_time, emailform = api.is_first_time(request.user, view.nick) loadmodal = first_time # If not logged in, cannot write is_owner = False try: is_owner = view.nick == request.user.nick except: pass presence = api.presence_get(request.user, view.nick) # for sidebar streams view_streams = dict([(x.key().name(), streams[x.key().name()]) for x in actor_streams]) #@begin zero code OVERVIEW # for sidebar info channels_count = view.extra.get('channel_count', 0) channels_more = channels_count > CHANNELS_PER_PAGE followers_count = view.extra.get('follower_count', 0) #@end # for sidebar_contacts contacts_count = view.extra.get('contact_count', 0) contacts_more = contacts_count > CONTACTS_PER_PAGE # Config for the template green_top = True sidebar_green_top = True selectable_icons = display.SELECTABLE_ICONS actor_link = True area = 'home' subtab = 'overview' # TODO(tyler/termie): This conflicts with the global settings import. # Also, this seems fishy. Do none of the settings.* items work in templates? c = template.RequestContext(request, locals()) if format == 'html': t = loader.get_template('actor/templates/overview.html') r = http.HttpResponse(t.render(c)) elif format == 'json': t = loader.get_template('actor/templates/overview.json') r = util.HttpJsonResponse(t.render(c), request) elif format == 'atom': t = loader.get_template('actor/templates/overview.atom') r = util.HttpAtomResponse(t.render(c), request) elif format == 'rss': t = loader.get_template('actor/templates/overview.rss') r = util.HttpRssResponse(t.render(c), request) return r
def actor_history(request, nick=None, format='html'): nick = clean.nick(nick) view = api.actor_lookup_nick(request.user, nick) if not view: raise exception.UserDoesNotExistError(nick, request.user) #twitter unauth = twitter.is_unauth(request) if 'twitter' in request.POST: if unauth: return http.HttpResponseRedirect('/twitter/auth?redirect_to=/') status = twitter.post_update(request) if status: flasherror = ["We have experimented some problems trying to post a cc in twitter"] called_subscribe, sub_ref = common_views.call_api_from_request( request, 'subscription_request') if called_subscribe: if sub_ref.state == 'subscribed': message = 'Subscribed.' else: message = 'Subscription requested.' return util.RedirectFlash(view.url(), message) handled = common_views.handle_view_action( request, { 'entry_remove': request.path, 'entry_remove_comment': request.path, 'entry_mark_as_spam': request.path, 'subscription_remove': view.url(), 'actor_add_contact': request.path, 'actor_remove_contact': request.path, 'post': request.path, 'presence_set': request.path, } ) if handled: return handled privacy = 'public' if request.user: if view.nick == request.user.nick: privacy = 'private' # ROOT because we care whether or not request.user is a contact of # the view user's, not whether the request.user can see the contacts elif api.actor_has_contact(api.ROOT, view.nick, request.user.nick): privacy = 'contacts' # we're going to hide a bunch of stuff if this user is private and we # aren't allowed to see user_is_private = False if view.privacy < models.PRIVACY_PUBLIC and privacy == 'public': user_is_private = True per_page = ENTRIES_PER_PAGE offset, prev = util.page_offset(request) if privacy == 'public': if user_is_private: inbox = [] else: 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(request.user, view.nick, limit=(per_page + 1), offset=offset) actor_streams = api.stream_get_actor_safe(request.user, view.nick) entries, more = helper.get_inbox_entries(request, inbox) contacts, channels, streams, entries = helper.assemble_inbox_data(request, entries, actor_streams, view) # If not logged in, cannot write is_owner = request.user and view.nick == request.user.nick try: presence = api.presence_get(request.user, view.nick) presence_stream = api.stream_get_presence(request.user, view.nick) last_entry = api.entry_get_last(request.user, presence_stream.keyname()) view.last_entry = last_entry except exception.ApiException: pass # for add/remove contact if request.user: user_is_contact = api.actor_has_contact(request.user, request.user.nick, view.nick) view.my_contact = user_is_contact else: user_is_contact = False show_dm_link = False if request.user: friends_keys = api.actor_get_followers(api.ROOT, request.user.nick, limit=200) if view.nick in friends_keys: show_dm_link = True #@begin zero code HISTORY # for sidebar info channels_count = view.extra.get('channel_count', 0) channels_more = channels_count > CHANNELS_PER_PAGE followers_count = view.extra.get('follower_count', 0) #@end # for sidebar_contacts contacts_count = view.extra.get('contact_count', 0) contacts_more = contacts_count > CONTACTS_PER_PAGE # Config for the template green_top = True sidebar_green_top = True selectable_icons = display.SELECTABLE_ICONS area = 'user' subtab = 'profile' hide_avatar = True c = template.RequestContext(request, locals()) if format == 'html': t = loader.get_template('actor/templates/history.html') return http.HttpResponse(t.render(c)) elif format == 'json': t = loader.get_template('actor/templates/history.json') r = util.HttpJsonResponse(t.render(c), request) return r elif format == 'atom': t = loader.get_template('actor/templates/history.atom') r = util.HttpAtomResponse(t.render(c), request) return r elif format == 'rss': t = loader.get_template('actor/templates/history.rss') r = util.HttpRssResponse(t.render(c), request) return r
def hashtag_search(request, tag=''): view = request.user page = util.paging_get_page(request) if view is not None: unauth = twitter.is_unauth(request) twitter_options = twitter.twitter_options(request) if 'twitter' in request.POST: if unauth: return http.HttpResponseRedirect('/twitter/auth?redirect_to=/%s/overview' % view.display_nick()) status = twitter.post_update(request) if status: flasherror = ["We have experimented some problems trying to post a cc in twitter"] handled = common_views.handle_view_action( request, { 'entry_remove': request.path, 'entry_remove_comment': request.path, 'entry_mark_as_spam': request.path, 'presence_set': request.path, 'settings_hide_comments': request.path, 'post': '/%s/overview' % view.display_nick(), } ) logging.info('handled: %s' % handled) if handled: return handled q = request.GET.get('q', None) if q is not None: result = hashtag_re.search(q) if result: tag = result.groupdict()['tag'] else: tag = q hashtag_match = tag_re.search(tag) if hashtag_match: match_dict = hashtag_match.groupdict() tag = '#'+match_dict['tag'].lower() limit = ENTRIES_PER_PAGE+ENTRIES_PER_PAGE*(page-1) more, relations = api.hashtag_get_relations( request.user, tag, limit) entries = api.hashtag_get_entries(request.user, [relation.uuid for relation in relations]) entries = api.entry_get_entries(request.user, [entry.key().name() for entry in entries]) stream_keys = [e.stream for e in entries] try: actor_streams = api.stream_get_actor(request.user, view.nick) except exception.ApiException: actor_streams = [] except: actor_streams = [] stream_keys += [s.key().name() for s in actor_streams] streams = api.stream_get_streams(request.user, stream_keys) try: contact_nicks = api.actor_get_contacts(request.user, view.nick, limit=CONTACTS_PER_PAGE) except exception.ApiException: contact_nicks = [] except: contact_nicks = [] actor_nicks = (contact_nicks + [s.owner for s in streams.values()] + [e.owner for e in entries] + [e.actor for e in entries]) actors = api.actor_get_actors(request.user, actor_nicks) 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) if more: last = entries[len(entries)-1].uuid else: entries = [] try: contact_nicks = api.actor_get_contacts(request.user, view.nick, limit=CONTACTS_PER_PAGE) except exception.ApiException: contact_nicks actor_nicks = (contact_nicks) actors = api.actor_get_actors(request.user, actor_nicks) contacts = [actors[x] for x in contact_nicks if actors[x]] is_owner = True if view is not None: channels_count = view.extra.get('channel_count', 0) channels_more = channels_count > CHANNELS_PER_PAGE followers_count = view.extra.get('follower_count', 0) contacts_count = view.extra.get('contact_count', 0) channels = api.actor_get_channels_member(request.user, view.nick, limit=(CHANNELS_PER_PAGE + 1)) templatebase = 'common/templates/base_sidebar.html' else: templatebase = 'common/templates/base_single.html' green_top = True sidebar_green_top = True next = page+1 actor_link = True c = template.RequestContext(request, locals()) t = loader.get_template('hashtag/templates/hashtag_search.html') return http.HttpResponse(t.render(c))
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