--- a/.hgtags Thu Jul 16 12:57:17 2009 -0700
+++ b/.hgtags Tue Jul 28 21:27:52 2009 +0200
@@ -48,3 +48,5 @@
1cf9e44e2f1f4415253b8892a0adfbd3b69e84fd cubicweb-version-3_3_3
47b5236774a0cf3b1cfe75f6d4bd2ec989644ace cubicweb-version-3_3_3
2ba27ce8ecd9828693ec53c517e1c8810cbbe33e cubicweb-debian-version-3_3_3-2
+d46363eac5d71bc1570d69337955154dfcd8fcc8 cubicweb-version-3.3.4
+7dc22caa7640bf70fcae55afb6d2326829dacced cubicweb-debian-version-3.3.4-1
--- a/__init__.py Thu Jul 16 12:57:17 2009 -0700
+++ b/__init__.py Tue Jul 28 21:27:52 2009 +0200
@@ -198,7 +198,7 @@
# abstract methods to override according to the web front-end #############
def base_url(self):
- """return the root url of the application"""
+ """return the root url of the instance"""
raise NotImplementedError
def decorate_rset(self, rset):
@@ -300,3 +300,6 @@
except AttributeError:
return neg_role(obj.role)
+def underline_title(title, car='-'):
+ return title+'\n'+(car*len(title))
+
--- a/__pkginfo__.py Thu Jul 16 12:57:17 2009 -0700
+++ b/__pkginfo__.py Tue Jul 28 21:27:52 2009 +0200
@@ -7,7 +7,7 @@
distname = "cubicweb"
modname = "cubicweb"
-numversion = (3, 3, 3)
+numversion = (3, 4, 0)
version = '.'.join(str(num) for num in numversion)
license = 'LGPL v2'
@@ -32,6 +32,13 @@
ftp = 'ftp://ftp.logilab.org/pub/cubicweb'
pyversions = ['2.4', '2.5']
+classifiers = [
+ 'Environment :: Web Environment',
+ 'Framework :: CubicWeb',
+ 'Programming Language :: Python',
+ 'Programming Language :: JavaScript',
+]
+
import sys
from os import listdir, environ
--- a/appobject.py Thu Jul 16 12:57:17 2009 -0700
+++ b/appobject.py Tue Jul 28 21:27:52 2009 +0200
@@ -40,11 +40,11 @@
At registration time, the following attributes are set on the class:
:vreg:
- the application's registry
+ the instance's registry
:schema:
- the application's schema
+ the instance's schema
:config:
- the application's configuration
+ the instance's configuration
At instantiation time, the following attributes are set on the instance:
:req:
@@ -276,7 +276,7 @@
return output.getvalue()
def format_date(self, date, date_format=None, time=False):
- """return a string for a date time according to application's
+ """return a string for a date time according to instance's
configuration
"""
if date:
@@ -289,7 +289,7 @@
return u''
def format_time(self, time):
- """return a string for a time according to application's
+ """return a string for a time according to instance's
configuration
"""
if time:
@@ -297,7 +297,7 @@
return u''
def format_float(self, num):
- """return a string for floating point number according to application's
+ """return a string for floating point number according to instance's
configuration
"""
if num:
--- a/common/i18n.py Thu Jul 16 12:57:17 2009 -0700
+++ b/common/i18n.py Tue Jul 28 21:27:52 2009 +0200
@@ -63,7 +63,7 @@
"""generate .mo files for a set of languages into the `destdir` i18n directory
"""
from logilab.common.fileutils import ensure_fs_mode
- print 'compiling %s catalogs...' % destdir
+ print '-> compiling %s catalogs...' % destdir
errors = []
for lang in langs:
langdir = join(destdir, lang, 'LC_MESSAGES')
@@ -73,7 +73,7 @@
pofiles = [pof for pof in pofiles if exists(pof)]
mergedpo = join(destdir, '%s_merged.po' % lang)
try:
- # merge application messages' catalog with the stdlib's one
+ # merge instance/cubes messages catalogs with the stdlib's one
execute('msgcat --use-first --sort-output --strict %s > %s'
% (' '.join(pofiles), mergedpo))
# make sure the .mo file is writeable and compile with *msgfmt*
--- a/common/mail.py Thu Jul 16 12:57:17 2009 -0700
+++ b/common/mail.py Tue Jul 28 21:27:52 2009 +0200
@@ -18,7 +18,7 @@
def addrheader(uaddr, uname=None):
# even if an email address should be ascii, encode it using utf8 since
- # application tests may generate non ascii email address
+ # automatic tests may generate non ascii email address
addr = uaddr.encode('UTF-8')
if uname:
return '%s <%s>' % (header(uname).encode(), addr)
--- a/common/migration.py Thu Jul 16 12:57:17 2009 -0700
+++ b/common/migration.py Tue Jul 28 21:27:52 2009 +0200
@@ -1,5 +1,4 @@
-"""utility to ease migration of application version to newly installed
-version
+"""utilities for instances migration
:organization: Logilab
:copyright: 2001-2009 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2.
@@ -11,7 +10,7 @@
import sys
import os
import logging
-from tempfile import mktemp
+import tempfile
from os.path import exists, join, basename, splitext
from logilab.common.decorators import cached
@@ -70,7 +69,7 @@
ability to show the script's content
"""
while True:
- confirm = raw_input('** execute %r (Y/n/s[how]) ?' % scriptpath)
+ confirm = raw_input('Execute %r (Y/n/s[how]) ?' % scriptpath)
confirm = confirm.strip().lower()
if confirm in ('n', 'no'):
return False
@@ -153,11 +152,15 @@
migrdir = self.config.cube_migration_scripts_dir(cube)
scripts = filter_scripts(self.config, migrdir, fromversion, toversion)
if scripts:
+ prevversion = None
for version, script in scripts:
+ # take care to X.Y.Z_Any.py / X.Y.Z_common.py: we've to call
+ # cube_upgraded once all script of X.Y.Z have been executed
+ if prevversion is not None and version != prevversion:
+ self.cube_upgraded(cube, version)
+ prevversion = version
self.process_script(script)
- self.cube_upgraded(cube, version)
- if version != toversion:
- self.cube_upgraded(cube, toversion)
+ self.cube_upgraded(cube, toversion)
else:
self.cube_upgraded(cube, toversion)
@@ -169,7 +172,7 @@
def interact(self, args, kwargs, meth):
"""execute the given method according to user's confirmation"""
- msg = 'execute command: %s(%s) ?' % (
+ msg = 'Execute command: %s(%s) ?' % (
meth.__name__[4:],
', '.join([repr(arg) for arg in args] +
['%s=%r' % (n,v) for n,v in kwargs.items()]))
@@ -337,7 +340,7 @@
configfile = self.config.main_config_file()
if self._option_changes:
read_old_config(self.config, self._option_changes, configfile)
- newconfig = mktemp()
+ _, newconfig = tempfile.mkstemp()
for optdescr in self._option_changes:
if optdescr[0] == 'added':
optdict = self.config.get_option_def(optdescr[1])
--- a/common/mttransforms.py Thu Jul 16 12:57:17 2009 -0700
+++ b/common/mttransforms.py Tue Jul 28 21:27:52 2009 +0200
@@ -46,8 +46,8 @@
from cubicweb.ext.tal import compile_template
except ImportError:
HAS_TAL = False
- from cubicweb.schema import FormatConstraint
- FormatConstraint.need_perm_formats.remove('text/cubicweb-page-template')
+ from cubicweb import schema
+ schema.NEED_PERM_FORMATS.remove('text/cubicweb-page-template')
else:
HAS_TAL = True
--- a/common/tags.py Thu Jul 16 12:57:17 2009 -0700
+++ b/common/tags.py Tue Jul 28 21:27:52 2009 +0200
@@ -7,7 +7,7 @@
"""
__docformat__ = "restructuredtext en"
-from cubicweb.common.uilib import simple_sgml_tag
+from cubicweb.common.uilib import simple_sgml_tag, sgml_attributes
class tag(object):
def __init__(self, name, escapecontent=True):
@@ -38,8 +38,7 @@
if id:
attrs['id'] = id
attrs['name'] = name
- html = [u'<select %s>' % ' '.join('%s="%s"' % kv
- for kv in sorted(attrs.items()))]
+ html = [u'<select %s>' % sgml_attributes(attrs)]
html += options
html.append(u'</select>')
return u'\n'.join(html)
--- a/common/uilib.py Thu Jul 16 12:57:17 2009 -0700
+++ b/common/uilib.py Tue Jul 28 21:27:52 2009 +0200
@@ -209,10 +209,18 @@
# HTML generation helper functions ############################################
+HTML4_EMPTY_TAGS = frozenset(('base', 'meta', 'link', 'hr', 'br', 'param',
+ 'img', 'area', 'input', 'col'))
+
+def sgml_attributes(attrs):
+ return u' '.join(u'%s="%s"' % (attr, xml_escape(unicode(value)))
+ for attr, value in sorted(attrs.items())
+ if value is not None)
+
def simple_sgml_tag(tag, content=None, escapecontent=True, **attrs):
"""generation of a simple sgml tag (eg without children tags) easier
- content and attributes will be escaped
+ content and attri butes will be escaped
"""
value = u'<%s' % tag
if attrs:
@@ -220,15 +228,16 @@
attrs['class'] = attrs.pop('klass')
except KeyError:
pass
- value += u' ' + u' '.join(u'%s="%s"' % (attr, xml_escape(unicode(value)))
- for attr, value in sorted(attrs.items())
- if value is not None)
+ value += u' ' + sgml_attributes(attrs)
if content:
if escapecontent:
content = xml_escape(unicode(content))
value += u'>%s</%s>' % (content, tag)
else:
- value += u'></%s>' % tag
+ if tag in HTML4_EMPTY_TAGS:
+ value += u' />'
+ else:
+ value += u'></%s>' % tag
return value
def tooltipize(text, tooltip, url=None):
--- a/cwconfig.py Thu Jul 16 12:57:17 2009 -0700
+++ b/cwconfig.py Tue Jul 28 21:27:52 2009 +0200
@@ -22,6 +22,7 @@
from os.path import exists, join, expanduser, abspath, normpath, basename, isdir
from logilab.common.decorators import cached
+from logilab.common.deprecation import deprecated_function
from logilab.common.logging_ext import set_log_methods, init_log
from logilab.common.configuration import (Configuration, Method,
ConfigurationMixIn, merge_options)
@@ -149,7 +150,7 @@
CUBES_DIR = '%(APYCOT_ROOT)s/local/share/cubicweb/cubes/' % os.environ
# create __init__ file
file(join(CUBES_DIR, '__init__.py'), 'w').close()
- elif exists(join(CW_SOFTWARE_ROOT, '.hg')):
+ elif exists(join(CW_SOFTWARE_ROOT, '.hg')) or os.environ.get('CW_MODE') == 'user':
mode = 'dev'
CUBES_DIR = abspath(normpath(join(CW_SOFTWARE_ROOT, '../cubes')))
else:
@@ -221,7 +222,7 @@
'group': 'appobjects', 'inputlevel': 2,
}),
)
- # static and class methods used to get application independant resources ##
+ # static and class methods used to get instance independant resources ##
@staticmethod
def cubicweb_version():
@@ -247,7 +248,7 @@
@classmethod
def i18n_lib_dir(cls):
- """return application's i18n directory"""
+ """return instance's i18n directory"""
if cls.mode in ('dev', 'test') and not os.environ.get('APYCOT_ROOT'):
return join(CW_SOFTWARE_ROOT, 'i18n')
return join(cls.shared_dir(), 'i18n')
@@ -424,7 +425,7 @@
@classmethod
def build_vregistry_path(cls, templpath, evobjpath=None, tvobjpath=None):
"""given a list of directories, return a list of sub files and
- directories that should be loaded by the application objects registry.
+ directories that should be loaded by the instance objects registry.
:param evobjpath:
optional list of sub-directories (or files without the .py ext) of
@@ -539,8 +540,10 @@
# for some commands (creation...) we don't want to initialize gettext
set_language = True
- # set this to true to avoid false error message while creating an application
+ # set this to true to avoid false error message while creating an instance
creating = False
+ # set this to true to allow somethings which would'nt be possible
+ repairing = False
options = CubicWebNoAppConfiguration.options + (
('log-file',
@@ -564,7 +567,7 @@
}),
('sender-name',
{'type' : 'string',
- 'default': Method('default_application_id'),
+ 'default': Method('default_instance_id'),
'help': 'name used as HELO name for outgoing emails from the \
repository.',
'group': 'email', 'inputlevel': 2,
@@ -581,49 +584,49 @@
@classmethod
def runtime_dir(cls):
"""run time directory for pid file..."""
- return env_path('CW_RUNTIME', cls.RUNTIME_DIR, 'run time')
+ return env_path('CW_RUNTIME_DIR', cls.RUNTIME_DIR, 'run time')
@classmethod
def registry_dir(cls):
"""return the control directory"""
- return env_path('CW_REGISTRY', cls.REGISTRY_DIR, 'registry')
+ return env_path('CW_INSTANCES_DIR', cls.REGISTRY_DIR, 'registry')
@classmethod
def instance_data_dir(cls):
"""return the instance data directory"""
- return env_path('CW_INSTANCE_DATA',
+ return env_path('CW_INSTANCES_DATA_DIR',
cls.INSTANCE_DATA_DIR or cls.REGISTRY_DIR,
'additional data')
@classmethod
def migration_scripts_dir(cls):
"""cubicweb migration scripts directory"""
- return env_path('CW_MIGRATION', cls.MIGRATION_DIR, 'migration')
+ return env_path('CW_MIGRATION_DIR', cls.MIGRATION_DIR, 'migration')
@classmethod
def config_for(cls, appid, config=None):
- """return a configuration instance for the given application identifier
+ """return a configuration instance for the given instance identifier
"""
- config = config or guess_configuration(cls.application_home(appid))
+ config = config or guess_configuration(cls.instance_home(appid))
configcls = configuration_cls(config)
return configcls(appid)
@classmethod
def possible_configurations(cls, appid):
"""return the name of possible configurations for the given
- application id
+ instance id
"""
- home = cls.application_home(appid)
+ home = cls.instance_home(appid)
return possible_configurations(home)
@classmethod
- def application_home(cls, appid):
- """return the home directory of the application with the given
- application id
+ def instance_home(cls, appid):
+ """return the home directory of the instance with the given
+ instance id
"""
home = join(cls.registry_dir(), appid)
if not exists(home):
- raise ConfigurationError('no such application %s (check it exists with "cubicweb-ctl list")' % appid)
+ raise ConfigurationError('no such instance %s (check it exists with "cubicweb-ctl list")' % appid)
return home
MODES = ('common', 'repository', 'Any', 'web')
@@ -637,14 +640,14 @@
# default configuration methods ###########################################
- def default_application_id(self):
- """return the application identifier, useful for option which need this
+ def default_instance_id(self):
+ """return the instance identifier, useful for option which need this
as default value
"""
return self.appid
def default_log_file(self):
- """return default path to the log file of the application'server"""
+ """return default path to the log file of the instance'server"""
if self.mode == 'dev':
basepath = '/tmp/%s-%s' % (basename(self.appid), self.name)
path = basepath + '.log'
@@ -660,10 +663,10 @@
return '/var/log/cubicweb/%s-%s.log' % (self.appid, self.name)
def default_pid_file(self):
- """return default path to the pid file of the application'server"""
+ """return default path to the pid file of the instance'server"""
return join(self.runtime_dir(), '%s-%s.pid' % (self.appid, self.name))
- # instance methods used to get application specific resources #############
+ # instance methods used to get instance specific resources #############
def __init__(self, appid):
self.appid = appid
@@ -722,7 +725,7 @@
self._cubes = self.reorder_cubes(list(self._cubes) + cubes)
def main_config_file(self):
- """return application's control configuration file"""
+ """return instance's control configuration file"""
return join(self.apphome, '%s.conf' % self.name)
def save(self):
@@ -739,7 +742,7 @@
return md5.new(';'.join(infos)).hexdigest()
def load_site_cubicweb(self):
- """load (web?) application's specific site_cubicweb file"""
+ """load instance's specific site_cubicweb file"""
for path in reversed([self.apphome] + self.cubes_path()):
sitefile = join(path, 'site_cubicweb.py')
if exists(sitefile) and not sitefile in self._site_loaded:
@@ -762,7 +765,7 @@
self.load_defaults()
def load_configuration(self):
- """load application's configuration files"""
+ """load instance's configuration files"""
super(CubicWebConfiguration, self).load_configuration()
if self.apphome and self.set_language:
# init gettext
@@ -781,7 +784,7 @@
logging.fileConfig(logconfig)
def available_languages(self, *args):
- """return available translation for an application, by looking for
+ """return available translation for an instance, by looking for
compiled catalog
take *args to be usable as a vocabulary method
@@ -861,6 +864,6 @@
set_log_methods(CubicWebConfiguration, logging.getLogger('cubicweb.configuration'))
-# alias to get a configuration instance from an application id
-application_configuration = CubicWebConfiguration.config_for
-
+# alias to get a configuration instance from an instance id
+instance_configuration = CubicWebConfiguration.config_for
+application_configuration = deprecated_function(instance_configuration, 'use instance_configuration')
--- a/cwctl.py Thu Jul 16 12:57:17 2009 -0700
+++ b/cwctl.py Tue Jul 28 21:27:52 2009 +0200
@@ -1,6 +1,6 @@
"""%%prog %s [options] %s
-CubicWeb main applications controller.
+CubicWeb main instances controller.
:license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses
%s"""
@@ -10,7 +10,7 @@
from logilab.common.clcommands import register_commands, pop_arg
-from cubicweb import ConfigurationError, ExecutionError, BadCommandUsage
+from cubicweb import ConfigurationError, ExecutionError, BadCommandUsage, underline_title
from cubicweb.cwconfig import CubicWebConfiguration as cwcfg, CONFIGURATIONS
from cubicweb.toolsutils import Command, main_run, rm, create_dir, confirm
@@ -45,11 +45,11 @@
return modes
-class ApplicationCommand(Command):
- """base class for command taking 0 to n application id as arguments
- (0 meaning all registered applications)
+class InstanceCommand(Command):
+ """base class for command taking 0 to n instance id as arguments
+ (0 meaning all registered instances)
"""
- arguments = '[<application>...]'
+ arguments = '[<instance>...]'
options = (
("force",
{'short': 'f', 'action' : 'store_true',
@@ -84,7 +84,7 @@
return allinstances
def run(self, args):
- """run the <command>_method on each argument (a list of application
+ """run the <command>_method on each argument (a list of instance
identifiers)
"""
if not args:
@@ -102,29 +102,29 @@
for appid in args:
if askconfirm:
print '*'*72
- if not confirm('%s application %r ?' % (self.name, appid)):
+ if not confirm('%s instance %r ?' % (self.name, appid)):
continue
self.run_arg(appid)
def run_arg(self, appid):
- cmdmeth = getattr(self, '%s_application' % self.name)
+ cmdmeth = getattr(self, '%s_instance' % self.name)
try:
cmdmeth(appid)
except (KeyboardInterrupt, SystemExit):
print >> sys.stderr, '%s aborted' % self.name
sys.exit(2) # specific error code
except (ExecutionError, ConfigurationError), ex:
- print >> sys.stderr, 'application %s not %s: %s' % (
+ print >> sys.stderr, 'instance %s not %s: %s' % (
appid, self.actionverb, ex)
except Exception, ex:
import traceback
traceback.print_exc()
- print >> sys.stderr, 'application %s not %s: %s' % (
+ print >> sys.stderr, 'instance %s not %s: %s' % (
appid, self.actionverb, ex)
-class ApplicationCommandFork(ApplicationCommand):
- """Same as `ApplicationCommand`, but command is forked in a new environment
+class InstanceCommandFork(InstanceCommand):
+ """Same as `InstanceCommand`, but command is forked in a new environment
for each argument
"""
@@ -136,7 +136,7 @@
for appid in args:
if askconfirm:
print '*'*72
- if not confirm('%s application %r ?' % (self.name, appid)):
+ if not confirm('%s instance %r ?' % (self.name, appid)):
continue
if forkcmd:
status = system('%s %s' % (forkcmd, appid))
@@ -148,10 +148,9 @@
# base commands ###############################################################
class ListCommand(Command):
- """List configurations, componants and applications.
+ """List configurations, cubes and instances.
- list available configurations, installed web and server componants, and
- registered applications
+ list available configurations, installed cubes, and registered instances
"""
name = 'list'
options = (
@@ -206,30 +205,30 @@
try:
regdir = cwcfg.registry_dir()
except ConfigurationError, ex:
- print 'No application available:', ex
+ print 'No instance available:', ex
print
return
instances = list_instances(regdir)
if instances:
- print 'Available applications (%s):' % regdir
+ print 'Available instances (%s):' % regdir
for appid in instances:
modes = cwcfg.possible_configurations(appid)
if not modes:
- print '* %s (BROKEN application, no configuration found)' % appid
+ print '* %s (BROKEN instance, no configuration found)' % appid
continue
print '* %s (%s)' % (appid, ', '.join(modes))
try:
config = cwcfg.config_for(appid, modes[0])
except Exception, exc:
- print ' (BROKEN application, %s)' % exc
+ print ' (BROKEN instance, %s)' % exc
continue
else:
- print 'No application available in %s' % regdir
+ print 'No instance available in %s' % regdir
print
-class CreateApplicationCommand(Command):
- """Create an application from a cube. This is an unified
+class CreateInstanceCommand(Command):
+ """Create an instance from a cube. This is an unified
command which can handle web / server / all-in-one installation
according to available parts of the software library and of the
desired cube.
@@ -238,11 +237,11 @@
the name of cube to use (list available cube names using
the "list" command). You can use several cubes by separating
them using comma (e.g. 'jpl,eemail')
- <application>
- an identifier for the application to create
+ <instance>
+ an identifier for the instance to create
"""
name = 'create'
- arguments = '<cube> <application>'
+ arguments = '<cube> <instance>'
options = (
("config-level",
{'short': 'l', 'type' : 'int', 'metavar': '<level>',
@@ -255,7 +254,7 @@
{'short': 'c', 'type' : 'choice', 'metavar': '<install type>',
'choices': ('all-in-one', 'repository', 'twisted'),
'default': 'all-in-one',
- 'help': 'installation type, telling which part of an application \
+ 'help': 'installation type, telling which part of an instance \
should be installed. You can list available configurations using the "list" \
command. Default to "all-in-one", e.g. an installation embedding both the RQL \
repository and the web server.',
@@ -285,21 +284,23 @@
print '\navailable cubes:',
print ', '.join(cwcfg.available_cubes())
return
- # create the registry directory for this application
+ # create the registry directory for this instance
+ print '\n'+underline_title('Creating the instance %s' % appid)
create_dir(config.apphome)
# load site_cubicweb from the cubes dir (if any)
config.load_site_cubicweb()
# cubicweb-ctl configuration
- print '** application\'s %s configuration' % configname
- print '-' * 72
+ print '\n'+underline_title('Configuring the instance (%s.conf)' % configname)
config.input_config('main', self.config.config_level)
# configuration'specific stuff
print
helper.bootstrap(cubes, self.config.config_level)
# write down configuration
config.save()
+ print '-> generated %s' % config.main_config_file()
# handle i18n files structure
# in the first cube given
+ print '-> preparing i18n catalogs'
from cubicweb.common import i18n
langs = [lang for lang, _ in i18n.available_catalogs(join(templdirs[0], 'i18n'))]
errors = config.i18ncompile(langs)
@@ -309,35 +310,31 @@
'continue anyway ?'):
print 'creation not completed'
return
- # create the additional data directory for this application
+ # create the additional data directory for this instance
if config.appdatahome != config.apphome: # true in dev mode
create_dir(config.appdatahome)
+ create_dir(join(config.appdatahome, 'backup'))
if config['uid']:
from logilab.common.shellutils import chown
# this directory should be owned by the uid of the server process
print 'set %s as owner of the data directory' % config['uid']
chown(config.appdatahome, config['uid'])
- print
- print
- print '*' * 72
- print 'application %s (%s) created in %r' % (appid, configname,
- config.apphome)
- print
+ print '\n-> creation done for %r.\n' % config.apphome
helper.postcreate()
-class DeleteApplicationCommand(Command):
- """Delete an application. Will remove application's files and
+class DeleteInstanceCommand(Command):
+ """Delete an instance. Will remove instance's files and
unregister it.
"""
name = 'delete'
- arguments = '<application>'
+ arguments = '<instance>'
options = ()
def run(self, args):
"""run the command with its specific arguments"""
- appid = pop_arg(args, msg="No application specified !")
+ appid = pop_arg(args, msg="No instance specified !")
configs = [cwcfg.config_for(appid, configname)
for configname in cwcfg.possible_configurations(appid)]
if not configs:
@@ -356,16 +353,16 @@
if ex.errno != errno.ENOENT:
raise
confignames = ', '.join([config.name for config in configs])
- print 'application %s (%s) deleted' % (appid, confignames)
+ print '-> instance %s (%s) deleted.' % (appid, confignames)
-# application commands ########################################################
+# instance commands ########################################################
-class StartApplicationCommand(ApplicationCommand):
- """Start the given applications. If no application is given, start them all.
+class StartInstanceCommand(InstanceCommand):
+ """Start the given instances. If no instance is given, start them all.
- <application>...
- identifiers of the applications to start. If no application is
+ <instance>...
+ identifiers of the instances to start. If no instance is
given, start them all.
"""
name = 'start'
@@ -377,7 +374,7 @@
("force",
{'short': 'f', 'action' : 'store_true',
'default': False,
- 'help': 'start the application even if it seems to be already \
+ 'help': 'start the instance even if it seems to be already \
running.'}),
('profile',
{'short': 'P', 'type' : 'string', 'metavar': '<stat file>',
@@ -386,8 +383,8 @@
}),
)
- def start_application(self, appid):
- """start the application's server"""
+ def start_instance(self, appid):
+ """start the instance's server"""
# use get() since start may be used from other commands (eg upgrade)
# without all options defined
debug = self.get('debug')
@@ -406,31 +403,31 @@
print "starting server with command :"
print command
if system(command):
- print 'an error occured while starting the application, not started'
+ print 'an error occured while starting the instance, not started'
print
return False
if not debug:
- print 'application %s started' % appid
+ print '-> instance %s started.' % appid
return True
-class StopApplicationCommand(ApplicationCommand):
- """Stop the given applications.
+class StopInstanceCommand(InstanceCommand):
+ """Stop the given instances.
- <application>...
- identifiers of the applications to stop. If no application is
+ <instance>...
+ identifiers of the instances to stop. If no instance is
given, stop them all.
"""
name = 'stop'
actionverb = 'stopped'
def ordered_instances(self):
- instances = super(StopApplicationCommand, self).ordered_instances()
+ instances = super(StopInstanceCommand, self).ordered_instances()
instances.reverse()
return instances
- def stop_application(self, appid):
- """stop the application's server"""
+ def stop_instance(self, appid):
+ """stop the instance's server"""
config = cwcfg.config_for(appid)
helper = self.config_helper(config, cmdname='stop')
helper.poststop() # do this anyway
@@ -461,15 +458,15 @@
except OSError:
# already removed by twistd
pass
- print 'application %s stopped' % appid
+ print 'instance %s stopped' % appid
-class RestartApplicationCommand(StartApplicationCommand,
- StopApplicationCommand):
- """Restart the given applications.
+class RestartInstanceCommand(StartInstanceCommand,
+ StopInstanceCommand):
+ """Restart the given instances.
- <application>...
- identifiers of the applications to restart. If no application is
+ <instance>...
+ identifiers of the instances to restart. If no instance is
given, restart them all.
"""
name = 'restart'
@@ -479,18 +476,18 @@
regdir = cwcfg.registry_dir()
if not isfile(join(regdir, 'startorder')) or len(args) <= 1:
# no specific startorder
- super(RestartApplicationCommand, self).run_args(args, askconfirm)
+ super(RestartInstanceCommand, self).run_args(args, askconfirm)
return
print ('some specific start order is specified, will first stop all '
- 'applications then restart them.')
+ 'instances then restart them.')
# get instances in startorder
stopped = []
for appid in args:
if askconfirm:
print '*'*72
- if not confirm('%s application %r ?' % (self.name, appid)):
+ if not confirm('%s instance %r ?' % (self.name, appid)):
continue
- self.stop_application(appid)
+ self.stop_instance(appid)
stopped.append(appid)
forkcmd = [w for w in sys.argv if not w in args]
forkcmd[1] = 'start'
@@ -500,46 +497,46 @@
if status:
sys.exit(status)
- def restart_application(self, appid):
- self.stop_application(appid)
- if self.start_application(appid):
- print 'application %s %s' % (appid, self.actionverb)
+ def restart_instance(self, appid):
+ self.stop_instance(appid)
+ if self.start_instance(appid):
+ print 'instance %s %s' % (appid, self.actionverb)
-class ReloadConfigurationCommand(RestartApplicationCommand):
- """Reload the given applications. This command is equivalent to a
+class ReloadConfigurationCommand(RestartInstanceCommand):
+ """Reload the given instances. This command is equivalent to a
restart for now.
- <application>...
- identifiers of the applications to reload. If no application is
+ <instance>...
+ identifiers of the instances to reload. If no instance is
given, reload them all.
"""
name = 'reload'
- def reload_application(self, appid):
- self.restart_application(appid)
+ def reload_instance(self, appid):
+ self.restart_instance(appid)
-class StatusCommand(ApplicationCommand):
- """Display status information about the given applications.
+class StatusCommand(InstanceCommand):
+ """Display status information about the given instances.
- <application>...
- identifiers of the applications to status. If no application is
- given, get status information about all registered applications.
+ <instance>...
+ identifiers of the instances to status. If no instance is
+ given, get status information about all registered instances.
"""
name = 'status'
options = ()
@staticmethod
- def status_application(appid):
- """print running status information for an application"""
+ def status_instance(appid):
+ """print running status information for an instance"""
for mode in cwcfg.possible_configurations(appid):
config = cwcfg.config_for(appid, mode)
print '[%s-%s]' % (appid, mode),
try:
pidf = config['pid-file']
except KeyError:
- print 'buggy application, pid file not specified'
+ print 'buggy instance, pid file not specified'
continue
if not exists(pidf):
print "doesn't seem to be running"
@@ -554,22 +551,22 @@
print "running with pid %s" % (pid)
-class UpgradeApplicationCommand(ApplicationCommandFork,
- StartApplicationCommand,
- StopApplicationCommand):
- """Upgrade an application after cubicweb and/or component(s) upgrade.
+class UpgradeInstanceCommand(InstanceCommandFork,
+ StartInstanceCommand,
+ StopInstanceCommand):
+ """Upgrade an instance after cubicweb and/or component(s) upgrade.
For repository update, you will be prompted for a login / password to use
to connect to the system database. For some upgrades, the given user
should have create or alter table permissions.
- <application>...
- identifiers of the applications to upgrade. If no application is
+ <instance>...
+ identifiers of the instances to upgrade. If no instance is
given, upgrade them all.
"""
name = 'upgrade'
actionverb = 'upgraded'
- options = ApplicationCommand.options + (
+ options = InstanceCommand.options + (
('force-componant-version',
{'short': 't', 'type' : 'csv', 'metavar': 'cube1=X.Y.Z,cube2=X.Y.Z',
'default': None,
@@ -587,7 +584,7 @@
('nostartstop',
{'short': 'n', 'action' : 'store_true',
'default': False,
- 'help': 'don\'t try to stop application before migration and to restart it after.'}),
+ 'help': 'don\'t try to stop instance before migration and to restart it after.'}),
('verbosity',
{'short': 'v', 'type' : 'int', 'metavar': '<0..2>',
@@ -598,7 +595,7 @@
('backup-db',
{'short': 'b', 'type' : 'yn', 'metavar': '<y or n>',
'default': None,
- 'help': "Backup the application database before upgrade.\n"\
+ 'help': "Backup the instance database before upgrade.\n"\
"If the option is ommitted, confirmation will be ask.",
}),
@@ -613,25 +610,24 @@
)
def ordered_instances(self):
- # need this since mro return StopApplicationCommand implementation
- return ApplicationCommand.ordered_instances(self)
+ # need this since mro return StopInstanceCommand implementation
+ return InstanceCommand.ordered_instances(self)
- def upgrade_application(self, appid):
+ def upgrade_instance(self, appid):
+ print '\n' + underline_title('Upgrading the instance %s' % appid)
from logilab.common.changelog import Version
config = cwcfg.config_for(appid)
- config.creating = True # notice we're not starting the server
+ config.repairing = True # notice we're not starting the server
config.verbosity = self.config.verbosity
try:
config.set_sources_mode(self.config.ext_sources or ('migration',))
except AttributeError:
# not a server config
pass
- # get application and installed versions for the server and the componants
- print 'getting versions configuration from the repository...'
+ # get instance and installed versions for the server and the componants
mih = config.migration_handler()
repo = mih.repo_connect()
vcconf = repo.get_versions()
- print 'done'
if self.config.force_componant_version:
packversions = {}
for vdef in self.config.force_componant_version:
@@ -657,13 +653,13 @@
if cubicwebversion > applcubicwebversion:
toupgrade.append(('cubicweb', applcubicwebversion, cubicwebversion))
if not self.config.fs_only and not toupgrade:
- print 'no software migration needed for application %s' % appid
+ print '-> no software migration needed for instance %s.' % appid
return
for cube, fromversion, toversion in toupgrade:
- print '**** %s migration %s -> %s' % (cube, fromversion, toversion)
+ print '-> migration needed from %s to %s for %s' % (fromversion, toversion, cube)
# only stop once we're sure we have something to do
if not (cwcfg.mode == 'dev' or self.config.nostartstop):
- self.stop_application(appid)
+ self.stop_instance(appid)
# run cubicweb/componants migration scripts
mih.migrate(vcconf, reversed(toupgrade), self.config)
# rewrite main configuration file
@@ -678,15 +674,15 @@
errors = config.i18ncompile(langs)
if errors:
print '\n'.join(errors)
- if not confirm('error while compiling message catalogs, '
+ if not confirm('Error while compiling message catalogs, '
'continue anyway ?'):
- print 'migration not completed'
+ print '-> migration not completed.'
return
mih.shutdown()
print
- print 'application migrated'
+ print '-> instance migrated.'
if not (cwcfg.mode == 'dev' or self.config.nostartstop):
- self.start_application(appid)
+ self.start_instance(appid)
print
@@ -696,11 +692,11 @@
argument may be given corresponding to a file containing commands to
execute in batch mode.
- <application>
- the identifier of the application to connect.
+ <instance>
+ the identifier of the instance to connect.
"""
name = 'shell'
- arguments = '<application> [batch command file]'
+ arguments = '<instance> [batch command file]'
options = (
('system-only',
{'short': 'S', 'action' : 'store_true',
@@ -720,7 +716,7 @@
)
def run(self, args):
- appid = pop_arg(args, 99, msg="No application specified !")
+ appid = pop_arg(args, 99, msg="No instance specified !")
config = cwcfg.config_for(appid)
if self.config.ext_sources:
assert not self.config.system_only
@@ -739,18 +735,18 @@
mih.shutdown()
-class RecompileApplicationCatalogsCommand(ApplicationCommand):
- """Recompile i18n catalogs for applications.
+class RecompileInstanceCatalogsCommand(InstanceCommand):
+ """Recompile i18n catalogs for instances.
- <application>...
- identifiers of the applications to consider. If no application is
- given, recompile for all registered applications.
+ <instance>...
+ identifiers of the instances to consider. If no instance is
+ given, recompile for all registered instances.
"""
name = 'i18ninstance'
@staticmethod
- def i18ninstance_application(appid):
- """recompile application's messages catalogs"""
+ def i18ninstance_instance(appid):
+ """recompile instance's messages catalogs"""
config = cwcfg.config_for(appid)
try:
config.bootstrap_cubes()
@@ -759,8 +755,8 @@
if ex.errno != errno.ENOENT:
raise
# bootstrap_cubes files doesn't exist
- # set creating to notify this is not a regular start
- config.creating = True
+ # notify this is not a regular start
+ config.repairing = True
# create an in-memory repository, will call config.init_cubes()
config.repository()
except AttributeError:
@@ -794,16 +790,16 @@
print cube
register_commands((ListCommand,
- CreateApplicationCommand,
- DeleteApplicationCommand,
- StartApplicationCommand,
- StopApplicationCommand,
- RestartApplicationCommand,
+ CreateInstanceCommand,
+ DeleteInstanceCommand,
+ StartInstanceCommand,
+ StopInstanceCommand,
+ RestartInstanceCommand,
ReloadConfigurationCommand,
StatusCommand,
- UpgradeApplicationCommand,
+ UpgradeInstanceCommand,
ShellCommand,
- RecompileApplicationCatalogsCommand,
+ RecompileInstanceCatalogsCommand,
ListInstancesCommand, ListCubesCommand,
))
--- a/cwvreg.py Thu Jul 16 12:57:17 2009 -0700
+++ b/cwvreg.py Tue Jul 28 21:27:52 2009 +0200
@@ -40,15 +40,15 @@
class CubicWebRegistry(VRegistry):
- """Central registry for the cubicweb application, extending the generic
+ """Central registry for the cubicweb instance, extending the generic
VRegistry with some cubicweb specific stuff.
- This is one of the central object in cubicweb application, coupling
+ This is one of the central object in cubicweb instance, coupling
dynamically loaded objects with the schema and the configuration objects.
It specializes the VRegistry by adding some convenience methods to access to
stored objects. Currently we have the following registries of objects known
- by the web application (library may use some others additional registries):
+ by the web instance (library may use some others additional registries):
* etypes
* views
@@ -91,7 +91,7 @@
self.register_property(key, **propdef)
def set_schema(self, schema):
- """set application'schema and load application objects"""
+ """set instance'schema and load application objects"""
self.schema = schema
clear_cache(self, 'rqlhelper')
# now we can load application's web objects
@@ -414,7 +414,7 @@
"""return an instance of the most specific object according
to parameters
- raise NoSelectableObject if not object apply
+ raise NoSelectableObject if no object apply
"""
for vobjectcls in vobjects:
self._fix_cls_attrs(vobjectcls)
--- a/dbapi.py Thu Jul 16 12:57:17 2009 -0700
+++ b/dbapi.py Tue Jul 28 21:27:52 2009 +0200
@@ -13,6 +13,7 @@
from logging import getLogger
from time import time, clock
+from itertools import count
from logilab.common.logging_ext import set_log_methods
from cubicweb import ETYPE_NAME_MAP, ConnectionError, RequestSessionMixIn
@@ -21,6 +22,12 @@
_MARKER = object()
+def _fake_property_value(self, name):
+ try:
+ return super(dbapi.DBAPIRequest, self).property_value(name)
+ except KeyError:
+ return ''
+
class ConnectionProperties(object):
def __init__(self, cnxtype=None, lang=None, close=True, log=False):
self.cnxtype = cnxtype or 'pyro'
@@ -60,7 +67,7 @@
raise ConnectionError('Could not get repository for %s '
'(not registered in Pyro), '
'you may have to restart your server-side '
- 'application' % nsid)
+ 'instance' % nsid)
return core.getProxyForURI(uri)
def repo_connect(repo, login, password, cnxprops=None):
@@ -394,7 +401,8 @@
raise ProgrammingError('Closed connection')
return self._repo.get_schema()
- def load_vobjects(self, cubes=_MARKER, subpath=None, expand=True, force_reload=None):
+ def load_vobjects(self, cubes=_MARKER, subpath=None, expand=True,
+ force_reload=None):
config = self.vreg.config
if cubes is _MARKER:
cubes = self._repo.get_cubes()
@@ -422,10 +430,35 @@
hm, config = self._repo.hm, self._repo.config
hm.set_schema(hm.schema) # reset structure
hm.register_system_hooks(config)
- # application specific hooks
- if self._repo.config.application_hooks:
+ # instance specific hooks
+ if self._repo.config.instance_hooks:
hm.register_hooks(config.load_hooks(self.vreg))
+ def use_web_compatible_requests(self, baseurl, sitetitle=None):
+ """monkey patch DBAPIRequest to fake a cw.web.request, so you should
+ able to call html views using rset from a simple dbapi connection.
+
+ You should call `load_vobjects` at some point to register those views.
+ """
+ from cubicweb.web.request import CubicWebRequestBase as cwrb
+ DBAPIRequest.build_ajax_replace_url = cwrb.build_ajax_replace_url.im_func
+ DBAPIRequest.list_form_param = cwrb.list_form_param.im_func
+ DBAPIRequest.property_value = _fake_property_value
+ DBAPIRequest.next_tabindex = count().next
+ DBAPIRequest.form = {}
+ DBAPIRequest.data = {}
+ fake = lambda *args, **kwargs: None
+ DBAPIRequest.relative_path = fake
+ DBAPIRequest.url = fake
+ DBAPIRequest.next_tabindex = fake
+ DBAPIRequest.add_js = fake #cwrb.add_js.im_func
+ DBAPIRequest.add_css = fake #cwrb.add_css.im_func
+ # XXX could ask the repo for it's base-url configuration
+ self.vreg.config.set_option('base-url', baseurl)
+ # XXX why is this needed? if really needed, could be fetched by a query
+ if sitetitle is not None:
+ self.vreg['propertydefs']['ui.site-title'] = {'default': sitetitle}
+
def source_defs(self):
"""Return the definition of sources used by the repository.
--- a/debian/changelog Thu Jul 16 12:57:17 2009 -0700
+++ b/debian/changelog Tue Jul 28 21:27:52 2009 +0200
@@ -1,3 +1,15 @@
+cubicweb (3.3.4-2) unstable; urgency=low
+
+ * fix conflicting test files
+
+ -- Sylvain Thénault <sylvain.thenault@logilab.fr> Tue, 21 Jul 2009 23:09:03 +0200
+
+cubicweb (3.3.4-1) unstable; urgency=low
+
+ * new upstream release
+
+ -- Sylvain Thénault <sylvain.thenault@logilab.fr> Tue, 21 Jul 2009 13:11:38 +0200
+
cubicweb (3.3.3-2) unstable; urgency=low
* re-release with "from __future__ import with_statement" commented out to
--- a/debian/control Thu Jul 16 12:57:17 2009 -0700
+++ b/debian/control Tue Jul 28 21:27:52 2009 +0200
@@ -62,7 +62,7 @@
Architecture: all
XB-Python-Version: ${python:Versions}
Depends: ${python:Depends}, cubicweb-common (= ${source:Version}), python-simplejson (>= 1.3), python-elementtree
-Recommends: python-docutils, python-vobject, fckeditor
+Recommends: python-docutils, python-vobject, fckeditor, python-fyzz
Description: web interface library for the CubicWeb framework
CubicWeb is a semantic web application framework.
.
@@ -76,8 +76,8 @@
Package: cubicweb-common
Architecture: all
XB-Python-Version: ${python:Versions}
-Depends: ${python:Depends}, graphviz, gettext, python-logilab-mtconverter (>= 0.6.0), python-logilab-common (>= 0.41.0), python-yams (>= 0.23.0), python-rql (>= 0.22.1)
-Recommends: python-simpletal (>= 4.0), python-lxml
+Depends: ${python:Depends}, graphviz, gettext, python-logilab-mtconverter (>= 0.6.0), python-logilab-common (>= 0.41.0), python-yams (>= 0.23.0), python-rql (>= 0.22.1), python-lxml
+Recommends: python-simpletal (>= 4.0)
Conflicts: cubicweb-core
Replaces: cubicweb-core
Description: common library for the CubicWeb framework
--- a/debian/cubicweb-dev.install.in Thu Jul 16 12:57:17 2009 -0700
+++ b/debian/cubicweb-dev.install.in Tue Jul 28 21:27:52 2009 +0200
@@ -1,2 +1,11 @@
debian/tmp/usr/lib/PY_VERSION/site-packages/cubicweb/devtools/ usr/lib/PY_VERSION/site-packages/cubicweb/
debian/tmp/usr/lib/PY_VERSION/site-packages/cubicweb/skeleton/ usr/lib/PY_VERSION/site-packages/cubicweb/
+debian/tmp/usr/lib/PY_VERSION/site-packages/cubicweb/test usr/lib/PY_VERSION/site-packages/cubicweb/
+debian/tmp/usr/lib/PY_VERSION/site-packages/cubicweb/common/test usr/lib/PY_VERSION/site-packages/cubicweb/common/
+debian/tmp/usr/lib/PY_VERSION/site-packages/cubicweb/entities/test usr/lib/PY_VERSION/site-packages/cubicweb/entities/
+debian/tmp/usr/lib/PY_VERSION/site-packages/cubicweb/ext/test usr/lib/PY_VERSION/site-packages/cubicweb/ext/
+debian/tmp/usr/lib/PY_VERSION/site-packages/cubicweb/server/test usr/lib/PY_VERSION/site-packages/cubicweb/server/
+debian/tmp/usr/lib/PY_VERSION/site-packages/cubicweb/sobjects/test usr/lib/PY_VERSION/site-packages/cubicweb/sobjects/
+debian/tmp/usr/lib/PY_VERSION/site-packages/cubicweb/web/test usr/lib/PY_VERSION/site-packages/cubicweb/web/
+debian/tmp/usr/lib/PY_VERSION/site-packages/cubicweb/etwist/test usr/lib/PY_VERSION/site-packages/cubicweb/etwist/
+debian/tmp/usr/lib/PY_VERSION/site-packages/cubicweb/goa/test usr/lib/PY_VERSION/site-packages/cubicweb/goa/
--- a/debian/rules Thu Jul 16 12:57:17 2009 -0700
+++ b/debian/rules Tue Jul 28 21:27:52 2009 +0200
@@ -47,12 +47,13 @@
dh_lintian
# Remove unittests directory (should be available in cubicweb-dev only)
- rm -rf debian/cubicweb-server/usr/share/pyshared/cubicweb/server/test
- rm -rf debian/cubicweb-server/usr/share/pyshared/cubicweb/sobjects/test
- rm -rf debian/cubicweb-dev/usr/share/pyshared/cubicweb/devtools/test
- rm -rf debian/cubicweb-web/usr/share/pyshared/cubicweb/web/test
- rm -rf debian/cubicweb-common/usr/share/pyshared/cubicweb/common/test
- rm -rf debian/cubicweb-common/usr/share/pyshared/cubicweb/entities/test
+ rm -rf debian/cubicweb-server/usr/lib/${PY_VERSION}/site-packages/cubicweb/server/test
+ rm -rf debian/cubicweb-server/usr/lib/${PY_VERSION}/site-packages/cubicweb/sobjects/test
+ rm -rf debian/cubicweb-web/usr/lib/${PY_VERSION}/site-packages/cubicweb/web/test
+ rm -rf debian/cubicweb-twisted/usr/lib/${PY_VERSION}/site-packages/cubicweb/etwist/test
+ rm -rf debian/cubicweb-common/usr/lib/${PY_VERSION}/site-packages/cubicweb/ext/test
+ rm -rf debian/cubicweb-common/usr/lib/${PY_VERSION}/site-packages/cubicweb/common/test
+ rm -rf debian/cubicweb-common/usr/lib/${PY_VERSION}/site-packages/cubicweb/entities/test
# cubes directory must be managed as a valid python module
touch debian/cubicweb-common/usr/share/cubicweb/cubes/__init__.py
--- a/devtools/__init__.py Thu Jul 16 12:57:17 2009 -0700
+++ b/devtools/__init__.py Tue Jul 28 21:27:52 2009 +0200
@@ -43,7 +43,7 @@
class TestServerConfiguration(ServerConfiguration):
mode = 'test'
set_language = False
- read_application_schema = False
+ read_instance_schema = False
bootstrap_schema = False
init_repository = True
options = merge_options(ServerConfiguration.options + (
@@ -77,12 +77,12 @@
def apphome(self):
if exists(self.appid):
return abspath(self.appid)
- # application cube test
+ # cube test
return abspath('..')
appdatahome = apphome
def main_config_file(self):
- """return application's control configuration file"""
+ """return instance's control configuration file"""
return join(self.apphome, '%s.conf' % self.name)
def instance_md5_version(self):
@@ -149,7 +149,7 @@
return ('en', 'fr', 'de')
def ext_resources_file(self):
- """return application's external resources file"""
+ """return instance's external resources file"""
return join(self.apphome, 'data', 'external_resources')
def pyro_enabled(self):
@@ -235,14 +235,14 @@
# XXX I'm afraid this test will prevent to run test from a production
# environment
self._sources = None
- # application cube test
+ # instance cube test
if cube is not None:
self.apphome = self.cube_dir(cube)
elif 'web' in os.getcwd().split(os.sep):
# web test
self.apphome = join(normpath(join(dirname(__file__), '..')), 'web')
else:
- # application cube test
+ # cube test
self.apphome = abspath('..')
self.sourcefile = sourcefile
self.global_set_option('realm', '')
--- a/devtools/apptest.py Thu Jul 16 12:57:17 2009 -0700
+++ b/devtools/apptest.py Tue Jul 28 21:27:52 2009 +0200
@@ -1,4 +1,4 @@
-"""This module provides misc utilities to test applications
+"""This module provides misc utilities to test instances
:organization: Logilab
:copyright: 2001-2009 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2.
@@ -59,7 +59,7 @@
def get_versions(self, checkversions=False):
- """return the a dictionary containing cubes used by this application
+ """return the a dictionary containing cubes used by this instance
as key with their version as value, including cubicweb version. This is a
public method, not requiring a session id.
@@ -406,7 +406,7 @@
rset.vreg = self.vreg
rset.req = self.session
# call to set_pool is necessary to avoid pb when using
- # application entities for convenience
+ # instance entities for convenience
self.session.set_pool()
return rset
--- a/devtools/devctl.py Thu Jul 16 12:57:17 2009 -0700
+++ b/devtools/devctl.py Tue Jul 28 21:27:52 2009 +0200
@@ -19,7 +19,7 @@
from logilab.common.textutils import get_csv
from logilab.common.clcommands import register_commands
-from cubicweb import CW_SOFTWARE_ROOT as BASEDIR, BadCommandUsage
+from cubicweb import CW_SOFTWARE_ROOT as BASEDIR, BadCommandUsage, underline_title
from cubicweb.__pkginfo__ import version as cubicwebversion
from cubicweb.toolsutils import Command, confirm, copy_skeleton
from cubicweb.web.webconfig import WebConfiguration
@@ -254,15 +254,14 @@
if args:
raise BadCommandUsage('Too much arguments')
import shutil
- from tempfile import mktemp
+ import tempfile
import yams
from logilab.common.fileutils import ensure_fs_mode
from logilab.common.shellutils import globfind, find, rm
from cubicweb.common.i18n import extract_from_tal, execute
- tempdir = mktemp()
- mkdir(tempdir)
- potfiles = [join(I18NDIR, 'entities.pot')]
- print '******** extract schema messages'
+ tempdir = tempdir.mkdtemp()
+ potfiles = [join(I18NDIR, 'static-messages.pot')]
+ print '-> extract schema messages.'
schemapot = join(tempdir, 'schema.pot')
potfiles.append(schemapot)
# explicit close necessary else the file may not be yet flushed when
@@ -270,10 +269,10 @@
schemapotstream = file(schemapot, 'w')
generate_schema_pot(schemapotstream.write, cubedir=None)
schemapotstream.close()
- print '******** extract TAL messages'
+ print '-> extract TAL messages.'
tali18nfile = join(tempdir, 'tali18n.py')
extract_from_tal(find(join(BASEDIR, 'web'), ('.py', '.pt')), tali18nfile)
- print '******** .pot files generation'
+ print '-> generate .pot files.'
for id, files, lang in [('pycubicweb', get_module_files(BASEDIR) + list(globfind(join(BASEDIR, 'misc', 'migration'), '*.py')), None),
('schemadescr', globfind(join(BASEDIR, 'schemas'), '*.py'), None),
('yams', get_module_files(yams.__path__[0]), None),
@@ -288,11 +287,11 @@
if exists(potfile):
potfiles.append(potfile)
else:
- print 'WARNING: %s file not generated' % potfile
- print '******** merging .pot files'
+ print '-> WARNING: %s file was not generated' % potfile
+ print '-> merging %i .pot files' % len(potfiles)
cubicwebpot = join(tempdir, 'cubicweb.pot')
execute('msgcat %s > %s' % (' '.join(potfiles), cubicwebpot))
- print '******** merging main pot file with existing translations'
+ print '-> merging main pot file with existing translations.'
chdir(I18NDIR)
toedit = []
for lang in LANGS:
@@ -304,11 +303,10 @@
# cleanup
rm(tempdir)
# instructions pour la suite
- print '*' * 72
- print 'you can now edit the following files:'
+ print '-> regenerated CubicWeb\'s .po catalogs.'
+ print '\nYou can now edit the following files:'
print '* ' + '\n* '.join(toedit)
- print
- print "then you'll have to update cubes catalogs using the i18ncube command"
+ print 'when you are done, run "cubicweb-ctl i18ncube yourcube".'
class UpdateTemplateCatalogCommand(Command):
@@ -329,39 +327,39 @@
def update_cubes_catalogs(cubes):
- toedit = []
for cubedir in cubes:
+ toedit = []
if not isdir(cubedir):
- print 'not a directory', cubedir
+ print '-> ignoring %s that is not a directory.' % cubedir
continue
try:
toedit += update_cube_catalogs(cubedir)
except Exception:
import traceback
traceback.print_exc()
- print 'error while updating catalogs for', cubedir
- # instructions pour la suite
- print '*' * 72
- print 'you can now edit the following files:'
- print '* ' + '\n* '.join(toedit)
-
+ print '-> error while updating catalogs for cube', cubedir
+ else:
+ # instructions pour la suite
+ print '-> regenerated .po catalogs for cube %s.' % cubedir
+ print '\nYou can now edit the following files:'
+ print '* ' + '\n* '.join(toedit)
+ print ('When you are done, run "cubicweb-ctl i18ninstance '
+ '<yourinstance>" to see changes in your instances.')
def update_cube_catalogs(cubedir):
import shutil
- from tempfile import mktemp
+ import tempfile
from logilab.common.fileutils import ensure_fs_mode
from logilab.common.shellutils import find, rm
from cubicweb.common.i18n import extract_from_tal, execute
toedit = []
cube = basename(normpath(cubedir))
- tempdir = mktemp()
- mkdir(tempdir)
- print '*' * 72
- print 'updating %s cube...' % cube
+ tempdir = tempfile.mkdtemp()
+ print underline_title('Updating i18n catalogs for cube %s' % cube)
chdir(cubedir)
- potfiles = [join('i18n', scfile) for scfile in ('entities.pot',)
+ potfiles = [join('i18n', scfile) for scfile in ('static-messages.pot',)
if exists(join('i18n', scfile))]
- print '******** extract schema messages'
+ print '-> extract schema messages'
schemapot = join(tempdir, 'schema.pot')
potfiles.append(schemapot)
# explicit close necessary else the file may not be yet flushed when
@@ -369,10 +367,10 @@
schemapotstream = file(schemapot, 'w')
generate_schema_pot(schemapotstream.write, cubedir)
schemapotstream.close()
- print '******** extract TAL messages'
+ print '-> extract TAL messages'
tali18nfile = join(tempdir, 'tali18n.py')
extract_from_tal(find('.', ('.py', '.pt'), blacklist=STD_BLACKLIST+('test',)), tali18nfile)
- print '******** extract Javascript messages'
+ print '-> extract Javascript messages'
jsfiles = [jsfile for jsfile in find('.', '.js') if basename(jsfile).startswith('cub')]
if jsfiles:
tmppotfile = join(tempdir, 'js.pot')
@@ -381,7 +379,7 @@
# no pot file created if there are no string to translate
if exists(tmppotfile):
potfiles.append(tmppotfile)
- print '******** create cube specific catalog'
+ print '-> create cube-specific catalog'
tmppotfile = join(tempdir, 'generated.pot')
cubefiles = find('.', '.py', blacklist=STD_BLACKLIST+('test',))
cubefiles.append(tali18nfile)
@@ -390,12 +388,12 @@
if exists(tmppotfile): # doesn't exists of no translation string found
potfiles.append(tmppotfile)
potfile = join(tempdir, 'cube.pot')
- print '******** merging .pot files'
+ print '-> merging %i .pot files:' % len(potfiles)
execute('msgcat %s > %s' % (' '.join(potfiles), potfile))
- print '******** merging main pot file with existing translations'
+ print '-> merging main pot file with existing translations:'
chdir('i18n')
for lang in LANGS:
- print '****', lang
+ print '-> language', lang
cubepo = '%s.po' % lang
if not exists(cubepo):
shutil.copy(potfile, cubepo)
--- a/devtools/fake.py Thu Jul 16 12:57:17 2009 -0700
+++ b/devtools/fake.py Tue Jul 28 21:27:52 2009 +0200
@@ -49,8 +49,7 @@
_registries = {
'controllers' : [Mock(id='view'), Mock(id='login'),
Mock(id='logout'), Mock(id='edit')],
- 'views' : [Mock(id='primary'), Mock(id='secondary'),
- Mock(id='oneline'), Mock(id='list')],
+ 'views' : [Mock(id='primary'), Mock(id='oneline'), Mock(id='list')],
}
def registry_objects(self, name, oid=None):
@@ -88,12 +87,12 @@
return None
def base_url(self):
- """return the root url of the application"""
+ """return the root url of the instance"""
return BASE_URL
def relative_path(self, includeparams=True):
"""return the normalized path of the request (ie at least relative
- to the application's root, but some other normalization may be needed
+ to the instance's root, but some other normalization may be needed
so that the returned path may be used to compare to generated urls
"""
if self._url.startswith(BASE_URL):
--- a/devtools/fill.py Thu Jul 16 12:57:17 2009 -0700
+++ b/devtools/fill.py Tue Jul 28 21:27:52 2009 +0200
@@ -225,7 +225,7 @@
:param etype: the entity's type
:type schema: cubicweb.schema.Schema
- :param schema: the application schema
+ :param schema: the instance schema
:type entity_num: int
:param entity_num: the number of entities to insert
@@ -325,7 +325,7 @@
def make_relations_queries(schema, edict, cursor, ignored_relations=(),
existingrels=None):
"""returns a list of generated RQL queries for relations
- :param schema: The application schema
+ :param schema: The instance schema
:param e_dict: mapping between etypes and eids
--- a/devtools/pkginfo.py Thu Jul 16 12:57:17 2009 -0700
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,126 +0,0 @@
-"""distutils / __pkginfo__ helpers for cubicweb applications
-
-:organization: Logilab
-:copyright: 2001-2009 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2.
-:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr
-:license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses
-"""
-
-import os
-from os.path import isdir, join
-
-
-def get_distutils_datafiles(cube, i18n=True, recursive=False):
- """
- :param cube: application cube's name
- """
- data_files = []
- data_files += get_basepyfiles(cube)
- data_files += get_webdatafiles(cube)
- if i18n:
- data_files += get_i18nfiles(cube)
- data_files += get_viewsfiles(cube, recursive=recursive)
- data_files += get_migrationfiles(cube)
- data_files += get_schemafiles(cube)
- return data_files
-
-
-
-## listdir filter funcs ################################################
-def nopyc_and_nodir(fname):
- if isdir(fname) or fname.endswith('.pyc') or fname.endswith('~'):
- return False
- return True
-
-def no_version_control(fname):
- if fname in ('CVS', '.svn', '.hg'):
- return False
- if fname.endswith('~'):
- return False
- return True
-
-def basepy_files(fname):
- if fname.endswith('.py') and fname != 'setup.py':
- return True
- return False
-
-def chain(*filters):
- def newfilter(fname):
- for filterfunc in filters:
- if not filterfunc(fname):
- return False
- return True
- return newfilter
-
-def listdir_with_path(path='.', filterfunc=None):
- if filterfunc:
- return [join(path, fname) for fname in os.listdir(path) if filterfunc(join(path, fname))]
- else:
- return [join(path, fname) for fname in os.listdir(path)]
-
-
-## data_files helpers ##################################################
-CUBES_DIR = join('share', 'cubicweb', 'cubes')
-
-def get_i18nfiles(cube):
- """returns i18n files in a suitable format for distutils's
- data_files parameter
- """
- i18ndir = join(CUBES_DIR, cube, 'i18n')
- potfiles = [(i18ndir, listdir_with_path('i18n', chain(no_version_control, nopyc_and_nodir)))]
- return potfiles
-
-
-def get_viewsfiles(cube, recursive=False):
- """returns views files in a suitable format for distutils's
- data_files parameter
-
- :param recursive: include views' subdirs recursively if True
- """
- if recursive:
- datafiles = []
- for dirpath, dirnames, filenames in os.walk('views'):
- filenames = [join(dirpath, fname) for fname in filenames
- if nopyc_and_nodir(join(dirpath, fname))]
- dirpath = join(CUBES_DIR, cube, dirpath)
- datafiles.append((dirpath, filenames))
- return datafiles
- else:
- viewsdir = join(CUBES_DIR, cube, 'views')
- return [(viewsdir,
- listdir_with_path('views', filterfunc=nopyc_and_nodir))]
-
-
-def get_basepyfiles(cube):
- """returns cube's base python scripts (tali18n.py, etc.)
- in a suitable format for distutils's data_files parameter
- """
- return [(join(CUBES_DIR, cube),
- [fname for fname in os.listdir('.')
- if fname.endswith('.py') and fname != 'setup.py'])]
-
-
-def get_webdatafiles(cube):
- """returns web's data files (css, png, js, etc.) in a suitable
- format for distutils's data_files parameter
- """
- return [(join(CUBES_DIR, cube, 'data'),
- listdir_with_path('data', filterfunc=no_version_control))]
-
-
-def get_migrationfiles(cube):
- """returns cube's migration scripts
- in a suitable format for distutils's data_files parameter
- """
- return [(join(CUBES_DIR, cube, 'migration'),
- listdir_with_path('migration', no_version_control))]
-
-
-def get_schemafiles(cube):
- """returns cube's schema files
- in a suitable format for distutils's data_files parameter
- """
- return [(join(CUBES_DIR, cube, 'schema'),
- listdir_with_path('schema', no_version_control))]
-
-
--- a/devtools/stresstester.py Thu Jul 16 12:57:17 2009 -0700
+++ b/devtools/stresstester.py Tue Jul 28 21:27:52 2009 +0200
@@ -1,4 +1,4 @@
-""" Usage: %s [OPTIONS] <application id> <queries file>
+""" Usage: %s [OPTIONS] <instance id> <queries file>
Stress test a CubicWeb repository
@@ -151,8 +151,8 @@
user = raw_input('login: ')
if password is None:
password = getpass('password: ')
- from cubicweb.cwconfig import application_configuration
- config = application_configuration(args[0])
+ from cubicweb.cwconfig import instance_configuration
+ config = instance_configuration(args[0])
# get local access to the repository
print "Creating repo", prof_file
repo = Repository(config, prof_file)
--- a/devtools/test/data/bootstrap_cubes Thu Jul 16 12:57:17 2009 -0700
+++ b/devtools/test/data/bootstrap_cubes Tue Jul 28 21:27:52 2009 +0200
@@ -1,1 +1,1 @@
-person, comment
+person
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/devtools/test/data/schema.py Tue Jul 28 21:27:52 2009 +0200
@@ -0,0 +1,20 @@
+"""
+
+:organization: Logilab
+:copyright: 2001-2009 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2.
+:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr
+:license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses
+"""
+from yams.buildobjs import EntityType, SubjectRelation, String, Int, Date
+
+from cubes.person.schema import Person
+
+Person.add_relation(Date(), 'birthday')
+
+class Bug(EntityType):
+ title = String(maxsize=64, required=True, fulltextindexed=True)
+ severity = String(vocabulary=('important', 'normal', 'minor'), default='normal')
+ cost = Int()
+ description = String(maxsize=4096, fulltextindexed=True)
+ identical_to = SubjectRelation('Bug', symetric=True)
+
--- a/devtools/test/data/schema/Bug.sql Thu Jul 16 12:57:17 2009 -0700
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,5 +0,0 @@
-title ivarchar(64) not null
-state CHOICE('open', 'rejected', 'validation pending', 'resolved') default 'open'
-severity CHOICE('important', 'normal', 'minor') default 'normal'
-cost integer
-description ivarchar(4096)
--- a/devtools/test/data/schema/Project.sql Thu Jul 16 12:57:17 2009 -0700
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,6 +0,0 @@
-name ivarchar(64) not null
-summary ivarchar(128)
-vcsurl varchar(256)
-reporturl varchar(256)
-description ivarchar(1024)
-url varchar(128)
--- a/devtools/test/data/schema/Story.sql Thu Jul 16 12:57:17 2009 -0700
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,5 +0,0 @@
-title ivarchar(64) not null
-state CHOICE('open', 'rejected', 'validation pending', 'resolved') default 'open'
-priority CHOICE('minor', 'normal', 'important') default 'normal'
-cost integer
-description ivarchar(4096)
--- a/devtools/test/data/schema/Version.sql Thu Jul 16 12:57:17 2009 -0700
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,3 +0,0 @@
-num varchar(16) not null
-diem date
-status CHOICE('planned', 'dev', 'published') default 'planned'
--- a/devtools/test/data/schema/custom.py Thu Jul 16 12:57:17 2009 -0700
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,9 +0,0 @@
-"""
-
-:organization: Logilab
-:copyright: 2001-2009 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2.
-:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr
-:license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses
-"""
-Person = import_erschema('Person')
-Person.add_relation(Date(), 'birthday')
--- a/devtools/test/data/schema/relations.rel Thu Jul 16 12:57:17 2009 -0700
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,33 +0,0 @@
-Bug concerns Project inline
-Story concerns Project inline
-
-Bug corrected_in Version inline CONSTRAINT E concerns P, X version_of P
-Story done_in Version inline CONSTRAINT E concerns P, X version_of P
-
-Bug identical_to Bug symetric
-Bug identical_to Story symetric
-Story identical_to Story symetric
-
-Story depends_on Story
-Story depends_on Bug
-Bug depends_on Story
-Bug depends_on Bug
-
-Bug see_also Bug symetric
-Bug see_also Story symetric
-Bug see_also Project symetric
-Story see_also Story symetric
-Story see_also Project symetric
-Project see_also Project symetric
-
-Project uses Project
-
-Version version_of Project inline
-Version todo_by CWUser
-
-Comment about Bug inline
-Comment about Story inline
-Comment about Comment inline
-
-CWUser interested_in Project
-
--- a/doc/book/en/B000-development.en.txt Thu Jul 16 12:57:17 2009 -0700
+++ b/doc/book/en/B000-development.en.txt Tue Jul 28 21:27:52 2009 +0200
@@ -1,7 +1,5 @@
.. -*- coding: utf-8 -*-
-.. _Part2:
-
=====================
Part II - Development
=====================
--- a/doc/book/en/Z012-create-instance.en.txt Thu Jul 16 12:57:17 2009 -0700
+++ b/doc/book/en/Z012-create-instance.en.txt Tue Jul 28 21:27:52 2009 +0200
@@ -8,14 +8,14 @@
--------------------
A *CubicWeb* instance is a container that
-refers to cubes and configuration parameters for your web application.
+refers to cubes and configuration parameters for your web instance.
Each instance is stored as a directory in ``~/etc/cubicweb.d`` which enables
-us to run your application.
+us to run your instance.
What is a cube?
---------------
-Cubes represent data and basic building bricks of your web applications :
+Cubes represent data and basic building bricks of your web instances :
blogs, person, date, addressbook and a lot more.
.. XXX They related to each other by a 'Schema' which is also the PostGres representation.
@@ -35,7 +35,7 @@
------------------------------------
We can create an instance to view our
-application in a web browser. ::
+instance in a web browser. ::
cubicweb-ctl create blog myblog
@@ -55,14 +55,14 @@
(:ref:`ConfigurationPostgres`).
It is important to distinguish here the user used to access the database and
-the user used to login to the cubicweb application. When a *CubicWeb* application
+the user used to login to the cubicweb instance. When a *CubicWeb* instance
starts, it uses the login/psswd for the database to get the schema and handle
low level transaction. But, when ``cubicweb-ctl create`` asks for
-a manager login/psswd of *CubicWeb*, it refers to an application user
-to administrate your web application.
+a manager login/psswd of *CubicWeb*, it refers to an instance user
+to administrate your web instance.
The configuration files are stored in *~/etc/cubicweb.d/myblog/*.
-To launch the web application, you just type ::
+To launch the web instance, you just type ::
cubicweb-ctl start myblog
--- a/doc/book/en/admin/create-instance.rst Thu Jul 16 12:57:17 2009 -0700
+++ b/doc/book/en/admin/create-instance.rst Tue Jul 28 21:27:52 2009 +0200
@@ -6,9 +6,8 @@
Instance creation
-----------------
-Now that we created our cube, we can create an instance to view our
-application in a web browser. To do so we will use a `all-in-one`
-configuration to simplify things ::
+Now that we created a cube, we can create an instance and access it via a web
+browser. We will use a `all-in-one` configuration to simplify things ::
cubicweb-ctl create -c all-in-one mycube myinstance
@@ -24,12 +23,12 @@
(:ref:`ConfigurationPostgres`).
It is important to distinguish here the user used to access the database and the
-user used to login to the cubicweb application. When an instance starts, it uses
+user used to login to the cubicweb instance. When an instance starts, it uses
the login/psswd for the database to get the schema and handle low level
transaction. But, when :command:`cubicweb-ctl create` asks for a manager
login/psswd of *CubicWeb*, it refers to the user you will use during the
-development to administrate your web application. It will be possible, later on,
-to use this user to create others users for your final web application.
+development to administrate your web instance. It will be possible, later on,
+to use this user to create others users for your final web instance.
Instance administration
@@ -60,5 +59,9 @@
upgrade
~~~~~~~
+The command is::
+
+ cubicweb-ctl upgrade myinstance
+
XXX write me
--- a/doc/book/en/admin/gae.rst Thu Jul 16 12:57:17 2009 -0700
+++ b/doc/book/en/admin/gae.rst Tue Jul 28 21:27:52 2009 +0200
@@ -126,14 +126,14 @@
'cubicweb'". They disappear after the first run of i18ninstance.
.. note:: The command myapp/bin/laxctl i18ncube needs to be executed
- only if your application is using cubes from cubicweb-apps.
+ only if your instance is using cubes from cubicweb-apps.
Otherwise, please skip it.
-You will never need to add new entries in the translation catalog. Instead we would
-recommand you to use ``self.req._("msgId")`` in your application code
-to flag new message id to add to the catalog, where ``_`` refers to
-xgettext that is used to collect new strings to translate.
-While running ``laxctl i18ncube``, new string will be added to the catalogs.
+You will never need to add new entries in the translation catalog. Instead we
+would recommand you to use ``self.req._("msgId")`` in your code to flag new
+message id to add to the catalog, where ``_`` refers to xgettext that is used to
+collect new strings to translate. While running ``laxctl i18ncube``, new string
+will be added to the catalogs.
Generating the data directory
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -152,18 +152,18 @@
$ python myapp/bin/laxctl genschema
-Application configuration
+Instance configuration
-------------------------
Authentication
~~~~~~~~~~~~~~
-You have the option of using or not google authentication for your application.
+You have the option of using or not google authentication for your instance.
This has to be define in ``app.conf`` and ``app.yaml``.
In ``app.conf`` modify the following variable::
Â
- # does this application rely on google authentication service or not.
+ # does this instance rely on google authentication service or not.
use-google-auth=no
In ``app.yaml`` comment the `login: required` set by default in the handler::
@@ -177,7 +177,7 @@
-Quickstart : launch the application
+Quickstart : launch the instance
-----------------------------------
On Mac OS X platforms, drag that directory on the
@@ -189,7 +189,7 @@
Once the local server is started, visit `http://MYAPP_URL/_load <http://localhost:8080/_load>`_ and sign in as administrator.
This will initialize the repository and enable you to log in into
-the application and continue the installation.
+the instance and continue the installation.
You should be redirected to a page displaying a message `content initialized`.
--- a/doc/book/en/admin/index.rst Thu Jul 16 12:57:17 2009 -0700
+++ b/doc/book/en/admin/index.rst Tue Jul 28 21:27:52 2009 +0200
@@ -7,7 +7,7 @@
-------------------------
This part is for installation and administration of the *CubicWeb* framework and
-applications based on that framework.
+instances based on that framework.
.. toctree::
:maxdepth: 1
@@ -25,11 +25,11 @@
RQL logs
--------
-You can configure the *CubicWeb* application to keep a log
+You can configure the *CubicWeb* instance to keep a log
of the queries executed against your database. To do so,
-edit the configuration file of your application
+edit the configuration file of your instance
``.../etc/cubicweb.d/myapp/all-in-one.conf`` and uncomment the
variable ``query-log-file``::
- # web application query log file
+ # web instance query log file
query-log-file=/tmp/rql-myapp.log
--- a/doc/book/en/admin/instance-config.rst Thu Jul 16 12:57:17 2009 -0700
+++ b/doc/book/en/admin/instance-config.rst Tue Jul 28 21:27:52 2009 +0200
@@ -6,11 +6,11 @@
While creating an instance, a configuration file is generated in::
- $ (CW_REGISTRY) / <instance> / <configuration name>.conf
+ $ (CW_INSTANCES_DIR) / <instance> / <configuration name>.conf
For example::
- /etc/cubicweb.d/JPL/all-in-one.conf
+ /etc/cubicweb.d/myblog/all-in-one.conf
It is a simple text file format INI. In the following description,
each option name is prefixed with its own section and followed by its
@@ -22,7 +22,7 @@
:`web.auth-model` [cookie]:
authentication mode, cookie or http
:`web.realm`:
- realm of the application in http authentication mode
+ realm of the instance in http authentication mode
:`web.http-session-time` [0]:
period of inactivity of an HTTP session before it closes automatically.
Duration in seconds, 0 meaning no expiration (or more exactly at the
@@ -70,7 +70,7 @@
regular expression matching sites which could be "embedded" in
the site (controllers 'embed')
:`web.submit-url`:
- url where the bugs encountered in the application can be mailed to
+ url where the bugs encountered in the instance can be mailed to
RQL server configuration
@@ -92,7 +92,7 @@
-----------------------------------
Web server side:
-:`pyro-client.pyro-application-id`:
+:`pyro-client.pyro-instance-id`:
pyro identifier of RQL server (e.g. the instance name)
RQL server side:
@@ -107,7 +107,7 @@
hostname hosting pyro server name. If no value is
specified, it is located by a request from broadcast
:`pyro-name-server.pyro-ns-group` [cubicweb]:
- pyro group in which to save the application
+ pyro group in which to save the instance
Configuring e-mail
@@ -125,9 +125,9 @@
:`email.smtp-port [25]`:
SMTP server port to use for outgoing mail
:`email.sender-name`:
- name to use for outgoing mail of the application
+ name to use for outgoing mail of the instance
:`email.sender-addr`:
- address for outgoing mail of the application
+ address for outgoing mail of the instance
:`email.default dest-addrs`:
destination addresses by default, if used by the configuration of the
dissemination of the model (separated by commas)
--- a/doc/book/en/admin/multisources.rst Thu Jul 16 12:57:17 2009 -0700
+++ b/doc/book/en/admin/multisources.rst Tue Jul 28 21:27:52 2009 +0200
@@ -1,4 +1,6 @@
-Integrating some data from another instance
-===========================================
+Multiple sources of data
+========================
-XXX feed me
\ No newline at end of file
+Data sources include SQL, LDAP, RQL, mercurial and subversion.
+
+XXX feed me
--- a/doc/book/en/admin/setup.rst Thu Jul 16 12:57:17 2009 -0700
+++ b/doc/book/en/admin/setup.rst Tue Jul 28 21:27:52 2009 +0200
@@ -39,7 +39,7 @@
apt-get install cubicweb cubicweb-dev
`cubicweb` installs the framework itself, allowing you to create
-new applications.
+new instances.
`cubicweb-dev` installs the development environment allowing you to
develop new cubes.
@@ -47,12 +47,12 @@
There is also a wide variety of cubes listed on http://www.cubicweb.org/Project available as debian packages and tarball.
The repositories are signed with `Logilab's gnupg key`_. To avoid warning on "apt-get update":
-1. become root using sudo
+1. become root using sudo
2. download http://ftp.logilab.org/dists/logilab-dists-key.asc using e.g. wget
3. run "apt-key add logilab-dists-key.asc"
4. re-run apt-get update (manually or through the package manager, whichever you prefer)
-.. `Logilab's gnupg key` _http://ftp.logilab.org/dists/logilab-dists-key.asc
+.. _`Logilab's gnupg key`: http://ftp.logilab.org/dists/logilab-dists-key.asc
Install from source
```````````````````
@@ -69,19 +69,29 @@
hg fclone http://www.logilab.org/hg/forests/cubicweb
See :ref:`MercurialPresentation` for more details about Mercurial.
+When cloning a repository, you might be set in a development branch
+(the 'default' branch). You should check that the branches of the
+repositories are set to 'stable' (using `hg up stable` for each one)
+if you do not intend to develop the framework itself.
-Postgres installation
-`````````````````````
+In both cases, make sure you have installed the dependencies (see appendixes for
+the list).
-Please refer to the `Postgresql project online documentation`_.
+PostgreSQL installation
+```````````````````````
+
+Please refer to the `PostgreSQL project online documentation`_.
-.. _`Postgresql project online documentation`: http://www.postgresql.org/
+.. _`PostgreSQL project online documentation`: http://www.postgresql.org/
-You need to install the three following packages: `postgres-8.3`,
-`postgres-contrib-8.3` and `postgresql-plpython-8.3`.
+You need to install the three following packages: `postgresql-8.3`,
+`postgresql-contrib-8.3` and `postgresql-plpython-8.3`.
-Then you can install:
+Other dependencies
+``````````````````
+
+You can also install:
* `pyro` if you wish the repository to be accessible through Pyro
or if the client and the server are not running on the same machine
@@ -102,19 +112,20 @@
Add the following lines to either `.bashrc` or `.bash_profile` to configure
your development environment ::
- export PYTHONPATH=/full/path/to/cubicweb-forest
+ export PYTHONPATH=/full/path/to/cubicweb-forest
-If you installed the debian packages, no configuration is required.
-Your new cubes will be placed in `/usr/share/cubicweb/cubes` and
-your applications will be placed in `/etc/cubicweb.d`.
+If you installed *CubicWeb* with packages, no configuration is required and your
+new cubes will be placed in `/usr/share/cubicweb/cubes` and your instances
+will be placed in `/etc/cubicweb.d`.
-To use others directories then you will have to configure the
-following environment variables as follows::
+You may run a system-wide install of *CubicWeb* in "user mode" and use it for
+development by setting the following environment variable::
+ export CW_MODE=user
export CW_CUBES_PATH=~/lib/cubes
- export CW_REGISTRY=~/etc/cubicweb.d/
- export CW_INSTANCE_DATA=$CW_REGISTRY
- export CW_RUNTIME=/tmp
+ export CW_INSTANCES_DIR=~/etc/cubicweb.d/
+ export CW_INSTANCES_DATA_DIR=$CW_INSTANCES_DIR
+ export CW_RUNTIME_DIR=/tmp
.. note::
The values given above are our suggestions but of course
@@ -126,22 +137,22 @@
-.. _ConfigurationPostgres:
+.. _ConfigurationPostgresql:
-Postgres configuration
-``````````````````````
+PostgreSQL configuration
+````````````````````````
.. note::
- If you already have an existing cluster and postgres server
+ If you already have an existing cluster and PostgreSQL server
running, you do not need to execute the initilization step
- of your Postgres database.
+ of your PostgreSQL database.
-* First, initialize the database Postgres with the command ``initdb``.
+* First, initialize the database PostgreSQL with the command ``initdb``.
::
$ initdb -D /path/to/pgsql
- Once initialized, start the database server Postgres
+ Once initialized, start the database server PostgreSQL
with the command::
$ postgres -D /path/to/psql
@@ -173,7 +184,7 @@
This login/password will be requested when you will create an
instance with `cubicweb-ctl create` to initialize the database of
- your application.
+ your instance.
.. note::
The authentication method can be configured in ``pg_hba.conf``.
@@ -191,13 +202,17 @@
MySql configuration
```````````````````
-Yout must add the following lines in /etc/mysql/my.cnf file::
+Yout must add the following lines in ``/etc/mysql/my.cnf`` file::
transaction-isolation = READ-COMMITTED
default-storage-engine=INNODB
default-character-set=utf8
max_allowed_packet = 128M
+.. note::
+ It is unclear whether mysql supports indexed string of arbitrary lenght or
+ not.
+
Pyro configuration
------------------
--- a/doc/book/en/admin/site-config.rst Thu Jul 16 12:57:17 2009 -0700
+++ b/doc/book/en/admin/site-config.rst Tue Jul 28 21:27:52 2009 +0200
@@ -5,7 +5,7 @@
.. image:: ../images/lax-book.03-site-config-panel.en.png
-This panel allows you to configure the appearance of your application site.
+This panel allows you to configure the appearance of your instance site.
Six menus are available and we will go through each of them to explain how
to use them.
@@ -65,9 +65,9 @@
Boxes
~~~~~
-The application has already a pre-defined set of boxes you can use right away.
+The instance has already a pre-defined set of boxes you can use right away.
This configuration section allows you to place those boxes where you want in the
-application interface to customize it.
+instance interface to customize it.
The available boxes are :
@@ -82,7 +82,7 @@
* search box : search box
* startup views box : box listing the configuration options available for
- the application site, such as `Preferences` and `Site Configuration`
+ the instance site, such as `Preferences` and `Site Configuration`
Components
~~~~~~~~~~
--- a/doc/book/en/annexes/cookbook.rst Thu Jul 16 12:57:17 2009 -0700
+++ b/doc/book/en/annexes/cookbook.rst Tue Jul 28 21:27:52 2009 +0200
@@ -9,8 +9,10 @@
* How to import LDAP users in *CubicWeb*?
+ [XXX distribute this script with cubicweb instead]
+
Here is a very useful script which enables you to import LDAP users
- into your *CubicWeb* application by running the following: ::
+ into your *CubicWeb* instance by running the following: ::
import os
@@ -66,7 +68,7 @@
* How to load data from a script?
The following script aims at loading data within a script assuming pyro-nsd is
- running and your application is configured with ``pyro-server=yes``, otherwise
+ running and your instance is configured with ``pyro-server=yes``, otherwise
you would not be able to use dbapi. ::
from cubicweb import dbapi
--- a/doc/book/en/annexes/cubicweb-ctl.rst Thu Jul 16 12:57:17 2009 -0700
+++ b/doc/book/en/annexes/cubicweb-ctl.rst Tue Jul 28 21:27:52 2009 +0200
@@ -26,8 +26,8 @@
------------------------
* ``newcube``, create a new cube on the file system based on the name
- given in the parameters. This command create a cube from an application
- skeleton that includes default files required for debian packaging.
+ given in the parameters. This command create a cube from a skeleton
+ that includes default files required for debian packaging.
Command to create an instance
@@ -69,7 +69,7 @@
* ``db-check``, checks data integrity of an instance. If the automatic correction
is activated, it is recommanded to create a dump before this operation.
* ``schema-sync``, synchronizes the persistent schema of an instance with
- the application schema. It is recommanded to create a dump before this operation.
+ the instance schema. It is recommanded to create a dump before this operation.
Commands to maintain i18n catalogs
----------------------------------
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/doc/book/en/annexes/depends.rst Tue Jul 28 21:27:52 2009 +0200
@@ -0,0 +1,51 @@
+.. -*- coding: utf-8 -*-
+
+.. _dependencies:
+
+Dependencies
+============
+
+When you run CubicWeb from source, either by downloading the tarball or
+cloning the mercurial forest, here is the list of tools and libraries you need
+to have installed in order for CubicWeb to work:
+
+* mxDateTime - http://www.egenix.com/products/python/mxBase/mxDateTime/ - http://pypi.python.org/pypi/egenix-mx-base
+
+* pyro - http://pyro.sourceforge.net/ - http://pypi.python.org/pypi/Pyro
+
+* yapps - http://theory.stanford.edu/~amitp/yapps/ -
+ http://pypi.python.org/pypi/Yapps2
+
+* pygraphviz - http://networkx.lanl.gov/pygraphviz/ -
+ http://pypi.python.org/pypi/pygraphviz
+
+* simplejson - http://code.google.com/p/simplejson/ -
+ http://pypi.python.org/pypi/simplejson
+
+* lxml - http://codespeak.net/lxml - http://pypi.python.org/pypi/lxml
+
+* twisted - http://twistedmatrix.com/ - http://pypi.python.org/pypi/Twisted
+
+* logilab-common - http://www.logilab.org/project/logilab-common -
+ http://pypi.python.org/pypi/logilab-common/ - included in the forest
+
+* logilab-constraint - http://www.logilab.org/project/logilab-constraint -
+ http://pypi.python.org/pypi/constraint/ - included in the forest
+
+* logilab-mtconverter - http://www.logilab.org/project/logilab-mtconverter -
+ http://pypi.python.org/pypi/logilab-mtconverter - included in the forest
+
+* rql - http://www.logilab.org/project/rql - http://pypi.python.org/pypi/rql -
+ included in the forest
+
+* yams - http://www.logilab.org/project/yams - http://pypi.python.org/pypi/yams
+ - included in the forest
+
+* indexer - http://www.logilab.org/project/indexer -
+ http://pypi.python.org/pypi/indexer - included in the forest
+
+* fyzz - http://www.logilab.org/project/fyzz - http://pypi.python.org/pypi/fyzz
+ - included in the forest
+
+Any help with the packaging of CubicWeb for more than Debian/Ubuntu (including
+eggs, buildouts, etc) will be greatly appreciated.
--- a/doc/book/en/annexes/faq.rst Thu Jul 16 12:57:17 2009 -0700
+++ b/doc/book/en/annexes/faq.rst Tue Jul 28 21:27:52 2009 +0200
@@ -39,11 +39,10 @@
When doing development, you need a real language and template
languages are not real languages.
- Using Python enables developing applications for which code is
- easier to maintain with real functions/classes/contexts
- without the need of learning a new dialect. By using Python,
- we use standard OOP techniques and this is a key factor in a
- robust application.
+ Using Python instead of a template langage for describing the user interface
+ makes it to maintain with real functions/classes/contexts without the need of
+ learning a new dialect. By using Python, we use standard OOP techniques and
+ this is a key factor in a robust application.
Why do you use the LGPL license to prevent me from doing X ?
------------------------------------------------------------
@@ -141,7 +140,7 @@
------------------------------------------------
While modifying the description of an entity, you get an error message in
- the application `Error while publishing ...` for Rest text and plain text.
+ the instance `Error while publishing ...` for Rest text and plain text.
The server returns a traceback like as follows ::
2008-10-06 15:05:08 - (cubicweb.rest) ERROR: error while publishing ReST text
@@ -188,11 +187,8 @@
It depends on what has been modified in the schema.
- * Update of an attribute permissions and properties:
- ``synchronize_eschema('MyEntity')``.
-
- * Update of a relation permissions and properties:
- ``synchronize_rschema('MyRelation')``.
+ * Update the permissions and properties of an entity or a relation:
+ ``sync_schema_props_perms('MyEntityOrRelation')``.
* Add an attribute: ``add_attribute('MyEntityType', 'myattr')``.
@@ -225,14 +221,14 @@
decribed above.
-How to change the application logo ?
+How to change the instance logo ?
------------------------------------
There are two ways of changing the logo.
1. The easiest way to use a different logo is to replace the existing
``logo.png`` in ``myapp/data`` by your prefered icon and refresh.
- By default all application will look for a ``logo.png`` to be
+ By default all instance will look for a ``logo.png`` to be
rendered in the logo section.
.. image:: ../images/lax-book.06-main-template-logo.en.png
@@ -270,7 +266,7 @@
user-attrs-map=gecos:email,uid:login
Any change applied to configuration file requires to restart your
- application.
+ instance.
I get NoSelectableObject exceptions, how do I debug selectors ?
---------------------------------------------------------------
@@ -316,14 +312,14 @@
If you have PostgreSQL set up to accept kerberos authentication, you can set
the db-host, db-name and db-user parameters in the `sources` configuration
file while leaving the password blank. It should be enough for your
- application to connect to postgresql with a kerberos ticket.
+ instance to connect to postgresql with a kerberos ticket.
How to load data from a script ?
--------------------------------
The following script aims at loading data within a script assuming pyro-nsd is
- running and your application is configured with ``pyro-server=yes``, otherwise
+ running and your instance is configured with ``pyro-server=yes``, otherwise
you would not be able to use dbapi. ::
from cubicweb import dbapi
@@ -337,7 +333,7 @@
What is the CubicWeb datatype corresponding to GAE datastore's UserProperty ?
-----------------------------------------------------------------------------
- If you take a look at your application schema and
+ If you take a look at your instance schema and
click on "display detailed view of metadata" you will see that there
is a Euser entity in there. That's the one that is modeling users. The
thing that corresponds to a UserProperty is a relationship between
--- a/doc/book/en/annexes/index.rst Thu Jul 16 12:57:17 2009 -0700
+++ b/doc/book/en/annexes/index.rst Tue Jul 28 21:27:52 2009 +0200
@@ -16,6 +16,7 @@
cubicweb-ctl
rql/index
mercurial
+ depends
(X)HTML tricks to apply
-----------------------
--- a/doc/book/en/annexes/rql/intro.rst Thu Jul 16 12:57:17 2009 -0700
+++ b/doc/book/en/annexes/rql/intro.rst Tue Jul 28 21:27:52 2009 +0200
@@ -5,41 +5,38 @@
Goals of RQL
~~~~~~~~~~~~
-The goal is to have a language emphasizing the way of browsing
-relations. As such, attributes will be regarded as cases of
-special relations (in terms of implementation, the language
-user should see virtually no difference between an attribute and a
+The goal is to have a language emphasizing the way of browsing relations. As
+such, attributes will be regarded as cases of special relations (in terms of
+implementation, the user should see no difference between an attribute and a
relation).
-RQL is inspired by SQL but is the highest level. A knowledge of the
-*CubicWeb* schema defining the application is necessary.
-
Comparison with existing languages
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
SQL
```
-RQL builds on the features of SQL but is at a higher level
-(the current implementation of RQL generates SQL). For that it is limited
-to the way of browsing relations and introduces variables.
-The user does not need to know the model underlying SQL, but the *CubicWeb*
-schema defining the application.
+
+RQL may remind of SQL but works at a higher abstraction level (the *CubicWeb*
+framework generates SQL from RQL to fetch data from relation databases). RQL is
+focused on browsing relations. The user needs only to know about the *CubicWeb*
+data model he is querying, but not about the underlying SQL model.
+
+Sparql
+``````
+
+The query language most similar to RQL is SPARQL_, defined by the W3C to serve
+for the semantic web.
Versa
`````
-We should look in more detail, but here are already some ideas for
-the moment ... Versa_ is the language most similar to what we wanted
-to do, but the model underlying data being RDF, there is some
-number of things such as namespaces or handling of the RDF types which
-does not interest us. On the functionality level, Versa_ is very comprehensive
-including through many functions of conversion and basic types manipulation,
-which may need to be guided at one time or another.
-Finally, the syntax is a little esoteric.
-Sparql
-``````
-The query language most similar to RQL is SPARQL_, defined by the W3C to serve
-for the semantic web.
+We should look in more detail, but here are already some ideas for the moment
+... Versa_ is the language most similar to what we wanted to do, but the model
+underlying data being RDF, there is some number of things such as namespaces or
+handling of the RDF types which does not interest us. On the functionality
+level, Versa_ is very comprehensive including through many functions of
+conversion and basic types manipulation, which may need to be guided at one time
+or another. Finally, the syntax is a little esoteric.
The different types of queries
--- a/doc/book/en/conf.py Thu Jul 16 12:57:17 2009 -0700
+++ b/doc/book/en/conf.py Tue Jul 28 21:27:52 2009 +0200
@@ -51,7 +51,7 @@
# The short X.Y version.
version = '0.54'
# The full version, including alpha/beta/rc tags.
-release = '3.2'
+release = '3.4'
# There are two options for replacing |today|: either, you set today to some
# non-false value, then it is used:
--- a/doc/book/en/development/cubes/available-cubes.rst Thu Jul 16 12:57:17 2009 -0700
+++ b/doc/book/en/development/cubes/available-cubes.rst Tue Jul 28 21:27:52 2009 +0200
@@ -2,7 +2,7 @@
Available cubes
---------------
-An application is based on several basic cubes. In the set of available
+An instance is based on several basic cubes. In the set of available
basic cubes we can find for example :
Base entity types
--- a/doc/book/en/development/cubes/layout.rst Thu Jul 16 12:57:17 2009 -0700
+++ b/doc/book/en/development/cubes/layout.rst Tue Jul 28 21:27:52 2009 +0200
@@ -80,7 +80,7 @@
* ``entities`` contains the entities definition (server side and web interface)
* ``sobjects`` contains hooks and/or views notifications (server side only)
* ``views`` contains the web interface components (web interface only)
-* ``test`` contains tests related to the application (not installed)
+* ``test`` contains tests related to the cube (not installed)
* ``i18n`` contains message catalogs for supported languages (server side and
web interface)
* ``data`` contains data files for static content (images, css, javascripts)
--- a/doc/book/en/development/datamodel/baseschema.rst Thu Jul 16 12:57:17 2009 -0700
+++ b/doc/book/en/development/datamodel/baseschema.rst Tue Jul 28 21:27:52 2009 +0200
@@ -1,9 +1,9 @@
-Pre-defined schemas in the library
+Pre-defined entities in the library
----------------------------------
The library defines a set of entity schemas that are required by the system
-or commonly used in *CubicWeb* applications.
+or commonly used in *CubicWeb* instances.
Entity types used to store the schema
@@ -18,7 +18,7 @@
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* `CWUser`, system users
* `CWGroup`, users groups
-* `CWPermission`, used to configure the security of the application
+* `CWPermission`, used to configure the security of the instance
Entity types used to manage workflows
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -28,11 +28,11 @@
Other entity types
~~~~~~~~~~~~~~~~~~
-* `CWCache`
-* `CWProperty`, used to configure the application
+* `CWCache`, cache entities used to improve performances
+* `CWProperty`, used to configure the instance
* `EmailAddress`, email address, used by the system to send notifications
to the users and also used by others optionnals schemas
* `Bookmark`, an entity type used to allow a user to customize his links within
- the application
+ the instance
--- a/doc/book/en/development/datamodel/define-workflows.rst Thu Jul 16 12:57:17 2009 -0700
+++ b/doc/book/en/development/datamodel/define-workflows.rst Tue Jul 28 21:27:52 2009 +0200
@@ -2,8 +2,8 @@
.. _Workflow:
-An Example: Workflow definition
-===============================
+Define a Workflow
+=================
General
-------
@@ -20,7 +20,7 @@
-----------------
We want to create a workflow to control the quality of the BlogEntry
-submitted on your application. When a BlogEntry is created by a user
+submitted on your instance. When a BlogEntry is created by a user
its state should be `submitted`. To be visible to all, it has to
be in the state `published`. To move it from `submitted` to `published`,
we need a transition that we can call `approve_blogentry`.
--- a/doc/book/en/development/datamodel/definition.rst Thu Jul 16 12:57:17 2009 -0700
+++ b/doc/book/en/development/datamodel/definition.rst Tue Jul 28 21:27:52 2009 +0200
@@ -3,7 +3,7 @@
Yams *schema*
-------------
-The **schema** is the core piece of a *CubicWeb* application as it defines
+The **schema** is the core piece of a *CubicWeb* instance as it defines
the handled data model. It is based on entity types that are either already
defined in the *CubicWeb* standard library; or more specific types, that
*CubicWeb* expects to find in one or more Python files under the directory
@@ -24,9 +24,8 @@
They are implicitely imported (as well as the special the function "_"
for translation :ref:`internationalization`).
-The instance schema of an application is defined on all appobjects by a .schema
-class attribute set on registration. It's an instance of
-:class:`yams.schema.Schema`.
+The instance schema is defined on all appobjects by a .schema class attribute set
+on registration. It's an instance of :class:`yams.schema.Schema`.
Entity type
~~~~~~~~~~~
--- a/doc/book/en/development/datamodel/index.rst Thu Jul 16 12:57:17 2009 -0700
+++ b/doc/book/en/development/datamodel/index.rst Tue Jul 28 21:27:52 2009 +0200
@@ -9,6 +9,5 @@
definition
metadata
baseschema
-
-.. define-workflows
-.. inheritance
+ define-workflows
+ inheritance
--- a/doc/book/en/development/datamodel/inheritance.rst Thu Jul 16 12:57:17 2009 -0700
+++ b/doc/book/en/development/datamodel/inheritance.rst Tue Jul 28 21:27:52 2009 +0200
@@ -1,1 +1,8 @@
-XXX WRITME
\ No newline at end of file
+
+Inheritance
+-----------
+
+When describing a data model, entities can inherit from other entities as is
+common in object-oriented programming.
+
+XXX WRITME
--- a/doc/book/en/development/devcore/appobject.rst Thu Jul 16 12:57:17 2009 -0700
+++ b/doc/book/en/development/devcore/appobject.rst Tue Jul 28 21:27:52 2009 +0200
@@ -19,9 +19,9 @@
At the recording, the following attributes are dynamically added to
the *subclasses*:
-* `vreg`, the `vregistry` of the application
-* `schema`, the application schema
-* `config`, the application configuration
+* `vreg`, the `vregistry` of the instance
+* `schema`, the instance schema
+* `config`, the instance configuration
We also find on instances, the following attributes:
@@ -36,7 +36,7 @@
can be specified through the special parameter `method` (the connection
is theoretically done automatically :).
- * `datadir_url()`, returns the directory of the application data
+ * `datadir_url()`, returns the directory of the instance data
(contains static files such as images, css, js...)
* `base_url()`, shortcut to `req.base_url()`
@@ -57,9 +57,9 @@
:Data formatting:
* `format_date(date, date_format=None, time=False)` returns a string for a
- mx date time according to application's configuration
+ mx date time according to instance's configuration
* `format_time(time)` returns a string for a mx date time according to
- application's configuration
+ instance's configuration
:And more...:
--- a/doc/book/en/development/devrepo/sessions.rst Thu Jul 16 12:57:17 2009 -0700
+++ b/doc/book/en/development/devrepo/sessions.rst Tue Jul 28 21:27:52 2009 +0200
@@ -5,21 +5,22 @@
There are three kinds of sessions.
-* user sessions are the most common: they are related to users and
+* `user sessions` are the most common: they are related to users and
carry security checks coming with user credentials
-* super sessions are children of ordinary user sessions and allow to
+* `super sessions` are children of ordinary user sessions and allow to
bypass security checks (they are created by calling unsafe_execute
on a user session); this is often convenient in hooks which may
touch data that is not directly updatable by users
-* internal sessions have all the powers; they are also used in only a
+* `internal sessions` have all the powers; they are also used in only a
few situations where you don't already have an adequate session at
hand, like: user authentication, data synchronisation in
multi-source contexts
-Do not confuse the session type with their connection mode, for
-instance : 'in memory' or 'pyro'.
+.. note::
+ Do not confuse the session type with their connection mode, for
+ instance : 'in memory' or 'pyro'.
[WRITE ME]
--- a/doc/book/en/development/devweb/index.rst Thu Jul 16 12:57:17 2009 -0700
+++ b/doc/book/en/development/devweb/index.rst Tue Jul 28 21:27:52 2009 +0200
@@ -1,7 +1,7 @@
Web development
===============
-In this chapter, we will core api for web development in the CubicWeb framework.
+In this chapter, we will describe the core api for web development in the *CubicWeb* framework.
.. toctree::
:maxdepth: 1
--- a/doc/book/en/development/devweb/internationalization.rst Thu Jul 16 12:57:17 2009 -0700
+++ b/doc/book/en/development/devweb/internationalization.rst Tue Jul 28 21:27:52 2009 +0200
@@ -6,7 +6,7 @@
Internationalisation
---------------------
-Cubicweb fully supports the internalization of it's content and interface.
+Cubicweb fully supports the internalization of its content and interface.
Cubicweb's interface internationalization is based on the translation project `GNU gettext`_.
@@ -16,7 +16,7 @@
* in your Python code and cubicweb-tal templates : mark translatable strings
-* in your application : handle the translation catalog
+* in your instance : handle the translation catalog
String internationalization
~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -66,16 +66,18 @@
.. note::
We dont need to mark the translation strings of entities/relations
- used by a particular application's schema as they are generated
+ used by a particular instance's schema as they are generated
automatically.
+If you need to add messages on top of those that can be found in the source,
+you can create a file named `i18n/static-messages.pot`.
Handle the translation catalog
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-Once the internationalization is done in your application's code, you need
-to populate and update the translation catalog. Cubicweb provides the
-following commands for this purpose:
+Once the internationalization is done in your code, you need to populate and
+update the translation catalog. Cubicweb provides the following commands for this
+purpose:
* `i18ncubicweb` updates Cubicweb framework's translation
@@ -83,28 +85,28 @@
need to use this command.
* `i18ncube` updates the translation catalogs of *one particular
- component* (or of all components). After this command is
+ cube* (or of all cubes). After this command is
executed you must update the translation files *.po* in the "i18n"
directory of your template. This command will of course not remove
existing translations still in use.
* `i18ninstance` recompile the translation catalogs of *one particular
instance* (or of all instances) after the translation catalogs of
- its components have been updated. This command is automatically
+ its cubes have been updated. This command is automatically
called every time you create or update your instance. The compiled
catalogs (*.mo*) are stored in the i18n/<lang>/LC_MESSAGES of
- application where `lang` is the language identifier ('en' or 'fr'
+ instance where `lang` is the language identifier ('en' or 'fr'
for exemple).
Example
```````
-You have added and/or modified some translation strings in your application
-(after creating a new view or modifying the application's schema for exemple).
+You have added and/or modified some translation strings in your cube
+(after creating a new view or modifying the cube's schema for exemple).
To update the translation catalogs you need to do:
-1. `cubicweb-ctl i18ncube <component>`
-2. Edit the <component>/xxx.po files and add missing translations (empty `msgstr`)
+1. `cubicweb-ctl i18ncube <cube>`
+2. Edit the <cube>/i18n/xxx.po files and add missing translations (empty `msgstr`)
3. `hg ci -m "updated i18n catalogs"`
-4. `cubicweb-ctl i18ninstance <myapplication>`
+4. `cubicweb-ctl i18ninstance <myinstance>`
--- a/doc/book/en/development/entityclasses/data-as-objects.rst Thu Jul 16 12:57:17 2009 -0700
+++ b/doc/book/en/development/entityclasses/data-as-objects.rst Tue Jul 28 21:27:52 2009 +0200
@@ -61,10 +61,10 @@
Tne :class:`AnyEntity` class
----------------------------
-To provide a specific behavior for each entity, we have to define
-a class inheriting from `cubicweb.entities.AnyEntity`. In general, we
-define this class in a module of `mycube.entities` package of an application
-so that it will be available on both server and client side.
+To provide a specific behavior for each entity, we have to define a class
+inheriting from `cubicweb.entities.AnyEntity`. In general, we define this class
+in `mycube.entities` module (or in a submodule if we want to split code among
+multiple files) so that it will be available on both server and client side.
The class `AnyEntity` is loaded dynamically from the class `Entity`
(`cubciweb.entity`). We define a sub-class to add methods or to
--- a/doc/book/en/development/entityclasses/index.rst Thu Jul 16 12:57:17 2009 -0700
+++ b/doc/book/en/development/entityclasses/index.rst Tue Jul 28 21:27:52 2009 +0200
@@ -2,7 +2,7 @@
===============
In this chapter, we will introduce the objects that are used to handle
-the data stored in the database.
+the logic associated to the data stored in the database.
.. toctree::
:maxdepth: 1
@@ -10,4 +10,4 @@
data-as-objects
load-sort
interfaces
- more
\ No newline at end of file
+ more
--- a/doc/book/en/development/entityclasses/interfaces.rst Thu Jul 16 12:57:17 2009 -0700
+++ b/doc/book/en/development/entityclasses/interfaces.rst Tue Jul 28 21:27:52 2009 +0200
@@ -1,16 +1,19 @@
Interfaces
----------
+Same thing as object-oriented programming interfaces.
+
XXX how to define a cw interface
Declaration of interfaces implemented by a class
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
XXX __implements__
Interfaces defined in the library
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-.. automodule:: cubicweb.interface
- :members:
-`````````````
+automodule:: cubicweb.interface :members:
+
+
--- a/doc/book/en/development/entityclasses/load-sort.rst Thu Jul 16 12:57:17 2009 -0700
+++ b/doc/book/en/development/entityclasses/load-sort.rst Tue Jul 28 21:27:52 2009 +0200
@@ -2,14 +2,14 @@
Loaded attributes and default sorting management
````````````````````````````````````````````````
-* The class attribute `fetch_attrs` allows to defined in an entity class
- a list of names of attributes or relations that should be automatically
- loaded when we recover the entities of this type. In the case of relations,
+* The class attribute `fetch_attrs` allows to define in an entity class a list
+ of names of attributes or relations that should be automatically loaded when
+ entities of this type are fetched from the database. In the case of relations,
we are limited to *subject of cardinality `?` or `1`* relations.
* The class method `fetch_order(attr, var)` expects an attribute (or relation)
name as a parameter and a variable name, and it should return a string
- to use in the requirement `ORDER BY` of an RQL query to automatically
+ to use in the requirement `ORDERBY` of an RQL query to automatically
sort the list of entities of such type according to this attribute, or
`None` if we do not want to sort on the attribute given in the parameter.
By default, the entities are sorted according to their creation date.
--- a/doc/book/en/development/index.rst Thu Jul 16 12:57:17 2009 -0700
+++ b/doc/book/en/development/index.rst Tue Jul 28 21:27:52 2009 +0200
@@ -18,3 +18,4 @@
testing/index
migration/index
webstdlib/index
+ profiling/index
--- a/doc/book/en/development/migration/index.rst Thu Jul 16 12:57:17 2009 -0700
+++ b/doc/book/en/development/migration/index.rst Tue Jul 28 21:27:52 2009 +0200
@@ -5,19 +5,19 @@
Migration
=========
-One of the main concept in *CubicWeb* is to create incremental applications.
-For this purpose, multiple actions are provided to facilitate the improvement
-of an application, and in particular to handle the changes to be applied
-to the data model, without loosing existing data.
+One of the main design goals of *CubicWeb* was to support iterative and agile
+development. For this purpose, multiple actions are provided to facilitate the
+improvement of an instance, and in particular to handle the changes to be
+applied to the data model, without loosing existing data.
-The current version of an application model is provided in the file
+The current version of a cube (and of cubicweb itself) is provided in the file
`__pkginfo__.py` as a tuple of 3 integers.
Migration scripts management
----------------------------
Migration scripts has to be located in the directory `migration` of your
-application and named accordingly:
+cube and named accordingly:
::
@@ -67,11 +67,8 @@
* `interactive_mode`, boolean indicating that the script is executed in
an interactive mode or not
-* `appltemplversion`, application model version of the instance
-
-* `templversion`, installed application model version
-
-* `cubicwebversion`, installed cubicweb version
+* `versions_map`, dictionary of migrated versions (key are cubes
+ names, including 'cubicweb', values are (from version, to version)
* `confirm(question)`, function asking the user and returning true
if the user answers yes, false otherwise (always returns true in
@@ -84,16 +81,14 @@
* `checkpoint`, request confirming and executing a "commit" at checking point
-* `repo_schema`, instance persisting schema (e.g. instance schema of the
- current migration)
+* `schema`, instance schema (readen from the database)
-* `newschema`, installed schema on the file system (e.g. schema of
+* `fsschema`, installed schema on the file system (e.g. schema of
the updated model and cubicweb)
-* `sqlcursor`, SQL cursor for very rare cases where it is really
- necessary or beneficial to go through the sql
+* `repo`, repository object
-* `repo`, repository object
+* `session`, repository session object
Schema migration
@@ -134,18 +129,12 @@
* `drop_relation_definition(subjtype, rtype, objtype, commit=True)`, removes
a relation definition.
-* `synchronize_permissions(ertype, commit=True)`, synchronizes permissions on
- an entity type or relation type.
-
-* `synchronize_rschema(rtype, commit=True)`, synchronizes properties and permissions
- on a relation type.
-
-* `synchronize_eschema(etype, commit=True)`, synchronizes properties and persmissions
- on an entity type.
-
-* `synchronize_schema(commit=True)`, synchronizes the persisting schema with the
- updated schema (but without adding or removing new entity types, relations types
- or even relations definitions).
+* `sync_schema_props_perms(ertype=None, syncperms=True,
+ syncprops=True, syncrdefs=True, commit=True)`,
+ synchronizes properties and/or permissions on:
+ * the whole schema if ertype is None
+ * an entity or relation type schema if ertype is a string
+ * a relation definition if ertype is a 3-uple (subject, relation, object)
* `change_relation_props(subjtype, rtype, objtype, commit=True, **kwargs)`, changes
properties of a relation definition by using the named parameters of the properties
@@ -204,7 +193,7 @@
accomplished otherwise or to repair damaged databases during interactive
session. They are available in `repository` scripts:
-* `sqlexec(sql, args=None, ask_confirm=True)`, executes an arbitrary SQL query
+* `sql(sql, args=None, ask_confirm=True)`, executes an arbitrary SQL query on the system source
* `add_entity_type_table(etype, commit=True)`
* `add_relation_type_table(rtype, commit=True)`
* `uninline_relation(rtype, commit=True)`
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/doc/book/en/development/profiling/index.rst Tue Jul 28 21:27:52 2009 +0200
@@ -0,0 +1,52 @@
+Profiling and performance
+=========================
+
+If you feel that one of your pages takes more time than it should to be
+generated, chances are that you're making too many RQL queries. Obviously,
+there are other reasons but experience tends to show this is the first thing to
+track down. Luckily, CubicWeb provides a configuration option to log RQL
+queries. In your ``all-in-one.conf`` file, set the **query-log-file** option::
+
+ # web application query log file
+ query-log-file=~/myapp-rql.log
+
+Then restart your application, reload your page and stop your application.
+The file ``myapp-rql.log`` now contains the list of RQL queries that were
+executed during your test. It's a simple text file containing lines such as::
+
+ Any A WHERE X eid %(x)s, X lastname A {'x': 448} -- (0.002 sec, 0.010 CPU sec)
+ Any A WHERE X eid %(x)s, X firstname A {'x': 447} -- (0.002 sec, 0.000 CPU sec)
+
+The structure of each line is::
+
+ <RQL QUERY> <QUERY ARGS IF ANY> -- <TIME SPENT>
+
+CubicWeb also provides the **exlog** command to examine and summarize data found
+in such a file::
+ $ cubicweb-ctl exlog < ~/myapp-rql.log
+ 0.07 50 Any A WHERE X eid %(x)s, X firstname A {}
+ 0.05 50 Any A WHERE X eid %(x)s, X lastname A {}
+ 0.01 1 Any X,AA ORDERBY AA DESC WHERE E eid %(x)s, E employees X, X modification_date AA {}
+ 0.01 1 Any X WHERE X eid %(x)s, X owned_by U, U eid %(u)s {, }
+ 0.01 1 Any B,T,P ORDERBY lower(T) WHERE B is Bookmark,B title T, B path P, B bookmarked_by U, U eid %(x)s {}
+ 0.01 1 Any A,B,C,D WHERE A eid %(x)s,A name B,A creation_date C,A modification_date D {}
+
+This command sorts and uniquifies queries so that it's easy to see where
+is the hot spot that needs optimization.
+
+Having said all this, it would probably be worth talking about the **fetch_attrs** attribute
+you can define in your entity classes because it can greatly reduce the
+number of queries executed. XXX say more about it XXX
+
+You should also know about the **profile** option in the ``all-in-on.conf``. If
+set, this option will make your application run in an `hotshot`_ session and
+store the results in the specified file.
+
+.. _hotshot: http://docs.python.org/library/hotshot.html#module-hotshot
+
+Last but no least, if you're using the PostgreSQL database backend, VACUUMing
+your database can significantly improve the performance of the queries (by
+updating the statistics used by the query optimizer). Nowadays, this is done
+automatically from time to time, but if you've just imported a large amount of
+data in your db, you will want to vacuum it (with the analyse option on). Read
+the documentation of your database for more information.
--- a/doc/book/en/development/webstdlib/basetemplates.rst Thu Jul 16 12:57:17 2009 -0700
+++ b/doc/book/en/development/webstdlib/basetemplates.rst Tue Jul 28 21:27:52 2009 +0200
@@ -159,7 +159,7 @@
.. _TheMainTemplate:
TheMainTemplate is responsible for the general layout of the entire application.
-It defines the template of ``id = main`` that is used by the application.
+It defines the template of ``id = main`` that is used by the instance.
The default main template (`cubicweb.web.views.basetemplates.TheMainTemplate`)
builds the page based on the following pattern:
--- a/doc/book/en/development/webstdlib/baseviews.rst Thu Jul 16 12:57:17 2009 -0700
+++ b/doc/book/en/development/webstdlib/baseviews.rst Tue Jul 28 21:27:52 2009 +0200
@@ -12,33 +12,6 @@
HTML views
~~~~~~~~~~
-*oneline*
- This is a hyper linked *text* view. Similar to the `secondary` view,
- but called when we want the view to stand on a single line, or just
- get a brief view. By default this view uses the
- parameter `MAX_LINE_CHAR` to control the result size.
-
-*secondary*
- This is a combinaison of an icon and a *oneline* view.
- By default it renders the two first attributes of the entity as a
- clickable link redirecting to the primary view.
-
-*incontext, outofcontext*
- Similar to the `secondary` view, but called when an entity is considered
- as in or out of context. By default it respectively returns the result of
- `textincontext` and `textoutofcontext` wrapped in a link leading to
- the primary view of the entity.
-
-List
-`````
-*list*
- This view displays a list of entities by creating a HTML list (`<ul>`)
- and call the view `listitem` for each entity of the result set.
-
-*listitem*
- This view redirects by default to the `outofcontext` view.
-
-
Special views
`````````````
@@ -54,11 +27,41 @@
This view is the default view used when nothing needs to be rendered.
It is always applicable and it does not return anything
-Text views
-~~~~~~~~~~
+Entity views
+````````````
+*incontext, outofcontext*
+ Those are used to display a link to an entity, depending if the entity is
+ considered as displayed in or out of context (of another entity). By default
+ it respectively returns the result of `textincontext` and `textoutofcontext`
+ wrapped in a link leading to the primary view of the entity.
+
+*oneline*
+ This view is used when we can't tell if the entity should be considered as
+ displayed in or out of context. By default it returns the result of `text`
+ in a link leading to the primary view of the entity.
+
+List
+`````
+*list*
+ This view displays a list of entities by creating a HTML list (`<ul>`)
+ and call the view `listitem` for each entity of the result set.
+
+*listitem*
+ This view redirects by default to the `outofcontext` view.
+
+*adaptedlist*
+ This view displays a list of entities of the same type, in HTML section (`<div>`)
+ and call the view `adaptedlistitem` for each entity of the result set.
+
+*adaptedlistitem*
+ This view redirects by default to the `outofcontext` view.
+
+Text entity views
+~~~~~~~~~~~~~~~~~
*text*
- This is the simplest text view for an entity. It displays the
- title of an entity. It should not contain HTML.
+ This is the simplest text view for an entity. By default it returns the
+ result of the `.dc_title` method, which is cut to fit the
+ `navigation.short-line-size` property if necessary.
*textincontext, textoutofcontext*
Similar to the `text` view, but called when an entity is considered out or
--- a/doc/book/en/development/webstdlib/startup.rst Thu Jul 16 12:57:17 2009 -0700
+++ b/doc/book/en/development/webstdlib/startup.rst Tue Jul 28 21:27:52 2009 +0200
@@ -9,5 +9,5 @@
a result set to apply to.
*schema*
- A view dedicated to the display of the schema of the application
+ A view dedicated to the display of the schema of the instance
--- a/doc/book/en/intro/concepts/index.rst Thu Jul 16 12:57:17 2009 -0700
+++ b/doc/book/en/intro/concepts/index.rst Tue Jul 28 21:27:52 2009 +0200
@@ -64,11 +64,12 @@
On a Unix system, the instances are usually stored in the directory
:file:`/etc/cubicweb.d/`. During development, the :file:`~/etc/cubicweb.d/`
-directory is looked up, as well as the paths in :envvar:`CW_REGISTRY`
+directory is looked up, as well as the paths in :envvar:`CW_INSTANCES_DIR`
environment variable.
-The term application can refer to an instance or to a cube, depending on the
-context. This book will try to avoid using this term and use *cube* and
+The term application is used to refer at "something that should do something as a
+whole", eg more like a project and so can refer to an instance or to a cube,
+depending on the context. This book will try to use *application*, *cube* and
*instance* as appropriate.
Data Repository
@@ -154,7 +155,7 @@
identifier in the same registry, At runtime, appobjects are selected in the
vregistry according to the context.
-Application objects are stored in the registry using a two level hierarchy :
+Application objects are stored in the registry using a two-level hierarchy :
object's `__registry__` : object's `id` : [list of app objects]
@@ -166,7 +167,7 @@
At startup, the `registry` or registers base, inspects a number of directories
looking for compatible classes definition. After a recording process, the objects
are assigned to registers so that they can be selected dynamically while the
-application is running.
+instance is running.
Selectors
~~~~~~~~~
@@ -215,7 +216,7 @@
**No need for a complicated ORM when you have a powerful query language**
-All the persistant data in a CubicWeb application is retrieved and modified by using the
+All the persistent data in a CubicWeb instance is retrieved and modified by using the
Relation Query Language.
This query language is inspired by SQL but is on a higher level in order to
--- a/doc/book/en/intro/tutorial/components.rst Thu Jul 16 12:57:17 2009 -0700
+++ b/doc/book/en/intro/tutorial/components.rst Tue Jul 28 21:27:52 2009 +0200
@@ -11,7 +11,7 @@
A library of standard cubes are available from `CubicWeb Forge`_
Cubes provide entities and views.
-The available application entities are:
+The available application entities in standard cubes are:
* addressbook: PhoneNumber and PostalAddress
@@ -43,7 +43,7 @@
Adding comments to BlogDemo
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-To import a cube in your application just change the line in the
+To import a cube in your instance just change the line in the
``__pkginfo__.py`` file and verify that the cube you are planning
to use is listed by the command ``cubicweb-ctl list``.
For example::
@@ -51,7 +51,7 @@
__use__ = ('comment',)
will make the ``Comment`` entity available in your ``BlogDemo``
-application.
+cube.
Change the schema to add a relationship between ``BlogEntry`` and
``Comment`` and you are done. Since the comment cube defines the
@@ -67,13 +67,12 @@
Once you modified your data model, you need to synchronize the
database with your model. For this purpose, *CubicWeb* provides
a very useful command ``cubicweb-ctl shell blogdemo`` which
-launches an interactive migration Python shell. (see
-:ref:`cubicweb-ctl` for more details))
-As you modified a relation from the `BlogEntry` schema,
-run the following command:
+launches an interactive shell where you can enter migration
+commands. (see :ref:`cubicweb-ctl` for more details))
+As you added the cube named `comment`, you need to run:
+
::
- synchronize_rschema('BlogEntry')
+ add_cube('comment')
-You can now start your application and add comments to each
-`BlogEntry`.
+You can now start your instance and comment your blog entries.
--- a/doc/book/en/intro/tutorial/conclusion.rst Thu Jul 16 12:57:17 2009 -0700
+++ b/doc/book/en/intro/tutorial/conclusion.rst Tue Jul 28 21:27:52 2009 +0200
@@ -3,15 +3,13 @@
What's next?
------------
-We demonstrated how from a straight out of the box *CubicWeb*
-installation, you can build your web-application based on a
-schema. It's all already there: views, templates, permissions,
-etc. The step forward is now for you to customize according
-to your needs.
+We demonstrated how from a straight out of the box *CubicWeb* installation, you
+can build your web application based on a data model. It's all already there:
+views, templates, permissions, etc. The step forward is now for you to customize
+according to your needs.
-More than a web application, many features are available to
-extend your application, for example: RSS channel integration
-(:ref:`rss`), hooks (:ref:`hooks`), support of sources such as
-Google App Engine (:ref:`gaecontents`) and lots of others to
-discover through our book.
+Many features are available to extend your application, for example: RSS channel
+integration (:ref:`rss`), hooks (:ref:`hooks`), support of sources such as
+Google App Engine (:ref:`gaecontents`) and lots of others to discover through
+our book.
--- a/doc/book/en/intro/tutorial/create-cube.rst Thu Jul 16 12:57:17 2009 -0700
+++ b/doc/book/en/intro/tutorial/create-cube.rst Tue Jul 28 21:27:52 2009 +0200
@@ -60,39 +60,39 @@
Create your instance
--------------------
-To use this cube as an application and create a new instance named ``blogdemo``, do::
+To use this cube as an instance and create a new instance named ``blogdemo``, do::
cubicweb-ctl create blog blogdemo
This command will create the corresponding database and initialize it.
-Welcome to your web application
+Welcome to your web instance
-------------------------------
-Start your application in debug mode with the following command: ::
+Start your instance in debug mode with the following command: ::
cubicweb-ctl start -D blogdemo
-You can now access your web application to create blogs and post messages
+You can now access your web instance to create blogs and post messages
by visiting the URL http://localhost:8080/.
-A login form will appear. By default, the application will not allow anonymous
-users to enter the application. To login, you need then use the admin account
+A login form will appear. By default, the instance will not allow anonymous
+users to enter the instance. To login, you need then use the admin account
you created at the time you initialized the database with ``cubicweb-ctl
create``.
.. image:: ../../images/login-form.png
-Once authenticated, you can start playing with your application
+Once authenticated, you can start playing with your instance
and create entities.
.. image:: ../../images/blog-demo-first-page.png
-Please notice that so far, the *CubicWeb* franework managed all aspects of
-the web application based on the schema provided at first.
+Please notice that so far, the *CubicWeb* framework managed all aspects of
+the web application based on the schema provided at the beginning.
Add entities
@@ -251,7 +251,7 @@
self.render_entity_relations(entity, siderelations)
.. note::
- When a view is modified, it is not required to restart the application
+ When a view is modified, it is not required to restart the instance
server. Save the Python file and reload the page in your web browser
to view the changes.
--- a/doc/book/en/intro/tutorial/maintemplate.rst Thu Jul 16 12:57:17 2009 -0700
+++ b/doc/book/en/intro/tutorial/maintemplate.rst Tue Jul 28 21:27:52 2009 +0200
@@ -36,8 +36,8 @@
Customize header
`````````````````
-Let's now move the search box in the header and remove the login form
-from the header. We'll show how to move it to the left column of the application.
+Let's now move the search box in the header and remove the login form from the
+header. We'll show how to move it to the left column of the user interface.
Let's say we do not want anymore the login menu to be in the header
--- a/entities/__init__.py Thu Jul 16 12:57:17 2009 -0700
+++ b/entities/__init__.py Tue Jul 28 21:27:52 2009 +0200
@@ -15,7 +15,6 @@
from cubicweb import Unauthorized, typed_eid
from cubicweb.entity import Entity
from cubicweb.utils import dump_class
-from cubicweb.schema import FormatConstraint
from cubicweb.interfaces import IBreadCrumbs, IFeed
--- a/entity.py Thu Jul 16 12:57:17 2009 -0700
+++ b/entity.py Tue Jul 28 21:27:52 2009 +0200
@@ -23,13 +23,9 @@
from cubicweb.appobject import AppRsetObject
from cubicweb.schema import RQLVocabularyConstraint, RQLConstraint, bw_normalize_etype
-try:
- from cubicweb.common.uilib import printable_value, soup2xhtml
- from cubicweb.common.mixins import MI_REL_TRIGGERS
- from cubicweb.common.mttransforms import ENGINE
-except ImportError:
- # missing -common
- MI_REL_TRIGGERS = {}
+from cubicweb.common.uilib import printable_value, soup2xhtml
+from cubicweb.common.mixins import MI_REL_TRIGGERS
+from cubicweb.common.mttransforms import ENGINE
_marker = object()
--- a/etwist/request.py Thu Jul 16 12:57:17 2009 -0700
+++ b/etwist/request.py Tue Jul 28 21:27:52 2009 +0200
@@ -38,7 +38,7 @@
self._headers = req.headers
def base_url(self):
- """return the root url of the application"""
+ """return the root url of the instance"""
return self._base_url
def http_method(self):
@@ -47,7 +47,7 @@
def relative_path(self, includeparams=True):
"""return the normalized path of the request (ie at least relative
- to the application's root, but some other normalization may be needed
+ to the instance's root, but some other normalization may be needed
so that the returned path may be used to compare to generated urls
:param includeparams:
--- a/etwist/server.py Thu Jul 16 12:57:17 2009 -0700
+++ b/etwist/server.py Tue Jul 28 21:27:52 2009 +0200
@@ -1,4 +1,4 @@
-"""twisted server for CubicWeb web applications
+"""twisted server for CubicWeb web instances
:organization: Logilab
:copyright: 2001-2009 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2.
@@ -271,9 +271,9 @@
# This part gets run when you run this file via: "twistd -noy demo.py"
def main(appid, cfgname):
- """Starts an cubicweb twisted server for an application
+ """Starts an cubicweb twisted server for an instance
- appid: application's identifier
+ appid: instance's identifier
cfgname: name of the configuration to use (twisted or all-in-one)
"""
from cubicweb.cwconfig import CubicWebConfiguration
--- a/etwist/twconfig.py Thu Jul 16 12:57:17 2009 -0700
+++ b/etwist/twconfig.py Tue Jul 28 21:27:52 2009 +0200
@@ -1,9 +1,9 @@
"""twisted server configurations:
-* the "twisted" configuration to get a web application running in a standalone
+* the "twisted" configuration to get a web instance running in a standalone
twisted web server which talk to a repository server using Pyro
-* the "all-in-one" configuration to get a web application running in a twisted
+* the "all-in-one" configuration to get a web instance running in a twisted
web server integrating a repository server in the same process (only available
if the repository part of the software is installed
@@ -19,7 +19,7 @@
from cubicweb.web.webconfig import WebConfiguration, merge_options, Method
class TwistedConfiguration(WebConfiguration):
- """web application (in a twisted web server) client of a RQL server"""
+ """web instance (in a twisted web server) client of a RQL server"""
name = 'twisted'
options = merge_options((
@@ -81,7 +81,7 @@
from cubicweb.server.serverconfig import ServerConfiguration
class AllInOneConfiguration(TwistedConfiguration, ServerConfiguration):
- """repository and web application in the same twisted process"""
+ """repository and web instance in the same twisted process"""
name = 'all-in-one'
repo_method = 'inmemory'
options = merge_options(TwistedConfiguration.options
--- a/etwist/twctl.py Thu Jul 16 12:57:17 2009 -0700
+++ b/etwist/twctl.py Tue Jul 28 21:27:52 2009 +0200
@@ -8,6 +8,7 @@
import sys
+from cubicweb import underline_title
from cubicweb.toolsutils import CommandHandler
from cubicweb.web.webctl import WebCreateHandler
@@ -20,7 +21,7 @@
def bootstrap(self, cubes, inputlevel=0):
"""bootstrap this configuration"""
- print '** twisted configuration'
+ print '\n'+underline_title('Configuring Twisted')
mainpyfile = self.config.server_file()
mainpy = open(mainpyfile, 'w')
mainpy.write('''
@@ -28,7 +29,7 @@
application = server.main(%r, %r)
''' % (self.config.appid, self.config.name))
mainpy.close()
- print 'application\'s twisted file %s generated' % mainpyfile
+ print '-> generated %s' % mainpyfile
super(TWCreateHandler, self).bootstrap(cubes, inputlevel)
@@ -63,8 +64,8 @@
from cubicweb.server import serverctl
class AllInOneCreateHandler(serverctl.RepositoryCreateHandler, TWCreateHandler):
- """configuration to get a web application running in a twisted web
- server integrating a repository server in the same process
+ """configuration to get an instance running in a twisted web server
+ integrating a repository server in the same process
"""
cfgname = 'all-in-one'
--- a/ext/rest.py Thu Jul 16 12:57:17 2009 -0700
+++ b/ext/rest.py Tue Jul 28 21:27:52 2009 +0200
@@ -31,6 +31,7 @@
from logilab.mtconverter import ESC_UCAR_TABLE, ESC_CAR_TABLE, xml_escape
+from cubicweb import UnknownEid
from cubicweb.ext.html4zope import Writer
# We provide our own parser as an attempt to get rid of
@@ -68,8 +69,13 @@
return [prb], [msg]
# Base URL mainly used by inliner.pep_reference; so this is correct:
context = inliner.document.settings.context
- refedentity = context.req.eid_rset(eid_num).get_entity(0, 0)
- ref = refedentity.absolute_url()
+ try:
+ refedentity = context.req.eid_rset(eid_num).get_entity(0, 0)
+ except UnknownEid:
+ ref = '#'
+ rest += u' ' + context.req._('(UNEXISTANT EID)')
+ else:
+ ref = refedentity.absolute_url()
set_classes(options)
return [nodes.reference(rawtext, utils.unescape(rest), refuri=ref,
**options)], []
--- a/goa/dbinit.py Thu Jul 16 12:57:17 2009 -0700
+++ b/goa/dbinit.py Tue Jul 28 21:27:52 2009 +0200
@@ -20,7 +20,7 @@
try:
group = Get(key)
except datastore_errors.EntityNotFoundError:
- raise Exception('can\'t find required group %s, is your application '
+ raise Exception('can\'t find required group %s, is your instance '
'correctly initialized (eg did you run the '
'initialization script) ?' % groupname)
_GROUP_CACHE[groupname] = group
--- a/goa/dbmyams.py Thu Jul 16 12:57:17 2009 -0700
+++ b/goa/dbmyams.py Tue Jul 28 21:27:52 2009 +0200
@@ -167,7 +167,7 @@
SCHEMAS_LIB_DIRECTORY = join(CW_SOFTWARE_ROOT, 'schemas')
def load_schema(config, schemaclasses=None, extrahook=None):
- """high level method to load all the schema for a lax application"""
+ """high level method to load all the schema for a lax instance"""
# IMPORTANT NOTE: dbmodel schemas must be imported **BEFORE**
# the loader is instantiated because this is where the dbmodels
# are registered in the yams schema
--- a/goa/gaesource.py Thu Jul 16 12:57:17 2009 -0700
+++ b/goa/gaesource.py Tue Jul 28 21:27:52 2009 +0200
@@ -155,7 +155,7 @@
return rqlst
def set_schema(self, schema):
- """set the application'schema"""
+ """set the instance'schema"""
self.interpreter = RQLInterpreter(schema)
self.schema = schema
if 'CWUser' in schema and not self.repo.config['use-google-auth']:
--- a/goa/goaconfig.py Thu Jul 16 12:57:17 2009 -0700
+++ b/goa/goaconfig.py Tue Jul 28 21:27:52 2009 +0200
@@ -17,7 +17,7 @@
from cubicweb.goa.dbmyams import load_schema
UNSUPPORTED_OPTIONS = set(('connections-pool-size',
- 'pyro-port', 'pyro-id', 'pyro-application-id',
+ 'pyro-port', 'pyro-id', 'pyro-instance-id',
'pyro-ns-host', 'pyro-ns-port', 'pyro-ns-group',
'https-url', 'host', 'pid-file', 'uid', 'base-url', 'log-file',
'smtp-host', 'smtp-port',
@@ -30,41 +30,41 @@
# * check auth-mode=http + fix doc (eg require use-google-auth = False)
class GAEConfiguration(ServerConfiguration, WebConfiguration):
- """repository and web application in the same twisted process"""
+ """repository and web instance in Google AppEngine environment"""
name = 'app'
repo_method = 'inmemory'
options = merge_options((
('included-cubes',
{'type' : 'csv',
'default': [],
- 'help': 'list of db model based cubes used by the application.',
+ 'help': 'list of db model based cubes used by the instance.',
'group': 'main', 'inputlevel': 1,
}),
('included-yams-cubes',
{'type' : 'csv',
'default': [],
- 'help': 'list of yams based cubes used by the application.',
+ 'help': 'list of yams based cubes used by the instance.',
'group': 'main', 'inputlevel': 1,
}),
('use-google-auth',
{'type' : 'yn',
'default': True,
- 'help': 'does this application rely on google authentication service or not.',
+ 'help': 'does this instance rely on google authentication service or not.',
'group': 'main', 'inputlevel': 1,
}),
('schema-type',
{'type' : 'choice', 'choices': ('yams', 'dbmodel'),
'default': 'yams',
- 'help': 'does this application is defining its schema using yams or db model.',
+ 'help': 'does this instance is defining its schema using yams or db model.',
'group': 'main', 'inputlevel': 1,
}),
# overriden options
('query-log-file',
{'type' : 'string',
'default': None,
- 'help': 'web application query log file: DON\'T SET A VALUE HERE WHEN '
- 'UPLOADING YOUR APPLICATION. This should only be used to analyse '
- 'queries issued by your application in the development environment.',
+ 'help': 'web instance query log file: DON\'T SET A VALUE HERE WHEN '
+ 'UPLOADING YOUR INSTANCE. This should only be used to analyse '
+ 'queries issued by your instance in the development environment.',
'group': 'main', 'inputlevel': 2,
}),
('anonymous-user',
@@ -86,7 +86,7 @@
cube_vobject_path = WebConfiguration.cube_vobject_path | ServerConfiguration.cube_vobject_path
# use file system schema
- bootstrap_schema = read_application_schema = False
+ bootstrap_schema = read_instance_schema = False
# schema is not persistent, don't load schema hooks (unavailable)
schema_hooks = False
# no user workflow for now
@@ -130,7 +130,7 @@
return self._cubes
def vc_config(self):
- """return CubicWeb's engine and application's cube versions number"""
+ """return CubicWeb's engine and instance's cube versions number"""
return {}
# overriden from cubicweb web configuration
--- a/goa/goactl.py Thu Jul 16 12:57:17 2009 -0700
+++ b/goa/goactl.py Tue Jul 28 21:27:52 2009 +0200
@@ -172,13 +172,13 @@
class NewGoogleAppCommand(Command):
- """Create a new google appengine application.
+ """Create a new google appengine instance.
- <application directory>
- the path to the appengine application directory
+ <instance directory>
+ the path to the appengine instance directory
"""
name = 'newgapp'
- arguments = '<application directory>'
+ arguments = '<instance directory>'
def run(self, args):
if len(args) != 1:
@@ -187,7 +187,7 @@
appldir = normpath(abspath(appldir))
appid = basename(appldir)
context = {'appname': appid}
- # goa application'skeleton
+ # goa instance'skeleton
copy_skeleton(join(CW_SOFTWARE_ROOT, 'goa', 'skel'),
appldir, context, askconfirm=True)
# cubicweb core dependancies
--- a/goa/goavreg.py Thu Jul 16 12:57:17 2009 -0700
+++ b/goa/goavreg.py Tue Jul 28 21:27:52 2009 +0200
@@ -37,7 +37,7 @@
'cubicweb.goa.appobjects')
for cube in reversed(self.config.cubes()):
self.load_cube(cube)
- self.load_application(applroot)
+ self.load_instance(applroot)
def load_directory(self, directory, cube, skip=()):
for filename in listdir(directory):
@@ -49,7 +49,7 @@
cube in self.config['included-cubes'],
cube)
- def load_application(self, applroot):
+ def load_instance(self, applroot):
self._auto_load(applroot, self.config['schema-type'] == 'dbmodel')
def _import(self, modname):
--- a/goa/overrides/toolsutils.py Thu Jul 16 12:57:17 2009 -0700
+++ b/goa/overrides/toolsutils.py Tue Jul 28 21:27:52 2009 +0200
@@ -17,7 +17,7 @@
return result
def read_config(config_file):
- """read the application configuration from a file and return it as a
+ """read the instance configuration from a file and return it as a
dictionnary
:type config_file: str
--- a/goa/skel/loader.py Thu Jul 16 12:57:17 2009 -0700
+++ b/goa/skel/loader.py Tue Jul 28 21:27:52 2009 +0200
@@ -12,11 +12,11 @@
from cubicweb.goa.goaconfig import GAEConfiguration
from cubicweb.goa.dbinit import create_user, create_groups
- # compute application's root directory
+ # compute instance's root directory
APPLROOT = dirname(abspath(__file__))
# apply monkey patches first
goa.do_monkey_patch()
- # get application's configuration (will be loaded from app.conf file)
+ # get instance's configuration (will be loaded from app.conf file)
GAEConfiguration.ext_resources['JAVASCRIPTS'].append('DATADIR/goa.js')
config = GAEConfiguration('toto', APPLROOT)
# create default groups
--- a/goa/skel/main.py Thu Jul 16 12:57:17 2009 -0700
+++ b/goa/skel/main.py Tue Jul 28 21:27:52 2009 +0200
@@ -1,4 +1,4 @@
-"""module defining the root handler for a lax application. You should not have
+"""module defining the root handler for a lax instance. You should not have
to change anything here.
:organization: Logilab
@@ -8,7 +8,7 @@
"""
__docformat__ = "restructuredtext en"
-# compute application's root directory
+# compute instance's root directory
from os.path import dirname, abspath
APPLROOT = dirname(abspath(__file__))
@@ -16,7 +16,7 @@
from cubicweb import goa
goa.do_monkey_patch()
-# get application's configuration (will be loaded from app.conf file)
+# get instance's configuration (will be loaded from app.conf file)
from cubicweb.goa.goaconfig import GAEConfiguration
GAEConfiguration.ext_resources['JAVASCRIPTS'].append('DATADIR/goa.js')
config = GAEConfiguration('toto', APPLROOT)
@@ -29,13 +29,13 @@
# before schema loading
import custom
-# load application'schema
+# load instance'schema
vreg.schema = config.load_schema()
# load dynamic objects
vreg.load(APPLROOT)
-# call the postinit so custom get a chance to do application specific stuff
+# call the postinit so custom get a chance to do instance specific stuff
custom.postinit(vreg)
from cubicweb.wsgi.handler import CubicWebWSGIApplication
--- a/goa/skel/schema.py Thu Jul 16 12:57:17 2009 -0700
+++ b/goa/skel/schema.py Tue Jul 28 21:27:52 2009 +0200
@@ -5,7 +5,6 @@
:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr
:license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses
"""
-from cubicweb.schema import format_constraint
class Blog(EntityType):
title = String(maxsize=50, required=True)
@@ -14,8 +13,6 @@
class BlogEntry(EntityType):
title = String(maxsize=100, required=True)
publish_date = Date(default='TODAY')
- text_format = String(meta=True, internationalizable=True, maxsize=50,
- default='text/rest', constraints=[format_constraint])
- text = String(fulltextindexed=True)
+ text = RichString(fulltextindexed=True)
category = String(vocabulary=('important','business'))
entry_of = SubjectRelation('Blog', cardinality='?*')
--- a/goa/test/unittest_views.py Thu Jul 16 12:57:17 2009 -0700
+++ b/goa/test/unittest_views.py Tue Jul 28 21:27:52 2009 +0200
@@ -51,7 +51,7 @@
def test_django_index(self):
self.vreg.render('views', 'index', self.req, rset=None)
-for vid in ('primary', 'secondary', 'oneline', 'incontext', 'outofcontext', 'text'):
+for vid in ('primary', 'oneline', 'incontext', 'outofcontext', 'text'):
setattr(SomeViewsTC, 'test_%s'%vid, lambda self, vid=vid: self.blog.view(vid))
if __name__ == '__main__':
--- a/goa/tools/laxctl.py Thu Jul 16 12:57:17 2009 -0700
+++ b/goa/tools/laxctl.py Tue Jul 28 21:27:52 2009 +0200
@@ -69,7 +69,7 @@
class PopulateDataDirCommand(LaxCommand):
- """populate application's data directory according to used cubes"""
+ """populate instance's data directory according to used cubes"""
name = 'populatedata'
def _run(self, args):
@@ -118,7 +118,7 @@
class URLCommand(LaxCommand):
- """abstract class for commands doing stuff by accessing the web application
+ """abstract class for commands doing stuff by accessing the web instance
"""
min_args = max_args = 1
arguments = '<site url>'
--- a/hercule.py Thu Jul 16 12:57:17 2009 -0700
+++ b/hercule.py Tue Jul 28 21:27:52 2009 +0200
@@ -1,4 +1,4 @@
-"""RQL client for cubicweb, connecting to application using pyro
+"""RQL client for cubicweb, connecting to instance using pyro
:organization: Logilab
:copyright: 2001-2009 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2.
@@ -79,7 +79,7 @@
'debug' : "Others",
})
- def __init__(self, application=None, user=None, password=None,
+ def __init__(self, instance=None, user=None, password=None,
host=None, debug=0):
CLIHelper.__init__(self, os.path.join(os.environ["HOME"], ".erqlhist"))
self.cnx = None
@@ -92,12 +92,12 @@
self.autocommit = False
self._last_result = None
self._previous_lines = []
- if application is not None:
- self.do_connect(application, user, password, host)
+ if instance is not None:
+ self.do_connect(instance, user, password, host)
self.do_debug(debug)
- def do_connect(self, application, user=None, password=None, host=None):
- """connect to an cubicweb application"""
+ def do_connect(self, instance, user=None, password=None, host=None):
+ """connect to an cubicweb instance"""
from cubicweb.dbapi import connect
if user is None:
user = raw_input('login: ')
@@ -106,17 +106,17 @@
password = getpass('password: ')
if self.cnx is not None:
self.cnx.close()
- self.cnx = connect(user=user, password=password, host=host,
- database=application)
+ self.cnx = connect(login=user, password=password, host=host,
+ database=instance)
self.schema = self.cnx.get_schema()
self.cursor = self.cnx.cursor()
# add entities types to the completion commands
self._completer.list = (self.commands.keys() +
self.schema.entities() + ['Any'])
- print _('You are now connected to %s') % application
+ print _('You are now connected to %s') % instance
- help_do_connect = ('connect', "connect <application> [<user> [<password> [<host>]]]",
+ help_do_connect = ('connect', "connect <instance> [<user> [<password> [<host>]]]",
_(do_connect.__doc__))
def do_debug(self, debug=1):
@@ -142,9 +142,9 @@
help_do_description = ('description', "description", _(do_description.__doc__))
def do_schema(self, name=None):
- """display information about the application schema """
+ """display information about the instance schema """
if self.cnx is None:
- print _('You are not connected to an application !')
+ print _('You are not connected to an instance !')
return
done = None
if name is None:
@@ -189,7 +189,7 @@
else, stores the query line and waits for the suite
"""
if self.cnx is None:
- print _('You are not connected to an application !')
+ print _('You are not connected to an instance !')
return
# append line to buffer
self._previous_lines.append(stripped_line)
@@ -232,11 +232,11 @@
class CubicWebClientCommand(Command):
"""A command line querier for CubicWeb, using the Relation Query Language.
- <application>
- identifier of the application to connect to
+ <instance>
+ identifier of the instance to connect to
"""
name = 'client'
- arguments = '<application>'
+ arguments = '<instance>'
options = CONNECT_OPTIONS + (
("verbose",
{'short': 'v', 'type' : 'int', 'metavar': '<level>',
--- a/i18n/entities.pot Thu Jul 16 12:57:17 2009 -0700
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,26 +0,0 @@
-msgid "__msg state changed"
-msgstr ""
-
-msgid "managers"
-msgstr ""
-
-msgid "users"
-msgstr ""
-
-msgid "guests"
-msgstr ""
-
-msgid "owners"
-msgstr ""
-
-msgid "read_perm"
-msgstr ""
-
-msgid "add_perm"
-msgstr ""
-
-msgid "update_perm"
-msgstr ""
-
-msgid "delete_perm"
-msgstr ""
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/i18n/static-messages.pot Tue Jul 28 21:27:52 2009 +0200
@@ -0,0 +1,26 @@
+msgid "__msg state changed"
+msgstr ""
+
+msgid "managers"
+msgstr ""
+
+msgid "users"
+msgstr ""
+
+msgid "guests"
+msgstr ""
+
+msgid "owners"
+msgstr ""
+
+msgid "read_perm"
+msgstr ""
+
+msgid "add_perm"
+msgstr ""
+
+msgid "update_perm"
+msgstr ""
+
+msgid "delete_perm"
+msgstr ""
--- a/misc/cwdesklets/rqlsensor/__init__.py Thu Jul 16 12:57:17 2009 -0700
+++ b/misc/cwdesklets/rqlsensor/__init__.py Tue Jul 28 21:27:52 2009 +0200
@@ -65,7 +65,7 @@
return self._v_cnx
except AttributeError:
appid, user, passwd = self._get_config("appid"), self._get_config("user"), self._get_config("passwd")
- cnx = connect(database=appid, user=user, password=passwd)
+ cnx = connect(database=appid, login=user, password=passwd)
self._v_cnx = cnx
return cnx
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/misc/migration/3.4.0_common.py Tue Jul 28 21:27:52 2009 +0200
@@ -0,0 +1,6 @@
+from os.path import join
+from cubicweb.toolsutils import create_dir
+
+option_renamed('pyro-application-id', 'pyro-instance-id')
+
+create_dir(join(config.appdatahome, 'backup'))
--- a/misc/migration/bootstrapmigration_repository.py Thu Jul 16 12:57:17 2009 -0700
+++ b/misc/migration/bootstrapmigration_repository.py Tue Jul 28 21:27:52 2009 +0200
@@ -10,49 +10,68 @@
applcubicwebversion, cubicwebversion = versions_map['cubicweb']
+if applcubicwebversion < (3, 4, 0) and cubicwebversion >= (3, 4, 0):
+ from cubicweb import RepositoryError
+ from cubicweb.server.hooks import uniquecstrcheck_before_modification
+ session.set_shared_data('do-not-insert-cwuri', True)
+ repo.hm.unregister_hook(uniquecstrcheck_before_modification, 'before_add_entity', '')
+ repo.hm.unregister_hook(uniquecstrcheck_before_modification, 'before_update_entity', '')
+ add_relation_type('cwuri')
+ base_url = session.base_url()
+ # use an internal session since some entity might forbid modifications to admin
+ isession = repo.internal_session()
+ for eid, in rql('Any X', ask_confirm=False):
+ try:
+ isession.execute('SET X cwuri %(u)s WHERE X eid %(x)s',
+ {'x': eid, 'u': base_url + u'eid/%s' % eid})
+ except RepositoryError:
+ print 'unable to set cwuri for', eid, session.describe(eid)
+ isession.commit()
+ repo.hm.register_hook(uniquecstrcheck_before_modification, 'before_add_entity', '')
+ repo.hm.register_hook(uniquecstrcheck_before_modification, 'before_update_entity', '')
+
if applcubicwebversion < (3, 2, 2) and cubicwebversion >= (3, 2, 1):
- from base64 import b64encode
- for table in ('entities', 'deleted_entities'):
- for eid, extid in sql('SELECT eid, extid FROM %s WHERE extid is NOT NULL'
- % table, ask_confirm=False):
- sql('UPDATE %s SET extid=%%(extid)s WHERE eid=%%(eid)s' % table,
- {'extid': b64encode(extid), 'eid': eid}, ask_confirm=False)
- checkpoint()
+ from base64 import b64encode
+ for table in ('entities', 'deleted_entities'):
+ for eid, extid in sql('SELECT eid, extid FROM %s WHERE extid is NOT NULL'
+ % table, ask_confirm=False):
+ sql('UPDATE %s SET extid=%%(extid)s WHERE eid=%%(eid)s' % table,
+ {'extid': b64encode(extid), 'eid': eid}, ask_confirm=False)
+ checkpoint()
if applcubicwebversion < (3, 2, 0) and cubicwebversion >= (3, 2, 0):
- add_cube('card', update_database=False)
+ add_cube('card', update_database=False)
if applcubicwebversion < (2, 47, 0) and cubicwebversion >= (2, 47, 0):
- from cubicweb.server import schemaserial
- schemaserial.HAS_FULLTEXT_CONTAINER = False
- session.set_shared_data('do-not-insert-is_instance_of', True)
- add_attribute('CWRType', 'fulltext_container')
- schemaserial.HAS_FULLTEXT_CONTAINER = True
+ from cubicweb.server import schemaserial
+ schemaserial.HAS_FULLTEXT_CONTAINER = False
+ session.set_shared_data('do-not-insert-is_instance_of', True)
+ add_attribute('CWRType', 'fulltext_container')
+ schemaserial.HAS_FULLTEXT_CONTAINER = True
if applcubicwebversion < (2, 50, 0) and cubicwebversion >= (2, 50, 0):
- session.set_shared_data('do-not-insert-is_instance_of', True)
- add_relation_type('is_instance_of')
- # fill the relation using an efficient sql query instead of using rql
- sql('INSERT INTO is_instance_of_relation '
- ' SELECT * from is_relation')
- checkpoint()
- session.set_shared_data('do-not-insert-is_instance_of', False)
+ session.set_shared_data('do-not-insert-is_instance_of', True)
+ add_relation_type('is_instance_of')
+ # fill the relation using an efficient sql query instead of using rql
+ sql('INSERT INTO is_instance_of_relation '
+ ' SELECT * from is_relation')
+ checkpoint()
+ session.set_shared_data('do-not-insert-is_instance_of', False)
if applcubicwebversion < (2, 42, 0) and cubicwebversion >= (2, 42, 0):
- sql('ALTER TABLE entities ADD COLUMN mtime TIMESTAMP')
- sql('UPDATE entities SET mtime=CURRENT_TIMESTAMP')
- sql('CREATE INDEX entities_mtime_idx ON entities(mtime)')
- sql('''CREATE TABLE deleted_entities (
+ sql('ALTER TABLE entities ADD COLUMN mtime TIMESTAMP')
+ sql('UPDATE entities SET mtime=CURRENT_TIMESTAMP')
+ sql('CREATE INDEX entities_mtime_idx ON entities(mtime)')
+ sql('''CREATE TABLE deleted_entities (
eid INTEGER PRIMARY KEY NOT NULL,
type VARCHAR(64) NOT NULL,
source VARCHAR(64) NOT NULL,
dtime TIMESTAMP NOT NULL,
extid VARCHAR(256)
)''')
- sql('CREATE INDEX deleted_entities_type_idx ON deleted_entities(type)')
- sql('CREATE INDEX deleted_entities_dtime_idx ON deleted_entities(dtime)')
- sql('CREATE INDEX deleted_entities_extid_idx ON deleted_entities(extid)')
- checkpoint()
-
+ sql('CREATE INDEX deleted_entities_type_idx ON deleted_entities(type)')
+ sql('CREATE INDEX deleted_entities_dtime_idx ON deleted_entities(dtime)')
+ sql('CREATE INDEX deleted_entities_extid_idx ON deleted_entities(extid)')
+ checkpoint()
--- a/schema.py Thu Jul 16 12:57:17 2009 -0700
+++ b/schema.py Tue Jul 28 21:27:52 2009 +0200
@@ -19,9 +19,10 @@
from yams import BadSchemaDefinition, buildobjs as ybo
from yams.schema import Schema, ERSchema, EntitySchema, RelationSchema
-from yams.constraints import BaseConstraint, StaticVocabularyConstraint
-from yams.reader import CONSTRAINTS, PyFileReader, SchemaLoader, \
- obsolete as yobsolete
+from yams.constraints import (BaseConstraint, StaticVocabularyConstraint,
+ FormatConstraint)
+from yams.reader import (CONSTRAINTS, PyFileReader, SchemaLoader,
+ obsolete as yobsolete, cleanup_sys_modules)
from rql import parse, nodes, RQLSyntaxError, TypeResolverException
@@ -36,7 +37,7 @@
# set of meta-relations available for every entity types
META_RELATIONS_TYPES = set((
'owned_by', 'created_by', 'is', 'is_instance_of', 'identity',
- 'eid', 'creation_date', 'modification_date', 'has_text',
+ 'eid', 'creation_date', 'modification_date', 'has_text', 'cwuri',
))
# set of entity and relation types used to build the schema
@@ -45,9 +46,6 @@
'CWConstraint', 'CWConstraintType', 'RQLExpression',
'relation_type', 'from_entity', 'to_entity',
'constrained_by', 'cstrtype',
- # XXX those are not really "schema" entity types
- # but we usually don't want them as @* targets
- 'CWProperty', 'CWPermission', 'State', 'Transition',
))
_LOGGER = getLogger('cubicweb.schemaloader')
@@ -65,50 +63,6 @@
etype = ETYPE_NAME_MAP[etype]
return etype
-
-## cubicweb provides a RichString class for convenience
-class RichString(ybo.String):
- """Convenience RichString attribute type
- The following declaration::
-
- class Card(EntityType):
- content = RichString(fulltextindexed=True, default_format='text/rest')
-
- is equivalent to::
-
- class Card(EntityType):
- content_format = String(internationalizable=True,
- default='text/rest', constraints=[format_constraint])
- content = String(fulltextindexed=True)
- """
- def __init__(self, default_format='text/plain', format_constraints=None, **kwargs):
- self.default_format = default_format
- self.format_constraints = format_constraints or [format_constraint]
- super(RichString, self).__init__(**kwargs)
-
-PyFileReader.context['RichString'] = yobsolete(RichString)
-
-## need to monkeypatch yams' _add_relation function to handle RichString
-yams_add_relation = ybo._add_relation
-@monkeypatch(ybo)
-def _add_relation(relations, rdef, name=None, insertidx=None):
- if isinstance(rdef, RichString):
- format_attrdef = ybo.String(internationalizable=True,
- default=rdef.default_format, maxsize=50,
- constraints=rdef.format_constraints)
- yams_add_relation(relations, format_attrdef, name+'_format', insertidx)
- yams_add_relation(relations, rdef, name, insertidx)
-
-
-@monkeypatch(ybo.EntityType, methodname='add_relation')
-@classmethod
-def add_relation(cls, rdef, name=None):
- ybo.add_relation_function(cls, rdef, name)
- if isinstance(rdef, RichString) and not rdef in cls._defined:
- format_attr_name = (name or rdef.name) + '_format'
- rdef = cls.get_relations(format_attr_name).next()
- cls._ensure_relation_type(rdef)
-
def display_name(req, key, form=''):
"""return a internationalized string for the key (schema entity or relation
name) in a given form
@@ -448,7 +402,7 @@
:type name: str
- :ivar name: name of the schema, usually the application identifier
+ :ivar name: name of the schema, usually the instance identifier
:type base: str
:ivar base: path of the directory where the schema is defined
@@ -840,6 +794,7 @@
PyFileReader.context['RRQLExpression'] = yobsolete(RRQLExpression)
# workflow extensions #########################################################
+from yams.buildobjs import _add_relation as yams_add_relation
class workflowable_definition(ybo.metadefinition):
"""extends default EntityType's metaclass to add workflow relations
@@ -902,7 +857,7 @@
class CubicWebSchemaLoader(BootstrapSchemaLoader):
"""cubicweb specific schema loader, automatically adding metadata to the
- application's schema
+ instance's schema
"""
def load(self, config, **kwargs):
@@ -914,7 +869,11 @@
path = reversed([config.apphome] + config.cubes_path())
else:
path = reversed(config.cubes_path())
- return super(CubicWebSchemaLoader, self).load(config, path=path, **kwargs)
+ try:
+ return super(CubicWebSchemaLoader, self).load(config, path=path, **kwargs)
+ finally:
+ # we've to cleanup modules imported from cubicweb.schemas as well
+ cleanup_sys_modules([self.lib_directory])
def _load_definition_files(self, cubes):
for filepath in (join(self.lib_directory, 'bootstrap.py'),
@@ -929,49 +888,22 @@
self.handle_file(filepath)
+set_log_methods(CubicWebSchemaLoader, getLogger('cubicweb.schemaloader'))
+set_log_methods(BootstrapSchemaLoader, getLogger('cubicweb.bootstrapschemaloader'))
+set_log_methods(RQLExpression, getLogger('cubicweb.schema'))
+
# _() is just there to add messages to the catalog, don't care about actual
# translation
PERM_USE_TEMPLATE_FORMAT = _('use_template_format')
-
-class FormatConstraint(StaticVocabularyConstraint):
- need_perm_formats = [_('text/cubicweb-page-template')]
-
- regular_formats = (_('text/rest'),
- _('text/html'),
- _('text/plain'),
- )
- def __init__(self):
- pass
-
- def serialize(self):
- """called to make persistent valuable data of a constraint"""
- return None
+NEED_PERM_FORMATS = [_('text/cubicweb-page-template')]
- @classmethod
- def deserialize(cls, value):
- """called to restore serialized data of a constraint. Should return
- a `cls` instance
- """
- return cls()
-
- def vocabulary(self, entity=None, req=None):
- if req is None and entity is not None:
- req = entity.req
- if req is not None and req.user.has_permission(PERM_USE_TEMPLATE_FORMAT):
- return self.regular_formats + tuple(self.need_perm_formats)
- return self.regular_formats
-
- def __str__(self):
- return 'value in (%s)' % u', '.join(repr(unicode(word)) for word in self.vocabulary())
-
-
-format_constraint = FormatConstraint()
-CONSTRAINTS['FormatConstraint'] = FormatConstraint
-PyFileReader.context['format_constraint'] = format_constraint
-
-set_log_methods(CubicWebSchemaLoader, getLogger('cubicweb.schemaloader'))
-set_log_methods(BootstrapSchemaLoader, getLogger('cubicweb.bootstrapschemaloader'))
-set_log_methods(RQLExpression, getLogger('cubicweb.schema'))
+@monkeypatch(FormatConstraint)
+def vocabulary(self, entity=None, req=None):
+ if req is None and entity is not None:
+ req = entity.req
+ if req is not None and req.user.has_permission(PERM_USE_TEMPLATE_FORMAT):
+ return self.regular_formats + tuple(NEED_PERM_FORMATS)
+ return self.regular_formats
# XXX monkey patch PyFileReader.import_erschema until bw_normalize_etype is
# necessary
--- a/schemas/__init__.py Thu Jul 16 12:57:17 2009 -0700
+++ b/schemas/__init__.py Tue Jul 28 21:27:52 2009 +0200
@@ -1,4 +1,5 @@
-
+# permissions for "meta" entity type (readable by anyone, can only be
+# added/deleted by managers)
META_ETYPE_PERMS = {
'read': ('managers', 'users', 'guests',),
'add': ('managers',),
@@ -6,8 +7,18 @@
'update': ('managers', 'owners',),
}
+# permissions for "meta" relation type (readable by anyone, can only be
+# added/deleted by managers)
META_RTYPE_PERMS = {
'read': ('managers', 'users', 'guests',),
'add': ('managers',),
'delete': ('managers',),
}
+
+# permissions for relation type that should only set by hooks using unsafe
+# execute, readable by anyone
+HOOKS_RTYPE_PERMS = {
+ 'read': ('managers', 'users', 'guests',),
+ 'add': (),
+ 'delete': (),
+ }
--- a/schemas/base.py Thu Jul 16 12:57:17 2009 -0700
+++ b/schemas/base.py Tue Jul 28 21:27:52 2009 +0200
@@ -102,7 +102,7 @@
# 0..n cardinality for entities created by internal session (no attached user)
# and to support later deletion of a user which has created some entities
cardinality = '**'
- subject = '**'
+ subject = '*'
object = 'CWUser'
class created_by(RelationType):
@@ -115,22 +115,28 @@
# 0..1 cardinality for entities created by internal session (no attached user)
# and to support later deletion of a user which has created some entities
cardinality = '?*'
- subject = '**'
+ subject = '*'
object = 'CWUser'
class creation_date(RelationType):
"""creation time of an entity"""
cardinality = '11'
- subject = '**'
+ subject = '*'
object = 'Datetime'
class modification_date(RelationType):
"""latest modification time of an entity"""
cardinality = '11'
- subject = '**'
+ subject = '*'
object = 'Datetime'
+class cwuri(RelationType):
+ """internal entity uri"""
+ cardinality = '11'
+ subject = '*'
+ object = 'String'
+
class CWProperty(EntityType):
"""used for cubicweb configuration. Once a property has been created you
@@ -205,6 +211,29 @@
"""generic relation to link one entity to another"""
symetric = True
+class ExternalUri(EntityType):
+ """a URI representing an object in external data store"""
+ uri = String(required=True, unique=True, maxsize=256,
+ description=_('the URI of the object'))
+
+class same_as(RelationType):
+ """generic relation to specify that an external entity represent the same
+ object as a local one:
+ http://www.w3.org/TR/owl-ref/#sameAs-def
+
+ NOTE: You'll have to explicitly declare which entity types can have a
+ same_as relation
+ """
+ permissions = {
+ 'read': ('managers', 'users', 'guests',),
+ 'add': ('managers', 'users'),
+ 'delete': ('managers', 'owners'),
+ }
+ cardinality = '*1'
+ symetric = True
+ # NOTE: the 'object = ExternalUri' declaration will still be mandatory
+ # in the cube's schema.
+ object = 'ExternalUri'
class CWCache(EntityType):
"""a simple cache entity characterized by a name and
--- a/schemas/bootstrap.py Thu Jul 16 12:57:17 2009 -0700
+++ b/schemas/bootstrap.py Tue Jul 28 21:27:52 2009 +0200
@@ -1,4 +1,4 @@
-"""core CubicWeb schema necessary for bootstrapping the actual application's schema
+"""core CubicWeb schema necessary for bootstrapping the actual instance's schema
:organization: Logilab
:copyright: 2001-2009 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2.
@@ -9,14 +9,14 @@
_ = unicode
from yams.buildobjs import (EntityType, RelationType, SubjectRelation,
- ObjectRelation, String, Boolean, Int)
-from cubicweb.schema import RichString, RQLConstraint
+ ObjectRelation, RichString, String, Boolean, Int)
+from cubicweb.schema import RQLConstraint
from cubicweb.schemas import META_ETYPE_PERMS, META_RTYPE_PERMS
# not restricted since as "is" is handled as other relations, guests need
# access to this
class CWEType(EntityType):
- """define an entity type, used to build the application schema"""
+ """define an entity type, used to build the instance schema"""
permissions = META_ETYPE_PERMS
name = String(required=True, indexed=True, internationalizable=True,
unique=True, maxsize=64)
@@ -27,7 +27,7 @@
class CWRType(EntityType):
- """define a relation type, used to build the application schema"""
+ """define a relation type, used to build the instance schema"""
permissions = META_ETYPE_PERMS
name = String(required=True, indexed=True, internationalizable=True,
unique=True, maxsize=64)
@@ -46,7 +46,7 @@
"""define a final relation: link a final relation type from a non final
entity to a final entity type.
- used to build the application schema
+ used to build the instance schema
"""
permissions = META_ETYPE_PERMS
relation_type = SubjectRelation('CWRType', cardinality='1*',
@@ -83,7 +83,7 @@
"""define a non final relation: link a non final relation type from a non
final entity to a non final entity type.
- used to build the application schema
+ used to build the instance schema
"""
permissions = META_ETYPE_PERMS
relation_type = SubjectRelation('CWRType', cardinality='1*',
@@ -233,7 +233,7 @@
'delete': (),
}
cardinality = '1*'
- subject = '**'
+ subject = '*'
object = 'CWEType'
class is_instance_of(RelationType):
@@ -248,7 +248,7 @@
'delete': (),
}
cardinality = '+*'
- subject = '**'
+ subject = '*'
object = 'CWEType'
class specializes(RelationType):
--- a/schemas/workflow.py Thu Jul 16 12:57:17 2009 -0700
+++ b/schemas/workflow.py Tue Jul 28 21:27:52 2009 +0200
@@ -9,9 +9,9 @@
_ = unicode
from yams.buildobjs import (EntityType, RelationType, SubjectRelation,
- ObjectRelation, String)
-from cubicweb.schema import RichString, RQLConstraint
-from cubicweb.schemas import META_ETYPE_PERMS, META_RTYPE_PERMS
+ ObjectRelation, RichString, String)
+from cubicweb.schema import RQLConstraint
+from cubicweb.schemas import META_ETYPE_PERMS, META_RTYPE_PERMS, HOOKS_RTYPE_PERMS
class State(EntityType):
"""used to associate simple states to an entity type and/or to define
@@ -75,11 +75,12 @@
class from_state(RelationType):
- permissions = META_RTYPE_PERMS
+ permissions = HOOKS_RTYPE_PERMS
inlined = True
class to_state(RelationType):
- permissions = META_RTYPE_PERMS
+ permissions = HOOKS_RTYPE_PERMS
inlined = True
+
class wf_info_for(RelationType):
"""link a transition information to its object"""
permissions = {
--- a/selectors.py Thu Jul 16 12:57:17 2009 -0700
+++ b/selectors.py Tue Jul 28 21:27:52 2009 +0200
@@ -616,10 +616,10 @@
@lltrace
def __call__(self, cls, req, *args, **kwargs):
try:
- etype = req.form['etype']
+ etype = kwargs['etype']
except KeyError:
try:
- etype = kwargs['etype']
+ etype = req.form['etype']
except KeyError:
return 0
else:
--- a/server/__init__.py Thu Jul 16 12:57:17 2009 -0700
+++ b/server/__init__.py Tue Jul 28 21:27:52 2009 +0200
@@ -31,9 +31,9 @@
from cubicweb.server.sqlutils import sqlexec, sqlschema, sqldropschema
# configuration to avoid db schema loading and user'state checking
# on connection
- read_application_schema = config.read_application_schema
+ read_instance_schema = config.read_instance_schema
bootstrap_schema = config.bootstrap_schema
- config.read_application_schema = False
+ config.read_instance_schema = False
config.creating = True
config.bootstrap_schema = True
config.consider_user_state = False
@@ -45,7 +45,8 @@
assert len(repo.sources) == 1, repo.sources
schema = repo.schema
sourcescfg = config.sources()
- print 'creating necessary tables into the system source'
+ _title = '-> creating tables '
+ print _title,
source = sourcescfg['system']
driver = source['db-driver']
sqlcnx = repo.system_source.get_connection()
@@ -56,7 +57,7 @@
try:
sqlexec(dropsql, execute)
except Exception, ex:
- print 'drop failed, skipped (%s)' % ex
+ print '-> drop failed, skipped (%s).' % ex
sqlcnx.rollback()
# schema entities and relations tables
# can't skip entities table even if system source doesn't support them,
@@ -68,14 +69,14 @@
schemasql = sqlschema(schema, driver)
#skip_entities=[str(e) for e in schema.entities()
# if not repo.system_source.support_entity(str(e))])
- sqlexec(schemasql, execute)
+ sqlexec(schemasql, execute, pbtitle=_title)
# install additional driver specific sql files
for fpath in glob(join(config.schemas_lib_dir(), '*.sql.%s' % driver)):
- print 'install', fpath
+ print '-> installing', fpath
sqlexec(open(fpath).read(), execute, False, delimiter=';;')
for directory in config.cubes_path():
for fpath in glob(join(directory, 'schema', '*.sql.%s' % driver)):
- print 'install', fpath
+ print '-> installing', fpath
sqlexec(open(fpath).read(), execute, False, delimiter=';;')
sqlcursor.close()
sqlcnx.commit()
@@ -90,7 +91,7 @@
login, pwd = manager_userpasswd(msg=msg, confirm=True)
else:
login, pwd = unicode(source['db-user']), source['db-password']
- print 'inserting default user and groups'
+ print '-> inserting default user and default groups.'
needisfix = []
for group in BASE_GROUPS:
rset = session.execute('INSERT CWGroup X: X name %(name)s',
@@ -136,11 +137,11 @@
session.close()
# restore initial configuration
config.creating = False
- config.read_application_schema = read_application_schema
+ config.read_instance_schema = read_instance_schema
config.bootstrap_schema = bootstrap_schema
config.consider_user_state = True
config.set_language = True
- print 'application %s initialized' % config.appid
+ print '-> database for instance %s initialized.' % config.appid
def initialize_schema(config, schema, mhandler, event='create'):
@@ -152,7 +153,7 @@
# execute cubes pre<event> script if any
for path in reversed(paths):
mhandler.exec_event_script('pre%s' % event, path)
- # enter application'schema into the database
+ # enter instance'schema into the database
serialize_schema(mhandler.rqlcursor, schema)
# execute cubicweb's post<event> script
mhandler.exec_event_script('post%s' % event)
--- a/server/checkintegrity.py Thu Jul 16 12:57:17 2009 -0700
+++ b/server/checkintegrity.py Tue Jul 28 21:27:52 2009 +0200
@@ -282,7 +282,7 @@
def check(repo, cnx, checks, reindex, fix):
- """check integrity of application's repository,
+ """check integrity of instance's repository,
using given user and password to locally connect to the repository
(no running cubicweb server needed)
"""
--- a/server/hooks.py Thu Jul 16 12:57:17 2009 -0700
+++ b/server/hooks.py Tue Jul 28 21:27:52 2009 +0200
@@ -33,6 +33,9 @@
entity['creation_date'] = datetime.now()
if not 'modification_date' in entity:
entity['modification_date'] = datetime.now()
+ if not 'cwuri' in entity:
+ if not session.get_shared_data('do-not-insert-cwuri'):
+ entity['cwuri'] = session.base_url() + u'eid/%s' % entity.eid
def setmtime_before_update_entity(session, entity):
"""update an entity -> set modification date"""
--- a/server/hooksmanager.py Thu Jul 16 12:57:17 2009 -0700
+++ b/server/hooksmanager.py Tue Jul 28 21:27:52 2009 +0200
@@ -34,7 +34,8 @@
'before_delete_entity', 'after_delete_entity')
RELATIONS_HOOKS = ('before_add_relation', 'after_add_relation' ,
'before_delete_relation','after_delete_relation')
-SYSTEM_HOOKS = ('server_startup', 'server_shutdown',
+SYSTEM_HOOKS = ('server_backup', 'server_restore',
+ 'server_startup', 'server_shutdown',
'session_open', 'session_close')
ALL_HOOKS = frozenset(ENTITIES_HOOKS + RELATIONS_HOOKS + SYSTEM_HOOKS)
@@ -220,9 +221,9 @@
'%s: events is expected to be a tuple, not %s' % (
cls, type(cls.events))
for event in cls.events:
- if event == 'server_startup':
+ if event in SYSTEM_HOOKS:
assert not cls.accepts or cls.accepts == ('Any',), \
- '%s doesnt make sense on server_startup' % cls.accepts
+ '%s doesnt make sense on %s' % (cls.accepts, event)
cls.accepts = ('Any',)
for ertype in cls.accepts:
if (event, ertype) in done:
@@ -251,7 +252,7 @@
raise NotImplementedError
class SystemHook(Hook):
- accepts = ('',)
+ accepts = ()
from logging import getLogger
from cubicweb import set_log_methods
--- a/server/migractions.py Thu Jul 16 12:57:17 2009 -0700
+++ b/server/migractions.py Tue Jul 28 21:27:52 2009 +0200
@@ -109,61 +109,26 @@
def backup_database(self, backupfile=None, askconfirm=True):
config = self.config
- source = config.sources()['system']
- helper = get_adv_func_helper(source['db-driver'])
- date = datetime.now().strftime('%Y-%m-%d_%H:%M:%S')
- app = config.appid
- backupfile = backupfile or join(config.backup_dir(),
- '%s-%s.dump' % (app, date))
- if exists(backupfile):
- if not self.confirm('a backup already exists for %s, overwrite it?' % app):
- return
- elif askconfirm and not self.confirm('backup %s database?' % app):
- return
- cmd = helper.backup_command(source['db-name'], source.get('db-host'),
- source.get('db-user'), backupfile,
- keepownership=False)
- while True:
- print cmd
- if os.system(cmd):
- print 'error while backuping the base'
- answer = self.confirm('continue anyway?',
- shell=False, abort=False, retry=True)
- if not answer:
- raise SystemExit(1)
- if answer == 1: # 1: continue, 2: retry
- break
- else:
- from cubicweb.toolsutils import restrict_perms_to_user
- print 'database backup:', backupfile
- restrict_perms_to_user(backupfile, self.info)
- break
+ repo = self.repo_connect()
+ timestamp = datetime.now().strftime('%Y-%m-%d_%H:%M:%S')
+ for source in repo.sources:
+ source.backup(self.confirm, backupfile, timestamp,
+ askconfirm=askconfirm)
+ repo.hm.call_hooks('server_backup', repo=repo, timestamp=timestamp)
- def restore_database(self, backupfile, drop=True):
+ def restore_database(self, backupfile, drop=True, systemonly=True,
+ askconfirm=True):
config = self.config
- source = config.sources()['system']
- helper = get_adv_func_helper(source['db-driver'])
- app = config.appid
- if not exists(backupfile):
- raise Exception("backup file %s doesn't exist" % backupfile)
- if self.confirm('restore %s database from %s ?' % (app, backupfile)):
- for cmd in helper.restore_commands(source['db-name'], source.get('db-host'),
- source.get('db-user'), backupfile,
- source['db-encoding'],
- keepownership=False, drop=drop):
- while True:
- print cmd
- if os.system(cmd):
- print 'error while restoring the base'
- answer = self.confirm('continue anyway?',
- shell=False, abort=False, retry=True)
- if not answer:
- raise SystemExit(1)
- if answer == 1: # 1: continue, 2: retry
- break
- else:
- break
- print 'database restored'
+ repo = self.repo_connect()
+ if systemonly:
+ repo.system_source.restore(self.confirm, backupfile=backupfile,
+ drop=drop, askconfirm=askconfirm)
+ else:
+ # in that case, backup file is expected to be a time stamp
+ for source in repo.sources:
+ source.backup(self.confirm, timestamp=backupfile, drop=drop,
+ askconfirm=askconfirm)
+ repo.hm.call_hooks('server_restore', repo=repo, timestamp=backupfile)
@property
def cnx(self):
@@ -477,7 +442,7 @@
def cmd_add_cubes(self, cubes, update_database=True):
"""update_database is telling if the database schema should be updated
or if only the relevant eproperty should be inserted (for the case where
- a cube has been extracted from an existing application, so the
+ a cube has been extracted from an existing instance, so the
cube schema is already in there)
"""
newcubes = super(ServerMigrationHelper, self).cmd_add_cubes(cubes)
@@ -642,7 +607,7 @@
rtypeadded = rschema.type in applschema
for targetschema in rschema.objects(etype):
# ignore relations where the targeted type is not in the
- # current application schema
+ # current instance schema
targettype = targetschema.type
if not targettype in applschema and targettype != etype:
continue
@@ -662,7 +627,7 @@
rtypeadded = rschema.type in applschema or rschema.type in added
for targetschema in rschema.subjects(etype):
# ignore relations where the targeted type is not in the
- # current application schema
+ # current instance schema
targettype = targetschema.type
# don't check targettype != etype since in this case the
# relation has already been added as a subject relation
--- a/server/querier.py Thu Jul 16 12:57:17 2009 -0700
+++ b/server/querier.py Tue Jul 28 21:27:52 2009 +0200
@@ -519,7 +519,7 @@
def __init__(self, repo, schema):
# system info helper
self._repo = repo
- # application schema
+ # instance schema
self.set_schema(schema)
def set_schema(self, schema):
--- a/server/repository.py Thu Jul 16 12:57:17 2009 -0700
+++ b/server/repository.py Tue Jul 28 21:27:52 2009 +0200
@@ -5,7 +5,7 @@
repository mainly:
* brings these classes all together to provide a single access
- point to a cubicweb application.
+ point to a cubicweb instance.
* handles session management
* provides method for pyro registration, to call if pyro is enabled
@@ -179,12 +179,12 @@
# open some connections pools
self._available_pools = Queue.Queue()
self._available_pools.put_nowait(ConnectionsPool(self.sources))
- if config.read_application_schema:
- # normal start: load the application schema from the database
+ if config.read_instance_schema:
+ # normal start: load the instance schema from the database
self.fill_schema()
elif config.bootstrap_schema:
# usually during repository creation
- self.warning("set fs application'schema as bootstrap schema")
+ self.warning("set fs instance'schema as bootstrap schema")
config.bootstrap_cubes()
self.set_bootstrap_schema(self.config.load_schema())
# need to load the Any and CWUser entity types
@@ -197,7 +197,7 @@
'cubicweb.entities.authobjs')
else:
# test start: use the file system schema (quicker)
- self.warning("set fs application'schema")
+ self.warning("set fs instance'schema")
config.bootstrap_cubes()
self.set_schema(self.config.load_schema())
if not config.creating:
@@ -217,11 +217,14 @@
# close initialization pool and reopen fresh ones for proper
# initialization now that we know cubes
self._get_pool().close(True)
+ # list of available pools (we can't iterated on Queue instance)
+ self.pools = []
for i in xrange(config['connections-pool-size']):
- self._available_pools.put_nowait(ConnectionsPool(self.sources))
+ self.pools.append(ConnectionsPool(self.sources))
+ self._available_pools.put_nowait(self.pools[-1])
self._shutting_down = False
- if not config.creating:
- # call application level initialisation hooks
+ if not (config.creating or config.repairing):
+ # call instance level initialisation hooks
self.hm.call_hooks('server_startup', repo=self)
# register a task to cleanup expired session
self.looping_task(self.config['session-time']/3.,
@@ -247,9 +250,9 @@
self.vreg.set_schema(schema)
self.hm.set_schema(schema)
self.hm.register_system_hooks(self.config)
- # application specific hooks
- if self.config.application_hooks:
- self.info('loading application hooks')
+ # instance specific hooks
+ if self.config.instance_hooks:
+ self.info('loading instance hooks')
self.hm.register_hooks(self.config.load_hooks(self.vreg))
def fill_schema(self):
@@ -297,13 +300,13 @@
config.usergroup_hooks = False
config.schema_hooks = False
config.notification_hooks = False
- config.application_hooks = False
+ config.instance_hooks = False
self.set_schema(schema, resetvreg=False)
config.core_hooks = True
config.usergroup_hooks = True
config.schema_hooks = True
config.notification_hooks = True
- config.application_hooks = True
+ config.instance_hooks = True
def start_looping_tasks(self):
assert isinstance(self._looping_tasks, list), 'already started'
@@ -441,7 +444,7 @@
# public (dbapi) interface ################################################
def get_schema(self):
- """return the application schema. This is a public method, not
+ """return the instance schema. This is a public method, not
requiring a session id
"""
try:
@@ -452,17 +455,18 @@
self.schema.__hashmode__ = None
def get_cubes(self):
- """return the list of cubes used by this application. This is a
+ """return the list of cubes used by this instance. This is a
public method, not requiring a session id.
"""
- versions = self.get_versions(not self.config.creating)
+ versions = self.get_versions(not (self.config.creating
+ or self.config.repairing))
cubes = list(versions)
cubes.remove('cubicweb')
return cubes
@cached
def get_versions(self, checkversions=False):
- """return the a dictionary containing cubes used by this application
+ """return the a dictionary containing cubes used by this instance
as key with their version as value, including cubicweb version. This is a
public method, not requiring a session id.
"""
@@ -485,7 +489,7 @@
else:
fsversion = self.config.cubicweb_version()
if version < fsversion:
- msg = ('application has %s version %s but %s '
+ msg = ('instance has %s version %s but %s '
'is installed. Run "cubicweb-ctl upgrade".')
raise ExecutionError(msg % (cube, version, fsversion))
finally:
--- a/server/schemahooks.py Thu Jul 16 12:57:17 2009 -0700
+++ b/server/schemahooks.py Tue Jul 28 21:27:52 2009 +0200
@@ -21,12 +21,12 @@
from cubicweb.server.sqlutils import SQL_PREFIX
from cubicweb.server.pool import Operation, SingleLastOperation, PreCommitOperation
from cubicweb.server.hookhelper import (entity_attr, entity_name,
- check_internal_entity)
+ check_internal_entity)
# core entity and relation types which can't be removed
CORE_ETYPES = list(BASE_TYPES) + ['CWEType', 'CWRType', 'CWUser', 'CWGroup',
'CWConstraint', 'CWAttribute', 'CWRelation']
-CORE_RTYPES = ['eid', 'creation_date', 'modification_date',
+CORE_RTYPES = ['eid', 'creation_date', 'modification_date', 'cwuri',
'login', 'upassword', 'name',
'is', 'instanceof', 'owned_by', 'created_by', 'in_group',
'relation_type', 'from_entity', 'to_entity',
@@ -105,7 +105,7 @@
class DropTableOp(PreCommitOperation):
- """actually remove a database from the application's schema"""
+ """actually remove a database from the instance's schema"""
table = None # make pylint happy
def precommit_event(self):
dropped = self.session.transaction_data.setdefault('droppedtables',
@@ -137,7 +137,7 @@
# deletion ####################################################################
class DeleteCWETypeOp(SchemaOperation):
- """actually remove the entity type from the application's schema"""
+ """actually remove the entity type from the instance's schema"""
def commit_event(self):
try:
# del_entity_type also removes entity's relations
@@ -166,7 +166,7 @@
class DeleteCWRTypeOp(SchemaOperation):
- """actually remove the relation type from the application's schema"""
+ """actually remove the relation type from the instance's schema"""
def commit_event(self):
try:
self.schema.del_relation_type(self.kobj)
@@ -189,8 +189,8 @@
DeleteCWRTypeOp(session, name)
-class DelRelationDefOp(SchemaOperation):
- """actually remove the relation definition from the application's schema"""
+class DeleteRelationDefOp(SchemaOperation):
+ """actually remove the relation definition from the instance's schema"""
def commit_event(self):
subjtype, rtype, objtype = self.kobj
try:
@@ -238,13 +238,13 @@
# if this is the last instance, drop associated relation type
if lastrel and not rteid in pendings:
execute('DELETE CWRType X WHERE X eid %(x)s', {'x': rteid}, 'x')
- DelRelationDefOp(session, (subjschema, rschema, objschema))
+ DeleteRelationDefOp(session, (subjschema, rschema, objschema))
# addition ####################################################################
class AddCWETypeOp(EarlySchemaOperation):
- """actually add the entity type to the application's schema"""
+ """actually add the entity type to the instance's schema"""
eid = None # make pylint happy
def commit_event(self):
self.schema.add_entity_type(self.kobj)
@@ -264,7 +264,7 @@
* set creation_date and modification_date by creating the necessary
CWAttribute entities
* add owned_by relation by creating the necessary CWRelation entity
- * register an operation to add the entity type to the application's
+ * register an operation to add the entity type to the instance's
schema on commit
"""
if entity.get('final'):
@@ -283,7 +283,7 @@
prefix=SQL_PREFIX)
relrqls = []
for rtype in ('is', 'is_instance_of', 'creation_date', 'modification_date',
- 'created_by', 'owned_by'):
+ 'cwuri', 'created_by', 'owned_by'):
rschema = schema[rtype]
sampletype = rschema.subjects()[0]
desttype = rschema.objects()[0]
@@ -306,7 +306,7 @@
class AddCWRTypeOp(EarlySchemaOperation):
- """actually add the relation type to the application's schema"""
+ """actually add the relation type to the instance's schema"""
eid = None # make pylint happy
def commit_event(self):
rschema = self.schema.add_relation_type(self.kobj)
@@ -315,7 +315,7 @@
def before_add_ertype(session, entity):
"""before adding a CWRType entity:
* check that we are not using an existing relation type,
- * register an operation to add the relation type to the application's
+ * register an operation to add the relation type to the instance's
schema on commit
We don't know yeat this point if a table is necessary
@@ -326,7 +326,7 @@
def after_add_ertype(session, entity):
"""after a CWRType entity has been added:
- * register an operation to add the relation type to the application's
+ * register an operation to add the relation type to the instance's
schema on commit
We don't know yeat this point if a table is necessary
"""
@@ -340,7 +340,7 @@
class AddErdefOp(EarlySchemaOperation):
- """actually add the attribute relation definition to the application's
+ """actually add the attribute relation definition to the instance's
schema
"""
def commit_event(self):
@@ -363,7 +363,7 @@
* add the necessary column
* set default on this column if any and possible
* register an operation to add the relation definition to the
- application's schema on commit
+ instance's schema on commit
constraints are handled by specific hooks
"""
@@ -436,7 +436,7 @@
else if it's the first instance of this relation type, add the
necessary table and set default permissions
* register an operation to add the relation definition to the
- application's schema on commit
+ instance's schema on commit
constraints are handled by specific hooks
"""
@@ -883,7 +883,7 @@
self.perm, erschema.type, self.group)
-class DelRQLExpressionPermissionOp(AddRQLExpressionPermissionOp):
+class DeleteRQLExpressionPermissionOp(AddRQLExpressionPermissionOp):
"""synchronize schema when a *_permission relation has been deleted from an rql expression"""
def commit_event(self):
@@ -919,7 +919,7 @@
else: # RQLExpression
expr = session.execute('Any EXPR WHERE X eid %(x)s, X expression EXPR',
{'x': object}, 'x')[0][0]
- DelRQLExpressionPermissionOp(session, perm, subject, expr)
+ DeleteRQLExpressionPermissionOp(session, perm, subject, expr)
def rebuild_infered_relations(session, subject, rtype, object):
--- a/server/schemaserial.py Thu Jul 16 12:57:17 2009 -0700
+++ b/server/schemaserial.py Tue Jul 28 21:27:52 2009 +0200
@@ -277,12 +277,13 @@
"""synchronize schema and permissions in the database according to
current schema
"""
- print 'serializing the schema, this may take some time'
+ _title = '-> storing the schema in the database '
+ print _title,
eschemas = schema.entities()
aller = eschemas + schema.relations()
if not verbose:
pb_size = len(aller) + len(CONSTRAINTS) + len([x for x in eschemas if x.specializes()])
- pb = ProgressBar(pb_size)
+ pb = ProgressBar(pb_size, title=_title)
for cstrtype in CONSTRAINTS:
rql = 'INSERT CWConstraintType X: X name "%s"' % cstrtype
if verbose:
--- a/server/serverconfig.py Thu Jul 16 12:57:17 2009 -0700
+++ b/server/serverconfig.py Tue Jul 28 21:27:52 2009 +0200
@@ -171,7 +171,7 @@
'help': 'Pyro server port. If not set, it will be choosen randomly',
'group': 'pyro-server', 'inputlevel': 2,
}),
- ('pyro-id', # XXX reuse pyro-application-id
+ ('pyro-id', # XXX reuse pyro-instance-id
{'type' : 'string',
'default': None,
'help': 'identifier of the repository in the pyro name server',
@@ -180,7 +180,7 @@
) + CubicWebConfiguration.options)
# read the schema from the database
- read_application_schema = True
+ read_instance_schema = True
bootstrap_schema = True
# check user's state at login time
@@ -193,7 +193,7 @@
schema_hooks = True
notification_hooks = True
security_hooks = True
- application_hooks = True
+ instance_hooks = True
# should some hooks be deactivated during [pre|post]create script execution
free_wheel = False
@@ -208,14 +208,9 @@
@classmethod
def schemas_lib_dir(cls):
- """application schema directory"""
+ """instance schema directory"""
return env_path('CW_SCHEMA_LIB', cls.SCHEMAS_LIB_DIR, 'schemas')
- @classmethod
- def backup_dir(cls):
- """backup directory where a stored db backups before migration"""
- return env_path('CW_BACKUP', cls.BACKUP_DIR, 'run time')
-
def bootstrap_cubes(self):
from logilab.common.textutils import get_csv
for line in file(join(self.apphome, 'bootstrap_cubes')):
@@ -269,23 +264,6 @@
def load_hooks(self, vreg):
hooks = {}
- for path in reversed([self.apphome] + self.cubes_path()):
- hooksfile = join(path, 'application_hooks.py')
- if exists(hooksfile):
- self.warning('application_hooks.py is deprecated, use dynamic '
- 'objects to register hooks (%s)', hooksfile)
- context = {}
- # Use execfile rather than `load_module_from_name` because
- # the latter gets fooled by the `sys.modules` cache when
- # loading different configurations one after the other
- # (another fix would have been to do :
- # sys.modules.pop('applications_hooks')
- # or to modify load_module_from_name so that it provides
- # a use_cache optional parameter
- execfile(hooksfile, context, context)
- for event, hooksdef in context['HOOKS'].items():
- for ertype, hookcbs in hooksdef.items():
- hooks.setdefault(event, {}).setdefault(ertype, []).extend(hookcbs)
try:
apphookdefs = vreg.registry_objects('hooks')
except RegistryNotFound:
@@ -342,9 +320,11 @@
clear_cache(self, 'sources')
def migration_handler(self, schema=None, interactive=True,
- cnx=None, repo=None, connect=True):
+ cnx=None, repo=None, connect=True, verbosity=None):
"""return a migration handler instance"""
from cubicweb.server.migractions import ServerMigrationHelper
+ if verbosity is None:
+ verbosity = getattr(self, 'verbosity', 0)
return ServerMigrationHelper(self, schema, interactive=interactive,
cnx=cnx, repo=repo, connect=connect,
- verbosity=getattr(self, 'verbosity', 0))
+ verbosity=verbosity)
--- a/server/serverctl.py Thu Jul 16 12:57:17 2009 -0700
+++ b/server/serverctl.py Tue Jul 28 21:27:52 2009 +0200
@@ -5,7 +5,7 @@
:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr
:license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses
"""
-__docformat__ = "restructuredtext en"
+__docformat__ = 'restructuredtext en'
import sys
import os
@@ -13,13 +13,12 @@
from logilab.common.configuration import Configuration
from logilab.common.clcommands import register_commands, cmd_run, pop_arg
-from cubicweb import AuthenticationError, ExecutionError, ConfigurationError
+from cubicweb import AuthenticationError, ExecutionError, ConfigurationError, underline_title
from cubicweb.toolsutils import Command, CommandHandler, confirm
from cubicweb.server import SOURCE_TYPES
from cubicweb.server.utils import ask_source_config
from cubicweb.server.serverconfig import USER_OPTIONS, ServerConfiguration
-
# utility functions ###########################################################
def source_cnx(source, dbname=None, special_privs=False, verbose=True):
@@ -32,7 +31,7 @@
if dbname is None:
dbname = source['db-name']
driver = source['db-driver']
- print '**** connecting to %s database %s@%s' % (driver, dbname, dbhost),
+ print '-> connecting to %s database %s@%s' % (driver, dbname, dbhost or 'localhost'),
if not verbose or (not special_privs and source.get('db-user')):
user = source['db-user']
print 'as', user
@@ -48,7 +47,7 @@
print special_privs
print
default_user = source.get('db-user', os.environ.get('USER', ''))
- user = raw_input('user (%r by default): ' % default_user)
+ user = raw_input('Connect as user ? [%r]: ' % default_user)
user = user or default_user
if user == source.get('db-user') and source.get('db-password'):
password = source['db-password']
@@ -59,10 +58,10 @@
def system_source_cnx(source, dbms_system_base=False,
special_privs='CREATE/DROP DATABASE', verbose=True):
- """shortcut to get a connextion to the application system database
+ """shortcut to get a connextion to the instance system database
defined in the given config. If <dbms_system_base> is True,
connect to the dbms system database instead (for task such as
- create/drop the application database)
+ create/drop the instance database)
"""
if dbms_system_base:
from logilab.common.adbh import get_adv_func_helper
@@ -74,7 +73,9 @@
"""return a connection on the RDMS system table (to create/drop a user
or a database
"""
+ import logilab.common as lgp
from logilab.common.adbh import get_adv_func_helper
+ lgp.USE_MX_DATETIME = False
special_privs = ''
driver = source['db-driver']
helper = get_adv_func_helper(driver)
@@ -106,7 +107,7 @@
try:
return in_memory_cnx(config, login, pwd)
except AuthenticationError:
- print 'wrong user/password'
+ print '-> Error: wrong user/password.'
# reset cubes else we'll have an assertion error on next retry
config._cubes = None
login, pwd = manager_userpasswd()
@@ -118,18 +119,15 @@
cfgname = 'repository'
def bootstrap(self, cubes, inputlevel=0):
- """create an application by copying files from the given cube and by
+ """create an instance by copying files from the given cube and by
asking information necessary to build required configuration files
"""
config = self.config
- print 'application\'s repository configuration'
- print '-' * 72
+ print underline_title('Configuring the repository')
config.input_config('email', inputlevel)
if config.pyro_enabled():
config.input_config('pyro-server', inputlevel)
- print
- print 'repository sources configuration'
- print '-' * 72
+ print '\n'+underline_title('Configuring the sources')
sourcesfile = config.sources_file()
sconfig = Configuration(options=SOURCE_TYPES['native'].options)
sconfig.adapter = 'native'
@@ -140,19 +138,20 @@
# source to use the cube, so add it.
if cube in SOURCE_TYPES:
sourcescfg[cube] = ask_source_config(cube, inputlevel)
- while raw_input('enter another source [y/N]: ').strip().lower() == 'y':
+ print
+ while confirm('Enter another source ?', default_is_yes=False):
available = sorted(stype for stype in SOURCE_TYPES
if not stype in cubes)
while True:
sourcetype = raw_input('source type (%s): ' % ', '.join(available))
if sourcetype in available:
break
- print 'unknown source type, use one of the available type'
+ print '-> unknown source type, use one of the available types.'
while True:
sourceuri = raw_input('source uri: ').strip()
if sourceuri != 'admin' and sourceuri not in sourcescfg:
break
- print 'uri already used, choose another one'
+ print '-> uri already used, choose another one.'
sourcescfg[sourceuri] = ask_source_config(sourcetype)
sourcemodule = SOURCE_TYPES[sourcetype].module
if not sourcemodule.startswith('cubicweb.'):
@@ -170,11 +169,12 @@
config.write_bootstrap_cubes_file(cubes)
def postcreate(self):
- if confirm('do you want to create repository\'s system database?'):
+ if confirm('Do you want to run db-create to create the system database ?'):
verbosity = (self.config.mode == 'installed') and 'y' or 'n'
cmd_run('db-create', self.config.appid, '--verbose=%s' % verbosity)
else:
- print 'nevermind, you can do it later using the db-create command'
+ print ('-> nevermind, you can do it later with '
+ '"cubicweb-ctl db-create %s".' % self.config.appid)
class RepositoryDeleteHandler(CommandHandler):
@@ -182,23 +182,23 @@
cfgname = 'repository'
def cleanup(self):
- """remove application's configuration and database"""
+ """remove instance's configuration and database"""
from logilab.common.adbh import get_adv_func_helper
source = self.config.sources()['system']
dbname = source['db-name']
helper = get_adv_func_helper(source['db-driver'])
- if confirm('delete database %s ?' % dbname):
+ if confirm('Delete database %s ?' % dbname):
user = source['db-user'] or None
cnx = _db_sys_cnx(source, 'DROP DATABASE', user=user)
cursor = cnx.cursor()
try:
cursor.execute('DROP DATABASE %s' % dbname)
- print 'database %s dropped' % dbname
+ print '-> database %s dropped.' % dbname
# XXX should check we are not connected as user
if user and helper.users_support and \
- confirm('delete user %s ?' % user, default_is_yes=False):
+ confirm('Delete user %s ?' % user, default_is_yes=False):
cursor.execute('DROP USER %s' % user)
- print 'user %s dropped' % user
+ print '-> user %s dropped.' % user
cnx.commit()
except:
cnx.rollback()
@@ -231,26 +231,26 @@
# repository specific commands ################################################
-class CreateApplicationDBCommand(Command):
- """Create the system database of an application (run after 'create').
+class CreateInstanceDBCommand(Command):
+ """Create the system database of an instance (run after 'create').
You will be prompted for a login / password to use to connect to
the system database. The given user should have almost all rights
on the database (ie a super user on the dbms allowed to create
database, users, languages...).
- <application>
- the identifier of the application to initialize.
+ <instance>
+ the identifier of the instance to initialize.
"""
name = 'db-create'
- arguments = '<application>'
+ arguments = '<instance>'
options = (
- ("create-db",
- {'short': 'c', 'type': "yn", 'metavar': '<y or n>',
+ ('create-db',
+ {'short': 'c', 'type': 'yn', 'metavar': '<y or n>',
'default': True,
'help': 'create the database (yes by default)'}),
- ("verbose",
+ ('verbose',
{'short': 'v', 'type' : 'yn', 'metavar': '<verbose>',
'default': 'n',
'help': 'verbose mode: will ask all possible configuration questions',
@@ -262,13 +262,14 @@
from logilab.common.adbh import get_adv_func_helper
from indexer import get_indexer
verbose = self.get('verbose')
- appid = pop_arg(args, msg="No application specified !")
+ appid = pop_arg(args, msg='No instance specified !')
config = ServerConfiguration.config_for(appid)
create_db = self.config.create_db
source = config.sources()['system']
driver = source['db-driver']
helper = get_adv_func_helper(driver)
if create_db:
+ print '\n'+underline_title('Creating the system database')
# connect on the dbms system base to create our base
dbcnx = _db_sys_cnx(source, 'CREATE DATABASE and / or USER', verbose=verbose)
cursor = dbcnx.cursor()
@@ -276,12 +277,12 @@
if helper.users_support:
user = source['db-user']
if not helper.user_exists(cursor, user) and \
- confirm('create db user %s ?' % user, default_is_yes=False):
+ confirm('Create db user %s ?' % user, default_is_yes=False):
helper.create_user(source['db-user'], source['db-password'])
- print 'user %s created' % user
+ print '-> user %s created.' % user
dbname = source['db-name']
if dbname in helper.list_databases(cursor):
- if confirm('DB %s already exists -- do you want to drop it ?' % dbname):
+ if confirm('Database %s already exists -- do you want to drop it ?' % dbname):
cursor.execute('DROP DATABASE %s' % dbname)
else:
return
@@ -292,7 +293,7 @@
helper.create_database(cursor, dbname,
encoding=source['db-encoding'])
dbcnx.commit()
- print 'database %s created' % source['db-name']
+ print '-> database %s created.' % source['db-name']
except:
dbcnx.rollback()
raise
@@ -307,29 +308,30 @@
helper.create_language(cursor, extlang)
cursor.close()
cnx.commit()
- print 'database for application %s created and necessary extensions installed' % appid
+ print '-> database for instance %s created and necessary extensions installed.' % appid
print
- if confirm('do you want to initialize the system database?'):
+ if confirm('Do you want to run db-init to initialize the system database ?'):
cmd_run('db-init', config.appid)
else:
- print 'nevermind, you can do it later using the db-init command'
+ print ('-> nevermind, you can do it later with '
+ '"cubicweb-ctl db-init %s".' % self.config.appid)
-class InitApplicationCommand(Command):
- """Initialize the system database of an application (run after 'db-create').
+class InitInstanceCommand(Command):
+ """Initialize the system database of an instance (run after 'db-create').
You will be prompted for a login / password to use to connect to
the system database. The given user should have the create tables,
and grant permissions.
- <application>
- the identifier of the application to initialize.
+ <instance>
+ the identifier of the instance to initialize.
"""
name = 'db-init'
- arguments = '<application>'
+ arguments = '<instance>'
options = (
- ("drop",
+ ('drop',
{'short': 'd', 'action': 'store_true',
'default': False,
'help': 'insert drop statements to remove previously existant \
@@ -337,26 +339,27 @@
)
def run(self, args):
+ print '\n'+underline_title('Initializing the system database')
from cubicweb.server import init_repository
- appid = pop_arg(args, msg="No application specified !")
+ appid = pop_arg(args, msg='No instance specified !')
config = ServerConfiguration.config_for(appid)
init_repository(config, drop=self.config.drop)
-class GrantUserOnApplicationCommand(Command):
+class GrantUserOnInstanceCommand(Command):
"""Grant a database user on a repository system database.
- <application>
- the identifier of the application
+ <instance>
+ the identifier of the instance
<user>
the database's user requiring grant access
"""
name = 'db-grant-user'
- arguments = '<application> <user>'
+ arguments = '<instance> <user>'
options = (
- ("set-owner",
- {'short': 'o', 'type' : "yn", 'metavar' : '<yes or no>',
+ ('set-owner',
+ {'short': 'o', 'type' : 'yn', 'metavar' : '<yes or no>',
'default' : False,
'help': 'Set the user as tables owner if yes (no by default).'}
),
@@ -364,8 +367,8 @@
def run(self, args):
"""run the command with its specific arguments"""
from cubicweb.server.sqlutils import sqlexec, sqlgrants
- appid = pop_arg(args, 1, msg="No application specified !")
- user = pop_arg(args, msg="No user specified !")
+ appid = pop_arg(args, 1, msg='No instance specified !')
+ user = pop_arg(args, msg='No user specified !')
config = ServerConfiguration.config_for(appid)
source = config.sources()['system']
set_owner = self.config.set_owner
@@ -379,31 +382,31 @@
cnx.rollback()
import traceback
traceback.print_exc()
- print 'An error occured:', ex
+ print '-> an error occured:', ex
else:
cnx.commit()
- print 'grants given to %s on application %s' % (appid, user)
+ print '-> rights granted to %s on instance %s.' % (appid, user)
class ResetAdminPasswordCommand(Command):
"""Reset the administrator password.
- <application>
- the identifier of the application
+ <instance>
+ the identifier of the instance
"""
name = 'reset-admin-pwd'
- arguments = '<application>'
+ arguments = '<instance>'
def run(self, args):
"""run the command with its specific arguments"""
from cubicweb.server.sqlutils import sqlexec, SQL_PREFIX
from cubicweb.server.utils import crypt_password, manager_userpasswd
- appid = pop_arg(args, 1, msg="No application specified !")
+ appid = pop_arg(args, 1, msg='No instance specified !')
config = ServerConfiguration.config_for(appid)
sourcescfg = config.read_sources_file()
try:
adminlogin = sourcescfg['admin']['login']
except KeyError:
- print 'could not get cubicweb administrator login'
+ print '-> Error: could not get cubicweb administrator login.'
sys.exit(1)
cnx = source_cnx(sourcescfg['system'])
cursor = cnx.cursor()
@@ -423,32 +426,32 @@
cnx.rollback()
import traceback
traceback.print_exc()
- print 'An error occured:', ex
+ print '-> an error occured:', ex
else:
cnx.commit()
- print 'password reset, sources file regenerated'
+ print '-> password reset, sources file regenerated.'
class StartRepositoryCommand(Command):
- """Start an CubicWeb RQL server for a given application.
+ """Start an CubicWeb RQL server for a given instance.
The server will be accessible through pyro
- <application>
- the identifier of the application to initialize.
+ <instance>
+ the identifier of the instance to initialize.
"""
name = 'start-repository'
- arguments = '<application>'
+ arguments = '<instance>'
options = (
- ("debug",
+ ('debug',
{'short': 'D', 'action' : 'store_true',
'help': 'start server in debug mode.'}),
)
def run(self, args):
from cubicweb.server.server import RepositoryServer
- appid = pop_arg(args, msg="No application specified !")
+ appid = pop_arg(args, msg='No instance specified !')
config = ServerConfiguration.config_for(appid)
debug = self.config.debug
# create the server
@@ -470,6 +473,7 @@
def _remote_dump(host, appid, output, sudo=False):
+ # XXX generate unique/portable file name
dmpcmd = 'cubicweb-ctl db-dump -o /tmp/%s.dump %s' % (appid, appid)
if sudo:
dmpcmd = 'sudo %s' % (dmpcmd)
@@ -488,20 +492,23 @@
rmcmd = 'ssh -t %s "rm -f /tmp/%s.dump"' % (host, appid)
print rmcmd
if os.system(rmcmd) and not confirm(
- 'an error occured while deleting remote dump. Continue anyway?'):
+ 'An error occured while deleting remote dump. Continue anyway?'):
raise ExecutionError('Error while deleting remote dump')
def _local_dump(appid, output):
config = ServerConfiguration.config_for(appid)
# schema=1 to avoid unnecessary schema loading
- mih = config.migration_handler(connect=False, schema=1)
+ mih = config.migration_handler(connect=False, schema=1, verbosity=1)
mih.backup_database(output, askconfirm=False)
+ mih.shutdown()
-def _local_restore(appid, backupfile, drop):
+def _local_restore(appid, backupfile, drop, systemonly=True):
config = ServerConfiguration.config_for(appid)
+ config.verbosity = 1 # else we won't be asked for confirmation on problems
+ config.repairing = 1 # don't check versions
# schema=1 to avoid unnecessary schema loading
- mih = config.migration_handler(connect=False, schema=1)
- mih.restore_database(backupfile, drop)
+ mih = config.migration_handler(connect=False, schema=1, verbosity=1)
+ mih.restore_database(backupfile, drop, systemonly, askconfirm=False)
repo = mih.repo_connect()
# version of the database
dbversions = repo.get_versions()
@@ -511,7 +518,7 @@
return
# version of installed software
eversion = dbversions['cubicweb']
- status = application_status(config, eversion, dbversions)
+ status = instance_status(config, eversion, dbversions)
# * database version > installed software
if status == 'needsoftupgrade':
print "database is using some earlier version than installed software!"
@@ -529,7 +536,7 @@
# ok!
-def application_status(config, cubicwebapplversion, vcconf):
+def instance_status(config, cubicwebapplversion, vcconf):
cubicwebversion = config.cubicweb_version()
if cubicwebapplversion > cubicwebversion:
return 'needsoftupgrade'
@@ -539,12 +546,12 @@
try:
softversion = config.cube_version(cube)
except ConfigurationError:
- print "no cube version information for %s, is the cube installed?" % cube
+ print '-> Error: no cube version information for %s, please check that the cube is installed.' % cube
continue
try:
applversion = vcconf[cube]
except KeyError:
- print "no cube version information for %s in version configuration" % cube
+ print '-> Error: no cube version information for %s in version configuration.' % cube
continue
if softversion == applversion:
continue
@@ -556,18 +563,18 @@
class DBDumpCommand(Command):
- """Backup the system database of an application.
+ """Backup the system database of an instance.
- <application>
- the identifier of the application to backup
+ <instance>
+ the identifier of the instance to backup
format [[user@]host:]appname
"""
name = 'db-dump'
- arguments = '<application>'
+ arguments = '<instance>'
options = (
- ("output",
- {'short': 'o', 'type' : "string", 'metavar' : '<file>',
+ ('output',
+ {'short': 'o', 'type' : 'string', 'metavar' : '<file>',
'default' : None,
'help': 'Specify the backup file where the backup will be stored.'}
),
@@ -579,7 +586,7 @@
)
def run(self, args):
- appid = pop_arg(args, 1, msg="No application specified !")
+ appid = pop_arg(args, 1, msg='No instance specified !')
if ':' in appid:
host, appid = appid.split(':')
_remote_dump(host, appid, self.config.output, self.config.sudo)
@@ -588,50 +595,58 @@
class DBRestoreCommand(Command):
- """Restore the system database of an application.
+ """Restore the system database of an instance.
- <application>
- the identifier of the application to restore
+ <instance>
+ the identifier of the instance to restore
"""
name = 'db-restore'
- arguments = '<application> <backupfile>'
+ arguments = '<instance> <backupfile>'
options = (
- ("no-drop",
- {'short': 'n', 'action' : 'store_true',
- 'default' : False,
+ ('no-drop',
+ {'short': 'n', 'action' : 'store_true', 'default' : False,
'help': 'for some reason the database doesn\'t exist and so '
'should not be dropped.'}
),
+ ('restore-all',
+ {'short': 'r', 'action' : 'store_true', 'default' : False,
+ 'help': 'restore everything, eg not only the system source database '
+ 'but also data for all sources supporting backup/restore and custom '
+ 'instance data. In that case, <backupfile> is expected to be the '
+ 'timestamp of the backup to restore, not a file'}
+ ),
)
def run(self, args):
- appid = pop_arg(args, 1, msg="No application specified !")
- backupfile = pop_arg(args, msg="No backup file specified !")
- _local_restore(appid, backupfile, not self.config.no_drop)
+ appid = pop_arg(args, 1, msg='No instance specified !')
+ backupfile = pop_arg(args, msg='No backup file or timestamp specified !')
+ _local_restore(appid, backupfile,
+ drop=not self.config.no_drop,
+ systemonly=not self.config.restore_all)
class DBCopyCommand(Command):
- """Copy the system database of an application (backup and restore).
+ """Copy the system database of an instance (backup and restore).
- <src-application>
- the identifier of the application to backup
+ <src-instance>
+ the identifier of the instance to backup
format [[user@]host:]appname
- <dest-application>
- the identifier of the application to restore
+ <dest-instance>
+ the identifier of the instance to restore
"""
name = 'db-copy'
- arguments = '<src-application> <dest-application>'
+ arguments = '<src-instance> <dest-instance>'
options = (
- ("no-drop",
+ ('no-drop',
{'short': 'n', 'action' : 'store_true',
'default' : False,
'help': 'For some reason the database doesn\'t exist and so '
'should not be dropped.'}
),
- ("keep-dump",
+ ('keep-dump',
{'short': 'k', 'action' : 'store_true',
'default' : False,
'help': 'Specify that the dump file should not be automatically removed.'}
@@ -645,9 +660,9 @@
def run(self, args):
import tempfile
- srcappid = pop_arg(args, 1, msg="No source application specified !")
- destappid = pop_arg(args, msg="No destination application specified !")
- output = tempfile.mktemp()
+ srcappid = pop_arg(args, 1, msg='No source instance specified !')
+ destappid = pop_arg(args, msg='No destination instance specified !')
+ _, output = tempfile.mkstemp()
if ':' in srcappid:
host, srcappid = srcappid.split(':')
_remote_dump(host, srcappid, output, self.config.sudo)
@@ -655,66 +670,72 @@
_local_dump(srcappid, output)
_local_restore(destappid, output, not self.config.no_drop)
if self.config.keep_dump:
- print 'you can get the dump file at', output
+ print '-> you can get the dump file at', output
else:
os.remove(output)
class CheckRepositoryCommand(Command):
- """Check integrity of the system database of an application.
+ """Check integrity of the system database of an instance.
- <application>
- the identifier of the application to check
+ <instance>
+ the identifier of the instance to check
"""
name = 'db-check'
- arguments = '<application>'
+ arguments = '<instance>'
options = (
- ("checks",
- {'short': 'c', 'type' : "csv", 'metavar' : '<check list>',
+ ('checks',
+ {'short': 'c', 'type' : 'csv', 'metavar' : '<check list>',
'default' : ('entities', 'relations', 'metadata', 'schema', 'text_index'),
'help': 'Comma separated list of check to run. By default run all \
checks, i.e. entities, relations, text_index and metadata.'}
),
- ("autofix",
- {'short': 'a', 'type' : "yn", 'metavar' : '<yes or no>',
+ ('autofix',
+ {'short': 'a', 'type' : 'yn', 'metavar' : '<yes or no>',
'default' : False,
'help': 'Automatically correct integrity problems if this option \
is set to "y" or "yes", else only display them'}
),
- ("reindex",
- {'short': 'r', 'type' : "yn", 'metavar' : '<yes or no>',
+ ('reindex',
+ {'short': 'r', 'type' : 'yn', 'metavar' : '<yes or no>',
'default' : False,
'help': 're-indexes the database for full text search if this \
option is set to "y" or "yes" (may be long for large database).'}
),
+ ('force',
+ {'short': 'f', 'action' : 'store_true',
+ 'default' : False,
+ 'help': 'don\'t check instance is up to date.'}
+ ),
)
def run(self, args):
from cubicweb.server.checkintegrity import check
- appid = pop_arg(args, 1, msg="No application specified !")
+ appid = pop_arg(args, 1, msg='No instance specified !')
config = ServerConfiguration.config_for(appid)
+ config.repairing = self.config.force
repo, cnx = repo_cnx(config)
check(repo, cnx,
self.config.checks, self.config.reindex, self.config.autofix)
class RebuildFTICommand(Command):
- """Rebuild the full-text index of the system database of an application.
+ """Rebuild the full-text index of the system database of an instance.
- <application>
- the identifier of the application to rebuild
+ <instance>
+ the identifier of the instance to rebuild
"""
name = 'db-rebuild-fti'
- arguments = '<application>'
+ arguments = '<instance>'
options = ()
def run(self, args):
from cubicweb.server.checkintegrity import reindex_entities
- appid = pop_arg(args, 1, msg="No application specified !")
+ appid = pop_arg(args, 1, msg='No instance specified !')
config = ServerConfiguration.config_for(appid)
repo, cnx = repo_cnx(config)
session = repo._get_session(cnx.sessionid, setpool=True)
@@ -722,28 +743,28 @@
cnx.commit()
-class SynchronizeApplicationSchemaCommand(Command):
+class SynchronizeInstanceSchemaCommand(Command):
"""Synchronize persistent schema with cube schema.
Will synchronize common stuff between the cube schema and the
actual persistent schema, but will not add/remove any entity or relation.
- <application>
- the identifier of the application to synchronize.
+ <instance>
+ the identifier of the instance to synchronize.
"""
name = 'schema-sync'
- arguments = '<application>'
+ arguments = '<instance>'
def run(self, args):
- appid = pop_arg(args, msg="No application specified !")
+ appid = pop_arg(args, msg='No instance specified !')
config = ServerConfiguration.config_for(appid)
mih = config.migration_handler()
mih.cmd_synchronize_schema()
-register_commands( (CreateApplicationDBCommand,
- InitApplicationCommand,
- GrantUserOnApplicationCommand,
+register_commands( (CreateInstanceDBCommand,
+ InitInstanceCommand,
+ GrantUserOnInstanceCommand,
ResetAdminPasswordCommand,
StartRepositoryCommand,
DBDumpCommand,
@@ -751,5 +772,5 @@
DBCopyCommand,
CheckRepositoryCommand,
RebuildFTICommand,
- SynchronizeApplicationSchemaCommand,
+ SynchronizeInstanceSchemaCommand,
) )
--- a/server/session.py Thu Jul 16 12:57:17 2009 -0700
+++ b/server/session.py Tue Jul 28 21:27:52 2009 +0200
@@ -194,7 +194,14 @@
raise KeyError(eid)
def base_url(self):
- return self.repo.config['base-url'] or u''
+ url = self.repo.config['base-url']
+ if not url:
+ try:
+ url = self.repo.config.default_base_url()
+ except AttributeError: # default_base_url() might not be available
+ self.warning('missing base-url definition in server config')
+ url = u''
+ return url
def from_controller(self):
"""return the id (string) of the controller issuing the request (no
--- a/server/sources/__init__.py Thu Jul 16 12:57:17 2009 -0700
+++ b/server/sources/__init__.py Tue Jul 28 21:27:52 2009 +0200
@@ -7,6 +7,7 @@
"""
__docformat__ = "restructuredtext en"
+from os.path import join, splitext
from datetime import datetime, timedelta
from logging import getLogger
@@ -14,6 +15,7 @@
from cubicweb.server.sqlutils import SQL_PREFIX
+
class TimedCache(dict):
def __init__(self, ttlm, ttls=0):
# time to live in minutes
@@ -53,7 +55,7 @@
uri = None
# a reference to the system information helper
repo = None
- # a reference to the application'schema (may differs from the source'schema)
+ # a reference to the instance'schema (may differs from the source'schema)
schema = None
def __init__(self, repo, appschema, source_config, *args, **kwargs):
@@ -71,6 +73,42 @@
"""method called by the repository once ready to handle request"""
pass
+ def backup_file(self, backupfile=None, timestamp=None):
+ """return a unique file name for a source's dump
+
+ either backupfile or timestamp (used to generated a backup file name if
+ needed) should be specified.
+ """
+ if backupfile is None:
+ config = self.repo.config
+ return join(config.appdatahome, 'backup',
+ '%s-%s-%s.dump' % (config.appid, timestamp, self.uri))
+ # backup file is the system database backup file, add uri to it if not
+ # already there
+ base, ext = splitext(backupfile)
+ if not base.endswith('-%s' % self.uri):
+ return '%s-%s%s' % (base, self.uri, ext)
+ return backupfile
+
+ def backup(self, confirm, backupfile=None, timestamp=None,
+ askconfirm=False):
+ """method called to create a backup of source's data"""
+ pass
+
+ def restore(self, confirm, backupfile=None, timestamp=None, drop=True,
+ askconfirm=False):
+ """method called to restore a backup of source's data"""
+ pass
+
+ def close_pool_connections(self):
+ for pool in self.repo.pools:
+ pool._cursors.pop(self.uri, None)
+ pool.source_cnxs[self.uri][1].close()
+
+ def open_pool_connections(self):
+ for pool in self.repo.pools:
+ pool.source_cnxs[self.uri] = (self, self.get_connection())
+
def reset_caches(self):
"""method called during test to reset potential source caches"""
pass
@@ -95,7 +133,7 @@
return cmp(self.uri, other.uri)
def set_schema(self, schema):
- """set the application'schema"""
+ """set the instance'schema"""
self.schema = schema
def support_entity(self, etype, write=False):
--- a/server/sources/extlite.py Thu Jul 16 12:57:17 2009 -0700
+++ b/server/sources/extlite.py Tue Jul 28 21:27:52 2009 +0200
@@ -11,7 +11,8 @@
from os.path import join, exists
from cubicweb import server
-from cubicweb.server.sqlutils import SQL_PREFIX, sqlexec, SQLAdapterMixIn
+from cubicweb.server.sqlutils import (SQL_PREFIX, SQLAdapterMixIn, sqlexec,
+ sql_source_backup, sql_source_restore)
from cubicweb.server.sources import AbstractSource, native
from cubicweb.server.sources.rql2sql import SQLGenerator
@@ -85,6 +86,19 @@
AbstractSource.__init__(self, repo, appschema, source_config,
*args, **kwargs)
+ def backup(self, confirm, backupfile=None, timestamp=None, askconfirm=False):
+ """method called to create a backup of source's data"""
+ backupfile = self.backup_file(backupfile, timestamp)
+ sql_source_backup(self, self.sqladapter, confirm, backupfile,
+ askconfirm)
+
+ def restore(self, confirm, backupfile=None, timestamp=None, drop=True,
+ askconfirm=False):
+ """method called to restore a backup of source's data"""
+ backupfile = self.backup_file(backupfile, timestamp)
+ sql_source_restore(self, self.sqladapter, confirm, backupfile, drop,
+ askconfirm)
+
@property
def _sqlcnx(self):
# XXX: sqlite connections can only be used in the same thread, so
--- a/server/sources/native.py Thu Jul 16 12:57:17 2009 -0700
+++ b/server/sources/native.py Tue Jul 28 21:27:52 2009 +0200
@@ -25,7 +25,8 @@
from cubicweb import UnknownEid, AuthenticationError, Binary, server
from cubicweb.server.utils import crypt_password
-from cubicweb.server.sqlutils import SQL_PREFIX, SQLAdapterMixIn
+from cubicweb.server.sqlutils import (SQL_PREFIX, SQLAdapterMixIn,
+ sql_source_backup, sql_source_restore)
from cubicweb.server.rqlannotation import set_qdata
from cubicweb.server.sources import AbstractSource
from cubicweb.server.sources.rql2sql import SQLGenerator
@@ -199,6 +200,18 @@
pool.pool_reset()
self.repo._free_pool(pool)
+ def backup(self, confirm, backupfile=None, timestamp=None,
+ askconfirm=False):
+ """method called to create a backup of source's data"""
+ backupfile = self.backup_file(backupfile, timestamp)
+ sql_source_backup(self, self, confirm, backupfile, askconfirm)
+
+ def restore(self, confirm, backupfile=None, timestamp=None, drop=True,
+ askconfirm=False):
+ """method called to restore a backup of source's data"""
+ backupfile = self.backup_file(backupfile, timestamp)
+ sql_source_restore(self, self, confirm, backupfile, drop, askconfirm)
+
def init(self):
self.init_creating()
pool = self.repo._get_pool()
@@ -213,7 +226,7 @@
def map_attribute(self, etype, attr, cb):
self._rql_sqlgen.attr_map['%s.%s' % (etype, attr)] = cb
-
+
# ISource interface #######################################################
def compile_rql(self, rql):
@@ -225,7 +238,7 @@
return rqlst
def set_schema(self, schema):
- """set the application'schema"""
+ """set the instance'schema"""
self._cache = Cache(self.repo.config['rql-cache-size'])
self.cache_hit, self.cache_miss, self.no_cache = 0, 0, 0
self.schema = schema
--- a/server/sqlutils.py Thu Jul 16 12:57:17 2009 -0700
+++ b/server/sqlutils.py Tue Jul 28 21:27:52 2009 +0200
@@ -7,6 +7,8 @@
"""
__docformat__ = "restructuredtext en"
+import os
+from os.path import exists
from warnings import warn
from datetime import datetime, date, timedelta
@@ -21,6 +23,7 @@
from cubicweb import Binary, ConfigurationError
from cubicweb.utils import todate, todatetime
from cubicweb.common.uilib import remove_html_tags
+from cubicweb.toolsutils import restrict_perms_to_user
from cubicweb.server import SQL_CONNECT_HOOKS
from cubicweb.server.utils import crypt_password
@@ -29,7 +32,7 @@
SQL_PREFIX = 'cw_'
-def sqlexec(sqlstmts, cursor_or_execute, withpb=True, delimiter=';'):
+def sqlexec(sqlstmts, cursor_or_execute, withpb=True, pbtitle='', delimiter=';'):
"""execute sql statements ignoring DROP/ CREATE GROUP or USER statements
error. If a cnx is given, commit at each statement
"""
@@ -39,7 +42,7 @@
execute = cursor_or_execute
sqlstmts = sqlstmts.split(delimiter)
if withpb:
- pb = ProgressBar(len(sqlstmts))
+ pb = ProgressBar(len(sqlstmts), title=pbtitle)
for sql in sqlstmts:
sql = sql.strip()
if withpb:
@@ -116,6 +119,39 @@
skip_relations=skip_relations))
return '\n'.join(output)
+
+def sql_source_backup(source, sqladapter, confirm, backupfile,
+ askconfirm=False):
+ if exists(backupfile):
+ if not confirm('Backup file %s exists, overwrite it?' % backupfile):
+ return
+ elif askconfirm and not confirm('Backup %s database?'
+ % source.repo.config.appid):
+ print '-> no backup done.'
+ return
+ # should close opened connection before backuping
+ source.close_pool_connections()
+ try:
+ sqladapter.backup_to_file(backupfile, confirm)
+ finally:
+ source.open_pool_connections()
+
+def sql_source_restore(source, sqladapter, confirm, backupfile, drop=True,
+ askconfirm=False):
+ if not exists(backupfile):
+ raise Exception("backup file %s doesn't exist" % backupfile)
+ app = source.repo.config.appid
+ if askconfirm and not confirm('Restore %s %s database from %s ?'
+ % (app, source.uri, backupfile)):
+ return
+ # should close opened connection before restoring
+ source.close_pool_connections()
+ try:
+ sqladapter.restore_from_file(backupfile, confirm, drop=drop)
+ finally:
+ source.open_pool_connections()
+
+
try:
from mx.DateTime import DateTimeType, DateTimeDeltaType
except ImportError:
@@ -159,6 +195,46 @@
#self.dbapi_module.type_code_test(cnx.cursor())
return cnx
+ def backup_to_file(self, backupfile, confirm):
+ cmd = self.dbhelper.backup_command(self.dbname, self.dbhost,
+ self.dbuser, backupfile,
+ keepownership=False)
+ while True:
+ print cmd
+ if os.system(cmd):
+ print '-> error while backuping the base'
+ answer = confirm('Continue anyway?',
+ shell=False, abort=False, retry=True)
+ if not answer:
+ raise SystemExit(1)
+ if answer == 1: # 1: continue, 2: retry
+ break
+ else:
+ print '-> backup file', backupfile
+ restrict_perms_to_user(backupfile, self.info)
+ break
+
+ def restore_from_file(self, backupfile, confirm, drop=True):
+ for cmd in self.dbhelper.restore_commands(self.dbname, self.dbhost,
+ self.dbuser, backupfile,
+ self.encoding,
+ keepownership=False,
+ drop=drop):
+ while True:
+ print cmd
+ if os.system(cmd):
+ print 'error while restoring the base'
+ print 'OOOOOPS', confirm
+ answer = confirm('continue anyway?',
+ shell=False, abort=False, retry=True)
+ if not answer:
+ raise SystemExit(1)
+ if answer == 1: # 1: continue, 2: retry
+ break
+ else:
+ break
+ print 'database restored'
+
def merge_args(self, args, query_args):
if args is not None:
args = dict(args)
--- a/server/test/data/migrschema/Folder2.py Thu Jul 16 12:57:17 2009 -0700
+++ b/server/test/data/migrschema/Folder2.py Tue Jul 28 21:27:52 2009 +0200
@@ -5,7 +5,6 @@
:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr
:license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses
"""
-from cubicweb.schema import format_constraint
class Folder2(MetaUserEntityType):
"""folders are used to classify entities. They may be defined as a tree.
@@ -14,9 +13,7 @@
"""
name = String(required=True, indexed=True, internationalizable=True,
constraints=[UniqueConstraint(), SizeConstraint(64)])
- description_format = String(meta=True, internationalizable=True,
- default='text/rest', constraints=[format_constraint])
- description = String(fulltextindexed=True)
+ description = RichString(fulltextindexed=True)
filed_under2 = BothWayRelation(
SubjectRelation('Folder2', description=_("parent folder")),
--- a/server/test/data/schema.py Thu Jul 16 12:57:17 2009 -0700
+++ b/server/test/data/schema.py Tue Jul 28 21:27:52 2009 +0200
@@ -5,7 +5,12 @@
:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr
:license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses
"""
-from cubicweb.schema import format_constraint
+from yams.buildobjs import (EntityType, RelationType, RelationDefinition,
+ SubjectRelation, ObjectRelation,
+ RichString, String, Int, Boolean, Datetime)
+from yams.constraints import SizeConstraint
+from cubicweb.schema import (WorkflowableEntityType, RQLConstraint,
+ ERQLExpression, RRQLExpression)
class Affaire(WorkflowableEntityType):
permissions = {
@@ -20,10 +25,8 @@
constraints=[SizeConstraint(16)])
sujet = String(fulltextindexed=True,
constraints=[SizeConstraint(256)])
- descr_format = String(meta=True, internationalizable=True,
- default='text/rest', constraints=[format_constraint])
- descr = String(fulltextindexed=True,
- description=_('more detailed description'))
+ descr = RichString(fulltextindexed=True,
+ description=_('more detailed description'))
duration = Int()
invoiced = Int()
@@ -63,8 +66,8 @@
__specializes_schema__ = True
travaille_subdivision = ObjectRelation('Personne')
-_euser = import_schema('base').CWUser
-_euser.__relations__[0].fulltextindexed = True
+from cubicweb.schemas.base import CWUser
+CWUser.get_relations('login').next().fulltextindexed = True
class Note(EntityType):
date = String(maxsize=10)
@@ -131,14 +134,14 @@
'delete': ('managers', RRQLExpression('O owned_by U')),
}
-class para(AttributeRelationType):
+class para(RelationType):
permissions = {
'read': ('managers', 'users', 'guests'),
'add': ('managers', ERQLExpression('X in_state S, S name "todo"')),
'delete': ('managers', ERQLExpression('X in_state S, S name "todo"')),
}
-class test(AttributeRelationType):
+class test(RelationType):
permissions = {'read': ('managers', 'users', 'guests'),
'delete': ('managers',),
'add': ('managers',)}
--- a/server/test/unittest_hookhelper.py Thu Jul 16 12:57:17 2009 -0700
+++ b/server/test/unittest_hookhelper.py Tue Jul 28 21:27:52 2009 +0200
@@ -41,7 +41,7 @@
from cubicweb.server import hooks, schemahooks
session = self.session
op1 = hooks.DelayedDeleteOp(session)
- op2 = schemahooks.DelErdefOp(session)
+ op2 = schemahooks.DeleteRelationDefOp(session)
# equivalent operation generated by op2 but replace it here by op3 so we
# can check the result...
op3 = schemahooks.UpdateSchemaOp(session)
--- a/server/test/unittest_hooks.py Thu Jul 16 12:57:17 2009 -0700
+++ b/server/test/unittest_hooks.py Tue Jul 28 21:27:52 2009 +0200
@@ -6,9 +6,13 @@
"""
from logilab.common.testlib import TestCase, unittest_main
+
+from datetime import datetime
+
+from cubicweb import (ConnectionError, RepositoryError, ValidationError,
+ AuthenticationError, BadConnectionId)
from cubicweb.devtools.apptest import RepositoryBasedTC, get_versions
-from cubicweb import ConnectionError, RepositoryError, ValidationError, AuthenticationError, BadConnectionId
from cubicweb.server.sqlutils import SQL_PREFIX
from cubicweb.server.repository import Repository
@@ -265,8 +269,8 @@
self.failIf(schema.has_entity('Societe2'))
self.failIf(schema.has_entity('concerne2'))
# schema should be update on insertion (after commit)
- self.execute('INSERT CWEType X: X name "Societe2", X description "", X meta FALSE, X final FALSE')
- self.execute('INSERT CWRType X: X name "concerne2", X description "", X meta FALSE, X final FALSE, X symetric FALSE')
+ self.execute('INSERT CWEType X: X name "Societe2", X description "", X final FALSE')
+ self.execute('INSERT CWRType X: X name "concerne2", X description "", X final FALSE, X symetric FALSE')
self.failIf(schema.has_entity('Societe2'))
self.failIf(schema.has_entity('concerne2'))
self.execute('SET X read_permission G WHERE X is CWEType, X name "Societe2", G is CWGroup')
@@ -614,5 +618,39 @@
self.failUnless(cu.execute("INSERT Note X: X type 'a', X in_state S WHERE S name 'todo'"))
cnx.commit()
+ def test_metadata_cwuri(self):
+ eid = self.execute('INSERT Note X')[0][0]
+ cwuri = self.execute('Any U WHERE X eid %s, X cwuri U' % eid)[0][0]
+ self.assertEquals(cwuri, self.repo.config['base-url'] + 'eid/%s' % eid)
+
+ def test_metadata_creation_modification_date(self):
+ _now = datetime.now()
+ eid = self.execute('INSERT Note X')[0][0]
+ creation_date, modification_date = self.execute('Any CD, MD WHERE X eid %s, '
+ 'X creation_date CD, '
+ 'X modification_date MD' % eid)[0]
+ self.assertEquals((creation_date - _now).seconds, 0)
+ self.assertEquals((modification_date - _now).seconds, 0)
+
+ def test_metadata__date(self):
+ _now = datetime.now()
+ eid = self.execute('INSERT Note X')[0][0]
+ creation_date = self.execute('Any D WHERE X eid %s, X creation_date D' % eid)[0][0]
+ self.assertEquals((creation_date - _now).seconds, 0)
+
+ def test_metadata_created_by(self):
+ eid = self.execute('INSERT Note X')[0][0]
+ self.commit() # fire operations
+ rset = self.execute('Any U WHERE X eid %s, X created_by U' % eid)
+ self.assertEquals(len(rset), 1) # make sure we have only one creator
+ self.assertEquals(rset[0][0], self.session.user.eid)
+
+ def test_metadata_owned_by(self):
+ eid = self.execute('INSERT Note X')[0][0]
+ self.commit() # fire operations
+ rset = self.execute('Any U WHERE X eid %s, X owned_by U' % eid)
+ self.assertEquals(len(rset), 1) # make sure we have only one owner
+ self.assertEquals(rset[0][0], self.session.user.eid)
+
if __name__ == '__main__':
unittest_main()
--- a/server/test/unittest_schemaserial.py Thu Jul 16 12:57:17 2009 -0700
+++ b/server/test/unittest_schemaserial.py Tue Jul 28 21:27:52 2009 +0200
@@ -23,15 +23,15 @@
def test_eschema2rql1(self):
self.assertListEquals(list(eschema2rql(schema.eschema('CWAttribute'))),
[
- ('INSERT CWEType X: X description %(description)s,X final %(final)s,X meta %(meta)s,X name %(name)s',
- {'description': u'define a final relation: link a final relation type from a non final entity to a final entity type. used to build the application schema',
- 'meta': True, 'name': u'CWAttribute', 'final': False})
+ ('INSERT CWEType X: X description %(description)s,X final %(final)s,X name %(name)s',
+ {'description': u'define a final relation: link a final relation type from a non final entity to a final entity type. used to build the instance schema',
+ 'name': u'CWAttribute', 'final': False})
])
def test_eschema2rql2(self):
self.assertListEquals(list(eschema2rql(schema.eschema('String'))), [
- ('INSERT CWEType X: X description %(description)s,X final %(final)s,X meta %(meta)s,X name %(name)s',
- {'description': u'', 'final': True, 'meta': True, 'name': u'String'})])
+ ('INSERT CWEType X: X description %(description)s,X final %(final)s,X name %(name)s',
+ {'description': u'', 'final': True, 'name': u'String'})])
def test_eschema2rql_specialization(self):
self.assertListEquals(list(specialize2rql(schema)),
@@ -44,8 +44,8 @@
def test_rschema2rql1(self):
self.assertListEquals(list(rschema2rql(schema.rschema('relation_type'))),
[
- ('INSERT CWRType X: X description %(description)s,X final %(final)s,X fulltext_container %(fulltext_container)s,X inlined %(inlined)s,X meta %(meta)s,X name %(name)s,X symetric %(symetric)s',
- {'description': u'link a relation definition to its relation type', 'meta': True, 'symetric': False, 'name': u'relation_type', 'final' : False, 'fulltext_container': None, 'inlined': True}),
+ ('INSERT CWRType X: X description %(description)s,X final %(final)s,X fulltext_container %(fulltext_container)s,X inlined %(inlined)s,X name %(name)s,X symetric %(symetric)s',
+ {'description': u'link a relation definition to its relation type', 'symetric': False, 'name': u'relation_type', 'final' : False, 'fulltext_container': None, 'inlined': True}),
('INSERT CWRelation X: X cardinality %(cardinality)s,X composite %(composite)s,X description %(description)s,X ordernum %(ordernum)s,X relation_type ER,X from_entity SE,X to_entity OE WHERE SE name %(se)s,ER name %(rt)s,OE name %(oe)s',
{'rt': 'relation_type', 'description': u'', 'composite': u'object', 'oe': 'CWRType',
@@ -63,7 +63,7 @@
def test_rschema2rql2(self):
self.assertListEquals(list(rschema2rql(schema.rschema('add_permission'))),
[
- ('INSERT CWRType X: X description %(description)s,X final %(final)s,X fulltext_container %(fulltext_container)s,X inlined %(inlined)s,X meta %(meta)s,X name %(name)s,X symetric %(symetric)s', {'description': u'core relation giving to a group the permission to add an entity or relation type', 'meta': True, 'symetric': False, 'name': u'add_permission', 'final': False, 'fulltext_container': None, 'inlined': False}),
+ ('INSERT CWRType X: X description %(description)s,X final %(final)s,X fulltext_container %(fulltext_container)s,X inlined %(inlined)s,X name %(name)s,X symetric %(symetric)s', {'description': u'core relation giving to a group the permission to add an entity or relation type', 'symetric': False, 'name': u'add_permission', 'final': False, 'fulltext_container': None, 'inlined': False}),
('INSERT CWRelation X: X cardinality %(cardinality)s,X composite %(composite)s,X description %(description)s,X ordernum %(ordernum)s,X relation_type ER,X from_entity SE,X to_entity OE WHERE SE name %(se)s,ER name %(rt)s,OE name %(oe)s',
{'rt': 'add_permission', 'description': u'groups allowed to add entities/relations of this type', 'composite': None, 'oe': 'CWGroup', 'ordernum': 3, 'cardinality': u'**', 'se': 'CWEType'}),
@@ -79,8 +79,8 @@
def test_rschema2rql3(self):
self.assertListEquals(list(rschema2rql(schema.rschema('cardinality'))),
[
- ('INSERT CWRType X: X description %(description)s,X final %(final)s,X fulltext_container %(fulltext_container)s,X inlined %(inlined)s,X meta %(meta)s,X name %(name)s,X symetric %(symetric)s',
- {'description': u'', 'meta': False, 'symetric': False, 'name': u'cardinality', 'final': True, 'fulltext_container': None, 'inlined': False}),
+ ('INSERT CWRType X: X description %(description)s,X final %(final)s,X fulltext_container %(fulltext_container)s,X inlined %(inlined)s,X name %(name)s,X symetric %(symetric)s',
+ {'description': u'', 'symetric': False, 'name': u'cardinality', 'final': True, 'fulltext_container': None, 'inlined': False}),
('INSERT CWAttribute X: X cardinality %(cardinality)s,X defaultval %(defaultval)s,X description %(description)s,X fulltextindexed %(fulltextindexed)s,X indexed %(indexed)s,X internationalizable %(internationalizable)s,X ordernum %(ordernum)s,X relation_type ER,X from_entity SE,X to_entity OE WHERE SE name %(se)s,ER name %(rt)s,OE name %(oe)s',
{'rt': 'cardinality', 'description': u'subject/object cardinality', 'internationalizable': True, 'fulltextindexed': False, 'ordernum': 5, 'defaultval': None, 'indexed': False, 'cardinality': u'?1', 'oe': 'String', 'se': 'CWRelation'}),
@@ -100,31 +100,31 @@
def test_updateeschema2rql1(self):
self.assertListEquals(list(updateeschema2rql(schema.eschema('CWAttribute'))),
- [('SET X description %(description)s,X final %(final)s,X meta %(meta)s,X name %(name)s WHERE X is CWEType, X name %(et)s',
- {'description': u'define a final relation: link a final relation type from a non final entity to a final entity type. used to build the application schema', 'meta': True, 'et': 'CWAttribute', 'final': False, 'name': u'CWAttribute'}),
+ [('SET X description %(description)s,X final %(final)s,X name %(name)s WHERE X is CWEType, X name %(et)s',
+ {'description': u'define a final relation: link a final relation type from a non final entity to a final entity type. used to build the instance schema', 'et': 'CWAttribute', 'final': False, 'name': u'CWAttribute'}),
])
def test_updateeschema2rql2(self):
self.assertListEquals(list(updateeschema2rql(schema.eschema('String'))),
- [('SET X description %(description)s,X final %(final)s,X meta %(meta)s,X name %(name)s WHERE X is CWEType, X name %(et)s',
- {'description': u'', 'meta': True, 'et': 'String', 'final': True, 'name': u'String'})
+ [('SET X description %(description)s,X final %(final)s,X name %(name)s WHERE X is CWEType, X name %(et)s',
+ {'description': u'', 'et': 'String', 'final': True, 'name': u'String'})
])
def test_updaterschema2rql1(self):
self.assertListEquals(list(updaterschema2rql(schema.rschema('relation_type'))),
[
- ('SET X description %(description)s,X final %(final)s,X fulltext_container %(fulltext_container)s,X inlined %(inlined)s,X meta %(meta)s,X name %(name)s,X symetric %(symetric)s WHERE X is CWRType, X name %(rt)s',
+ ('SET X description %(description)s,X final %(final)s,X fulltext_container %(fulltext_container)s,X inlined %(inlined)s,X name %(name)s,X symetric %(symetric)s WHERE X is CWRType, X name %(rt)s',
{'rt': 'relation_type', 'symetric': False,
'description': u'link a relation definition to its relation type',
- 'meta': True, 'final': False, 'fulltext_container': None, 'inlined': True, 'name': u'relation_type'})
+ 'final': False, 'fulltext_container': None, 'inlined': True, 'name': u'relation_type'})
])
def test_updaterschema2rql2(self):
expected = [
- ('SET X description %(description)s,X final %(final)s,X fulltext_container %(fulltext_container)s,X inlined %(inlined)s,X meta %(meta)s,X name %(name)s,X symetric %(symetric)s WHERE X is CWRType, X name %(rt)s',
+ ('SET X description %(description)s,X final %(final)s,X fulltext_container %(fulltext_container)s,X inlined %(inlined)s,X name %(name)s,X symetric %(symetric)s WHERE X is CWRType, X name %(rt)s',
{'rt': 'add_permission', 'symetric': False,
'description': u'core relation giving to a group the permission to add an entity or relation type',
- 'meta': True, 'final': False, 'fulltext_container': None, 'inlined': False, 'name': u'add_permission'})
+ 'final': False, 'fulltext_container': None, 'inlined': False, 'name': u'add_permission'})
]
for i, (rql, args) in enumerate(updaterschema2rql(schema.rschema('add_permission'))):
yield self.assertEquals, (rql, args), expected[i]
--- a/server/test/unittest_security.py Thu Jul 16 12:57:17 2009 -0700
+++ b/server/test/unittest_security.py Tue Jul 28 21:27:52 2009 +0200
@@ -499,7 +499,7 @@
self.assertRaises(Unauthorized,
self.schema['Affaire'].check_perm, session, 'update', eid)
cu = cnx.cursor()
- cu.execute('SET X in_state S WHERE X ref "ARCT01", S name "abort"')
+ cu.execute('SET X in_state S WHERE X ref "ARCT01", S name "ben non"')
cnx.commit()
# though changing a user state (even logged user) is reserved to managers
rql = u"SET X in_state S WHERE X eid %(x)s, S name 'deactivated'"
@@ -508,5 +508,25 @@
# from the current state but Unauthorized if it exists but user can't pass it
self.assertRaises(ValidationError, cu.execute, rql, {'x': cnx.user(self.current_session()).eid}, 'x')
+ def test_trinfo_security(self):
+ aff = self.execute('INSERT Affaire X: X ref "ARCT01"').get_entity(0, 0)
+ self.commit()
+ # can change tr info comment
+ self.execute('SET TI comment %(c)s WHERE TI wf_info_for X, X ref "ARCT01"',
+ {'c': u'creation'})
+ self.commit()
+ self.assertEquals(aff.latest_trinfo().comment, 'creation')
+ # but not from_state/to_state
+ self.execute('SET X in_state S WHERE X ref "ARCT01", S name "ben non"')
+ self.commit()
+ aff.clear_related_cache('wf_info_for', role='object')
+ trinfo = aff.latest_trinfo()
+ self.assertRaises(Unauthorized,
+ self.execute, 'SET TI from_state S WHERE TI eid %(ti)s, S name "ben non"',
+ {'ti': trinfo.eid}, 'ti')
+ self.assertRaises(Unauthorized,
+ self.execute, 'SET TI to_state S WHERE TI eid %(ti)s, S name "pitetre"',
+ {'ti': trinfo.eid}, 'ti')
+
if __name__ == '__main__':
unittest_main()
--- a/sobjects/hooks.py Thu Jul 16 12:57:17 2009 -0700
+++ b/sobjects/hooks.py Tue Jul 28 21:27:52 2009 +0200
@@ -7,11 +7,32 @@
"""
__docformat__ = "restructuredtext en"
+from datetime import datetime
+
+from cubicweb import RepositoryError
from cubicweb.common.uilib import soup2xhtml
from cubicweb.server.hooksmanager import Hook
from cubicweb.server.pool import PreCommitOperation
+class SetModificationDateOnStateChange(Hook):
+ """update entity's modification date after changing its state"""
+ events = ('after_add_relation',)
+ accepts = ('in_state',)
+
+ def call(self, session, fromeid, rtype, toeid):
+ if fromeid in session.transaction_data.get('neweids', ()):
+ # new entity, not needed
+ return
+ entity = session.entity_from_eid(fromeid)
+ try:
+ entity.set_attributes(modification_date=datetime.now())
+ except RepositoryError, ex:
+ # usually occurs if entity is coming from a read-only source
+ # (eg ldap user)
+ self.warning('cant change modification date for %s: %s', entity, ex)
+
+
class AddUpdateCWUserHook(Hook):
"""ensure user logins are stripped"""
events = ('before_add_entity', 'before_update_entity',)
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/spa2rql.py Tue Jul 28 21:27:52 2009 +0200
@@ -0,0 +1,207 @@
+"""SPARQL -> RQL translator
+
+:organization: Logilab
+:copyright: 2009 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2.
+:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr
+:license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses
+"""
+from logilab.common import make_domains
+from rql import TypeResolverException
+from fyzz.yappsparser import parse
+from fyzz import ast
+
+from cubicweb.xy import xy
+
+
+class UnsupportedQuery(Exception): pass
+
+def order_limit_offset(sparqlst):
+ addons = ''
+ if sparqlst.orderby:
+ sortterms = ', '.join('%s %s' % (var.name.upper(), ascdesc.upper())
+ for var, ascdesc in sparqlst.orderby)
+ addons += ' ORDERBY %s' % sortterms
+ if sparqlst.limit:
+ addons += ' LIMIT %s' % sparqlst.limit
+ if sparqlst.offset:
+ addons += ' OFFSET %s' % sparqlst.offset
+ return addons
+
+
+class QueryInfo(object):
+ """wrapper class containing necessary information to generate a RQL query
+ from a sparql syntax tree
+ """
+ def __init__(self, sparqlst):
+ self.sparqlst = sparqlst
+ if sparqlst.selected == ['*']:
+ self.selection = [var.upper() for var in sparqlst.variables]
+ else:
+ self.selection = [var.name.upper() for var in sparqlst.selected]
+ self.possible_types = {}
+ self.infer_types_info = []
+ self.union_params = []
+ self.restrictions = []
+ self.literals = {}
+ self._litcount = 0
+
+ def add_literal(self, value):
+ key = chr(ord('a') + self._litcount)
+ self._litcount += 1
+ self.literals[key] = value
+ return key
+
+ def set_possible_types(self, var, varpossibletypes):
+ """set/restrict possible types for the given variable.
+
+ :return: True if something changed, else false.
+ :raise: TypeResolverException if no more type allowed
+ """
+ varpossibletypes = set(varpossibletypes)
+ try:
+ ctypes = self.possible_types[var]
+ nbctypes = len(ctypes)
+ ctypes &= varpossibletypes
+ if not ctypes:
+ raise TypeResolverException()
+ return len(ctypes) != nbctypes
+ except KeyError:
+ self.possible_types[var] = varpossibletypes
+ return True
+
+ def infer_types(self):
+ # XXX should use something similar to rql.analyze for proper type inference
+ modified = True
+ # loop to infer types until nothing changed
+ while modified:
+ modified = False
+ for yams_predicates, subjvar, obj in self.infer_types_info:
+ nbchoices = len(yams_predicates)
+ # get possible types for the subject variable, according to the
+ # current predicate
+ svptypes = set(s for s, r, o in yams_predicates)
+ if not '*' in svptypes:
+ if self.set_possible_types(subjvar, svptypes):
+ modified = True
+ # restrict predicates according to allowed subject var types
+ if subjvar in self.possible_types:
+ yams_predicates = [(s, r, o) for s, r, o in yams_predicates
+ if s == '*' or s in self.possible_types[subjvar]]
+ if isinstance(obj, ast.SparqlVar):
+ # make a valid rql var name
+ objvar = obj.name.upper()
+ # get possible types for the object variable, according to
+ # the current predicate
+ ovptypes = set(o for s, r, o in yams_predicates)
+ if not '*' in ovptypes:
+ if self.set_possible_types(objvar, ovptypes):
+ modified = True
+ # restrict predicates according to allowed object var types
+ if objvar in self.possible_types:
+ yams_predicates = [(s, r, o) for s, r, o in yams_predicates
+ if o == '*' or o in self.possible_types[objvar]]
+ # ensure this still make sense
+ if not yams_predicates:
+ raise TypeResolverException()
+ if len(yams_predicates) != nbchoices:
+ modified = True
+
+ def build_restrictions(self):
+ # now, for each predicate
+ for yams_predicates, subjvar, obj in self.infer_types_info:
+ rel = yams_predicates[0]
+ # if there are several yams relation type equivalences, we will have
+ # to generate several unioned rql queries
+ for s, r, o in yams_predicates[1:]:
+ if r != rel[1]:
+ self.union_params.append((yams_predicates, subjvar, obj))
+ break
+ # else we can simply add it to base rql restrictions
+ else:
+ restr = self.build_restriction(subjvar, rel[1], obj)
+ self.restrictions.append(restr)
+
+ def build_restriction(self, subjvar, rtype, obj):
+ if isinstance(obj, ast.SparqlLiteral):
+ key = self.add_literal(obj.value)
+ objvar = '%%(%s)s' % key
+ else:
+ assert isinstance(obj, ast.SparqlVar)
+ # make a valid rql var name
+ objvar = obj.name.upper()
+ # else we can simply add it to base rql restrictions
+ return '%s %s %s' % (subjvar, rtype, objvar)
+
+ def finalize(self):
+ """return corresponding rql query (string) / args (dict)"""
+ for varname, ptypes in self.possible_types.iteritems():
+ if len(ptypes) == 1:
+ self.restrictions.append('%s is %s' % (varname, iter(ptypes).next()))
+ unions = []
+ for releq, subjvar, obj in self.union_params:
+ thisunions = []
+ for st, rt, ot in releq:
+ thisunions.append([self.build_restriction(subjvar, rt, obj)])
+ if st != '*':
+ thisunions[-1].append('%s is %s' % (subjvar, st))
+ if isinstance(obj, ast.SparqlVar) and ot != '*':
+ objvar = obj.name.upper()
+ thisunions[-1].append('%s is %s' % (objvar, objvar))
+ if not unions:
+ unions = thisunions
+ else:
+ unions = zip(*make_domains([unions, thisunions]))
+ selection = 'Any ' + ', '.join(self.selection)
+ sparqlst = self.sparqlst
+ if sparqlst.distinct:
+ selection = 'DISTINCT ' + selection
+ if unions:
+ baserql = '%s WHERE %s' % (selection, ', '.join(self.restrictions))
+ rqls = ['(%s, %s)' % (baserql, ', '.join(unionrestrs))
+ for unionrestrs in unions]
+ rql = ' UNION '.join(rqls)
+ if sparqlst.orderby or sparqlst.limit or sparqlst.offset:
+ rql = '%s%s WITH %s BEING (%s)' % (
+ selection, order_limit_offset(sparqlst),
+ ', '.join(self.selection), rql)
+ else:
+ rql = '%s%s WHERE %s' % (selection, order_limit_offset(sparqlst),
+ ', '.join(self.restrictions))
+ return rql, self.literals
+
+
+class Sparql2rqlTranslator(object):
+ def __init__(self, yschema):
+ self.yschema = yschema
+
+ def translate(self, sparql):
+ sparqlst = parse(sparql)
+ if sparqlst.type != 'select':
+ raise UnsupportedQuery()
+ qi = QueryInfo(sparqlst)
+ for subj, predicate, obj in sparqlst.where:
+ if not isinstance(subj, ast.SparqlVar):
+ raise UnsupportedQuery()
+ # make a valid rql var name
+ subjvar = subj.name.upper()
+ if predicate == ('', 'a'):
+ # special 'is' relation
+ if not isinstance(obj, tuple):
+ raise UnsupportedQuery()
+ # restrict possible types for the subject variable
+ qi.set_possible_types(
+ subjvar, xy.yeq(':'.join(obj), isentity=True))
+ else:
+ # 'regular' relation (eg not 'is')
+ if not isinstance(predicate, tuple):
+ raise UnsupportedQuery()
+ # list of 3-uple
+ # (yams etype (subject), yams rtype, yams etype (object))
+ # where subject / object entity type may '*' if not specified
+ yams_predicates = xy.yeq(':'.join(predicate))
+ qi.infer_types_info.append((yams_predicates, subjvar, obj))
+ if not isinstance(obj, (ast.SparqlLiteral, ast.SparqlVar)):
+ raise UnsupportedQuery()
+ qi.infer_types()
+ qi.build_restrictions()
+ return qi
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/stdlib.txt Tue Jul 28 21:27:52 2009 +0200
@@ -0,0 +1,18 @@
+addressbook
+basket
+blog
+book
+calendar
+comment
+company
+email
+file
+folder
+i18ncontent
+keyword
+link
+mailinglist
+person
+tag
+timeseries
+vcsfile
--- a/test/unittest_cwconfig.py Thu Jul 16 12:57:17 2009 -0700
+++ b/test/unittest_cwconfig.py Tue Jul 28 21:27:52 2009 +0200
@@ -8,7 +8,6 @@
import sys
import os
from os.path import dirname, join, abspath
-from tempfile import mktemp
from logilab.common.testlib import TestCase, unittest_main
from logilab.common.changelog import Version
--- a/test/unittest_cwctl.py Thu Jul 16 12:57:17 2009 -0700
+++ b/test/unittest_cwctl.py Tue Jul 28 21:27:52 2009 +0200
@@ -13,9 +13,9 @@
if os.environ.get('APYCOT_ROOT'):
root = os.environ['APYCOT_ROOT']
CUBES_DIR = '%s/local/share/cubicweb/cubes/' % root
- os.environ['CW_CUBES'] = CUBES_DIR
+ os.environ['CW_CUBES_PATH'] = CUBES_DIR
REGISTRY_DIR = '%s/etc/cubicweb.d/' % root
- os.environ['CW_REGISTRY_DIR'] = REGISTRY_DIR
+ os.environ['CW_INSTANCES_DIR'] = REGISTRY_DIR
from cubicweb.cwconfig import CubicWebConfiguration
CubicWebConfiguration.load_cwctl_plugins()
--- a/test/unittest_schema.py Thu Jul 16 12:57:17 2009 -0700
+++ b/test/unittest_schema.py Tue Jul 28 21:27:52 2009 +0200
@@ -150,7 +150,7 @@
'CWCache', 'CWConstraint', 'CWConstraintType', 'CWEType',
'CWAttribute', 'CWGroup', 'EmailAddress', 'CWRelation',
'CWPermission', 'CWProperty', 'CWRType', 'CWUser',
- 'File', 'Float', 'Image', 'Int', 'Interval', 'Note',
+ 'ExternalUri', 'File', 'Float', 'Image', 'Int', 'Interval', 'Note',
'Password', 'Personne',
'RQLExpression',
'Societe', 'State', 'String', 'SubNote', 'Tag', 'Time',
@@ -163,7 +163,7 @@
'cardinality', 'comment', 'comment_format',
'composite', 'condition', 'connait', 'constrained_by', 'content',
- 'content_format', 'created_by', 'creation_date', 'cstrtype',
+ 'content_format', 'created_by', 'creation_date', 'cstrtype', 'cwuri',
'data', 'data_encoding', 'data_format', 'defaultval', 'delete_permission',
'description', 'description_format', 'destination_state',
@@ -179,7 +179,7 @@
'label', 'last_login_time', 'login',
- 'mainvars', 'meta', 'modification_date',
+ 'mainvars', 'modification_date',
'name', 'nom',
@@ -193,7 +193,7 @@
'tags', 'timestamp', 'title', 'to_entity', 'to_state', 'transition_of', 'travaille', 'type',
- 'upassword', 'update_permission', 'use_email',
+ 'upassword', 'update_permission', 'uri', 'use_email',
'value',
@@ -203,7 +203,7 @@
eschema = schema.eschema('CWUser')
rels = sorted(str(r) for r in eschema.subject_relations())
- self.assertListEquals(rels, ['created_by', 'creation_date', 'eid',
+ self.assertListEquals(rels, ['created_by', 'creation_date', 'cwuri', 'eid',
'evaluee', 'firstname', 'has_text', 'identity',
'in_group', 'in_state', 'is',
'is_instance_of', 'last_login_time',
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test/unittest_spa2rql.py Tue Jul 28 21:27:52 2009 +0200
@@ -0,0 +1,180 @@
+from logilab.common.testlib import TestCase, unittest_main
+from cubicweb.devtools import TestServerConfiguration
+from cubicweb.xy import xy
+from cubicweb.spa2rql import Sparql2rqlTranslator
+
+xy.add_equivalence('Project', 'doap:Project')
+xy.add_equivalence('Project creation_date', 'doap:Project doap:created')
+xy.add_equivalence('Project name', 'doap:Project doap:name')
+
+
+config = TestServerConfiguration('data')
+config.bootstrap_cubes()
+schema = config.load_schema()
+
+
+class XYTC(TestCase):
+ def setUp(self):
+ self.tr = Sparql2rqlTranslator(schema)
+
+ def _test(self, sparql, rql, args={}):
+ qi = self.tr.translate(sparql)
+ self.assertEquals(qi.finalize(), (rql, args))
+
+ def XXX_test_base_01(self):
+ self._test('SELECT * WHERE { }', 'Any X')
+
+
+ def test_base_is(self):
+ self._test('''
+ PREFIX doap: <http://usefulinc.com/ns/doap#>
+ SELECT ?project
+ WHERE {
+ ?project a doap:Project;
+ }''', 'Any PROJECT WHERE PROJECT is Project')
+
+
+ def test_base_attr_sel(self):
+ self._test('''
+ PREFIX doap: <http://usefulinc.com/ns/doap#>
+ SELECT ?created
+ WHERE {
+ ?project a doap:Project;
+ doap:created ?created.
+ }''', 'Any CREATED WHERE PROJECT creation_date CREATED, PROJECT is Project')
+
+
+ def test_base_attr_sel_distinct(self):
+ self._test('''
+ PREFIX doap: <http://usefulinc.com/ns/doap#>
+ SELECT DISTINCT ?name
+ WHERE {
+ ?project a doap:Project;
+ doap:name ?name.
+ }''', 'DISTINCT Any NAME WHERE PROJECT name NAME, PROJECT is Project')
+
+
+ def test_base_attr_sel_reduced(self):
+ self._test('''
+ PREFIX doap: <http://usefulinc.com/ns/doap#>
+ SELECT REDUCED ?name
+ WHERE {
+ ?project a doap:Project;
+ doap:name ?name.
+ }''', 'Any NAME WHERE PROJECT name NAME, PROJECT is Project')
+
+
+ def test_base_attr_sel_limit_offset(self):
+ self._test('''
+ PREFIX doap: <http://usefulinc.com/ns/doap#>
+ SELECT ?name
+ WHERE {
+ ?project a doap:Project;
+ doap:name ?name.
+ }
+ LIMIT 20''', 'Any NAME LIMIT 20 WHERE PROJECT name NAME, PROJECT is Project')
+ self._test('''
+ PREFIX doap: <http://usefulinc.com/ns/doap#>
+ SELECT ?name
+ WHERE {
+ ?project a doap:Project;
+ doap:name ?name.
+ }
+ LIMIT 20 OFFSET 10''', 'Any NAME LIMIT 20 OFFSET 10 WHERE PROJECT name NAME, PROJECT is Project')
+
+
+ def test_base_attr_sel_orderby(self):
+ self._test('''
+ PREFIX doap: <http://usefulinc.com/ns/doap#>
+ SELECT ?name
+ WHERE {
+ ?project a doap:Project;
+ doap:name ?name;
+ doap:created ?created.
+ }
+ ORDER BY ?name DESC(?created)''', 'Any NAME ORDERBY NAME ASC, CREATED DESC WHERE PROJECT name NAME, PROJECT creation_date CREATED, PROJECT is Project')
+
+
+ def test_base_any_attr_sel(self):
+ self._test('''
+ PREFIX dc: <http://purl.org/dc/elements/1.1/>
+ SELECT ?x ?cd
+ WHERE {
+ ?x dc:date ?cd;
+ }''', 'Any X, CD WHERE X creation_date CD')
+
+
+ def test_base_any_attr_sel_amb(self):
+ xy.add_equivalence('Version publication_date', 'doap:Version dc:date')
+ try:
+ self._test('''
+ PREFIX dc: <http://purl.org/dc/elements/1.1/>
+ SELECT ?x ?cd
+ WHERE {
+ ?x dc:date ?cd;
+ }''', '(Any X, CD WHERE , X creation_date CD) UNION (Any X, CD WHERE , X publication_date CD, X is Version)')
+ finally:
+ xy.remove_equivalence('Version publication_date', 'doap:Version dc:date')
+
+
+ def test_base_any_attr_sel_amb_limit_offset(self):
+ xy.add_equivalence('Version publication_date', 'doap:Version dc:date')
+ try:
+ self._test('''
+ PREFIX dc: <http://purl.org/dc/elements/1.1/>
+ SELECT ?x ?cd
+ WHERE {
+ ?x dc:date ?cd;
+ }
+ LIMIT 20 OFFSET 10''', 'Any X, CD LIMIT 20 OFFSET 10 WITH X, CD BEING ((Any X, CD WHERE , X creation_date CD) UNION (Any X, CD WHERE , X publication_date CD, X is Version))')
+ finally:
+ xy.remove_equivalence('Version publication_date', 'doap:Version dc:date')
+
+
+ def test_base_any_attr_sel_amb_orderby(self):
+ xy.add_equivalence('Version publication_date', 'doap:Version dc:date')
+ try:
+ self._test('''
+ PREFIX dc: <http://purl.org/dc/elements/1.1/>
+ SELECT ?x ?cd
+ WHERE {
+ ?x dc:date ?cd;
+ }
+ ORDER BY DESC(?cd)''', 'Any X, CD ORDERBY CD DESC WITH X, CD BEING ((Any X, CD WHERE , X creation_date CD) UNION (Any X, CD WHERE , X publication_date CD, X is Version))')
+ finally:
+ xy.remove_equivalence('Version publication_date', 'doap:Version dc:date')
+
+
+ def test_restr_attr(self):
+ self._test('''
+ PREFIX doap: <http://usefulinc.com/ns/doap#>
+ SELECT ?project
+ WHERE {
+ ?project a doap:Project;
+ doap:name "cubicweb".
+ }''', 'Any PROJECT WHERE PROJECT name %(a)s, PROJECT is Project', {'a': 'cubicweb'})
+
+# # Two elements in the group
+# PREFIX : <http://example.org/ns#>
+# SELECT *
+# { :p :q :r OPTIONAL { :a :b :c }
+# :p :q :r OPTIONAL { :a :b :c }
+# }
+
+# PREFIX : <http://example.org/ns#>
+# SELECT *
+# {
+# { ?s ?p ?o } UNION { ?a ?b ?c }
+# }
+
+# PREFIX dob: <http://placetime.com/interval/gregorian/1977-01-18T04:00:00Z/P>
+# PREFIX time: <http://www.ai.sri.com/daml/ontologies/time/Time.daml#>
+# PREFIX dc: <http://purl.org/dc/elements/1.1/>
+# SELECT ?desc
+# WHERE {
+# dob:1D a time:ProperInterval;
+# dc:description ?desc.
+# }
+
+if __name__ == '__main__':
+ unittest_main()
--- a/toolsutils.py Thu Jul 16 12:57:17 2009 -0700
+++ b/toolsutils.py Tue Jul 28 21:27:52 2009 +0200
@@ -7,6 +7,8 @@
"""
__docformat__ = "restructuredtext en"
+# XXX move most of this in logilab.common (shellutils ?)
+
import os, sys
from os import listdir, makedirs, symlink, environ, chmod, walk, remove
from os.path import exists, join, abspath, normpath
@@ -14,6 +16,7 @@
from logilab.common.clcommands import Command as BaseCommand, \
main_run as base_main_run
from logilab.common.compat import any
+from logilab.common.shellutils import confirm
from cubicweb import warning
from cubicweb import ConfigurationError, ExecutionError
@@ -34,12 +37,12 @@
"""create a directory if it doesn't exist yet"""
try:
makedirs(directory)
- print 'created directory', directory
+ print '-> created directory %s.' % directory
except OSError, ex:
import errno
if ex.errno != errno.EEXIST:
raise
- print 'directory %s already exists' % directory
+ print '-> directory %s already exists, no need to create it.' % directory
def create_symlink(source, target):
"""create a symbolic link"""
@@ -56,7 +59,7 @@
def rm(whatever):
import shutil
shutil.rmtree(whatever)
- print 'removed %s' % whatever
+ print '-> removed %s' % whatever
def show_diffs(appl_file, ref_file, askconfirm=True):
"""interactivly replace the old file with the new file according to
@@ -133,26 +136,11 @@
if log:
log('set %s permissions to 0600', filepath)
else:
- print 'set %s permissions to 0600' % filepath
+ print '-> set %s permissions to 0600' % filepath
chmod(filepath, 0600)
-def confirm(question, default_is_yes=True):
- """ask for confirmation and return true on positive answer"""
- if default_is_yes:
- input_str = '%s [Y/n]: '
- else:
- input_str = '%s [y/N]: '
- answer = raw_input(input_str % (question)).strip().lower()
- if default_is_yes:
- if answer in ('n', 'no'):
- return False
- return True
- if answer in ('y', 'yes'):
- return True
- return False
-
def read_config(config_file):
- """read the application configuration from a file and return it as a
+ """read the instance configuration from a file and return it as a
dictionnary
:type config_file: str
@@ -289,5 +277,5 @@
password = optconfig.password
if not password:
password = getpass('password: ')
- return connect(user=user, password=password, host=optconfig.host, database=appid)
+ return connect(login=user, password=password, host=optconfig.host, database=appid)
--- a/view.py Thu Jul 16 12:57:17 2009 -0700
+++ b/view.py Tue Jul 28 21:27:52 2009 +0200
@@ -195,10 +195,27 @@
necessary for non linkable views, but a default implementation
is provided anyway.
"""
- try:
- return self.build_url(vid=self.id, rql=self.req.form['rql'])
- except KeyError:
- return self.build_url(vid=self.id)
+ rset = self.rset
+ if rset is None:
+ return self.build_url('view', vid=self.id)
+ coltypes = rset.column_types(0)
+ if len(coltypes) == 1:
+ etype = iter(coltypes).next()
+ if not self.schema.eschema(etype).is_final():
+ if len(rset) == 1:
+ entity = rset.get_entity(0, 0)
+ return entity.absolute_url(vid=self.id)
+ # don't want to generate /<etype> url if there is some restriction
+ # on something else than the entity type
+ restr = rset.syntax_tree().children[0].where
+ # XXX norestriction is not correct here. For instance, in cases like
+ # "Any P,N WHERE P is Project, P name N" norestriction should equal
+ # True
+ norestriction = (isinstance(restr, nodes.Relation) and
+ restr.is_types_restriction())
+ if norestriction:
+ return self.build_url(etype.lower(), vid=self.id)
+ return self.build_url('view', rql=rset.printable_rql(), vid=self.id)
def set_request_content_type(self):
"""set the content type returned by this view"""
@@ -313,10 +330,6 @@
category = 'startupview'
- def url(self):
- """return the url associated with this view. We can omit rql here"""
- return self.build_url('view', vid=self.id)
-
def html_headers(self):
"""return a list of html headers (eg something to be inserted between
<head> and </head> of the returned page
@@ -334,7 +347,7 @@
default_rql = None
- def __init__(self, req, rset, **kwargs):
+ def __init__(self, req, rset=None, **kwargs):
super(EntityStartupView, self).__init__(req, rset, **kwargs)
if rset is None:
# this instance is not in the "entityview" category
@@ -354,14 +367,6 @@
for i in xrange(len(rset)):
self.wview(self.id, rset, row=i, **kwargs)
- def url(self):
- """return the url associated with this view. We can omit rql if we are
- on a result set on which we do not apply.
- """
- if self.rset is None:
- return self.build_url(vid=self.id)
- return super(EntityStartupView, self).url()
-
class AnyRsetView(View):
"""base class for views applying on any non empty result sets"""
--- a/vregistry.py Thu Jul 16 12:57:17 2009 -0700
+++ b/vregistry.py Tue Jul 28 21:27:52 2009 +0200
@@ -356,7 +356,7 @@
sys.path.remove(webdir)
if CW_SOFTWARE_ROOT in sys.path:
sys.path.remove(CW_SOFTWARE_ROOT)
- # load views from each directory in the application's path
+ # load views from each directory in the instance's path
filemods = self.init_registration(path, extrapath)
change = False
for filepath, modname in filemods:
--- a/web/application.py Thu Jul 16 12:57:17 2009 -0700
+++ b/web/application.py Tue Jul 28 21:27:52 2009 +0200
@@ -201,7 +201,7 @@
raise Redirect(req.build_url(path, **args))
def logout(self, req):
- """logout from the application by cleaning the session and raising
+ """logout from the instance by cleaning the session and raising
`AuthenticationError`
"""
self.session_manager.close_session(req.cnx)
@@ -218,11 +218,11 @@
session_handler_fact=CookieSessionHandler,
vreg=None):
super(CubicWebPublisher, self).__init__()
- # connect to the repository and get application's schema
+ # connect to the repository and get instance's schema
if vreg is None:
vreg = cwvreg.CubicWebRegistry(config, debug=debug)
self.vreg = vreg
- self.info('starting web application from %s', config.apphome)
+ self.info('starting web instance from %s', config.apphome)
self.repo = config.repository(vreg)
if not vreg.initialized:
self.config.init_cubes(self.repo.get_cubes())
Binary file web/data/accessories-text-editor.png has changed
--- a/web/data/cubicweb.compat.js Thu Jul 16 12:57:17 2009 -0700
+++ b/web/data/cubicweb.compat.js Tue Jul 28 21:27:52 2009 +0200
@@ -247,9 +247,10 @@
if ('name' in params){
try {
var node = document.createElement('<iframe name="'+params['name']+'">');
- }catch (ex) {
- var node = document.createElement('iframe');
- }
+ } catch (ex) {
+ var node = document.createElement('iframe');
+ node.id = node.name = params.name;
+ }
}
else{
var node = document.createElement('iframe');
--- a/web/data/cubicweb.edition.js Thu Jul 16 12:57:17 2009 -0700
+++ b/web/data/cubicweb.edition.js Tue Jul 28 21:27:52 2009 +0200
@@ -453,6 +453,8 @@
* @param rtype : the attribute being edited
* @param eid : the eid of the entity being edited
* @param reload: boolean to reload page if true (when changing URL dependant data)
+ * @param default_value : value if the field is empty
+ * @param lzone : html fragment (string) for a clic-zone triggering actual edition
*/
function inlineValidateAttributeForm(rtype, eid, divid, reload, default_value) {
try {
@@ -475,9 +477,9 @@
d.addCallback(function (result, req) {
handleFormValidationResponse(divid+'-form', noop, noop, result);
if (reload) {
- document.location.href = result[1];
+ document.location.href = result[1].split('?')[0];
} else {
- var fieldview = getNode(divid);
+ var fieldview = getNode('value-' + divid);
// XXX using innerHTML is very fragile and won't work if
// we mix XHTML and HTML
fieldview.innerHTML = result[2];
@@ -512,8 +514,9 @@
document.location.href = result[1];
} else {
if (result[0]) {
- var d = asyncRemoteExec('reledit_form', eid, rtype, role, lzone);
+ var d = asyncRemoteExec('reledit_form', eid, rtype, role, default_value, lzone);
d.addCallback(function (result) {
+ // XXX brittle ... replace with loadxhtml
jQuery('#'+divid+'-reledit').replaceWith(result);
});
}
--- a/web/data/cubicweb.widgets.js Thu Jul 16 12:57:17 2009 -0700
+++ b/web/data/cubicweb.widgets.js Tue Jul 28 21:27:52 2009 +0200
@@ -184,8 +184,7 @@
Widgets.TreeView = defclass("TreeView", null, {
__init__: function(wdgnode) {
jQuery(wdgnode).treeview({toggle: toggleTree,
- prerendered: true
- });
+ prerendered: true});
}
});
--- a/web/data/external_resources Thu Jul 16 12:57:17 2009 -0700
+++ b/web/data/external_resources Tue Jul 28 21:27:52 2009 +0200
@@ -18,7 +18,7 @@
#IE_STYLESHEETS = DATADIR/cubicweb.ie.css
# Javascripts files to include in HTML headers
-#JAVASCRIPTS = DATADIR/jqyery.js, DATADIR/cubicweb.python.js, DATADIR/jquery.json.js, DATADIR/cubicweb.compat.js, DATADIR/cubicweb.htmlhelpers.js
+#JAVASCRIPTS = DATADIR/jquery.js, DATADIR/cubicweb.python.js, DATADIR/jquery.json.js, DATADIR/cubicweb.compat.js, DATADIR/cubicweb.htmlhelpers.js
# path to favicon (relative to the application main script, seen as a
# directory, hence .. when you are not using an absolute path)
--- a/web/data/goa.js Thu Jul 16 12:57:17 2009 -0700
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,10 +0,0 @@
-/*
- * functions specific to ginco on google appengine
- *
- * :organization: Logilab
- * :copyright: 2008 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
- * :contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr
- */
-
-/* overrides rql_for_eid function from htmlhelpers.hs */
-function rql_for_eid(eid) { return 'Any X WHERE X eid "' + eid + '"'; }
--- a/web/formfields.py Thu Jul 16 12:57:17 2009 -0700
+++ b/web/formfields.py Tue Jul 28 21:27:52 2009 +0200
@@ -11,9 +11,9 @@
from datetime import datetime
from logilab.mtconverter import xml_escape
-from yams.constraints import SizeConstraint, StaticVocabularyConstraint
+from yams.constraints import (SizeConstraint, StaticVocabularyConstraint,
+ FormatConstraint)
-from cubicweb.schema import FormatConstraint
from cubicweb.utils import ustrftime, compute_cardinality
from cubicweb.common import tags, uilib
from cubicweb.web import INTERNAL_FIELD_VALUE
@@ -63,6 +63,8 @@
:role:
when the field is linked to an entity attribute or relation, tells the
role of the entity in the relation (eg 'subject' or 'object')
+ :fieldset:
+ optional fieldset to which this field belongs to
"""
# default widget associated to this class of fields. May be overriden per
@@ -76,7 +78,7 @@
def __init__(self, name=None, id=None, label=None, help=None,
widget=None, required=False, initial=None,
choices=None, sort=True, internationalizable=False,
- eidparam=False, role='subject'):
+ eidparam=False, role='subject', fieldset=None):
self.name = name
self.id = id or name
self.label = label or name
@@ -88,6 +90,7 @@
self.internationalizable = internationalizable
self.eidparam = eidparam
self.role = role
+ self.fieldset = fieldset
self.init_widget(widget)
# ordering number for this field instance
self.creation_rank = Field.__creation_rank
@@ -158,7 +161,13 @@
"""render this field, which is part of form, using the given form
renderer
"""
- return self.get_widget(form).render(form, self)
+ widget = self.get_widget(form)
+ try:
+ return widget.render(form, self, renderer)
+ except TypeError:
+ warn('widget.render now take the renderer as third argument, please update %s implementation'
+ % widget.__class__.__name__, DeprecationWarning)
+ return widget.render(form, self)
def vocabulary(self, form):
"""return vocabulary for this field. This method will be called by
@@ -287,7 +296,7 @@
result = format_field.render(form, renderer)
else:
result = u''
- return result + self.get_widget(form).render(form, self)
+ return result + self.get_widget(form).render(form, self, renderer)
class FileField(StringField):
@@ -307,7 +316,7 @@
yield self.encoding_field
def render(self, form, renderer):
- wdgs = [self.get_widget(form).render(form, self)]
+ wdgs = [self.get_widget(form).render(form, self, renderer)]
if self.format_field or self.encoding_field:
divid = '%s-advanced' % form.context[self]['name']
wdgs.append(u'<a href="%s" title="%s"><img src="%s" alt="%s"/></a>' %
@@ -361,7 +370,7 @@
'You can either submit a new file using the browse button above'
', or edit file content online with the widget below.')
wdgs.append(u'<p><b>%s</b></p>' % msg)
- wdgs.append(TextArea(setdomid=False).render(form, self))
+ wdgs.append(TextArea(setdomid=False).render(form, self, renderer))
# XXX restore form context?
return '\n'.join(wdgs)
@@ -464,6 +473,15 @@
return value
+class CompoundField(Field):
+ def __init__(self, fields, *args, **kwargs):
+ super(CompoundField, self).__init__(*args, **kwargs)
+ self.fields = fields
+
+ def actual_fields(self, form):
+ return [self] + list(self.fields)
+
+
def guess_field(eschema, rschema, role='subject', skip_meta_attr=True, **kwargs):
"""return the most adapated widget to edit the relation
'subjschema rschema objschema' according to information found in the schema
--- a/web/formwidgets.py Thu Jul 16 12:57:17 2009 -0700
+++ b/web/formwidgets.py Tue Jul 28 21:27:52 2009 +0200
@@ -10,7 +10,7 @@
from datetime import date
from warnings import warn
-from cubicweb.common import tags
+from cubicweb.common import tags, uilib
from cubicweb.web import stdmsgs, INTERNAL_FIELD_VALUE
@@ -43,7 +43,7 @@
if self.needs_css:
form.req.add_css(self.needs_css)
- def render(self, form, field):
+ def render(self, form, field, renderer):
"""render the widget for the given `field` of `form`.
To override in concrete class
"""
@@ -68,7 +68,7 @@
"""abstract widget class for <input> tag based widgets"""
type = None
- def render(self, form, field):
+ def render(self, form, field, renderer):
"""render the widget for the given `field` of `form`.
Generate one <input> tag for each field's value
@@ -96,7 +96,7 @@
"""
type = 'password'
- def render(self, form, field):
+ def render(self, form, field, renderer):
self.add_media(form)
name, values, attrs = self._render_attrs(form, field)
assert len(values) == 1
@@ -105,9 +105,11 @@
confirmname = '%s-confirm:%s' % tuple(name.rsplit(':', 1))
except TypeError:
confirmname = '%s-confirm' % name
- inputs = [tags.input(name=name, value=values[0], type=self.type, id=id, **attrs),
+ inputs = [tags.input(name=name, value=values[0], type=self.type, id=id,
+ **attrs),
'<br/>',
- tags.input(name=confirmname, value=values[0], type=self.type, **attrs),
+ tags.input(name=confirmname, value=values[0], type=self.type,
+ **attrs),
' ', tags.span(form.req._('confirm password'),
**{'class': 'emphasis'})]
return u'\n'.join(inputs)
@@ -147,7 +149,7 @@
class TextArea(FieldWidget):
"""<textarea>"""
- def render(self, form, field):
+ def render(self, form, field, renderer):
name, values, attrs = self._render_attrs(form, field)
attrs.setdefault('onkeyup', 'autogrow(this)')
if not values:
@@ -171,9 +173,9 @@
super(FCKEditor, self).__init__(*args, **kwargs)
self.attrs['cubicweb:type'] = 'wysiwyg'
- def render(self, form, field):
+ def render(self, form, field, renderer):
form.req.fckeditor_config()
- return super(FCKEditor, self).render(form, field)
+ return super(FCKEditor, self).render(form, field, renderer)
class Select(FieldWidget):
@@ -184,23 +186,30 @@
super(Select, self).__init__(attrs)
self._multiple = multiple
- def render(self, form, field):
+ def render(self, form, field, renderer):
name, curvalues, attrs = self._render_attrs(form, field)
if not 'size' in attrs:
attrs['size'] = self._multiple and '5' or '1'
options = []
optgroup_opened = False
- for label, value in field.vocabulary(form):
+ for option in field.vocabulary(form):
+ try:
+ label, value, oattrs = option
+ except ValueError:
+ label, value = option
+ oattrs = {}
if value is None:
# handle separator
if optgroup_opened:
options.append(u'</optgroup>')
- options.append(u'<optgroup label="%s">' % (label or ''))
+ oattrs.setdefault('label', label or '')
+ options.append(u'<optgroup %s>' % uilib.sgml_attributes(oattrs))
optgroup_opened = True
elif value in curvalues:
- options.append(tags.option(label, value=value, selected='selected'))
+ options.append(tags.option(label, value=value,
+ selected='selected', **oattrs))
else:
- options.append(tags.option(label, value=value))
+ options.append(tags.option(label, value=value, **oattrs))
if optgroup_opened:
options.append(u'</optgroup>')
return tags.select(name=name, multiple=self._multiple,
@@ -214,20 +223,26 @@
type = 'checkbox'
vocabulary_widget = True
- def render(self, form, field):
+ def render(self, form, field, renderer):
name, curvalues, attrs = self._render_attrs(form, field)
domid = attrs.pop('id', None)
- sep = attrs.pop('separator', u'<br/>')
+ sep = attrs.pop('separator', u'<br/>\n')
options = []
- for i, (label, value) in enumerate(field.vocabulary(form)):
+ for i, option in enumerate(field.vocabulary(form)):
+ try:
+ label, value, oattrs = option
+ except ValueError:
+ label, value = option
+ oattrs = {}
iattrs = attrs.copy()
+ iattrs.update(oattrs)
if i == 0 and domid is not None:
- iattrs['id'] = domid
+ iattrs.setdefault('id', domid)
if value in curvalues:
iattrs['checked'] = u'checked'
tag = tags.input(name=name, type=self.type, value=value, **iattrs)
- options.append(tag + label + sep)
- return '\n'.join(options)
+ options.append(tag + label)
+ return sep.join(options)
class Radio(CheckBox):
@@ -237,6 +252,51 @@
type = 'radio'
+# compound widgets #############################################################
+
+class IntervalWidget(FieldWidget):
+ """custom widget to display an interval composed by 2 fields. This widget
+ is expected to be used with a CompoundField containing the two actual
+ fields.
+
+ Exemple usage::
+
+from uicfg import autoform_field, autoform_section
+autoform_field.tag_attribute(('Concert', 'minprice'),
+ CompoundField(fields=(IntField(name='minprice'),
+ IntField(name='maxprice')),
+ label=_('price'),
+ widget=IntervalWidget()
+ ))
+# we've to hide the other field manually for now
+autoform_section.tag_attribute(('Concert', 'maxprice'), 'generated')
+ """
+ def render(self, form, field, renderer):
+ actual_fields = field.fields
+ assert len(actual_fields) == 2
+ return u'<div>%s %s %s %s</div>' % (
+ form.req._('from_interval_start'),
+ actual_fields[0].render(form, renderer),
+ form.req._('to_interval_end'),
+ actual_fields[1].render(form, renderer),
+ )
+
+
+class HorizontalLayoutWidget(FieldWidget):
+ """custom widget to display a set of fields grouped together horizontally
+ in a form. See `IntervalWidget` for example usage.
+ """
+ def render(self, form, field, renderer):
+ if self.attrs.get('display_label', True):
+ subst = self.attrs.get('label_input_substitution', '%(label)s %(input)s')
+ fields = [subst % {'label': renderer.render_label(form, f),
+ 'input': f.render(form, renderer)}
+ for f in field.fields]
+ else:
+ fields = [f.render(form, renderer) for f in field.fields]
+ return u'<div>%s</div>' % ' '.join(fields)
+
+
# javascript widgets ###########################################################
class DateTimePicker(TextInput):
@@ -262,8 +322,8 @@
req.html_headers.define_var('MONTHNAMES', monthnames)
req.html_headers.define_var('DAYNAMES', daynames)
- def render(self, form, field):
- txtwidget = super(DateTimePicker, self).render(form, field)
+ def render(self, form, field, renderer):
+ txtwidget = super(DateTimePicker, self).render(form, field, renderer)
self.add_localized_infos(form.req)
cal_button = self._render_calendar_popup(form, field)
return txtwidget + cal_button
@@ -302,7 +362,7 @@
if inputid is not None:
self.attrs['cubicweb:inputid'] = inputid
- def render(self, form, field):
+ def render(self, form, field, renderer):
self.add_media(form)
attrs = self._render_attrs(form, field)[-1]
return tags.div(**attrs)
@@ -373,8 +433,8 @@
etype_from = entity.e_schema.subject_relation(self.name).objects(entity.e_schema)[0]
attrs['cubicweb:etype_from'] = etype_from
- def render(self, form, field):
- return super(AddComboBoxWidget, self).render(form, field) + u'''
+ def render(self, form, field, renderer):
+ return super(AddComboBoxWidget, self).render(form, field, renderer) + u'''
<div id="newvalue">
<input type="text" id="newopt" />
<a href="javascript:noop()" id="add_newopt"> </a></div>
@@ -400,7 +460,7 @@
self.cwaction = cwaction
self.attrs.setdefault('klass', 'validateButton')
- def render(self, form, field=None):
+ def render(self, form, field=None, renderer=None):
label = form.req._(self.label)
attrs = self.attrs.copy()
if self.cwaction:
@@ -443,7 +503,7 @@
self.imgressource = imgressource
self.label = label
- def render(self, form, field=None):
+ def render(self, form, field=None, renderer=None):
label = form.req._(self.label)
imgsrc = form.req.external_resource(self.imgressource)
return '<a id="%(domid)s" href="%(href)s">'\
--- a/web/request.py Thu Jul 16 12:57:17 2009 -0700
+++ b/web/request.py Tue Jul 28 21:27:52 2009 +0200
@@ -515,7 +515,7 @@
return self.base_url() + self.relative_path(includeparams)
def _datadir_url(self):
- """return url of the application's data directory"""
+ """return url of the instance's data directory"""
return self.base_url() + 'data%s/' % self.vreg.config.instance_md5_version()
def selected(self, url):
@@ -587,7 +587,7 @@
def relative_path(self, includeparams=True):
"""return the normalized path of the request (ie at least relative
- to the application's root, but some other normalization may be needed
+ to the instance's root, but some other normalization may be needed
so that the returned path may be used to compare to generated urls
:param includeparams:
--- a/web/test/data/schema/testschema.py Thu Jul 16 12:57:17 2009 -0700
+++ b/web/test/data/schema/testschema.py Tue Jul 28 21:27:52 2009 +0200
@@ -5,6 +5,11 @@
:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr
:license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses
"""
+
+from yams.buildobjs import (EntityType, RelationDefinition, RelationType, String,
+ Int, SubjectRelation)
+from yams.constraints import IntervalBoundConstraint
+
class Salesterm(EntityType):
described_by_test = SubjectRelation('File', cardinality='1*', composite='subject')
amount = Int(constraints=[IntervalBoundConstraint(0, 100)])
--- a/web/test/unittest_form.py Thu Jul 16 12:57:17 2009 -0700
+++ b/web/test/unittest_form.py Tue Jul 28 21:27:52 2009 +0200
@@ -161,7 +161,7 @@
def test_richtextfield_2(self):
self.req.use_fckeditor = lambda: True
- self._test_richtextfield('<input name="description_format:%(eid)s" style="display: block" type="hidden" value="text/rest"></input><textarea cols="80" cubicweb:type="wysiwyg" id="description:%(eid)s" name="description:%(eid)s" onkeyup="autogrow(this)" rows="2" tabindex="0"></textarea>')
+ self._test_richtextfield('<input name="description_format:%(eid)s" style="display: block" type="hidden" value="text/rest" /><textarea cols="80" cubicweb:type="wysiwyg" id="description:%(eid)s" name="description:%(eid)s" onkeyup="autogrow(this)" rows="2" tabindex="0"></textarea>')
def test_filefield(self):
@@ -172,14 +172,14 @@
data=Binary('new widgets system'))
form = FFForm(self.req, redirect_path='perdu.com', entity=file)
self.assertTextEquals(self._render_entity_field('data', form),
- '''<input id="data:%(eid)s" name="data:%(eid)s" tabindex="0" type="file" value=""></input>
+ '''<input id="data:%(eid)s" name="data:%(eid)s" tabindex="0" type="file" value="" />
<a href="javascript: toggleVisibility('data:%(eid)s-advanced')" title="show advanced fields"><img src="http://testing.fr/cubicweb/data/puce_down.png" alt="show advanced fields"/></a>
<div id="data:%(eid)s-advanced" class="hidden">
-<label for="data_format:%(eid)s">data_format</label><input id="data_format:%(eid)s" maxlength="50" name="data_format:%(eid)s" size="45" tabindex="1" type="text" value="text/plain"></input><br/>
-<label for="data_encoding:%(eid)s">data_encoding</label><input id="data_encoding:%(eid)s" maxlength="20" name="data_encoding:%(eid)s" size="20" tabindex="2" type="text" value="UTF-8"></input><br/>
+<label for="data_format:%(eid)s">data_format</label><input id="data_format:%(eid)s" maxlength="50" name="data_format:%(eid)s" size="45" tabindex="1" type="text" value="text/plain" /><br/>
+<label for="data_encoding:%(eid)s">data_encoding</label><input id="data_encoding:%(eid)s" maxlength="20" name="data_encoding:%(eid)s" size="20" tabindex="2" type="text" value="UTF-8" /><br/>
</div>
<br/>
-<input name="data:%(eid)s__detach" type="checkbox"></input>
+<input name="data:%(eid)s__detach" type="checkbox" />
detach attached file
''' % {'eid': file.eid})
@@ -196,14 +196,14 @@
data=Binary('new widgets system'))
form = EFFForm(self.req, redirect_path='perdu.com', entity=file)
self.assertTextEquals(self._render_entity_field('data', form),
- '''<input id="data:%(eid)s" name="data:%(eid)s" tabindex="0" type="file" value=""></input>
+ '''<input id="data:%(eid)s" name="data:%(eid)s" tabindex="0" type="file" value="" />
<a href="javascript: toggleVisibility('data:%(eid)s-advanced')" title="show advanced fields"><img src="http://testing.fr/cubicweb/data/puce_down.png" alt="show advanced fields"/></a>
<div id="data:%(eid)s-advanced" class="hidden">
-<label for="data_format:%(eid)s">data_format</label><input id="data_format:%(eid)s" maxlength="50" name="data_format:%(eid)s" size="45" tabindex="1" type="text" value="text/plain"></input><br/>
-<label for="data_encoding:%(eid)s">data_encoding</label><input id="data_encoding:%(eid)s" maxlength="20" name="data_encoding:%(eid)s" size="20" tabindex="2" type="text" value="UTF-8"></input><br/>
+<label for="data_format:%(eid)s">data_format</label><input id="data_format:%(eid)s" maxlength="50" name="data_format:%(eid)s" size="45" tabindex="1" type="text" value="text/plain" /><br/>
+<label for="data_encoding:%(eid)s">data_encoding</label><input id="data_encoding:%(eid)s" maxlength="20" name="data_encoding:%(eid)s" size="20" tabindex="2" type="text" value="UTF-8" /><br/>
</div>
<br/>
-<input name="data:%(eid)s__detach" type="checkbox"></input>
+<input name="data:%(eid)s__detach" type="checkbox" />
detach attached file
<p><b>You can either submit a new file using the browse button above, or choose to remove already uploaded file by checking the "detach attached file" check-box, or edit file content online with the widget below.</b></p>
<textarea cols="80" name="data:%(eid)s" onkeyup="autogrow(this)" rows="3" tabindex="3">new widgets system</textarea>''' % {'eid': file.eid})
@@ -214,9 +214,9 @@
upassword = StringField(widget=PasswordInput)
form = PFForm(self.req, redirect_path='perdu.com', entity=self.entity)
self.assertTextEquals(self._render_entity_field('upassword', form),
- '''<input id="upassword:%(eid)s" name="upassword:%(eid)s" tabindex="0" type="password" value="__cubicweb_internal_field__"></input>
+ '''<input id="upassword:%(eid)s" name="upassword:%(eid)s" tabindex="0" type="password" value="__cubicweb_internal_field__" />
<br/>
-<input name="upassword-confirm:%(eid)s" tabindex="0" type="password" value="__cubicweb_internal_field__"></input>
+<input name="upassword-confirm:%(eid)s" tabindex="0" type="password" value="__cubicweb_internal_field__" />
<span class="emphasis">confirm password</span>''' % {'eid': self.entity.eid})
--- a/web/test/unittest_urlrewrite.py Thu Jul 16 12:57:17 2009 -0700
+++ b/web/test/unittest_urlrewrite.py Tue Jul 28 21:27:52 2009 +0200
@@ -29,12 +29,14 @@
self.assertListEquals(rules, [
('foo' , dict(rql='Foo F')),
('/index' , dict(vid='index2')),
- ('/schema', {'vid': 'schema'}),
+ ('/schema', dict(vid='schema')),
('/myprefs', dict(vid='propertiesform')),
('/siteconfig', dict(vid='systempropertiesform')),
+ ('/siteinfo', dict(vid='info')),
('/manage', dict(vid='manage')),
- ('/notfound', {'vid': '404'}),
- ('/error', {'vid': 'error'}),
+ ('/notfound', dict(vid='404')),
+ ('/error', dict(vid='error')),
+ ('/sparql', dict(vid='sparql')),
('/schema/([^/]+?)/?$', {'rql': r'Any X WHERE X is CWEType, X name "\1"', 'vid': 'eschema'}),
('/add/([^/]+?)/?$' , dict(vid='creation', etype=r'\1')),
('/doc/images/(.+?)/?$', dict(fid='\\1', vid='wdocimages')),
--- a/web/test/unittest_viewselector.py Thu Jul 16 12:57:17 2009 -0700
+++ b/web/test/unittest_viewselector.py Tue Jul 28 21:27:52 2009 +0200
@@ -1,4 +1,4 @@
-# -*- coding: iso-8859-1 -*-
+# -*- coding: utf-8 -*-
"""XXX rename, split, reorganize this
:license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses
"""
@@ -22,8 +22,9 @@
('logout', actions.LogoutAction)]
SITEACTIONS = [('siteconfig', actions.SiteConfigurationAction),
('manage', actions.ManageAction),
- ('schema', schema.ViewSchemaAction)]
-
+ ('schema', schema.ViewSchemaAction),
+ ('siteinfo', actions.SiteInfoAction),
+ ]
class ViewSelectorTC(EnvBasedTC):
@@ -59,6 +60,9 @@
print 'missing', [v for v in content.keys() if not v in expected]
raise
+ def setUp(self):
+ super(VRegistryTC, self).setUp()
+ assert self.vreg['views']['propertiesform']
def test_possible_views_none_rset(self):
req = self.request()
@@ -122,6 +126,31 @@
('xml', xmlrss.XMLView),
])
+ def test_propertiesform_admin(self):
+ assert self.vreg['views']['propertiesform']
+ rset1, req1 = self.env.get_rset_and_req('CWUser X WHERE X login "admin"')
+ rset2, req2 = self.env.get_rset_and_req('CWUser X WHERE X login "anon"')
+ self.failUnless(self.vreg.select_object('views', 'propertiesform', req1, rset=None))
+ self.failUnless(self.vreg.select_object('views', 'propertiesform', req1, rset=rset1))
+ self.failUnless(self.vreg.select_object('views', 'propertiesform', req2, rset=rset2))
+
+ def test_propertiesform_anon(self):
+ self.login('anon')
+ rset1, req1 = self.env.get_rset_and_req('CWUser X WHERE X login "admin"')
+ rset2, req2 = self.env.get_rset_and_req('CWUser X WHERE X login "anon"')
+ self.assertRaises(NoSelectableObject, self.vreg.select_object, 'views', 'propertiesform', req1, rset=None)
+ self.assertRaises(NoSelectableObject, self.vreg.select_object, 'views', 'propertiesform', req1, rset=rset1)
+ self.assertRaises(NoSelectableObject, self.vreg.select_object, 'views', 'propertiesform', req1, rset=rset2)
+
+ def test_propertiesform_jdoe(self):
+ self.create_user('jdoe')
+ self.login('jdoe')
+ rset1, req1 = self.env.get_rset_and_req('CWUser X WHERE X login "admin"')
+ rset2, req2 = self.env.get_rset_and_req('CWUser X WHERE X login "jdoe"')
+ self.failUnless(self.vreg.select_object('views', 'propertiesform', req1, rset=None))
+ self.assertRaises(NoSelectableObject, self.vreg.select_object, 'views', 'propertiesform', req1, rset=rset1)
+ self.failUnless(self.vreg.select_object('views', 'propertiesform', req2, rset=rset2))
+
def test_possible_views_multiple_different_types(self):
rset, req = self.env.get_rset_and_req('Any X')
self.assertListEqual(self.pviews(req, rset),
@@ -173,6 +202,7 @@
('text', baseviews.TextView),
('treeview', treeview.TreeView),
('vcard', vcard.VCardCWUserView),
+ ('wfhistory', workflow.WFHistoryView),
('xbel', xbel.XbelView),
('xml', xmlrss.XMLView),
])
--- a/web/uicfg.py Thu Jul 16 12:57:17 2009 -0700
+++ b/web/uicfg.py Tue Jul 28 21:27:52 2009 +0200
@@ -102,7 +102,7 @@
init_primaryview_section,
frozenset(('attributes', 'relations',
'sideboxes', 'hidden')))
-for rtype in ('eid', 'creation_date', 'modification_date',
+for rtype in ('eid', 'creation_date', 'modification_date', 'cwuri',
'is', 'is_instance_of', 'identity',
'owned_by', 'created_by',
'in_state', 'wf_info_for', 'require_permission',
@@ -113,9 +113,9 @@
primaryview_section.tag_subject_of(('*', 'use_email', '*'), 'attributes')
primaryview_section.tag_subject_of(('*', 'primary_email', '*'), 'hidden')
-for attr in ('name', 'meta', 'final'):
+for attr in ('name', 'final'):
primaryview_section.tag_attribute(('CWEType', attr), 'hidden')
-for attr in ('name', 'meta', 'final', 'symetric', 'inlined'):
+for attr in ('name', 'final', 'symetric', 'inlined'):
primaryview_section.tag_attribute(('CWRType', attr), 'hidden')
@@ -186,7 +186,7 @@
card = rschema.rproperty(sschema, oschema, 'cardinality')[1]
composed = rschema.rproperty(sschema, oschema, 'composite') == 'subject'
if sschema.is_metadata(rschema):
- section = 'generated'
+ section = 'metadata'
elif card in '1+':
if not rschema.is_final() and composed:
section = 'generated'
@@ -206,6 +206,7 @@
autoform_section.tag_attribute(('*', 'description'), 'secondary')
autoform_section.tag_attribute(('*', 'creation_date'), 'metadata')
autoform_section.tag_attribute(('*', 'modification_date'), 'metadata')
+autoform_section.tag_attribute(('*', 'cwuri'), 'metadata')
autoform_section.tag_attribute(('*', 'has_text'), 'generated')
autoform_section.tag_subject_of(('*', 'in_state', '*'), 'primary')
autoform_section.tag_subject_of(('*', 'owned_by', '*'), 'metadata')
@@ -228,8 +229,8 @@
autoform_section.tag_attribute(('CWUser', 'surname'), 'secondary')
autoform_section.tag_attribute(('CWUser', 'last_login_time'), 'metadata')
autoform_section.tag_subject_of(('CWUser', 'in_group', '*'), 'primary')
-autoform_section.tag_object_of(('*', 'owned_by', 'CWUser'), 'generated')
-autoform_section.tag_object_of(('*', 'created_by', 'CWUser'), 'generated')
+autoform_section.tag_object_of(('*', 'owned_by', 'CWUser'), 'metadata')
+autoform_section.tag_object_of(('*', 'created_by', 'CWUser'), 'metadata')
autoform_section.tag_object_of(('*', 'bookmarked_by', 'CWUser'), 'metadata')
autoform_section.tag_attribute(('Bookmark', 'path'), 'primary')
autoform_section.tag_subject_of(('*', 'use_email', '*'), 'generated') # inlined actually
--- a/web/views/__init__.py Thu Jul 16 12:57:17 2009 -0700
+++ b/web/views/__init__.py Tue Jul 28 21:27:52 2009 +0200
@@ -8,7 +8,7 @@
__docformat__ = "restructuredtext en"
import os
-from tempfile import mktemp
+import tempfile
from rql import nodes
@@ -81,6 +81,8 @@
if req.search_state[0] == 'normal':
return 'primary'
return 'outofcontext-search'
+ if len(rset.column_types(0)) == 1:
+ return 'adaptedlist'
return 'list'
return 'table'
@@ -109,7 +111,7 @@
def cell_call(self, row=0, col=0):
self.row, self.col = row, col # in case one need it
- tmpfile = mktemp('.png')
+ _, tmpfile = tempfile.mkstemp('.png')
try:
self._generate(tmpfile)
self.w(open(tmpfile).read())
--- a/web/views/actions.py Thu Jul 16 12:57:17 2009 -0700
+++ b/web/views/actions.py Tue Jul 28 21:27:52 2009 +0200
@@ -66,7 +66,7 @@
return 1
return 0
-# generic primary actions #####################################################
+# generic 'main' actions #######################################################
class SelectAction(Action):
"""base class for link search actions. By default apply on
@@ -146,7 +146,7 @@
return self.build_url('view', rql=self.rset.rql, vid='muledit')
-# generic secondary actions ###################################################
+# generic "more" actions #######################################################
class ManagePermissionsAction(Action):
id = 'managepermission'
@@ -286,6 +286,12 @@
title = _('manage')
order = 20
+class SiteInfoAction(ManagersAction):
+ id = 'siteinfo'
+ title = _('info')
+ order = 30
+ __select__ = match_user_groups('users','managers')
+
from logilab.common.deprecation import class_moved
from cubicweb.web.views.bookmark import FollowAction
--- a/web/views/basecomponents.py Thu Jul 16 12:57:17 2009 -0700
+++ b/web/views/basecomponents.py Tue Jul 28 21:27:52 2009 +0200
@@ -57,7 +57,7 @@
class ApplLogo(component.Component):
- """build the application logo, usually displayed in the header"""
+ """build the instance logo, usually displayed in the header"""
id = 'logo'
property_defs = VISIBLE_PROP_DEF
# don't want user to hide this component using an cwproperty
@@ -118,8 +118,8 @@
class ApplicationMessage(component.Component):
- """display application's messages given using the __message parameter
- into a special div section
+ """display messages given using the __message parameter into a special div
+ section
"""
__select__ = yes()
id = 'applmessages'
@@ -138,7 +138,7 @@
class ApplicationName(component.Component):
- """display the application name"""
+ """display the instance name"""
id = 'appliname'
property_defs = VISIBLE_PROP_DEF
# don't want user to hide this component using an cwproperty
--- a/web/views/basecontrollers.py Thu Jul 16 12:57:17 2009 -0700
+++ b/web/views/basecontrollers.py Tue Jul 28 21:27:52 2009 +0200
@@ -78,7 +78,7 @@
id = 'login'
def publish(self, rset=None):
- """log in the application"""
+ """log in the instance"""
if self.config['auth-mode'] == 'http':
# HTTP authentication
raise ExplicitLogin()
@@ -91,7 +91,7 @@
id = 'logout'
def publish(self, rset=None):
- """logout from the application"""
+ """logout from the instance"""
return self.appli.session_handler.logout(self.req)
@@ -400,10 +400,11 @@
return (success, args, None)
@jsonize
- def js_reledit_form(self, eid, rtype, role, lzone):
+ def js_reledit_form(self, eid, rtype, role, default, lzone):
+ """XXX we should get rid of this and use loadxhtml"""
entity = self.req.eid_rset(eid).get_entity(0, 0)
return entity.view('reledit', rtype=rtype, role=role,
- landing_zone=lzone)
+ default=default, landing_zone=lzone)
@jsonize
def js_i18n(self, msgids):
@@ -567,7 +568,8 @@
self.smtp.sendmail(helo_addr, [recipient], msg.as_string())
def publish(self, rset=None):
- # XXX this allow anybody with access to an cubicweb application to use it as a mail relay
+ # XXX this allows users with access to an cubicweb instance to use it as
+ # a mail relay
body = self.req.form['mailbody']
subject = self.req.form['subject']
for recipient in self.recipients():
--- a/web/views/baseviews.py Thu Jul 16 12:57:17 2009 -0700
+++ b/web/views/baseviews.py Tue Jul 28 21:27:52 2009 +0200
@@ -2,7 +2,7 @@
* noresult, final
* primary, sidebox
-* secondary, oneline, incontext, outofcontext, text
+* oneline, incontext, outofcontext, text
* list
@@ -20,7 +20,8 @@
from logilab.mtconverter import TransformError, xml_escape, xml_escape
from cubicweb import NoSelectableObject
-from cubicweb.selectors import yes, empty_rset
+from cubicweb.selectors import yes, empty_rset, one_etype_rset
+from cubicweb.schema import display_name
from cubicweb.view import EntityView, AnyRsetView, View
from cubicweb.common.uilib import cut, printable_value
@@ -100,6 +101,7 @@
self.wdata(printable_value(self.req, etype, value, props, displaytime=displaytime))
+# XXX deprecated
class SecondaryView(EntityView):
id = 'secondary'
title = _('secondary')
@@ -179,9 +181,6 @@
self.w(u'</div>')
-# new default views for finner control in general views , to use instead of
-# oneline / secondary
-
class InContextTextView(TextView):
id = 'textincontext'
title = None # not listed as a possible view
@@ -236,6 +235,7 @@
:param listid: the DOM id to use for the root element
"""
+ # XXX much of the behaviour here should probably be outside this view
if subvid is None and 'subvid' in self.req.form:
subvid = self.req.form.pop('subvid') # consume it
if listid:
@@ -258,28 +258,6 @@
self.wview(self.item_vid, self.rset, row=row, col=col, vid=vid, **kwargs)
self.w(u'</li>\n')
- def url(self):
- """overrides url method so that by default, the view list is called
- with sorted entities
- """
- coltypes = self.rset.column_types(0)
- # don't want to generate the rql if there is some restriction on
- # something else than the entity type
- if len(coltypes) == 1:
- # XXX norestriction is not correct here. For instance, in cases like
- # Any P,N WHERE P is Project, P name N
- # norestriction should equal True
- restr = self.rset.syntax_tree().children[0].where
- norestriction = (isinstance(restr, nodes.Relation) and
- restr.is_types_restriction())
- if norestriction:
- etype = iter(coltypes).next()
- return self.build_url(etype.lower(), vid=self.id)
- if len(self.rset) == 1:
- entity = self.rset.get_entity(0, 0)
- return self.build_url(entity.rest_path(), vid=self.id)
- return self.build_url(rql=self.rset.printable_rql(), vid=self.id)
-
class ListItemView(EntityView):
id = 'listitem'
@@ -307,6 +285,31 @@
redirect_vid = 'incontext'
+class AdaptedListView(EntityView):
+ """list of entities of the same type"""
+ id = 'adaptedlist'
+ __select__ = one_etype_rset()
+ item_vid = 'adaptedlistitem'
+
+ @property
+ def title(self):
+ etype = iter(self.rset.column_types(0)).next()
+ return display_name(self.req, etype, form='plural')
+
+ def call(self, **kwargs):
+ """display a list of entities by calling their <item_vid> view"""
+ if not 'vtitle' in self.req.form:
+ self.w(u'<h1>%s</h1>' % self.title)
+ super(AdaptedListView, self).call(**kwargs)
+
+ def cell_call(self, row, col=0, vid=None, **kwargs):
+ self.wview(self.item_vid, self.rset, row=row, col=col, vid=vid, **kwargs)
+
+
+class AdaptedListItemView(ListItemView):
+ id = 'adaptedlistitem'
+
+
class CSVView(SimpleListView):
id = 'csv'
redirect_vid = 'incontext'
--- a/web/views/bookmark.py Thu Jul 16 12:57:17 2009 -0700
+++ b/web/views/bookmark.py Tue Jul 28 21:27:52 2009 +0200
@@ -85,7 +85,7 @@
if eschema.has_perm(req, 'add') and rschema.has_perm(req, 'add', toeid=ueid):
boxmenu = BoxMenu(req._('manage bookmarks'))
linkto = 'bookmarked_by:%s:subject' % ueid
- # use a relative path so that we can move the application without
+ # use a relative path so that we can move the instance without
# loosing bookmarks
path = req.relative_path()
url = self.create_url(self.etype, __linkto=linkto, path=path)
--- a/web/views/boxes.py Thu Jul 16 12:57:17 2009 -0700
+++ b/web/views/boxes.py Tue Jul 28 21:27:52 2009 +0200
@@ -144,20 +144,16 @@
if 'in_state' in entity.e_schema.subject_relations() and entity.in_state:
_ = self.req._
state = entity.in_state[0]
- transitions = list(state.transitions(entity))
- if transitions:
- menu_title = u'%s: %s' % (_('state'), state.view('text'))
- menu_items = []
- for tr in transitions:
- url = entity.absolute_url(vid='statuschange', treid=tr.eid)
- menu_items.append(self.mk_action(_(tr.name), url))
- box.append(BoxMenu(menu_title, menu_items))
- # when there are no possible transition, put state if the menu if
- # there are some other actions
- elif not box.is_empty():
- menu_title = u'<a title="%s">%s: <i>%s</i></a>' % (
- _('no possible transition'), _('state'), state.view('text'))
- box.append(RawBoxItem(menu_title, 'boxMainactions'))
+ menu_title = u'%s: %s' % (_('state'), state.view('text'))
+ menu_items = []
+ for tr in state.transitions(entity):
+ url = entity.absolute_url(vid='statuschange', treid=tr.eid)
+ menu_items.append(self.mk_action(_(tr.name), url))
+ wfurl = self.build_url('cwetype/%s'%entity.e_schema, vid='workflow')
+ menu_items.append(self.mk_action(_('view workflow'), wfurl))
+ wfurl = entity.absolute_url(vid='wfhistory')
+ menu_items.append(self.mk_action(_('view history'), wfurl))
+ box.append(BoxMenu(menu_title, menu_items))
return None
def linkto_url(self, entity, rtype, etype, target):
--- a/web/views/cwproperties.py Thu Jul 16 12:57:17 2009 -0700
+++ b/web/views/cwproperties.py Tue Jul 28 21:27:52 2009 +0200
@@ -64,6 +64,7 @@
class SystemCWPropertiesForm(FormViewMixIn, StartupView):
+ """site-wide properties edition form"""
id = 'systempropertiesform'
__select__ = none_rset() & match_user_groups('managers')
@@ -94,7 +95,6 @@
return status
def call(self, **kwargs):
- """The default view representing the application's index"""
self.req.add_js(('cubicweb.edition.js', 'cubicweb.preferences.js', 'cubicweb.ajax.js'))
self.req.add_css('cubicweb.preferences.css')
vreg = self.vreg
@@ -226,12 +226,12 @@
class CWPropertiesForm(SystemCWPropertiesForm):
+ """user's preferences properties edition form"""
id = 'propertiesform'
__select__ = (
- # we don't want guests to be able to come here
- match_user_groups('users', 'managers') &
- (none_rset() | ((one_line_rset() & is_user_prefs()) &
- (one_line_rset() & match_user_groups('managers'))))
+ (none_rset() & match_user_groups('users','managers'))
+ | (one_line_rset() & match_user_groups('users') & is_user_prefs())
+ | (one_line_rset() & match_user_groups('managers') & implements('CWUser'))
)
title = _('preferences')
--- a/web/views/cwuser.py Thu Jul 16 12:57:17 2009 -0700
+++ b/web/views/cwuser.py Tue Jul 28 21:27:52 2009 +0200
@@ -25,7 +25,7 @@
def url(self):
login = self.rset.get_entity(self.row or 0, self.col or 0).login
- return self.build_url('cwuser/%s'%login, vid='epropertiesform')
+ return self.build_url('cwuser/%s'%login, vid='propertiesform')
class FoafView(EntityView):
--- a/web/views/editforms.py Thu Jul 16 12:57:17 2009 -0700
+++ b/web/views/editforms.py Tue Jul 28 21:27:52 2009 +0200
@@ -87,11 +87,16 @@
"""
id = 'reledit'
__select__ = non_final_entity() & match_kwargs('rtype')
-
# FIXME editableField class could be toggleable from userprefs
+ # add metadata to allow edition of metadata attributes (not considered by
+ # edition form by default)
+ attrcategories = ('primary', 'secondary', 'metadata')
+
_onclick = u"showInlineEditionForm(%(eid)s, '%(rtype)s', '%(divid)s')"
- _defaultlandingzone = u'<img title="%(msg)s" src="data/file.gif" alt="%(msg)s"/>'
+ _defaultlandingzone = (u'<img title="%(msg)s" '
+ 'src="data/accessories-text-editor.png" '
+ 'alt="%(msg)s"/>')
_landingzonemsg = _('click to edit this field')
# default relation vids according to cardinality
_one_rvid = 'incontext'
@@ -105,7 +110,7 @@
return self._one_rvid
def _build_landing_zone(self, lzone):
- return lzone or self._defaultlandingzone % {'msg' : self.req._(self._landingzonemsg)}
+ return lzone or self._defaultlandingzone % {'msg' : xml_escape(self.req._(self._landingzonemsg))}
def _build_renderer(self, entity, rtype, role):
return self.vreg.select_object('formrenderers', 'base', self.req,
@@ -129,14 +134,19 @@
default = xml_escape(self.req._('<no value>'))
entity = self.entity(row, col)
rschema = entity.schema.rschema(rtype)
+ lzone = self._build_landing_zone(landing_zone)
# compute value, checking perms, build form
if rschema.is_final():
- value = entity.printable_value(rtype) or default
- if not entity.has_perm('update'):
+ value = entity.printable_value(rtype)
+ etype = str(entity.e_schema)
+ ttype = rschema.targets(etype, role)[0]
+ afs = uicfg.autoform_section.etype_get(etype, rtype, role, ttype)
+ if not (afs in self.attrcategories and entity.has_perm('update')):
self.w(value)
return
+ value = value or default
self._attribute_form(entity, value, rtype, role, reload,
- row, col, default, landing_zone)
+ row, col, default, lzone)
else:
dispctrl = uicfg.primaryview_display_ctrl.etype_get(entity.e_schema,
rtype, role)
@@ -147,8 +157,11 @@
if rvid is None:
rvid = self._compute_best_vid(entity, rtype, role)
rset = entity.related(rtype, role)
- candidate = self.view(rvid, rset, 'null')
- value = candidate or default
+ if rset:
+ value = self.view(rvid, rset)
+ else:
+ value = default
+ # XXX check autoform_section. what if 'generic'?
if role == 'subject' and not rschema.has_perm(self.req, 'add',
fromeid=entity.eid):
return self.w(value)
@@ -160,57 +173,79 @@
self.warning('reledit cannot be applied : (... %s %s [composite])'
% (rtype, entity.e_schema))
return self.w(value)
- self._relation_form(entity, value, rtype, role, reload, row, col,
- rvid, default, landing_zone)
+ self._relation_form(entity, value, rtype, role, reload, rvid,
+ default, lzone)
- def _relation_form(self, entity, value, rtype, role, row, col, reload, rvid, default, lzone):
- lzone = self._build_landing_zone(lzone)
- value = lzone + value
+ def _relation_form(self, entity, value, rtype, role, reload, rvid, default, lzone):
+ """xxx-reledit div (class=field)
+ +-xxx div (class="editableField")
+ | +-landing zone
+ +-value
+ +-form-xxx div
+ """
divid = 'd%s' % make_uid('%s-%s' % (rtype, entity.eid))
event_data = {'divid' : divid, 'eid' : entity.eid, 'rtype' : rtype, 'vid' : rvid,
- 'reload' : reload, 'default' : default, 'role' : role,
+ 'reload' : dumps(reload), 'default' : default, 'role' : role,
'lzone' : lzone}
onsubmit = ("return inlineValidateRelationForm('%(rtype)s', '%(role)s', '%(eid)s', "
"'%(divid)s', %(reload)s, '%(vid)s', '%(default)s', '%(lzone)s');"
% event_data)
cancelclick = "hideInlineEdit(%s,\'%s\',\'%s\')" % (
entity.eid, rtype, divid)
- form = self.vreg.select_object('forms', 'base', self.req, entity=entity,
- domid='%s-form' % divid, cssstyle='display: none',
- onsubmit=onsubmit, action='#',
- form_buttons=[SubmitButton(),
- Button(stdmsgs.BUTTON_CANCEL,
- onclick=cancelclick)])
+ form = self.vreg.select('forms', 'base', self.req, entity=entity,
+ domid='%s-form' % divid, cssstyle='display: none',
+ onsubmit=onsubmit, action='#',
+ form_buttons=[SubmitButton(),
+ Button(stdmsgs.BUTTON_CANCEL,
+ onclick=cancelclick)])
field = guess_field(entity.e_schema, entity.schema.rschema(rtype), role)
form.append_field(field)
- self.w(u'<div id="%s-reledit" class="field">' % divid)
- self.w(tags.div(value, klass='editableField', id=divid,
- onclick=self._onclick % event_data))
+ w = self.w
+ w(u'<div id="%s-reledit" class="field">' % divid)
+ w(tags.div(lzone, klass='editableField', id=divid,
+ onclick=self._onclick % event_data))
+ w(value)
renderer = self._build_renderer(entity, rtype, role)
- self.w(form.form_render(renderer=renderer))
- self.w(u'</div>')
+ w(form.form_render(renderer=renderer))
+ w(u'</div>')
def _attribute_form(self, entity, value, rtype, role, reload, row, col, default, lzone):
+ """div (class=field)
+ +-xxx div
+ | +-xxx div (class=editableField)
+ | | +-landing zone
+ | +-value-xxx div
+ | +-value
+ +-form-xxx div
+ """
eid = entity.eid
divid = 'd%s' % make_uid('%s-%s' % (rtype, eid))
event_data = {'divid' : divid, 'eid' : eid, 'rtype' : rtype,
- 'reload' : dumps(reload), 'default' : default, 'lzone' : lzone}
+ 'reload' : dumps(reload), 'default' : default}
onsubmit = ("return inlineValidateAttributeForm('%(rtype)s', '%(eid)s', '%(divid)s', "
- "%(reload)s, '%(default)s', '%(lzone)s');")
+ "%(reload)s, '%(default)s');")
buttons = [SubmitButton(stdmsgs.BUTTON_OK),
Button(stdmsgs.BUTTON_CANCEL,
onclick="hideInlineEdit(%s,\'%s\',\'%s\')" % (
eid, rtype, divid))]
- form = self.vreg.select_object('forms', 'edition', self.req, self.rset,
- row=row, col=col, form_buttons=buttons,
- domid='%s-form' % divid, action='#',
- cssstyle='display: none',
- onsubmit=onsubmit % event_data)
- self.w(tags.div(value, klass='editableField', id=divid,
- onclick=self._onclick % event_data))
+ form = self.vreg.select('forms', 'edition', self.req, rset=self.rset,
+ row=row, col=col, form_buttons=buttons,
+ attrcategories=self.attrcategories,
+ domid='%s-form' % divid, action='#',
+ cssstyle='display: none',
+ onsubmit=onsubmit % event_data)
+ w = self.w
+ w(u'<div class="field">')
+ w(u'<div id="%s" style="display: inline">' % divid)
+ w(tags.div(lzone, klass='editableField',
+ onclick=self._onclick % event_data))
+ w(u'<div id="value-%s" style="display: inline">%s</div>' %
+ (divid, value))
+ w(u'</div>')
renderer = self._build_renderer(entity, rtype, role)
- self.w(form.form_render(renderer=renderer))
+ w(form.form_render(renderer=renderer))
+ w(u'</div>')
class EditionFormView(FormViewMixIn, EntityView):
--- a/web/views/formrenderers.py Thu Jul 16 12:57:17 2009 -0700
+++ b/web/views/formrenderers.py Tue Jul 28 21:27:52 2009 +0200
@@ -85,6 +85,8 @@
return '\n'.join(data)
def render_label(self, form, field):
+ if field.label is None:
+ return u''
label = self.req._(field.label)
attrs = {'for': form.context[field]['id']}
if field.required:
@@ -188,22 +190,29 @@
return fields
def _render_fields(self, fields, w, form):
- w(u'<table class="%s">' % self.table_class)
+ byfieldset = {}
for field in fields:
- w(u'<tr>')
- if self.display_label:
- w(u'<th class="labelCol">%s</th>' % self.render_label(form, field))
- error = form.form_field_error(field)
- if error:
- w(u'<td class="error">')
- w(error)
- else:
- w(u'<td>')
- w(field.render(form, self))
- if self.display_help:
- w(self.render_help(form, field))
- w(u'</td></tr>')
- w(u'</table>')
+ byfieldset.setdefault(field.fieldset, []).append(field)
+ for fieldset, fields in byfieldset.iteritems():
+ w(u'<fieldset class="%s">' % (fieldset or u'default'))
+ if fieldset:
+ w(u'<legend>%s</legend>' % self.req._(fieldset))
+ w(u'<table class="%s">' % self.table_class)
+ for field in fields:
+ w(u'<tr id="%s_%s">' % (field.name, field.role))
+ if self.display_label:
+ w(u'<th class="labelCol">%s</th>' % self.render_label(form, field))
+ error = form.form_field_error(field)
+ if error:
+ w(u'<td class="error">')
+ w(error)
+ else:
+ w(u'<td>')
+ w(field.render(form, self))
+ if self.display_help:
+ w(self.render_help(form, field))
+ w(u'</td></tr>')
+ w(u'</table></fieldset>')
def render_buttons(self, w, form):
if not form.form_buttons:
--- a/web/views/idownloadable.py Thu Jul 16 12:57:17 2009 -0700
+++ b/web/views/idownloadable.py Tue Jul 28 21:27:52 2009 +0200
@@ -122,7 +122,7 @@
__select__ = implements(IDownloadable)
def cell_call(self, row, col, title=None, **kwargs):
- """the secondary view is a link to download the file"""
+ """the oneline view is a link to download the file"""
entity = self.entity(row, col)
url = xml_escape(entity.absolute_url())
name = xml_escape(title or entity.download_file_name())
@@ -144,9 +144,21 @@
self.wview(self.id, rset, row=i, col=0)
self.w(u'</div>')
- def cell_call(self, row, col):
+ def cell_call(self, row, col, width=None, height=None, link=False):
entity = self.entity(row, col)
#if entity.data_format.startswith('image/'):
- self.w(u'<img src="%s" alt="%s"/>' % (xml_escape(entity.download_url()),
- xml_escape(entity.download_file_name())))
+ imgtag = u'<img src="%s" alt="%s" ' % (xml_escape(entity.download_url()),
+ xml_escape(entity.download_file_name()))
+ if width:
+ imgtag += u'width="%i" ' % width
+ if height:
+ imgtag += u'height="%i" ' % height
+ imgtag += u'/>'
+ if link:
+ self.w(u'<a href="%s" alt="%s">%s</a>' % (entity.absolute_url(vid='download'),
+ self.req._('download image'),
+ imgtag))
+ else:
+ self.w(imgtag)
+
--- a/web/views/magicsearch.py Thu Jul 16 12:57:17 2009 -0700
+++ b/web/views/magicsearch.py Tue Jul 28 21:27:52 2009 +0200
@@ -42,7 +42,7 @@
:param translations: the reverted l10n dict
:type schema: `cubicweb.schema.Schema`
- :param schema: the application's schema
+ :param schema: the instance's schema
"""
# var_types is used as a map : var_name / var_type
vartypes = {}
@@ -94,7 +94,7 @@
:param ambiguous_nodes: a map : relation_node / (var_name, available_translations)
:type schema: `cubicweb.schema.Schema`
- :param schema: the application's schema
+ :param schema: the instance's schema
"""
# Now, try to resolve ambiguous translations
for relation, (var_name, translations_found) in ambiguous_nodes.items():
--- a/web/views/management.py Thu Jul 16 12:57:17 2009 -0700
+++ b/web/views/management.py Tue Jul 28 21:27:52 2009 +0200
@@ -283,7 +283,7 @@
class ProcessInformationView(StartupView):
id = 'info'
- __select__ = none_rset() & match_user_groups('managers')
+ __select__ = none_rset() & match_user_groups('users', 'managers')
title = _('server information')
--- a/web/views/primary.py Thu Jul 16 12:57:17 2009 -0700
+++ b/web/views/primary.py Tue Jul 28 21:27:52 2009 +0200
@@ -39,7 +39,11 @@
def cell_call(self, row, col):
self.row = row
+ self.maxrelated = self.req.property_value('navigation.related-limit')
entity = self.complete_entity(row, col)
+ self.render_entity(entity)
+
+ def render_entity(self, entity):
self.render_entity_title(entity)
self.render_entity_metadata(entity)
# entity's attributes and relations, excluding meta data
@@ -64,7 +68,6 @@
self.w(u'</div>')
self.w(u'</td></tr></table>')
self.content_navigation_components('navcontentbottom')
- self.maxrelated = self.req.property_value('navigation.related-limit')
def content_navigation_components(self, context):
self.w(u'<div class="%s">' % context)
--- a/web/views/schema.py Thu Jul 16 12:57:17 2009 -0700
+++ b/web/views/schema.py Tue Jul 28 21:27:52 2009 +0200
@@ -10,37 +10,178 @@
from itertools import cycle
from logilab.mtconverter import xml_escape
-from yams import schema2dot as s2d
+from yams import BASE_TYPES, schema2dot as s2d
-from cubicweb.selectors import implements, yes
+from cubicweb.selectors import implements, yes, match_user_groups
from cubicweb.schema import META_RELATIONS_TYPES, SCHEMA_TYPES
from cubicweb.schemaviewer import SchemaViewer
from cubicweb.view import EntityView, StartupView
from cubicweb.common import tags, uilib
-from cubicweb.web import action
-from cubicweb.web.views import TmpFileViewMixin, primary, baseviews, tabs
-from cubicweb.web.facet import AttributeFacet
+from cubicweb.web import action, facet
+from cubicweb.web.views import TmpFileViewMixin
+from cubicweb.web.views import primary, baseviews, tabs, management
-SKIP_TYPES = set()
-SKIP_TYPES.update(META_RELATIONS_TYPES)
-SKIP_TYPES.update(SCHEMA_TYPES)
+ALWAYS_SKIP_TYPES = BASE_TYPES | SCHEMA_TYPES
+SKIP_TYPES = ALWAYS_SKIP_TYPES | META_RELATIONS_TYPES
+SKIP_TYPES.update(set(('Transition', 'State', 'TrInfo',
+ 'CWUser', 'CWGroup',
+ 'CWCache', 'CWProperty', 'CWPermission',
+ 'ExternalUri')))
def skip_types(req):
if int(req.form.get('skipmeta', True)):
return SKIP_TYPES
- return ()
+ return ALWAYS_SKIP_TYPES
+
+# global schema view ###########################################################
+
+class SchemaView(tabs.TabsMixin, StartupView):
+ id = 'schema'
+ title = _('instance schema')
+ tabs = [_('schema-text'), _('schema-image')]
+ default_tab = 'schema-text'
+
+ def call(self):
+ """display schema information"""
+ self.req.add_js('cubicweb.ajax.js')
+ self.req.add_css(('cubicweb.schema.css','cubicweb.acl.css'))
+ self.w(u'<h1>%s</h1>' % _('Schema of the data model'))
+ self.render_tabs(self.tabs, self.default_tab)
+
+
+class SchemaTabImageView(StartupView):
+ id = 'schema-image'
-class ViewSchemaAction(action.Action):
- id = 'schema'
- __select__ = yes()
+ def call(self):
+ self.w(_(u'<div>This schema of the data model <em>excludes</em> the '
+ u'meta-data, but you can also display a <a href="%s">complete '
+ u'schema with meta-data</a>.</div>')
+ % xml_escape(self.build_url('view', vid='schemagraph', skipmeta=0)))
+ self.w(u'<img src="%s" alt="%s"/>\n' % (
+ xml_escape(self.req.build_url('view', vid='schemagraph', skipmeta=1)),
+ self.req._("graphical representation of the instance'schema")))
+
+
+class SchemaTabTextView(StartupView):
+ id = 'schema-text'
+
+ def call(self):
+ rset = self.req.execute('Any X ORDERBY N WHERE X is CWEType, X name N, '
+ 'X final FALSE')
+ self.wview('table', rset, displayfilter=True)
+
+
+class ManagerSchemaPermissionsView(StartupView, management.SecurityViewMixIn):
+ id = 'schema-security'
+ __select__ = StartupView.__select__ & match_user_groups('managers')
- title = _("site schema")
- category = 'siteactions'
- order = 30
+ def call(self, display_relations=True):
+ self.req.add_css('cubicweb.acl.css')
+ skiptypes = skip_types(self.req)
+ formparams = {}
+ formparams['sec'] = self.id
+ if not skiptypes:
+ formparams['skipmeta'] = u'0'
+ schema = self.schema
+ # compute entities
+ entities = sorted(eschema for eschema in schema.entities()
+ if not (eschema.is_final() or eschema in skiptypes))
+ # compute relations
+ if display_relations:
+ relations = sorted(rschema for rschema in schema.relations()
+ if not (rschema.is_final()
+ or rschema in skiptypes
+ or rschema in META_RELATIONS_TYPES))
+ else:
+ relations = []
+ # index
+ _ = self.req._
+ self.w(u'<div id="schema_security"><a id="index" href="index"/>')
+ self.w(u'<h2 class="schema">%s</h2>' % _('index').capitalize())
+ self.w(u'<h4>%s</h4>' % _('Entities').capitalize())
+ ents = []
+ for eschema in sorted(entities):
+ url = xml_escape(self.build_url('schema', **formparams))
+ ents.append(u'<a class="grey" href="%s#%s">%s</a> (%s)' % (
+ url, eschema.type, eschema.type, _(eschema.type)))
+ self.w(u', '.join(ents))
+ self.w(u'<h4>%s</h4>' % (_('relations').capitalize()))
+ rels = []
+ for rschema in sorted(relations):
+ url = xml_escape(self.build_url('schema', **formparams))
+ rels.append(u'<a class="grey" href="%s#%s">%s</a> (%s), ' % (
+ url , rschema.type, rschema.type, _(rschema.type)))
+ self.w(u', '.join(ents))
+ # entities
+ self.display_entities(entities, formparams)
+ # relations
+ if relations:
+ self.display_relations(relations, formparams)
+ self.w(u'</div>')
- def url(self):
- return self.build_url(self.id)
+ def display_entities(self, entities, formparams):
+ _ = self.req._
+ self.w(u'<a id="entities" href="entities"/>')
+ self.w(u'<h2 class="schema">%s</h2>' % _('permissions for entities').capitalize())
+ for eschema in entities:
+ self.w(u'<a id="%s" href="%s"/>' % (eschema.type, eschema.type))
+ self.w(u'<h3 class="schema">%s (%s) ' % (eschema.type, _(eschema.type)))
+ url = xml_escape(self.build_url('schema', **formparams) + '#index')
+ self.w(u'<a href="%s"><img src="%s" alt="%s"/></a>' % (
+ url, self.req.external_resource('UP_ICON'), _('up')))
+ self.w(u'</h3>')
+ self.w(u'<div style="margin: 0px 1.5em">')
+ self.schema_definition(eschema, link=False)
+ # display entity attributes only if they have some permissions modified
+ modified_attrs = []
+ for attr, etype in eschema.attribute_definitions():
+ if self.has_schema_modified_permissions(attr, attr.ACTIONS):
+ modified_attrs.append(attr)
+ if modified_attrs:
+ self.w(u'<h4>%s</h4>' % _('attributes with modified permissions:').capitalize())
+ self.w(u'</div>')
+ self.w(u'<div style="margin: 0px 6em">')
+ for attr in modified_attrs:
+ self.w(u'<h4 class="schema">%s (%s)</h4> ' % (attr.type, _(attr.type)))
+ self.schema_definition(attr, link=False)
+ self.w(u'</div>')
+ def display_relations(self, relations, formparams):
+ _ = self.req._
+ self.w(u'<a id="relations" href="relations"/>')
+ self.w(u'<h2 class="schema">%s </h2>' % _('permissions for relations').capitalize())
+ for rschema in relations:
+ self.w(u'<a id="%s" href="%s"/>' % (rschema.type, rschema.type))
+ self.w(u'<h3 class="schema">%s (%s) ' % (rschema.type, _(rschema.type)))
+ url = xml_escape(self.build_url('schema', **formparams) + '#index')
+ self.w(u'<a href="%s"><img src="%s" alt="%s"/></a>' % (
+ url, self.req.external_resource('UP_ICON'), _('up')))
+ self.w(u'</h3>')
+ self.w(u'<div style="margin: 0px 1.5em">')
+ subjects = [str(subj) for subj in rschema.subjects()]
+ self.w(u'<div><strong>%s</strong> %s (%s)</div>' % (
+ _('subject_plural:'),
+ ', '.join(str(subj) for subj in rschema.subjects()),
+ ', '.join(_(str(subj)) for subj in rschema.subjects())))
+ self.w(u'<div><strong>%s</strong> %s (%s)</div>' % (
+ _('object_plural:'),
+ ', '.join(str(obj) for obj in rschema.objects()),
+ ', '.join(_(str(obj)) for obj in rschema.objects())))
+ self.schema_definition(rschema, link=False)
+ self.w(u'</div>')
+
+
+class SchemaUreportsView(StartupView):
+ id = 'schema-block'
+
+ def call(self):
+ viewer = SchemaViewer(self.req)
+ layout = viewer.visit_schema(self.schema, display_relations=True,
+ skiptypes=skip_types(self.req))
+ self.w(uilib.ureport_as_html(layout))
+
+
+# CWAttribute / CWRelation #####################################################
class CWRDEFPrimaryView(primary.PrimaryView):
__select__ = implements('CWAttribute', 'CWRelation')
@@ -196,11 +337,13 @@
def should_display_schema(self, rschema):
return (super(RestrictedSchemaVisitorMixIn, self).should_display_schema(rschema)
- and rschema.has_local_role('read') or rschema.has_perm(self.req, 'read'))
+ and (rschema.has_local_role('read')
+ or rschema.has_perm(self.req, 'read')))
def should_display_attr(self, rschema):
return (super(RestrictedSchemaVisitorMixIn, self).should_display_attr(rschema)
- and rschema.has_local_role('read') or rschema.has_perm(self.req, 'read'))
+ and (rschema.has_local_role('read')
+ or rschema.has_perm(self.req, 'read')))
class FullSchemaVisitor(RestrictedSchemaVisitorMixIn, s2d.FullSchemaVisitor):
@@ -221,10 +364,12 @@
def _generate(self, tmpfile):
"""display global schema information"""
+ print 'skipedtypes', skip_types(self.req)
visitor = FullSchemaVisitor(self.req, self.schema,
skiptypes=skip_types(self.req))
s2d.schema2dot(outputfile=tmpfile, visitor=visitor)
+
class CWETypeSchemaImageView(TmpFileViewMixin, EntityView):
id = 'schemagraph'
__select__ = implements('CWEType')
@@ -238,6 +383,7 @@
skiptypes=skip_types(self.req))
s2d.schema2dot(outputfile=tmpfile, visitor=visitor)
+
class CWRTypeSchemaImageView(CWETypeSchemaImageView):
__select__ = implements('CWRType')
@@ -248,9 +394,21 @@
visitor = OneHopRSchemaVisitor(self.req, rschema)
s2d.schema2dot(outputfile=tmpfile, visitor=visitor)
-### facets
+
+# misc: facets, actions ########################################################
+
+class CWFinalFacet(facet.AttributeFacet):
+ id = 'cwfinal-facet'
+ __select__ = facet.AttributeFacet.__select__ & implements('CWEType', 'CWRType')
+ rtype = 'final'
-class CWFinalFacet(AttributeFacet):
- id = 'cwfinal-facet'
- __select__ = AttributeFacet.__select__ & implements('CWEType', 'CWRType')
- rtype = 'final'
+class ViewSchemaAction(action.Action):
+ id = 'schema'
+ __select__ = yes()
+
+ title = _("site schema")
+ category = 'siteactions'
+ order = 30
+
+ def url(self):
+ return self.build_url(self.id)
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/web/views/sparql.py Tue Jul 28 21:27:52 2009 +0200
@@ -0,0 +1,122 @@
+"""SPARQL integration
+
+:organization: Logilab
+:copyright: 2009 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2.
+:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr
+:license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses
+"""
+v__docformat__ = "restructuredtext en"
+
+import rql
+from yams import xy
+
+from lxml import etree
+from lxml.builder import E
+
+from cubicweb.view import StartupView, AnyRsetView
+from cubicweb.web import Redirect, form, formfields, formwidgets as fwdgs
+from cubicweb.web.views import forms, urlrewrite
+try:
+ from cubicweb.spa2rql import Sparql2rqlTranslator
+except ImportError:
+ # fyzz not available (only a recommends)
+ Sparql2rqlTranslator = None
+
+class SparqlForm(forms.FieldsForm):
+ id = 'sparql'
+ sparql = formfields.StringField(help=_('type here a sparql query'))
+ resultvid = formfields.StringField(choices=((_('table'), 'table'),
+ (_('sparql xml'), 'sparqlxml')),
+ widget=fwdgs.Radio,
+ initial='table')
+ form_buttons = [fwdgs.SubmitButton()]
+ @property
+ def action(self):
+ return self.req.url()
+
+
+class SparqlFormView(form.FormViewMixIn, StartupView):
+ id = 'sparql'
+ def call(self):
+ form = self.vreg.select('forms', 'sparql', self.req)
+ self.w(form.form_render())
+ sparql = self.req.form.get('sparql')
+ vid = self.req.form.get('resultvid', 'table')
+ if sparql:
+ try:
+ qinfo = Sparql2rqlTranslator(self.schema).translate(sparql)
+ except rql.TypeResolverException, ex:
+ self.w(self.req._('can not resolve entity types:') + u' ' + unicode('ex'))
+ except UnsupportedQuery:
+ self.w(self.req._('we are not yet ready to handle this query'))
+ except xy.UnsupportedVocabulary, ex:
+ self.w(self.req._('unknown vocabulary:') + u' ' + unicode('ex'))
+ if vid == 'sparqlxml':
+ url = self.build_url('view', rql=qinfo.finalize(), vid=vid)
+ raise Redirect(url)
+ rset = self.req.execute(qinfo.finalize())
+ self.wview(vid, rset, 'null')
+
+
+## sparql resultset views #####################################################
+
+YAMS_XMLSCHEMA_MAPPING = {
+ 'String': 'string',
+ 'Int': 'integer',
+ 'Float': 'float',
+ 'Boolean': 'boolean',
+ 'Datetime': 'dateTime',
+ 'Date': 'date',
+ 'Time': 'time',
+ # XXX the following types don't have direct mapping
+ 'Decimal': 'string',
+ 'Interval': 'duration',
+ 'Password': 'string',
+ 'Bytes': 'base64Binary',
+ }
+
+def xmlschema(yamstype):
+ return 'http://www.w3.org/2001/XMLSchema#%s' % YAMS_XMLSCHEMA_MAPPING[yamstype]
+
+class SparqlResultXmlView(AnyRsetView):
+ """The spec can be found here: http://www.w3.org/TR/rdf-sparql-XMLres/
+ """
+ id = 'sparqlxml'
+ content_type = 'application/sparql-results+xml'
+ templatable = False
+
+ def call(self):
+ # XXX handle UNION
+ rqlst = self.rset.syntax_tree().children[0]
+ varnames = [var.name for var in rqlst.selection]
+ results = E.results()
+ for rowidx in xrange(len(self.rset)):
+ result = E.result()
+ for colidx, varname in enumerate(varnames):
+ result.append(self.cell_binding(rowidx, colidx, varname))
+ results.append(result)
+ sparql = E.sparql(E.head(*(E.variable(name=name) for name in varnames)),
+ results)
+ self.w(u'<?xml version="1.0"?>\n')
+ self.w(etree.tostring(sparql, encoding=unicode, pretty_print=True))
+
+ def cell_binding(self, row, col, varname):
+ celltype = self.rset.description[row][col]
+ if self.schema.eschema(celltype).is_final():
+ cellcontent = self.view('cell', self.rset, row=row, col=col)
+ return E.binding(E.literal(cellcontent,
+ datatype=xmlschema(celltype)),
+ name=varname)
+ else:
+ entity = self.entity(row, col)
+ return E.binding(E.uri(entity.absolute_url()), name=varname)
+
+ def set_request_content_type(self):
+ """overriden to set the correct filetype and filename"""
+ self.req.set_content_type(self.content_type,
+ filename='sparql.xml',
+ encoding=self.req.encoding)
+
+def registration_callback(vreg):
+ if Sparql2rqlTranslator is not None:
+ vreg.register_all(globals().values(), __name__)
--- a/web/views/startup.py Thu Jul 16 12:57:17 2009 -0700
+++ b/web/views/startup.py Tue Jul 28 21:27:52 2009 +0200
@@ -14,10 +14,8 @@
from cubicweb.view import StartupView
from cubicweb.selectors import match_user_groups, implements
-from cubicweb.schema import META_RELATIONS_TYPES, display_name
-from cubicweb.common.uilib import ureport_as_html
+from cubicweb.schema import display_name
from cubicweb.web import ajax_replace_url, uicfg, httpcache
-from cubicweb.web.views import tabs, management, schema as schemamod
class ManageView(StartupView):
id = 'manage'
@@ -38,7 +36,7 @@
return False
def call(self, **kwargs):
- """The default view representing the application's management"""
+ """The default view representing the instance's management"""
self.req.add_css('cubicweb.manageview.css')
self.w(u'<div>\n')
if not self.display_folders():
@@ -137,12 +135,7 @@
etype = eschema.type
label = display_name(req, etype, 'plural')
nb = req.execute('Any COUNT(X) WHERE X is %s' % etype)[0][0]
- if nb > 1:
- view = self.vreg.select('views', 'list', req,
- rset=req.etype_rset(etype))
- url = view.url()
- else:
- url = self.build_url('view', rql='%s X' % etype)
+ url = self.build_url(etype)
etypelink = u' <a href="%s">%s</a> (%d)' % (
xml_escape(url), label, nb)
yield (label, etypelink, self.add_entity_link(eschema, req))
@@ -163,154 +156,3 @@
def display_folders(self):
return 'Folder' in self.schema and self.req.execute('Any COUNT(X) WHERE X is Folder')[0][0]
-class SchemaView(tabs.TabsMixin, StartupView):
- id = 'schema'
- title = _('application schema')
- tabs = [_('schema-text'), _('schema-image')]
- default_tab = 'schema-text'
-
- def call(self):
- """display schema information"""
- self.req.add_js('cubicweb.ajax.js')
- self.req.add_css(('cubicweb.schema.css','cubicweb.acl.css'))
- self.w(u'<h1>%s</h1>' % _('Schema of the data model'))
- self.render_tabs(self.tabs, self.default_tab)
-
-
-class SchemaTabImageView(StartupView):
- id = 'schema-image'
-
- def call(self):
- self.w(_(u'<div>This schema of the data model <em>excludes</em> the '
- u'meta-data, but you can also display a <a href="%s">complete '
- u'schema with meta-data</a>.</div>')
- % xml_escape(self.build_url('view', vid='schemagraph', withmeta=1)))
- self.w(u'<img src="%s" alt="%s"/>\n' % (
- xml_escape(self.req.build_url('view', vid='schemagraph', skipmeta=1)),
- self.req._("graphical representation of the application'schema")))
-
-
-class SchemaTabTextView(StartupView):
- id = 'schema-text'
-
- def call(self):
- rset = self.req.execute('Any X ORDERBY N WHERE X is CWEType, X name N, '
- 'X final FALSE')
- self.wview('table', rset, displayfilter=True)
-
-
-class ManagerSchemaPermissionsView(StartupView, management.SecurityViewMixIn):
- id = 'schema-security'
- __select__ = StartupView.__select__ & match_user_groups('managers')
-
- def call(self, display_relations=True):
- self.req.add_css('cubicweb.acl.css')
- skiptypes = schemamod.skip_types(self.req)
- formparams = {}
- formparams['sec'] = self.id
- if not skiptypes:
- formparams['skipmeta'] = u'0'
- schema = self.schema
- # compute entities
- entities = sorted(eschema for eschema in schema.entities()
- if not (eschema.is_final() or eschema in skiptypes))
- # compute relations
- if display_relations:
- relations = sorted(rschema for rschema in schema.relations()
- if not (rschema.is_final()
- or rschema in skiptypes
- or rschema in META_RELATIONS_TYPES))
- else:
- relations = []
- # index
- _ = self.req._
- self.w(u'<div id="schema_security"><a id="index" href="index"/>')
- self.w(u'<h2 class="schema">%s</h2>' % _('index').capitalize())
- self.w(u'<h4>%s</h4>' % _('Entities').capitalize())
- ents = []
- for eschema in sorted(entities):
- url = xml_escape(self.build_url('schema', **formparams))
- ents.append(u'<a class="grey" href="%s#%s">%s</a> (%s)' % (
- url, eschema.type, eschema.type, _(eschema.type)))
- self.w(u', '.join(ents))
- self.w(u'<h4>%s</h4>' % (_('relations').capitalize()))
- rels = []
- for rschema in sorted(relations):
- url = xml_escape(self.build_url('schema', **formparams))
- rels.append(u'<a class="grey" href="%s#%s">%s</a> (%s), ' % (
- url , rschema.type, rschema.type, _(rschema.type)))
- self.w(u', '.join(ents))
- # entities
- self.display_entities(entities, formparams)
- # relations
- if relations:
- self.display_relations(relations, formparams)
- self.w(u'</div>')
-
- def display_entities(self, entities, formparams):
- _ = self.req._
- self.w(u'<a id="entities" href="entities"/>')
- self.w(u'<h2 class="schema">%s</h2>' % _('permissions for entities').capitalize())
- for eschema in entities:
- self.w(u'<a id="%s" href="%s"/>' % (eschema.type, eschema.type))
- self.w(u'<h3 class="schema">%s (%s) ' % (eschema.type, _(eschema.type)))
- url = xml_escape(self.build_url('schema', **formparams) + '#index')
- self.w(u'<a href="%s"><img src="%s" alt="%s"/></a>' % (
- url, self.req.external_resource('UP_ICON'), _('up')))
- self.w(u'</h3>')
- self.w(u'<div style="margin: 0px 1.5em">')
- self.schema_definition(eschema, link=False)
- # display entity attributes only if they have some permissions modified
- modified_attrs = []
- for attr, etype in eschema.attribute_definitions():
- if self.has_schema_modified_permissions(attr, attr.ACTIONS):
- modified_attrs.append(attr)
- if modified_attrs:
- self.w(u'<h4>%s</h4>' % _('attributes with modified permissions:').capitalize())
- self.w(u'</div>')
- self.w(u'<div style="margin: 0px 6em">')
- for attr in modified_attrs:
- self.w(u'<h4 class="schema">%s (%s)</h4> ' % (attr.type, _(attr.type)))
- self.schema_definition(attr, link=False)
- self.w(u'</div>')
-
- def display_relations(self, relations, formparams):
- _ = self.req._
- self.w(u'<a id="relations" href="relations"/>')
- self.w(u'<h2 class="schema">%s </h2>' % _('permissions for relations').capitalize())
- for rschema in relations:
- self.w(u'<a id="%s" href="%s"/>' % (rschema.type, rschema.type))
- self.w(u'<h3 class="schema">%s (%s) ' % (rschema.type, _(rschema.type)))
- url = xml_escape(self.build_url('schema', **formparams) + '#index')
- self.w(u'<a href="%s"><img src="%s" alt="%s"/></a>' % (
- url, self.req.external_resource('UP_ICON'), _('up')))
- self.w(u'</h3>')
- self.w(u'<div style="margin: 0px 1.5em">')
- subjects = [str(subj) for subj in rschema.subjects()]
- self.w(u'<div><strong>%s</strong> %s (%s)</div>' % (
- _('subject_plural:'),
- ', '.join(str(subj) for subj in rschema.subjects()),
- ', '.join(_(str(subj)) for subj in rschema.subjects())))
- self.w(u'<div><strong>%s</strong> %s (%s)</div>' % (
- _('object_plural:'),
- ', '.join(str(obj) for obj in rschema.objects()),
- ', '.join(_(str(obj)) for obj in rschema.objects())))
- self.schema_definition(rschema, link=False)
- self.w(u'</div>')
-
-
-class SchemaUreportsView(StartupView):
- id = 'schematext'
-
- def call(self):
- from cubicweb.schemaviewer import SchemaViewer
- if int(self.req.form.get('skipmeta', True)):
- skip = schema.SKIP_TYPES
- else:
- skip = ()
- viewer = SchemaViewer(self.req)
- layout = viewer.visit_schema(self.schema, display_relations=True,
- skiptypes=skip)
- self.w(ureport_as_html(layout))
-
-
--- a/web/views/timetable.py Thu Jul 16 12:57:17 2009 -0700
+++ b/web/views/timetable.py Tue Jul 28 21:27:52 2009 +0200
@@ -138,7 +138,7 @@
for user, width in zip(users, widths):
self.w(u'<th colspan="%s">' % max(MIN_COLS, width))
if user != u"*":
- user.view('secondary', w=self.w)
+ user.view('oneline', w=self.w)
else:
self.w(user)
self.w(u'</th>')
--- a/web/views/treeview.py Thu Jul 16 12:57:17 2009 -0700
+++ b/web/views/treeview.py Tue Jul 28 21:27:52 2009 +0200
@@ -16,7 +16,7 @@
from cubicweb.view import EntityView
def treecookiename(treeid):
- return str('treestate-%s' % treeid)
+ return str('%s-treestate' % treeid)
class TreeView(EntityView):
id = 'treeview'
--- a/web/views/urlrewrite.py Thu Jul 16 12:57:17 2009 -0700
+++ b/web/views/urlrewrite.py Tue Jul 28 21:27:52 2009 +0200
@@ -76,9 +76,11 @@
('/index', dict(vid='index')),
('/myprefs', dict(vid='propertiesform')),
('/siteconfig', dict(vid='systempropertiesform')),
+ ('/siteinfo', dict(vid='info')),
('/manage', dict(vid='manage')),
('/notfound', dict(vid='404')),
('/error', dict(vid='error')),
+ ('/sparql', dict(vid='sparql')),
(rgx('/schema/([^/]+?)/?'), dict(vid='eschema', rql=r'Any X WHERE X is CWEType, X name "\1"')),
(rgx('/add/([^/]+?)/?'), dict(vid='creation', etype=r'\1')),
(rgx('/doc/images/(.+?)/?'), dict(vid='wdocimages', fid=r'\1')),
--- a/web/views/workflow.py Thu Jul 16 12:57:17 2009 -0700
+++ b/web/views/workflow.py Tue Jul 28 21:27:52 2009 +0200
@@ -18,6 +18,7 @@
from cubicweb.selectors import (implements, has_related_entities,
relation_possible, match_form_params)
from cubicweb.interfaces import IWorkflowable
+from cubicweb.view import EntityView
from cubicweb.web import stdmsgs, action, component, form
from cubicweb.web.form import FormViewMixIn
from cubicweb.web.formfields import StringField, RichTextField
@@ -67,12 +68,9 @@
return entity.rest_path()
-class WFHistoryVComponent(component.EntityVComponent):
- """display the workflow history for entities supporting it"""
+class WFHistoryView(EntityView):
id = 'wfhistory'
- __select__ = (component.EntityVComponent.__select__
- & relation_possible('wf_info_for', role='object'))
- context = 'navcontentbottom'
+ __select__ = relation_possible('wf_info_for', role='object')
title = _('Workflow history')
def cell_call(self, row, col, view=None):
@@ -102,6 +100,16 @@
displaycols=displaycols, headers=headers)
+class WFHistoryVComponent(component.EntityVComponent):
+ """display the workflow history for entities supporting it"""
+ id = 'wfhistory'
+ __select__ = WFHistoryView.__select__ & component.EntityVComponent.__select__
+ context = 'navcontentbottom'
+ title = _('Workflow history')
+
+ def cell_call(self, row, col, view=None):
+ self.wview('wfhistory', self.rset, row=row, col=col, view=view)
+
# workflow entity types views #################################################
class CellView(view.EntityView):
@@ -109,7 +117,7 @@
__select__ = implements('TrInfo')
def cell_call(self, row, col, cellvid=None):
- self.w(self.entity(row, col).printable_value('comment'))
+ self.w(self.entity(row, col).view('reledit', rtype='comment'))
class StateInContextView(view.EntityView):
--- a/web/webconfig.py Thu Jul 16 12:57:17 2009 -0700
+++ b/web/webconfig.py Tue Jul 28 21:27:52 2009 +0200
@@ -1,4 +1,4 @@
-"""common web configuration for twisted/modpython applications
+"""common web configuration for twisted/modpython instances
:organization: Logilab
:copyright: 2001-2009 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2.
@@ -60,7 +60,7 @@
class WebConfiguration(CubicWebConfiguration):
- """the WebConfiguration is a singleton object handling application's
+ """the WebConfiguration is a singleton object handling instance's
configuration and preferences
"""
cubicweb_vobject_path = CubicWebConfiguration.cubicweb_vobject_path | set(['web/views'])
@@ -83,13 +83,13 @@
('query-log-file',
{'type' : 'string',
'default': None,
- 'help': 'web application query log file',
+ 'help': 'web instance query log file',
'group': 'main', 'inputlevel': 2,
}),
- ('pyro-application-id',
+ ('pyro-instance-id',
{'type' : 'string',
- 'default': Method('default_application_id'),
- 'help': 'CubicWeb application identifier in the Pyro name server',
+ 'default': Method('default_instance_id'),
+ 'help': 'CubicWeb instance identifier in the Pyro name server',
'group': 'pyro-client', 'inputlevel': 1,
}),
# web configuration
@@ -156,7 +156,7 @@
('submit-url',
{'type' : 'string',
'default': Method('default_submit_url'),
- 'help': ('URL that may be used to report bug in this application '
+ 'help': ('URL that may be used to report bug in this instance '
'by direct access to the project\'s (jpl) tracker, '
'if you want this feature on. The url should looks like '
'http://mytracker.com/view?__linkto=concerns:1234:subject&etype=Ticket&type=bug&vid=creation '
@@ -168,7 +168,7 @@
('submit-mail',
{'type' : 'string',
'default': None,
- 'help': ('Mail used as recipient to report bug in this application, '
+ 'help': ('Mail used as recipient to report bug in this instance, '
'if you want this feature on'),
'group': 'web', 'inputlevel': 2,
}),
@@ -215,7 +215,7 @@
# don't use @cached: we want to be able to disable it while this must still
# be cached
def repository(self, vreg=None):
- """return the application's repository object"""
+ """return the instance's repository object"""
try:
return self.__repo
except AttributeError:
@@ -223,7 +223,7 @@
if self.repo_method == 'inmemory':
repo = get_repository('inmemory', vreg=vreg, config=self)
else:
- repo = get_repository('pyro', self['pyro-application-id'],
+ repo = get_repository('pyro', self['pyro-instance-id'],
config=self)
self.__repo = repo
return repo
@@ -298,7 +298,7 @@
yield join(fpath)
def load_configuration(self):
- """load application's configuration files"""
+ """load instance's configuration files"""
super(WebConfiguration, self).load_configuration()
# load external resources definition
self._build_ext_resources()
--- a/web/webctl.py Thu Jul 16 12:57:17 2009 -0700
+++ b/web/webctl.py Tue Jul 28 21:27:52 2009 +0200
@@ -8,6 +8,7 @@
"""
__docformat__ = "restructuredtext en"
+from cubicweb import underline_title
from cubicweb.toolsutils import CommandHandler, confirm
@@ -16,16 +17,14 @@
def bootstrap(self, cubes, inputlevel=0):
"""bootstrap this configuration"""
- print '** generic web configuration'
+ print '\n'+underline_title('Generic web configuration')
config = self.config
if config.repo_method == 'pyro':
- print
- print '** repository server configuration'
- print '-' * 72
+ print '\n'+underline_title('Repository server configuration')
config.input_config('pyro-client', inputlevel)
- if confirm('allow anonymous access', False):
+ if confirm('Allow anonymous access ?', False):
config.global_set_option('anonymous-user', 'anon')
config.global_set_option('anonymous-password', 'anon')
def postcreate(self):
- """hooks called once application's initialization has been completed"""
+ """hooks called once instance's initialization has been completed"""
--- a/wsgi/request.py Thu Jul 16 12:57:17 2009 -0700
+++ b/wsgi/request.py Tue Jul 28 21:27:52 2009 +0200
@@ -34,7 +34,7 @@
self._headers = dict([(normalize_header(k[5:]), v) for k, v in self.environ.items()
if k.startswith('HTTP_')])
https = environ.get("HTTPS") in ('yes', 'on', '1')
- self._base_url = base_url or self.application_uri()
+ self._base_url = base_url or self.instance_uri()
post, files = self.get_posted_data()
super(CubicWebWsgiRequest, self).__init__(vreg, https, post)
if files is not None:
@@ -63,7 +63,7 @@
def relative_path(self, includeparams=True):
"""return the normalized path of the request (ie at least relative
- to the application's root, but some other normalization may be needed
+ to the instance's root, but some other normalization may be needed
so that the returned path may be used to compare to generated urls
:param includeparams:
@@ -105,10 +105,10 @@
## wsgi request helpers ###################################################
- def application_uri(self):
- """Return the application's base URI (no PATH_INFO or QUERY_STRING)
+ def instance_uri(self):
+ """Return the instance's base URI (no PATH_INFO or QUERY_STRING)
- see python2.5's wsgiref.util.application_uri code
+ see python2.5's wsgiref.util.instance_uri code
"""
environ = self.environ
url = environ['wsgi.url_scheme'] + '://'
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/xy.py Tue Jul 28 21:27:52 2009 +0200
@@ -0,0 +1,20 @@
+"""map standard cubicweb schema to xml vocabularies
+
+:organization: Logilab
+:copyright: 2009 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2.
+:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr
+:license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses
+"""
+
+from yams import xy
+
+xy.register_prefix('http://purl.org/dc/elements/1.1/', 'dc')
+xy.register_prefix('http://xmlns.com/foaf/0.1/', 'foaf')
+xy.register_prefix('http://usefulinc.com/ns/doap#', 'doap')
+
+xy.add_equivalence('creation_date', 'dc:date')
+xy.add_equivalence('created_by', 'dc:creator')
+xy.add_equivalence('description', 'dc:description')
+xy.add_equivalence('CWUser', 'foaf:Person')
+xy.add_equivalence('CWUser login', 'dc:title')
+xy.add_equivalence('CWUser surname', 'foaf:Person foaf:name')