Просмотр исходного кода

Differentiate between base_path and storage_base_path

version-14
Pratik Vyas 11 лет назад
Родитель
Сommit
01abf65b1f
4 измененных файлов: 21 добавлений и 10 удалений
  1. +1
    -0
      conf/conf.py
  2. +3
    -2
      core/doctype/file_data/file_data.py
  3. +11
    -3
      webnotes/utils/__init__.py
  4. +6
    -5
      webnotes/utils/file_manager.py

+ 1
- 0
conf/conf.py Просмотреть файл

@@ -10,6 +10,7 @@ db_password = '%(db_password)s'

# user attachments stored in
files_path = 'public/files'
public_path = 'public'

# max file attachment size (default 1MB)
max_file_size = 1000000


+ 3
- 2
core/doctype/file_data/file_data.py Просмотреть файл

@@ -9,6 +9,7 @@ naming for same name files: file.gif, file-1.gif, file-2.gif etc
"""

import webnotes, webnotes.utils, os
from webnotes import conf

class DocType():
def __init__(self, d, dl):
@@ -28,7 +29,7 @@ class DocType():
def on_trash(self):
if self.doc.file_name and webnotes.conn.sql("""select count(*) from `tabFile Data`
where file_name=%s""", self.doc.file_name)[0][0]==1:
path = webnotes.utils.get_path("public", "files", self.doc.file_name)
path = webnotes.utils.get_storage_path(conf.files_path, self.doc.file_name)
if os.path.exists(path):
os.remove(path)
@@ -38,4 +39,4 @@ class DocType():
"write", self.doc.attached_to_name):
webnotes.msgprint(webnotes._("No permission to write / remove."),
raise_exception=True)

+ 11
- 3
webnotes/utils/__init__.py Просмотреть файл

@@ -810,18 +810,26 @@ def filter_strip_join(some_list, sep):
"""given a list, filter None values, strip spaces and join"""
return (cstr(sep)).join((cstr(a).strip() for a in filter(None, some_list)))
def get_path(*path):
def get_path(base=None, *path):
if not base:
base = get_base_path()
import os
return os.path.join(get_base_path(), *path)
return os.path.join(base, *path)
def get_base_path():
import conf
import os
return os.path.dirname(os.path.abspath(conf.__file__))

def get_storage_base_path(sites_dir, hostname):
def get_storage_base_path(sites_dir=None, hostname=None):
import os
if not sites_dir and not hostname:
sites_dir = conf.sites_dir
hostname = conf.site
return os.path.join(sites_dir, hostname)

def get_storage_path(*path):
return get_path(base=get_storage_base_path(), *path)
def get_url(uri=None):
url = get_request_site_address()


+ 6
- 5
webnotes/utils/file_manager.py Просмотреть файл

@@ -3,9 +3,10 @@

from __future__ import unicode_literals
import webnotes
import os, conf
from webnotes.utils import cstr, get_path, cint
import os
from webnotes.utils import cstr, cint, get_storage_path
from webnotes import _
from webnotes import conf

class MaxFileSizeReachedError(webnotes.ValidationError): pass

@@ -64,7 +65,7 @@ def get_uploaded_content():
def save_file(fname, content, dt, dn):
import filecmp
from webnotes.model.code import load_doctype_module
files_path = get_path("public", "files")
files_path = get_storage_path(conf.public_path)
module = load_doctype_module(dt, webnotes.conn.get_value("DocType", dt, "module"))
if hasattr(module, "attachments_folder"):
@@ -102,7 +103,7 @@ def save_file(fname, content, dt, dn):

f = webnotes.bean({
"doctype": "File Data",
"file_name": os.path.relpath(os.path.join(files_path, fname), get_path("public")),
"file_name": os.path.relpath(os.path.join(files_path, fname), get_storage_path(conf.public_path)),
"attached_to_doctype": dt,
"attached_to_name": dn,
"file_size": file_size
@@ -183,7 +184,7 @@ def get_file(fname):

# read the file
import os
files_path = get_path("public", "files")
files_path = get_storage_path(conf.files_path)
file_path = os.path.join(files_path, file_name)
if not os.path.exists(file_path):
# check in folders


Загрузка…
Отмена
Сохранить