def upload(request): pk = int(request.POST.get('pk', 0)) image = request.FILES['photo'] if (image.content_type in ['image/jpeg', 'image/jpg', 'image/png']): if pk==0: obj = Question() else: obj = Answer() obj.question = Question.objects.get(pk=pk) obj.user = request.user obj.active = 1 # TODO set to 0 to enable premoderation after first wave obj.save() # to obtain key filename = '/data/bottle/%s-%s.jpg'%(pk,obj.pk) with open(STATICFILES_DIRS[0].rstrip("/") + filename, 'wb+') as destination: for chunk in image.chunks(): destination.write(chunk) obj.url = STATIC_URL.rstrip("/") + filename obj.save() return HttpResponse(tpls('bottle/iframe_signal.html', dict( pk = pk, is_question=(pk == 0), ), request), content_type='text/html; charset=UTF-8') else: data = dict( pk=pk, is_question=(pk > 0), ) data.update(csrf(request)) return HttpResponse(tpls('bottle/iframe.html', data, request), content_type='text/html; charset=UTF-8')
def get_current_ontology(request, url, startpage=False): """ If testing in local, loads the ontology file from the local folder. Otherwise it just expects a standard rdf-returning URI. """ if url.startswith("file://localhost/"): # then it's a local file realpath = os.path.join(LOCAL_ONTOLOGIES_FOLDER, url.replace("file://localhost/", "")) # onto = getCached_Onto(request, realpath) onto = Ontology(realpath) # hide the physical location set by OntoSpy (so to hide server path infos in display & url parameters) onto.ontologyMaskedLocation = url # override physical location set by OntosPy (so to allow source download via Django static handler) prefix = 'https://' if request.is_secure() else 'http://' if STATIC_URL.startswith("http"): onto.ontologyPhysicalLocation = STATIC_URL + 'ontospyweb/ontologies/' + url.replace( "file://localhost/", "") else: onto.ontologyPhysicalLocation = prefix + request.get_host( ) + STATIC_URL + 'ontospyweb/ontologies/' + url.replace( "file://localhost/", "") return onto else: if url.startswith("http://"): pass else: url = "http://" + url onto = Ontology(url) onto.ontologyMaskedLocation = url # what is this for? # in theory the onto has loaded succesfully - so we save it # (ps: only if the request comes from the startpage!) if startpage: updateHistory(onto) return onto
def get_current_ontology(request, url, startpage=False): """ If testing in local, loads the ontology file from the local folder. Otherwise it just expects a standard rdf-returning URI. """ if url.startswith("file://localhost/"): # then it's a local file realpath = os.path.join(LOCAL_ONTOLOGIES_FOLDER, url.replace("file://localhost/", "")) # onto = getCached_Onto(request, realpath) onto = Ontology(realpath) # hide the physical location set by OntoSpy (so to hide server path infos in display & url parameters) onto.ontologyMaskedLocation = url # override physical location set by OntosPy (so to allow source download via Django static handler) prefix = 'https://' if request.is_secure() else 'http://' if STATIC_URL.startswith("http"): onto.ontologyPhysicalLocation = STATIC_URL + 'ontospyweb/ontologies/' + url.replace("file://localhost/", "") else: onto.ontologyPhysicalLocation = prefix + request.get_host() + STATIC_URL + 'ontospyweb/ontologies/' + url.replace("file://localhost/", "") return onto else: if url.startswith("http://"): pass else: url = "http://" + url onto = Ontology(url) onto.ontologyMaskedLocation = url # what is this for? # in theory the onto has loaded succesfully - so we save it # (ps: only if the request comes from the startpage!) if startpage: updateHistory(onto) return onto
# URL that handles the media served from MEDIA_ROOT. Make sure to use a # trailing slash. # Examples: "http://media.lawrence.com/media/", "http://example.com/media/" # Absolute path to the directory static files should be collected to. # Don't put anything in this directory yourself; store your static files # in apps' "static/" subdirectories and in STATICFILES_DIRS. # Example: "/home/media/media.lawrence.com/static/" STATIC_ROOT = PROJECT_PATH + "/assets/" + THE_THEME + "/static/" os.sys.path.insert(0, os.path.join(PROJECT_PATH, "src")) # This set of things hacks mediabrute so that the RUNSERVER can serve our static files # In production, DEBUG should be False, so this will all automatically deactivate if DEBUG and STATIC_URL.startswith("/") and not STATIC_URL.startswith("//"): MEDIABRUTE_CACHE_BASE_URL = "/" CSS_DIR = "static/css" JS_DIR = "static/js" MEDIABRUTE_CSS_URL_PATH = "css" MEDIABRUTE_JS_URL_PATH = "js" STATICFILES_DIRS = ( # Put strings here, like "/home/html/static" or "C:/www/django/static". # Always use forward slashes, even on Windows. # Don't forget to use absolute paths, not relative paths. PROJECT_PATH + "/assets/" + THE_THEME + "/static/", ) STATIC_ROOT = PROJECT_PATH + "/assets/" + THE_THEME + "/"