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) 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 # 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, nick, password) response = util.RedirectFlash(view.url() + '/settings/password', 'password updated') request.user.password = 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, request.user.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, 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 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': '%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 in ['password', 'delete']: # Catch for remaining pages before we generate a 404. pass else: return common_views.common_404(request) # rendering c = template.RequestContext(request, locals()) t = loader.get_template('settings_%s.html' % page) 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()) 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_overview(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) 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')] 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) # 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]) # 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 = 'home' # 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('overview.html') return http.HttpResponse(t.render(c)) elif format == 'json': t = loader.get_template('overview.json') r = util.HttpJsonResponse(t.render(c), request) return r elif format == 'atom': t = loader.get_template('overview.atom') r = util.HttpAtomResponse(t.render(c), request) return r elif format == 'rss': t = loader.get_template('overview.rss') r = util.HttpRssResponse(t.render(c), request) return r