fix UID handling in commerce

This commit is contained in:
Helmut Merz 2024-10-01 15:40:38 +02:00
parent 968aeab42a
commit 2cbd4c11d3
5 changed files with 27 additions and 82 deletions

View file

@ -84,16 +84,16 @@ A cart is just a collection of order items belonging to a certain customer
>>> orderItems = manager.orderItems >>> orderItems = manager.orderItems
>>> orderItems.add(p001, c001, shop=shop1, quantity=3) >>> orderItems.add(p001, c001, shop=shop1, quantity=3)
<OrderItem [2, 1, 7, '... ...', -1]: {'quantity': 3, 'shop': 0}> <OrderItem ['2', 1, '7', '... ...', '???']: {'quantity': 3, 'shop': '0'}>
>>> orderItems.getCart(c001) >>> orderItems.getCart(c001)
[<OrderItem [2, 1, 7, '... ...', -1]: {'quantity': 3, 'shop': 0}>] [<OrderItem ['2', 1, '7', '... ...', '???']: {'quantity': 3, 'shop': '0'}>]
>>> item1 = orderItems.getCart(c001, shop=shop1, product=p001)[0] >>> item1 = orderItems.getCart(c001, shop=shop1, product=p001)[0]
>>> item1 >>> item1
<OrderItem [2, 1, 7, '... ...', -1]: {'quantity': 3, 'shop': 0}> <OrderItem ['2', 1, '7', '... ...', '???']: {'quantity': 3, 'shop': '0'}>
>>> orderItems.add(p003, c001, shop=shop1, quantity=1) >>> orderItems.add(p003, c001, shop=shop1, quantity=1)
<OrderItem [4, 2, 7, '... ...', -1]: {'quantity': 1, 'shop': 0}> <OrderItem ['4', 2, '7', '... ...', '???']: {'quantity': 1, 'shop': '0'}>
>>> len(orderItems.getCart(c001)) >>> len(orderItems.getCart(c001))
2 2
@ -102,7 +102,7 @@ If we add the same product again to the cart no new item is created but
the quantity is added to the existing item. the quantity is added to the existing item.
>>> orderItems.add(p003, c001, shop=shop1, quantity=1) >>> orderItems.add(p003, c001, shop=shop1, quantity=1)
<OrderItem [4, 2, 7, '... ...', -1]: {'quantity': 2, 'shop': 0}> <OrderItem ['4', 2, '7', '... ...', '???']: {'quantity': 2, 'shop': '0'}>
>>> len(orderItems.getCart(c001)) >>> len(orderItems.getCart(c001))
2 2
@ -127,4 +127,4 @@ retrieving the order items.
>>> orderItems.getCart(c001) >>> orderItems.getCart(c001)
[] []
>>> orderItems.getCart(c001, ord001) >>> orderItems.getCart(c001, ord001)
[<OrderItem [4, 2, 7, '... ...', 11]: {'quantity': 2, 'shop': 0}>] [<OrderItem ['4', 2, '7', '... ...', '11']: {'quantity': 2, 'shop': '0'}>]

View file

@ -1,26 +1,7 @@
#-*- coding: UTF-8 -*- #-*- coding: UTF-8 -*-
# # cybertools.commerce.common
# Copyright (c) 2011 Helmut Merz helmutm@cy55.de
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
""" """ Common functionality.
Common functionality.
$Id$
""" """
from zope import component from zope import component
@ -147,10 +128,12 @@ class FloatValue(float):
def getUidForObject(obj, intIds=None): def getUidForObject(obj, intIds=None):
if intIds is None: if intIds is None:
intIds = component.getUtility(IIntIds) intIds = component.getUtility(IIntIds)
return intIds.getId(obj) return str(intIds.getId(obj))
def getObjectForUid(uid, intIds=None): def getObjectForUid(uid, intIds=None):
if intIds is None: if intIds is None:
intIds = component.getUtility(IIntIds) intIds = component.getUtility(IIntIds)
if isinstance(uid, str) and isdigit(uid):
uid = int(uid)
return intIds.getObject(uid) return intIds.getObject(uid)

View file

@ -96,7 +96,7 @@ class OrderItems(object):
criteria['runId'] = criteria.pop('run') criteria['runId'] = criteria.pop('run')
return self.context.query(**criteria) return self.context.query(**criteria)
def add(self, product, party, shop, order=-1, run=0, **kw): def add(self, product, party, shop, order='???', run=0, **kw):
kw['shop'] = self.getUid(shop) kw['shop'] = self.getUid(shop)
existing = self.getCart(party, order, shop, run, product=product) existing = self.getCart(party, order, shop, run, product=product)
options = kw.get('options') options = kw.get('options')
@ -114,7 +114,7 @@ class OrderItems(object):
self.context.indexTrack(0, track, 'order') self.context.indexTrack(0, track, 'order')
return track return track
def getCart(self, party=None, order=-1, shop=None, run=None, **kw): def getCart(self, party=None, order='???', shop=None, run=None, **kw):
if run: if run:
kw['run'] = run kw['run'] = run
result = self.query(party=party, order=order, **kw) result = self.query(party=party, order=order, **kw)

