Пример #1
0
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)
Пример #2
0
def hubSettingsView(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 request.method == 'GET':
            details = render_to_response(
                "partial_hub_settings.html", {
                    "current_user": logged_in_user,
                    "payload": {
                        "hub": hub
                    }
                },
                context_instance=RequestContext(request))
            return assembleHubResponse(request, logged_in_user, hub, details)
        else:
            hub.hub_name = request.POST['hub_name']
            hub.hub_desc = request.POST['hub_desc']
            hub.site_link = request.POST['site_link']
            saved = saveHub(hub, logged_in_user, request)
            if saved == True:
                if request.is_ajax():
                    details = render_to_response(
                        "partial_hub_settings.html", {
                            "current_user": logged_in_user,
                            "payload": {
                                "hub": hub
                            },
                            "message": "Hub settings changed successfully"
                        },
                        context_instance=RequestContext(request))
                    return assembleHubResponse(request, logged_in_user, hub,
                                               details)
                else:
                    return HttpResponseRedirect(
                        reverse('hub-wall', args=('id/', hub.hub_id)))
            else:
                return assembleHubErrorResponse(request, saved)
    except:
        logger = logging.getLogger(__name__)
        return errorscreen(request, logger, sys)
Пример #3
0
def hubSettingsView(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 request.method == 'GET' :
            details = render_to_response("partial_hub_settings.html",
                                        {
                                            "current_user": logged_in_user,
                                            "payload": {"hub": hub}
                                        }
                                        ,context_instance=RequestContext(request))
            return assembleHubResponse(request, logged_in_user, hub, details)
        else :
            hub.hub_name = request.POST['hub_name']
            hub.hub_desc = request.POST['hub_desc']
            hub.site_link = request.POST['site_link']
            saved = saveHub(hub, logged_in_user, request)
            if saved == True :
                if request.is_ajax() :
                    details = render_to_response("partial_hub_settings.html",
                                                {
                                                    "current_user": logged_in_user,
                                                    "payload": {"hub": hub},
                                                    "message": "Hub settings changed successfully"
                                                }
                                                ,context_instance=RequestContext(request))
                    return assembleHubResponse(request, logged_in_user, hub, details)
                else :
                    return HttpResponseRedirect(reverse('hub-wall',args=('id/',hub.hub_id)))
            else :
                return assembleHubErrorResponse(request, saved)
    except :
        logger=logging.getLogger(__name__)
        return errorscreen(request,logger, sys)
Пример #4
0
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)