def handle(request):
    myself = siteaction.getLoggedInUser(request)
    if not myself:
        return HttpResponseRedirect('/login.htm')

    if request.method == 'GET':      
        action_result = ''
        if dataplus.dictGetVal(request.REQUEST, 'flashId'):
            action_result = dataplus.dictGetVal(statix.action_messages, dataplus.dictGetVal(request.REQUEST, 'flashId'), '')
            
        myself.image_url = dataplus.getStaticUrl(myself.image_size3_file_path)
        return siteaction.render_to_response('me/changephoto.htm', { 'action_result':action_result, 'myself':myself})
    elif request.method == 'POST':
        success, error_code, img1, img2, img3, img4 = studio.saveImage_x4_ByDate(request, 'user_' + myself.username, 'photograph')
        if success:
            if myself.image_file_path != img1:
                iolib.deleteFiles([myself.image_file_path, myself.image_size1_file_path, \
                        myself.image_size2_file_path, myself.image_size3_file_path])
                myself.image_file_path = img1
                myself.image_size1_file_path = img2
                myself.image_size2_file_path = img3
                myself.image_size3_file_path = img4
                myself.save()
                
                chat_settings = models.ChatSettings.objects.get(account=myself.account)
                chat_settings.image_size1_file_path = img2
                chat_settings.image_size2_file_path = img3
                chat_settings.image_size3_file_path = img4
                chat_settings.save()
                session_id = request.COOKIES['session_id']
                siteaction.updateLivewireData(session_id, myself.account)
        else:
            return HttpResponseRedirect('/me/changephoto.htm?flashId=' + error_code)
        
        return HttpResponseRedirect('/me/?flashId=usrpic_chnged')
def handle(request): 
    try:
        account = siteaction.getLoggedInAccount(request)
        if not account:
            return ajaxian.getFailureResp('not_logged_in')
        
        status = dataplus.dictGetSafeVal(request.REQUEST,'status','everyone')
        cs = models.ChatSettings.objects.get(account=account)
        cs.online_status = status
        cs.save()
        
        session_id = request.COOKIES['session_id']
        siteaction.updateLivewireData(session_id, account)
        
        return ajaxian.getSuccessResp('')
    except:
        return ajaxian.getFailureResp('unknown')
def handle(request):
    myself = siteaction.getLoggedInUser(request)
    if not myself:
        return HttpResponseRedirect('/login.htm')
    
    user_settings = models.UserSettings.objects.get(user=myself)
    chat_settings = models.ChatSettings.objects.get(account=myself.account)
        
    if request.method == 'GET':
        action_result = ''
        if dataplus.dictGetVal(request.REQUEST, 'flashId'):
            action_result = dataplus.dictGetVal(statix.action_messages, dataplus.dictGetVal(request.REQUEST, 'flashId'), '')
        
        online_status_select_html = hotmetal.elemSelect([('Everyone', 'everyone'), ('Friends only', 'friends'), ('Nobody', 'nobody')], [],
            lambda x:x[0], lambda x:x[1], chat_settings.online_status, 'name="online_status" id="online_status" style="width:160px;"')
        
        invite_preference_select_html = hotmetal.elemSelect([('Everyone', 'everyone'), ('Friends only', 'friends'), ('Nobody', 'nobody')], [],
            lambda x:x[0], lambda x:x[1], chat_settings.invite_preference, 'name="invite_preference" id="invite_preference" style="width:160px;"')
            
        ignored_usernames = chat_settings.ignore_list.split(',')
        ignored_accounts = []
        for username in ignored_usernames:
            try:
                ignored_accounts.append(models.Account.objects.get(username=username))
            except:
                pass
        
        ignore_list_select_html = hotmetal.elemSelect([], ignored_accounts,
            lambda x:x.name + ' (' + x.username + ')', lambda x:x.username, '', 'name="ignore_list_select" id="ignore_list_select" size="8" multiple="multiple" style="width:240px;"')
            
        skype_username = ''
        yahoo_username = ''
        for msnger in models.WebMessenger.objects.filter(account=myself.account):
            if msnger.provider == 'skype':  skype_username = msnger.username
            elif msnger.provider == 'yahoo':  yahoo_username = msnger.username
        
        return siteaction.render_to_response('me/editconnectsettings.htm',
        {'online_status_select_html': online_status_select_html,
         'custom_message': chat_settings.custom_message,
         'invite_preference_select_html': invite_preference_select_html, 
         'ignore_list_select_html': ignore_list_select_html, 
         'phone': dataplus.replaceNull(myself.phone, ''),
         'enable_voip_dial': dataplus.conditionalValue(lambda: user_settings.enable_voip_dial == True, 'checked="checked"', ''),
         'skype_username':skype_username,
         'yahoo_username':yahoo_username,
         'blog_url': dataplus.replaceNull(myself.blog_url, ''),
         'action_result':action_result,
         'myself': myself})
        
    elif request.method == 'POST':            
        action = dataplus.dictGetVal(request.REQUEST, 'action')
        if action == 'save_chat_settings':
            chat_settings.online_status = dataplus.dictGetSafeVal(request.REQUEST, 'online_status')
            chat_settings.custom_message = dataplus.dictGetSafeVal(request.REQUEST, 'custom_message')
            chat_settings.invite_preference = dataplus.dictGetSafeVal(request.REQUEST, 'invite_preference')
            chat_settings.ignore_list = dataplus.dictGetSafeVal(request.REQUEST, 'ignore_list')
            chat_settings.save()
        
            session_id = request.COOKIES['session_id']
            siteaction.updateLivewireData(session_id, myself.account)
        
        elif action == 'save_telephone_settings':
            myself.phone = dataplus.dictGetSafeVal(request.REQUEST, 'phone')
            myself.save()
            user_settings.enable_voip_dial = dataplus.dictGetVal(request.REQUEST, 'enable_voip_dial', False, lambda x:True)
            user_settings.save()
        
        elif action == 'save_messengers_settings':
            for msnger in models.WebMessenger.objects.filter(account=myself.account):
                msnger.delete()
                
            if dataplus.dictGetSafeVal(request.REQUEST, 'skype_username'):
                skype_profile = models.WebMessenger(provider='skype')
                skype_profile.account=myself.account
                skype_profile.username = dataplus.dictGetSafeVal(request.REQUEST, 'skype_username')
                skype_profile.save()
            
            if dataplus.dictGetSafeVal(request.REQUEST, 'yahoo_username'):
                #remove '@yahoo.com' if its there
                yahoo_username = dataplus.dictGetSafeVal(request.REQUEST, 'yahoo_username').partition('@')[0]
                yahoo_profile = models.WebMessenger(provider='yahoo')
                yahoo_profile.account=myself.account
                yahoo_profile.username = yahoo_username
                yahoo_profile.save()
        
        elif action == 'save_blog_settings':
            myself.blog_url = dataplus.dictGetSafeVal(request.REQUEST, 'blog_url')
            if myself.blog_url and not myself.blog_url.lower().startswith('http://'):
                myself.blog_url = 'http://' + myself.blog_url
            myself.save()
            
        return HttpResponseRedirect('/me/editconnectsettings.htm?flashId=connectset_saved')