def i18n_forwarding(request): """select display language""" if not valid_token(request): return token_splash_page(request) if request.user.is_authenticated(): user_profile = request.user.get_profile() restore_profile_from_session(request, user_profile) old_lang = user_profile.display_language lang_code = request.POST.get('language', None) if lang_code and check_for_language(lang_code): user_profile.display_language = lang_code if old_lang != user_profile.display_language: user_profile.notify_mailmanager ( user_profile.email,user_profile.email ) user_profile.save() request.session["display_language"] = user_profile.display_language return i18n.set_language(request)
def user(request, friend_id): """show friend profile""" if not valid_token(request): return token_splash_page(request) template_vars = {} user_ = request.user profile_ = user.get_profile() restore_profile_from_session(request, profile_) local_friends = profile_.friend_list(request.session, friend_type="local") remote_friends = profile_.friend_list(request.session, friend_type="remote") template_vars['user'] = user_ template_vars['profile'] = profile_ template_vars['localFriends'] = local_friends template_vars['remoteFriends'] = remote_friends template_vars['friend_id'] = friend_id found = False friend = None for frnd in local_friends: if frnd.profile.id == friend_id: template_vars['friend'] = frnd friend = frnd found = True friend_type = "local" break if not found: for i, frnd in enumerate(remote_friends): if frnd.profile.id == friend_id: template_vars['match_lang'] = profile.get_global_token(i) template_vars['friend'] = frnd friend = frnd found = True friend_type = "global" break if not found and friend_id == profile.id: class XFriend(object): """temporary friend class""" def __init__(self, prf): """init xfriend instance""" self.profile = prf me_as_friend = XFriend(profile_) template_vars['ownPage'] = True template_vars['friend'] = me_as_friend friend_type = choice(["global", "local"]) friend = me_as_friend found = True if found: template_vars['uniqueLanguages'] = friend.profile.getUniqueLanguages() template_vars['ownUniqueLanguages'] = profile_.getUniqueLanguages() template_path = 'user/user_found.html' template_vars['title'] = __('Friend') + ' ' + \ friend.profile.human_public_name() template_vars['use_maps_single'] = True template_vars['friendType'] = friend_type template_vars['cityDict'] = { 'latitude' : friend.profile.latitude, 'longitude' : friend.profile.longitude, } else: template_vars['title'] = \ __('Friend %(friend_id)s not found') % {'friend_id' : friend_id} template_path = 'user/user_not_found.html' return render_to_response( template_path, template_vars, context_instance=RequestContext(request) )
def profile(request): """show profile""" if not valid_token(request): return token_splash_page(request) user_ = request.user profile_ = user_.get_profile() restore_profile_from_session(request, profile_) # show the page in the user's language response = display_in_native_language(request, profile_) if response: return response template_path = 'user/profile.html' template_vars = {} template_vars['title'] = __('My Profile') if request.method == "POST": if settings.VERBOSE: print "POST on the profile. this is a Drop-attempt" password = request.POST.get("loginphrase", "") dropped_fid = request.POST.get('dropped_fid', None) reason = request.POST.get('reason', "") comment = request.POST.get('comment', "") reason_map = { "unresponsive":"nice", "differences":"middle", "rude":"bad", } if settings.VERBOSE: print "Trying to drop %s for reason %s with comment\n%s" \ % (dropped_fid, reason, comment) if user.check_password(password): if dropped_fid is not None and reason in reason_map: reason = reason_map[reason] dropped = profile_.defriend(dropped_fid, reason, comment) if dropped: populate_session(request, password) if dropped_fid in request.session: del request.session[dropped_fid] template_vars['droppedFriend'] = dropped_fid template_vars['message'] = \ __('Your contact has been dropped. ' 'We will find you another one soon.') if settings.VERBOSE: print "Drop successful." elif settings.VERBOSE: print "Drop failed: Wrong password" template_vars['user'] = user_ template_vars['profile'] = profile_ template_vars['localFriends'] = \ profile_.friend_list(request.session, friend_type="local") + \ request.session.get("display_local", []) template_vars['remoteFriends'] = \ profile_.friend_list(request.session, friend_type="remote") + \ request.session.get("display_remote", []) template_vars['ownUniqueLanguages'] = \ set(profile_.get_unique_languages()) template_vars['newFriends'] = request.session.get("new_friends", []) template_vars['use_maps_multiple'] = True if request.session.get("changes_saved", False): template_vars['success_message'] = __("Changes saved.") del request.session['changes_saved'] if settings.VERBOSE: print "============SESSION DUMP============" for key, value in request.session.items(): print key, smart_str(value) return render_to_response( template_path, template_vars, context_instance=RequestContext(request) )
def edit(request, clicked): """edit profile""" if not valid_token(request): return token_splash_page(request) template_vars = {} if request.method == "POST": loginphrase = request.POST.get("password","") password = get_password_from_loginphrase(loginphrase) if request.user.check_password(password): if edit_captcha_ok(request): validation_errors = contactinfo_errors(request) or \ aboutme_errors(request) or \ location_errors(request) or \ language_errors(request) or \ email_errors(request) or None if validation_errors: validation_errors = ([contactinfo_errors(request)] + \ [aboutme_errors(request)] + \ [location_errors(request)] + \ [language_errors(request)] + \ [email_errors(request)]) for val_error in validation_errors: if val_error is not None: template_vars[val_error[-1]] = val_error[2] else: save_edited_info(request) # Get the newly encrypted data into the session again populate_session(request, password) return HttpResponseRedirect( reverse('user.views.profile_forwarding') ) else: template_vars["captchaerror"] = True template_vars["captcha"] = CaptchaTestForm(request.POST) else: template_vars["passworderror"] = __("Wrong passphrase.") else: if edit_needs_captcha(request): template_vars["captcha"] = CaptchaTestForm() template_vars['contact_info'] = request.POST.get("contact_info", False) template_vars['about_me'] = request.POST.get("about_me", False) template_vars['email'] = request.POST.get("email", False) template_vars['user'] = request.user profile_ = request.user.get_profile() restore_profile_from_session(request, profile_) template_vars['profile'] = profile_ for num, lang in enumerate(profile_.get_langs_spoken()): template_vars['lang_'+str(num)] = \ request.POST.get("lang_" + str(num), lang) template_vars['use_maps_single'] = True template_vars['cityDict'] = { 'latitude' : request.POST.get("latitude", profile_.latitude), 'longitude' : request.POST.get("longitude", profile_.longitude), } template_vars["clicked"] = clicked template_vars['title'] = __('Edit the information about you') template_path = "user/edit_profile.html" return render_to_response(template_path, template_vars, context_instance=RequestContext(request))