def check(self, record): data = record.data() if record['parent'].value() is not None: if record['parent'].value() == record['menu_item_id'].value(): return ('parent', _("Položka nemůže být nadřízená sama sobě.")) if not record.new(): # A new record can't be a parent of existing records. condition = pd.AND( pd.EQ('menu_item_id', record['parent']), pd.LTreeDescendant('tree_order', record['tree_order'])) count = data.select(condition=condition) data.close() if count: return ( 'parent', _("Nelze přiřadit podřízenou položku jako nadřízenou " "(cyklus v hierarchii).")) count = data.select(condition=pd.AND( *self._check_menu_order_condition(record))) data.close() if count: return ( 'ord', _("Stejné pořadové číslo už má jiná položka na této úrovni menu." ))
def _product_filter(self, row, marked, filter): condition = pd.WM('product', pd.WMValue(pd.String(), filter or '*')) if marked: value = pd.Value(pd.Boolean(), True) condition = pd.AND(condition, pd.EQ('marked', value)) return condition
def _update_spec_help(self, spec_name): if self._done.get(spec_name): return self._done[spec_name] = True resolver = pytis.util.resolver() try: view_spec = resolver.get(spec_name, 'view_spec') except pytis.util.ResolverError as e: print(e) return description = view_spec.description() help_text = (view_spec.help() or '').strip() or None self._update(self._spec_help_data, dict(spec_name=spec_name), description=description, help=help_text) data = self._spec_help_items_data for kind, items in (('field', view_spec.fields()), ('profile', view_spec.profiles().unnest()), ('binding', view_spec.bindings()), ('action', view_spec.actions(unnest=True))): for item in items: self._update(data, dict(spec_name=spec_name, kind=kind, identifier=item.id()), content=item.descr()) # Items which were modified (content changed by hand) are kept with # the 'removed' flag set, since the texts may be reused for other # items in case of identifier change or other rearrangements. It # will also automatically resurrect texts for items which are # removed temporarily (eg. commented out) which is quite common # during development. Items which were not ever modified or have # no content may be safely deleted (they contain no hand-edited # data). conds = [pd.EQ('spec_name', pd.sval(spec_name)), pd.EQ('kind', pd.sval(kind)), pd.NOT(pd.ANY_OF('identifier', *[pd.sval(item.id()) for item in items])), ] data.delete_many(pd.AND(*(conds + [pd.OR(pd.EQ('changed', pd.bval(False)), pd.EQ('content', pd.sval(None)))]))) data.update_many(pd.AND(*(conds + [pd.EQ('removed', pd.bval(False))])), pd.Row(self._values(data, removed=True)))
def _authorize(self, req): uri = req.server_uri(current=True) + '/' + '/'.join(req.path[:2]) username = req.header('X-Pytis-Attachment-Storage-Username') key = req.header('X-Pytis-Attachment-Storage-Key') if username and key: data = self._data data.select(condition=pd.AND(pd.EQ('uri', pd.sval(uri)), pd.EQ('username', pd.sval(username)))) row = data.fetchone() data.close() if row and row['key'].value() == key: req.set_param('authorized_readonly', row['readonly'].value()) return raise wiking.AuthorizationError()
def _row(self, data, **kwargs): data.select(condition=pd.AND(*[pd.EQ(k, v) for k, v in self._values(data, **kwargs)])) row = data.fetchone() data.close() return row
def _country_filter(self, row, filter, switch): """Return the validity condition as pd.Operator instance.""" cond = pd.WM('name', pd.WMValue(pd.String(), filter or '*')) if switch: cond = pd.AND(cond, pd.EQ('continent', pd.Value(pd.String(), 'EU'))) return cond
def _new_uid_filter(self, row, name): assigned_users = wiking.module(self._resolver).assigned_users( row['name']) return pd.AND(*[pd.NE('uid', u) for u in assigned_users])
def close(self, req, user, session_key): # This deletion will lead to end_time in cms_session_log_data being set to last_access # value of the deleted row. Use delete_many() because we don't know session_id. self._data.delete_many( pd.AND(pd.EQ('uid', pd.Value(pd.Integer(), user.uid())), pd.EQ('session_key', pd.Value(pd.DateTime(), session_key))))