View file

@ -1,35 +1,17 @@
# # cybertools.pyscript.script
# Copyright (c) 2008 Helmut Merz helmutm@cy55.de
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
""" Simple implementation of Python scripts. """ Simple implementation of Python scripts.
$Id$
""" """
import os, re import os, re
import compiler.pycodegen import compiler.pycodegen
from cStringIO import StringIO from io import StringIO
from persistent import Persistent from persistent import Persistent
import RestrictedPython.RCompile import RestrictedPython.RCompile
from RestrictedPython.SelectCompiler import ast from RestrictedPython.SelectCompiler import ast
from zope.app.container.btree import BTreeContainer from zope.app.container.btree import BTreeContainer
from zope.app.container.contained import Contained from zope.app.container.contained import Contained
from zope.interface import implements from zope.interface import implementer
from zope.proxy import removeAllProxies from zope.proxy import removeAllProxies
from zope.security.untrustedpython.builtins import SafeBuiltins from zope.security.untrustedpython.builtins import SafeBuiltins
from zope.security.untrustedpython.rcompile import RestrictionMutator as BaseRM from zope.security.untrustedpython.rcompile import RestrictionMutator as BaseRM
@ -84,12 +66,11 @@ class RestrictionMutator(BaseRM):
[node.expr, ast.Const(node.attrname)]) [node.expr, ast.Const(node.attrname)])
@implementer(IPythonScript)
class PythonScript(Contained, Persistent): class PythonScript(Contained, Persistent):
"""Persistent Python Page - Content Type """Persistent Python Page - Content Type
""" """
implements(IPythonScript)
_v_compiled = None _v_compiled = None
title = u'' title = u''
@ -178,13 +159,13 @@ class Function(object):
lines = [] lines = []
if parameters: if parameters:
self.parameters = [str(p).strip() for p in parameters.split(',')] self.parameters = [str(p).strip() for p in parameters.split(',')]
#print '*** Function.parameters:', repr(self.parameters) #print('*** Function.parameters:', repr(self.parameters))
lines.insert(0, 'def dummy(): \n pass') lines.insert(0, 'def dummy(): \n pass')
for line in source.splitlines(): for line in source.splitlines():
lines.append(' ' + line) lines.append(' ' + line)
lines.append('script_result = dummy()') lines.append('script_result = dummy()')
source = '\n'.join(lines) source = '\n'.join(lines)
#print '*** source:', source #print('*** source:', source)
self.code = compile(source, filename, 'exec') self.code = compile(source, filename, 'exec')
def __call__(self, args, globals): def __call__(self, args, globals):
@ -192,21 +173,21 @@ class Function(object):
for idx, p in enumerate(self.parameters): for idx, p in enumerate(self.parameters):
# TODO: handle parameters with default values like ``attr=abc`` # TODO: handle parameters with default values like ``attr=abc``
globals[p] = args[idx] globals[p] = args[idx]
exec self.code in globals, None exec(self.code, globals, None)
def _print_usrc(match): def _print_usrc(match):
string = match.group(3) string = match.group(3)
raw = match.group(2) raw = match.group(2)
if raw: if raw:
return match.group(1)+'print '+`string` #return match.group(1)+'print '+`string`
return match.group(1)+'print '+match.group(3).encode('unicode-escape') return match.group(1) + 'print(' + eval('string') + ')'
return match.group(1) + 'print(' + match.group(3).encode('unicode-escape') + ')'
@implementer(IScriptContainer)
class ScriptContainer(BTreeContainer): class ScriptContainer(BTreeContainer):
implements(IScriptContainer)
unrestricted_objects = ('rstat',) # not used (yet) unrestricted_objects = ('rstat',) # not used (yet)
def getItems(self): def getItems(self):

View file

@ -1,30 +1,11 @@
# # cybertools.wiki.tracking.link
# Copyright (c) 2010 Helmut Merz helmutm@cy55.de
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
""" """ Store wiki links as tracks.
Store wiki links as tracks.
$Id$
""" """
from zope import component from zope import component
from zope.component import adapts from zope.component import adapts
from zope.interface import implementer, implements from zope.interface import implementer
from zope.traversing.api import getName, getParent from zope.traversing.api import getName, getParent
from cybertools.stateful.base import Stateful from cybertools.stateful.base import Stateful