ソースを参照

fixes to page: restrict name to 20 chars and ignore files if no module, doclist

version-14
Rushabh Mehta 14年前
コミット
b204cbb708
3個のファイルの変更74行の追加22行の削除
  1. +29
    -6
      cgi-bin/core/doctype/page/page.py
  2. +25
    -6
      cgi-bin/webnotes/model/doclist.py
  3. +20
    -10
      cgi-bin/webnotes/widgets/page.py

+ 29
- 6
cgi-bin/core/doctype/page/page.py ファイルの表示

@@ -1,12 +1,30 @@
import webnotes

class DocType:
def __init__(self, d, dl):
self.doc, self.doclist = d,dl

def autoname(self):
"""
Creates a url friendly name for this page.
Will restrict the name to 30 characters, if there exists a similar name,
it will add name-1, name-2 etc.
"""
from webnotes.utils import cint
if (self.doc.name and self.doc.name.startswith('New Page')) or not self.doc.name:
self.doc.name = self.doc.page_name.lower().replace(' ', '-')
self.doc.name = self.doc.page_name.lower().replace('"','').replace("'",'').replace(' ', '-')[:20]
if webnotes.conn.exists('Page',self.doc.name):
cnt = webnotes.conn.sql('select name from tabPage where name like "%s-%%" order by name desc limit 1' % self.doc.name)
if cnt:
cnt = cint(cnt[0][0].split('-')[-1]) + 1
else:
cnt = 1
self.doc.name += '-' + str(cnt)

def onload(self):
"""
loads html from file before passing
"""
import os
from webnotes.modules import get_module_path, scrub
@@ -19,9 +37,10 @@ class DocType:
if e.args[0]!=2:
raise e

# replace $image
# ------------------
def validate(self):
"""
Update $image tags
"""
import re
p = re.compile('\$image\( (?P<name> [^)]*) \)', re.VERBOSE)
if self.doc.content:
@@ -34,12 +53,16 @@ class DocType:
# export
def on_update(self):
from webnotes.modules.export_module import export_to_files
from webnotes.modules import get_module_path, scrub
import os
"""
Writes the .txt for this page and if write_content is checked,
it will write out a .html file
"""
from webnotes import defs
if getattr(defs,'developer_mode', 0):
from webnotes.modules.export_module import export_to_files
from webnotes.modules import get_module_path, scrub
import os
export_to_files(record_list=[['Page', self.doc.name]])
if self.doc.write_content and self.doc.content:


+ 25
- 6
cgi-bin/webnotes/model/doclist.py ファイルの表示

@@ -16,17 +16,36 @@ class DocList:
self.docs = []
self.obj = None
self.to_docstatus = 0
if dt and dn:
self.load_from_db(dt, dn)
def load_from_db(self, dt, dn):
"""
Load doclist from dt
"""
from webnotes.model.doc import Document, getchildren

doc = Document(dt, dn, prefix=prefix)

# get all children types
tablefields = webnotes.model.meta.get_table_fields(dt)

# load chilren
doclist = [doc,]
for t in tablefields:
doclist += getchildren(doc.name, t[0], t[1], dt, prefix=prefix)
self.docs = docs
def __iter__(self):
"""
Make this iterable
Make this iterable
"""
return self.docs.__iter__()
def from_compressed(self, data, docname):
"""
Expand called from client
Expand called from client
"""
from webnotes.model.utils import expand
self.docs = expand(data)
@@ -34,7 +53,7 @@ class DocList:
def objectify(self, docname=None):
"""
Converts self.docs from a list of dicts to list of Documents
Converts self.docs from a list of dicts to list of Documents
"""
from webnotes.model.doc import Document
@@ -52,7 +71,7 @@ class DocList:
def make_obj(self):
"""
Create a DocType object
Create a DocType object
"""
if self.obj: return self.obj
@@ -62,13 +81,13 @@ class DocList:
def next(self):
"""
Next doc
Next doc
"""
return self.docs.next()

def to_dict(self):
"""
return as a list of dictionaries
return as a list of dictionaries
"""
return [d.fields for d in self.docs]



+ 20
- 10
cgi-bin/webnotes/widgets/page.py ファイルの表示

@@ -14,25 +14,39 @@ class Page:
def __init__(self, name):
self.name = name

def load(self):
def get_from_files(self, doc):
"""
Returns :term:`doclist` of the `Page`
Loads page info from files in module
"""
from webnotes.modules import compress
from webnotes.model.code import get_code

# load js
doc.fields['__script'] = compress.get_page_js(doc)
doc.script = None

# load css
css = get_code(doc.module, 'page', doc.name, 'css')
if css: doc.style = css
# html
doc.content = get_code(doc.module, 'page', doc.name, 'html') or doc.content
def load(self):
"""
Returns :term:`doclist` of the `Page`
"""
from webnotes.model.code import get_code
doclist = webnotes.model.doc.get('Page', self.name)
doc = doclist[0]

doc.fields['__script'] = compress.get_page_js(doc)
doc.script = None
if doc.module: self.get_from_files(doc)

template = '%(content)s'
# load code from template
if doc.template:
template = get_code(webnotes.conn.get_value('Page Template', doc.template, 'module'), 'Page Template', doc.template, 'html', fieldname='template')

doc.content = get_code(doc.module, 'page', doc.name, 'html') or doc.content
# execute content
if doc.content and doc.content.startswith('#!python'):
@@ -40,10 +54,6 @@ class Page:
else:
doc.__content = template % {'content': doc.content or ''}

# local stylesheet
css = get_code(doc.module, 'page', doc.name, 'css')
if css: doc.style = css
# add stylesheet
if doc.stylesheet:
doclist += self.load_stylesheet(doc.stylesheet)


読み込み中…
キャンセル
保存