def uploadBackground(request, data_type, data_value): try : logged_in_user = get_logged_in_user(request) if data_type == "id" : hubid = data_value hub = get_hub_by_id(request, hubid, logged_in_user) if hub == None: return assembleHubErrorResponse(request, "Sorry that Hub was not found") elif hub.creater_id != logged_in_user.user_id : return assembleHubErrorResponse(request, "Sorry, you don't have permission to edit this Hub's settings") if len(str(request.POST.get('background_src',""))) > 0 and len(str(request.POST.get('background_name',""))) > 0 and len(str(request.POST.get('background_type',""))) > 0 : files = {} from django.core.files.uploadedfile import SimpleUploadedFile import base64 files['background_upload'] = SimpleUploadedFile(request.POST['background_name'],base64.b64decode(mark_safe(request.POST['background_src'])),request.POST['background_type']) else : files = request.FILES if request.method == 'POST' : aToken = request.COOKIES['access_token'] upload = UploadBackgroundForm(request.POST, files) statusmsg = "User Background update successful!" if not upload.is_valid() : statusmsg = ''.join(["User Background update failed: ",upload.errors.as_text().replace('\r','').replace('\n','')]) return assembleHubErrorResponse(request, statusmsg) else : from website.settings import MEDIA_URL if 'background_delete' in request.POST or 'background_upload' in request.POST : background_url = '' if 'background_upload' in files : background_url = ''.join([MEDIA_URL,handleUploadedAvatar(files['background_upload'], hub.hub_id, aToken, '', "400x197")]) if 'background_url' in locals() and background_url != hub.hub_image : hub.hub_image = background_url saved = saveHub(hub, logged_in_user, request) if saved == True : if not request.is_ajax : details = render_to_response("partial_hub_settings.html", { "current_user": logged_in_user, "payload": {"hub": hub}, "backgroundmessage": "Background Image uploaded successfully" } ,context_instance=RequestContext(request)) return assembleHubResponse(request, logged_in_user, hub, details) else : payload = {'hub':hub} jsonReturn = simplejson.dumps({'hubBackground':mark_safe('<img data-dj-view="hubBackground" src="'+background_url+'" alt="" />'),'hubBackgroundForm':mark_safe(render_to_response('partial_hubsettings_background.html',locals(),context_instance=RequestContext(request)).content)}) return render_to_response('ajax_ttag_create.html',locals(),context_instance=RequestContext(request)) else : statusmsg = ''.join(["User Avatar update failed: ",saved]) return assembleHubErrorResponse(request, statusmsg) else : return assembleHubErrorResponse(request, 'You are not authorized to access this area') except : logger=logging.getLogger(__name__) return errorscreen(request,logger, sys)
def userAvatarUpload(request, isAndroid=False): try : authed, data = ttagServiceAuth(request) if authed and request.method == 'POST' : aToken = request.COOKIES['access_token'] formdata = {'gender':'','google_map_address':'','pro_description':''} if len(str(request.POST.get('avatar_src',""))) > 0 and len(str(request.POST.get('avatar_name',""))) > 0 and len(str(request.POST.get('avatar_type',""))) > 0 : files = {} from django.core.files.uploadedfile import SimpleUploadedFile import base64 files['avatar_upload'] = SimpleUploadedFile(request.POST['avatar_name'],base64.b64decode(mark_safe(request.POST['avatar_src'])),request.POST['avatar_type']) else : files = request.FILES for key in data : formdata[key] = data[key] upload = UploadFileForm(request.POST, files) statusmsg = "User Avatar update successful!" print request.POST if 'avatar_upload' not in request.POST and 'avatar_src' not in request.POST and len(str(request.POST.get('avatar_url',''))) > 0 : upload = SettingsAvatarForm(request.POST) if upload.is_valid() : avatar_url = upload.clean_AvatarURL() if not upload.is_valid() : statusmsg = ''.join(["User Avatar update failed: ",upload.errors.as_text().replace('\r','').replace('\n','')]) svcResp = {'result':'ERROR','msg':statusmsg} else : from website.settings import MEDIA_URL if 'avatar_delete' in request.POST or 'avatar_upload' in request.POST : avatar_url = '' if 'avatar_upload' in files : avatar_url = ''.join([MEDIA_URL,handleUploadedAvatar(files['avatar_upload'], data['user_name'], aToken)]) if 'avatar_url' in locals() and avatar_url != data['avatar_url'] : svcResp = ttagServiceAvatarChange(aToken,avatar_url) if svcResp.get('result',"OK") == 'OK' : svcResp['data'], data['avatar_url'] = {'filename':avatar_url}, avatar_url else : statusmsg = ''.join(["User Avatar update failed: ",svcResp['msg']]) svcResp['msg'] = statusmsg else : svcResp = {'result':'OK','msg':'Nothing changed'} svcResp = mark_safe(simplejson.dumps(svcResp)) form = SettingsForm(formdata) context = {'request':request,'loggedin':True,'data':data,'form':form,'settings_message':statusmsg, 'location':'Settings', 'svcResp':svcResp} ajax_page = 'user_avataruploaded.html' if not isAndroid else 'android_avataruploaded.html' page = ajax_page if ( request.is_ajax() or isAndroid ) else 'home_settings.html' thereturn = render_to_response(page,context,context_instance=RequestContext(request)) if request.is_ajax() and not isAndroid and 'avatar_url' in locals() and len(str(avatar_url)) > 0 : jsonReturn = simplejson.dumps({'userAvatar':mark_safe('<img data-dj-view="userAvatar" src="'+avatar_url+'" alt="" />'),'userAvatarForm':mark_safe(thereturn.content)}) thereturn = render_to_response('ajax_ttag_create.html',locals(),context_instance=RequestContext(request)) return thereturn else : return loginscreen(request) except : logger=logging.getLogger(__name__) return errorscreen(request,logger, sys)
def upload(request): try : thereturn = HttpResponse('You are not authorized to view this area of the website') loggedin, data = ttagServiceAuth(request) if loggedin and request.method == 'POST' and 'avatar_upload' in request.FILES : upload = UploadFileForm(request.POST, request.FILES) avatar_url = '' if upload.is_valid() : avatar_url = ''.join([paths.AD_URL,handleUploadedAvatar(request.FILES['avatar_upload'], data['user_name'], request.COOKIES['access_token'], paths.AD_ROOT)]) thereturn = render_to_response('marketing_avatar.html',locals(),context_instance=RequestContext(request)) return thereturn except : logger=logging.getLogger(__name__) return errorscreen(request,logger, sys)
def upload(request): try: thereturn = HttpResponse( 'You are not authorized to view this area of the website') loggedin, data = ttagServiceAuth(request) if loggedin and request.method == 'POST' and 'avatar_upload' in request.FILES: upload = UploadFileForm(request.POST, request.FILES) avatar_url = '' if upload.is_valid(): avatar_url = ''.join([ paths.AD_URL, handleUploadedAvatar(request.FILES['avatar_upload'], data['user_name'], request.COOKIES['access_token'], paths.AD_ROOT) ]) thereturn = render_to_response( 'marketing_avatar.html', locals(), context_instance=RequestContext(request)) return thereturn except: logger = logging.getLogger(__name__) return errorscreen(request, logger, sys)
def image(request, isAndroid=False): try: thereturn = loginscreen(request) loggedin, data = ttagServiceAuth(request) if loggedin: if request.method == 'GET': ttagimage = TtagImage() thereturn = render_to_response( 'mce_image_uploadform.html', locals(), context_instance=RequestContext(request)) else: import urllib post = {} files = {} for key in request.POST: post[key] = request.POST[key] post['image_url'] = urllib.unquote_plus( post.get('image_url', "")) if 'background_upload' in request.FILES: files = request.FILES if 'image_data' in post and len(post['image_data']) > 0: from django.core.files.uploadedfile import SimpleUploadedFile from django.core.files.base import ContentFile import base64 files['background_upload'] = SimpleUploadedFile( post['image_filename'], base64.b64decode(mark_safe(post['image_data'])), 'image/gif') upload = UploadBackgroundForm({}, files) if len(str(post.get('image_url', ""))) == 0 and upload.is_valid(): from webapp.genUtil import handleUploadedAvatar from website.settings import MEDIA_URL post['image_url'] = ''.join([ MEDIA_URL, handleUploadedAvatar(files['background_upload'], data['user_name'], request.COOKIES['access_token'], '', False) ]) ttagimage = TtagImage(post, files) if ttagimage.is_valid(): import simplejson preview = mark_safe( simplejson.dumps({ 'result': 'OK', 'data': { 'html_data': { 'thumbnail_list': [ttagimage.clean_ImageURL()], 'title': ttagimage.clean_MetaTitle(), 'm_title': ttagimage.clean_MetaTitle(), 'm_desc': ttagimage.clean_MetaDesc() } } })) if isAndroid: thereturn = HttpResponse(preview) else: #thereturn = HttpResponse(mark_safe('<img src="'+mark_safe(post['image_url'])+'" />')) thereturn = render_to_response( 'mce_image_uploadhandle.html', locals(), context_instance=RequestContext(request)) else: thereturn = render_to_response( 'mce_image_uploadform.html', locals(), context_instance=RequestContext(request)) thereturn = thereturn return thereturn except: logger = logging.getLogger(__name__) return errorscreen(request, logger, sys)
def uploadBackground(request, data_type, data_value): try: logged_in_user = get_logged_in_user(request) if data_type == "id": hubid = data_value hub = get_hub_by_id(request, hubid, logged_in_user) if hub == None: return assembleHubErrorResponse(request, "Sorry that Hub was not found") elif hub.creater_id != logged_in_user.user_id: return assembleHubErrorResponse( request, "Sorry, you don't have permission to edit this Hub's settings") if len(str(request.POST.get('background_src', ""))) > 0 and len( str(request.POST.get('background_name', ""))) > 0 and len( str(request.POST.get('background_type', ""))) > 0: files = {} from django.core.files.uploadedfile import SimpleUploadedFile import base64 files['background_upload'] = SimpleUploadedFile( request.POST['background_name'], base64.b64decode(mark_safe(request.POST['background_src'])), request.POST['background_type']) else: files = request.FILES if request.method == 'POST': aToken = request.COOKIES['access_token'] upload = UploadBackgroundForm(request.POST, files) statusmsg = "User Background update successful!" if not upload.is_valid(): statusmsg = ''.join([ "User Background update failed: ", upload.errors.as_text().replace('\r', '').replace('\n', '') ]) return assembleHubErrorResponse(request, statusmsg) else: from website.settings import MEDIA_URL if 'background_delete' in request.POST or 'background_upload' in request.POST: background_url = '' if 'background_upload' in files: background_url = ''.join([ MEDIA_URL, handleUploadedAvatar(files['background_upload'], hub.hub_id, aToken, '', "400x197") ]) if 'background_url' in locals( ) and background_url != hub.hub_image: hub.hub_image = background_url saved = saveHub(hub, logged_in_user, request) if saved == True: if not request.is_ajax: details = render_to_response( "partial_hub_settings.html", { "current_user": logged_in_user, "payload": { "hub": hub }, "backgroundmessage": "Background Image uploaded successfully" }, context_instance=RequestContext(request)) return assembleHubResponse(request, logged_in_user, hub, details) else: payload = {'hub': hub} jsonReturn = simplejson.dumps({ 'hubBackground': mark_safe( '<img data-dj-view="hubBackground" src="' + background_url + '" alt="" />'), 'hubBackgroundForm': mark_safe( render_to_response( 'partial_hubsettings_background.html', locals(), context_instance=RequestContext( request)).content) }) return render_to_response( 'ajax_ttag_create.html', locals(), context_instance=RequestContext(request)) else: statusmsg = ''.join( ["User Avatar update failed: ", saved]) return assembleHubErrorResponse(request, statusmsg) else: return assembleHubErrorResponse( request, 'You are not authorized to access this area') except: logger = logging.getLogger(__name__) return errorscreen(request, logger, sys)
def image(request, isAndroid=False): try: thereturn = loginscreen(request) loggedin, data = ttagServiceAuth(request) if loggedin: if request.method == "GET": ttagimage = TtagImage() thereturn = render_to_response( "mce_image_uploadform.html", locals(), context_instance=RequestContext(request) ) else: import urllib post = {} files = {} for key in request.POST: post[key] = request.POST[key] post["image_url"] = urllib.unquote_plus(post.get("image_url", "")) if "background_upload" in request.FILES: files = request.FILES if "image_data" in post and len(post["image_data"]) > 0: from django.core.files.uploadedfile import SimpleUploadedFile from django.core.files.base import ContentFile import base64 files["background_upload"] = SimpleUploadedFile( post["image_filename"], base64.b64decode(mark_safe(post["image_data"])), "image/gif" ) upload = UploadBackgroundForm({}, files) if len(str(post.get("image_url", ""))) == 0 and upload.is_valid(): from webapp.genUtil import handleUploadedAvatar from website.settings import MEDIA_URL post["image_url"] = "".join( [ MEDIA_URL, handleUploadedAvatar( files["background_upload"], data["user_name"], request.COOKIES["access_token"], "", False, ), ] ) ttagimage = TtagImage(post, files) if ttagimage.is_valid(): import simplejson preview = mark_safe( simplejson.dumps( { "result": "OK", "data": { "html_data": { "thumbnail_list": [ttagimage.clean_ImageURL()], "title": ttagimage.clean_MetaTitle(), "m_title": ttagimage.clean_MetaTitle(), "m_desc": ttagimage.clean_MetaDesc(), } }, } ) ) if isAndroid: thereturn = HttpResponse(preview) else: # thereturn = HttpResponse(mark_safe('<img src="'+mark_safe(post['image_url'])+'" />')) thereturn = render_to_response( "mce_image_uploadhandle.html", locals(), context_instance=RequestContext(request) ) else: thereturn = render_to_response( "mce_image_uploadform.html", locals(), context_instance=RequestContext(request) ) thereturn = thereturn return thereturn except: logger = logging.getLogger(__name__) return errorscreen(request, logger, sys)