# HG changeset patch # User Sylvain Thénault # Date 1250156996 -7200 # Node ID b864288fd316d58477639c063fb49d0f09be9552 # Parent 3263755614122f6dbbfe92781af15854c19a03ac remove more 3.2 deprecated code, reintroduce checkbox used by formrenderers diff -r 326375561412 -r b864288fd316 appobject.py --- a/appobject.py Thu Aug 13 11:32:34 2009 +0200 +++ b/appobject.py Thu Aug 13 11:49:56 2009 +0200 @@ -244,29 +244,6 @@ """returns a unique identifier for the appobject""" return '%s.%s' % (cls.__module__, cls.__name__) - # XXX bw compat code - @classmethod - def build___select__(cls): - for klass in cls.mro(): - if klass.__name__ == 'AppObject': - continue # the bw compat __selector__ is there - klassdict = klass.__dict__ - if ('__select__' in klassdict and '__selectors__' in klassdict - and '__selgenerated__' not in klassdict): - raise TypeError("__select__ and __selectors__ can't be used together on class %s" % cls) - if '__selectors__' in klassdict and '__selgenerated__' not in klassdict: - cls.__selgenerated__ = True - # case where __selectors__ is defined locally (but __select__ - # is in a parent class) - selectors = klassdict['__selectors__'] - if len(selectors) == 1: - # micro optimization: don't bother with AndSelector if there's - # only one selector - select = _instantiate_selector(selectors[0]) - else: - select = AndSelector(*selectors) - cls.__select__ = select - @classmethod def registered(cls, registry): """called by the registry when the appobject has been registered. diff -r 326375561412 -r b864288fd316 entities/__init__.py --- a/entities/__init__.py Thu Aug 13 11:32:34 2009 +0200 +++ b/entities/__init__.py Thu Aug 13 11:49:56 2009 +0200 @@ -204,85 +204,6 @@ """ return () - # XXX deprecates, may be killed once old widgets system is gone ########### - - @classmethod - def get_widget(cls, rschema, x='subject'): - """return a widget to view or edit a relation - - notice that when the relation support multiple target types, the widget - is necessarily the same for all those types - """ - # let ImportError propage if web par isn't available - from cubicweb.web.widgets import widget - if isinstance(rschema, basestring): - rschema = cls.schema.rschema(rschema) - if x == 'subject': - tschema = rschema.objects(cls.e_schema)[0] - wdg = widget(cls.vreg, cls, rschema, tschema, 'subject') - else: - tschema = rschema.subjects(cls.e_schema)[0] - wdg = widget(cls.vreg, tschema, rschema, cls, 'object') - return wdg - - @deprecated('[3.4] use EntityFieldsForm.subject_relation_vocabulary') - def subject_relation_vocabulary(self, rtype, limit): - form = self.vreg.select('forms', 'edition', self.req, entity=self) - return form.subject_relation_vocabulary(rtype, limit) - - @deprecated('[3.4] use EntityFieldsForm.object_relation_vocabulary') - def object_relation_vocabulary(self, rtype, limit): - form = self.vreg.select('forms', 'edition', self.req, entity=self) - return form.object_relation_vocabulary(rtype, limit) - - @deprecated('[3.4] use AutomaticEntityForm.[e]relations_by_category') - def relations_by_category(self, categories=None, permission=None): - from cubicweb.web.views.autoform import AutomaticEntityForm - return AutomaticEntityForm.erelations_by_category(self, categories, permission) - - @deprecated('[3.4] use AutomaticEntityForm.[e]srelations_by_category') - def srelations_by_category(self, categories=None, permission=None): - from cubicweb.web.views.autoform import AutomaticEntityForm - return AutomaticEntityForm.esrelations_by_category(self, categories, permission) - - def attribute_values(self, attrname): - if self.has_eid() or attrname in self: - try: - values = self[attrname] - except KeyError: - values = getattr(self, attrname) - # actual relation return a list of entities - if isinstance(values, list): - return [v.eid for v in values] - return (values,) - # the entity is being created, try to find default value for - # this attribute - try: - values = self.req.form[attrname] - except KeyError: - try: - values = self[attrname] # copying - except KeyError: - values = getattr(self, 'default_%s' % attrname, - self.e_schema.default(attrname)) - if callable(values): - values = values() - if values is None: - values = () - elif not isinstance(values, (list, tuple)): - values = (values,) - return values - - def use_fckeditor(self, attr): - """return True if fckeditor should be used to edit entity's attribute named - `attr`, according to user preferences - """ - if self.req.use_fckeditor() and self.e_schema.has_metadata(attr, 'format'): - if self.has_eid() or '%s_format' % attr in self: - return self.attr_metadata(attr, 'format') == 'text/html' - return self.req.property_value('ui.default-text-format') == 'text/html' - return False - # XXX: store a reference to the AnyEntity class since it is hijacked in goa # configuration and we need the actual reference to avoid infinite loops # in mro diff -r 326375561412 -r b864288fd316 entities/test/unittest_base.py --- a/entities/test/unittest_base.py Thu Aug 13 11:32:34 2009 +0200 +++ b/entities/test/unittest_base.py Thu Aug 13 11:49:56 2009 +0200 @@ -17,7 +17,6 @@ from cubicweb.interfaces import IMileStone, IWorkflowable from cubicweb.entities import AnyEntity from cubicweb.entities.authobjs import CWUser -from cubicweb.web.widgets import AutoCompletionWidget class BaseEntityTC(CubicWebTC): diff -r 326375561412 -r b864288fd316 goa/goactl.py --- a/goa/goactl.py Thu Aug 13 11:32:34 2009 +0200 +++ b/goa/goactl.py Thu Aug 13 11:49:56 2009 +0200 @@ -112,7 +112,6 @@ 'web/httpcache.py', 'web/request.py', 'web/webconfig.py', - 'web/widgets.py', 'web/views/__init__.py', 'web/views/actions.py', diff -r 326375561412 -r b864288fd316 selectors.py --- a/selectors.py Thu Aug 13 11:32:34 2009 +0200 +++ b/selectors.py Thu Aug 13 11:49:56 2009 +0200 @@ -960,83 +960,3 @@ def __init__(self, scorefunc, once_is_enough=False): super(score_entity, self).__init__(once_is_enough) self.score_entity = scorefunc - - -def unbind_method(selector): - def new_selector(registered): - # get the unbound method - if hasattr(registered, 'im_func'): - registered = registered.im_func - # don't rebind since it will be done automatically during - # the assignment, inside the destination class body - return selector(registered) - new_selector.__name__ = selector.__name__ - return new_selector - - -def deprecate(registered, msg): - # get the unbound method - if hasattr(registered, 'im_func'): - registered = registered.im_func - def _deprecate(cls, vreg): - warn(msg, DeprecationWarning) - return registered(cls, vreg) - return _deprecate - -@unbind_method -def require_group_compat(registered): - def plug_selector(cls, vreg): - cls = registered(cls, vreg) - if getattr(cls, 'require_groups', None): - warn('use "match_user_groups(group1, group2)" instead of using require_groups', - DeprecationWarning) - cls.__select__ &= match_user_groups(cls.require_groups) - return cls - return plug_selector - -@unbind_method -def accepts_compat(registered): - def plug_selector(cls, vreg): - cls = registered(cls, vreg) - if getattr(cls, 'accepts', None): - warn('use "implements("EntityType", IFace)" instead of using accepts on %s' - % cls, - DeprecationWarning) - cls.__select__ &= implements(*cls.accepts) - return cls - return plug_selector - -@unbind_method -def accepts_etype_compat(registered): - def plug_selector(cls, vreg): - cls = registered(cls, vreg) - if getattr(cls, 'accepts', None): - warn('use "specified_etype_implements("EntityType", IFace)" instead of using accepts', - DeprecationWarning) - cls.__select__ &= specified_etype_implements(*cls.accepts) - return cls - return plug_selector - -@unbind_method -def condition_compat(registered): - def plug_selector(cls, vreg): - cls = registered(cls, vreg) - if getattr(cls, 'condition', None): - warn('use "use rql_condition(expression)" instead of using condition', - DeprecationWarning) - cls.__select__ &= rql_condition(cls.condition) - return cls - return plug_selector - -@unbind_method -def has_relation_compat(registered): - def plug_selector(cls, vreg): - cls = registered(cls, vreg) - if getattr(cls, 'etype', None): - warn('use relation_possible selector instead of using etype_rtype', - DeprecationWarning) - cls.__select__ &= relation_possible(cls.rtype, role(cls), - getattr(cls, 'etype', None), - action=getattr(cls, 'require_permission', 'read')) - return cls - return plug_selector diff -r 326375561412 -r b864288fd316 view.py --- a/view.py Thu Aug 13 11:32:34 2009 +0200 +++ b/view.py Thu Aug 13 11:49:56 2009 +0200 @@ -17,7 +17,6 @@ from cubicweb import NotAnEntity from cubicweb.selectors import yes, non_final_entity, nonempty_rset, none_rset -from cubicweb.selectors import require_group_compat, accepts_compat from cubicweb.appobject import AppObject from cubicweb.utils import UStringIO, HTMLStream from cubicweb.schema import display_name @@ -93,7 +92,6 @@ time to a write function to use. """ __registry__ = 'views' - registered = require_group_compat(AppObject.registered) templatable = True need_navigation = True @@ -330,8 +328,6 @@ class EntityView(View): """base class for views applying on an entity (i.e. uniform result set)""" __select__ = non_final_entity() - registered = accepts_compat(View.registered) - category = 'entityview' @@ -340,7 +336,6 @@ displayed (so they can always be displayed !) """ __select__ = none_rset() - registered = require_group_compat(View.registered) category = 'startupview' @@ -413,7 +408,6 @@ There is usually at least a regular main template and a simple fallback one to display error if the first one failed """ - registered = require_group_compat(View.registered) @property def doctype(self): diff -r 326375561412 -r b864288fd316 web/action.py --- a/web/action.py Thu Aug 13 11:32:34 2009 +0200 +++ b/web/action.py Thu Aug 13 11:49:56 2009 +0200 @@ -10,8 +10,7 @@ from cubicweb import target from cubicweb.selectors import (partial_relation_possible, match_search_state, - one_line_rset, partial_may_add_relation, yes, - accepts_compat, condition_compat, deprecate) + one_line_rset, partial_may_add_relation, yes) from cubicweb.appobject import AppObject @@ -73,8 +72,6 @@ __select__ = (match_search_state('normal') & one_line_rset() & partial_relation_possible(action='add') & partial_may_add_relation()) - registered = accepts_compat(Action.registered) - category = 'addrelated' def url(self): @@ -85,10 +82,3 @@ __redirectpath=current_entity.rest_path(), # should not be url quoted! __redirectvid=self.req.form.get('__redirectvid', '')) -class EntityAction(Action): - """DEPRECATED / BACKWARD COMPAT - """ - registered = deprecate(condition_compat(accepts_compat(Action.registered)), - msg='EntityAction is deprecated, use Action with ' - 'appropriate selectors') - diff -r 326375561412 -r b864288fd316 web/box.py --- a/web/box.py Thu Aug 13 11:32:34 2009 +0200 +++ b/web/box.py Thu Aug 13 11:49:56 2009 +0200 @@ -13,9 +13,7 @@ from cubicweb import Unauthorized, role as get_role, target as get_target from cubicweb.schema import display_name from cubicweb.selectors import (one_line_rset, primary_view, - match_context_prop, partial_has_related_entities, - accepts_compat, has_relation_compat, - condition_compat, require_group_compat) + match_context_prop, partial_has_related_entities) from cubicweb.view import View, ReloadableMixIn from cubicweb.web.htmlwidgets import (BoxLink, BoxWidget, SideBoxWidget, @@ -39,7 +37,6 @@ """ __registry__ = 'boxes' __select__ = match_context_prop() - registered = classmethod(require_group_compat(View.registered)) categories_in_order = () cw_property_defs = { @@ -138,7 +135,6 @@ class EntityBoxTemplate(BoxTemplate): """base class for boxes related to a single entity""" __select__ = BoxTemplate.__select__ & one_line_rset() & primary_view() - registered = accepts_compat(has_relation_compat(condition_compat(BoxTemplate.registered))) context = 'incontext' def call(self, row=0, col=0, **kwargs): diff -r 326375561412 -r b864288fd316 web/component.py --- a/web/component.py Thu Aug 13 11:32:34 2009 +0200 +++ b/web/component.py Thu Aug 13 11:49:56 2009 +0200 @@ -13,11 +13,10 @@ from cubicweb import role from cubicweb.utils import merge_dicts -from cubicweb.view import View, Component +from cubicweb.view import Component from cubicweb.selectors import ( paginated_rset, one_line_rset, primary_view, match_context_prop, - partial_has_related_entities, condition_compat, accepts_compat, - has_relation_compat) + partial_has_related_entities) class EntityVComponent(Component): @@ -33,7 +32,6 @@ __registry__ = 'contentnavigation' __select__ = one_line_rset() & primary_view() & match_context_prop() - registered = accepts_compat(has_relation_compat(condition_compat(View.registered))) cw_property_defs = { _('visible'): dict(type='Boolean', default=True, diff -r 326375561412 -r b864288fd316 web/controller.py --- a/web/controller.py Thu Aug 13 11:32:34 2009 +0200 +++ b/web/controller.py Thu Aug 13 11:49:56 2009 +0200 @@ -11,7 +11,7 @@ import datetime from cubicweb import typed_eid -from cubicweb.selectors import yes, require_group_compat +from cubicweb.selectors import yes from cubicweb.appobject import AppObject from cubicweb.web import LOGGER, Redirect, RequestError @@ -68,7 +68,6 @@ """ __registry__ = 'controllers' __select__ = yes() - registered = require_group_compat(AppObject.registered) def __init__(self, *args, **kwargs): self.appli = kwargs.pop('appli', None) diff -r 326375561412 -r b864288fd316 web/views/editcontroller.py --- a/web/views/editcontroller.py Thu Aug 13 11:32:34 2009 +0200 +++ b/web/views/editcontroller.py Thu Aug 13 11:49:56 2009 +0200 @@ -198,7 +198,7 @@ # if it is a file, transport it using a Binary (StringIO) # XXX later __detach is for the new widget system, the former is to # be removed once web/widgets.py has been dropped - if formparams.has_key('__%s_detach' % attr) or formparams.has_key('%s__detach' % attr): + if formparams.has_key('%s__detach' % attr): # drop current file value value = None # no need to check value when nor explicit detach nor new file diff -r 326375561412 -r b864288fd316 web/views/formrenderers.py --- a/web/views/formrenderers.py Thu Aug 13 11:32:34 2009 +0200 +++ b/web/views/formrenderers.py Thu Aug 13 11:49:56 2009 +0200 @@ -15,11 +15,16 @@ from cubicweb.common import tags from cubicweb.appobject import AppObject from cubicweb.selectors import entity_implements, yes -from cubicweb.web import eid_param -from cubicweb.web import formwidgets as fwdgs -from cubicweb.web.widgets import checkbox +from cubicweb.web import eid_param, formwidgets as fwdgs from cubicweb.web.formfields import HiddenInitialValueField +def checkbox(name, value, attrs='', checked=None): + if checked is None: + checked = value + checked = checked and 'checked="checked"' or '' + return u'' % ( + name, value, checked, attrs) + class FormRenderer(AppObject): """basic renderer displaying fields in a two columns table label | value