fix UID handling in commerce
This commit is contained in:
parent
968aeab42a
commit
2cbd4c11d3
5 changed files with 27 additions and 82 deletions
|
@ -84,16 +84,16 @@ A cart is just a collection of order items belonging to a certain customer
|
|||
>>> orderItems = manager.orderItems
|
||||
|
||||
>>> 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)
|
||||
[<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
|
||||
<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)
|
||||
<OrderItem [4, 2, 7, '... ...', -1]: {'quantity': 1, 'shop': 0}>
|
||||
<OrderItem ['4', 2, '7', '... ...', '???']: {'quantity': 1, 'shop': '0'}>
|
||||
|
||||
>>> len(orderItems.getCart(c001))
|
||||
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.
|
||||
|
||||
>>> 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))
|
||||
2
|
||||
|
||||
|
@ -127,4 +127,4 @@ retrieving the order items.
|
|||
>>> orderItems.getCart(c001)
|
||||
[]
|
||||
>>> orderItems.getCart(c001, ord001)
|
||||
[<OrderItem [4, 2, 7, '... ...', 11]: {'quantity': 2, 'shop': 0}>]
|
||||
[<OrderItem ['4', 2, '7', '... ...', '11']: {'quantity': 2, 'shop': '0'}>]
|
||||
|
|
|
@ -1,26 +1,7 @@
|
|||
#-*- coding: UTF-8 -*-
|
||||
#
|
||||
# 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
|
||||
#
|
||||
# cybertools.commerce.common
|
||||
|
||||
"""
|
||||
Common functionality.
|
||||
|
||||
$Id$
|
||||
""" Common functionality.
|
||||
"""
|
||||
|
||||
from zope import component
|
||||
|
@ -147,10 +128,12 @@ class FloatValue(float):
|
|||
def getUidForObject(obj, intIds=None):
|
||||
if intIds is None:
|
||||
intIds = component.getUtility(IIntIds)
|
||||
return intIds.getId(obj)
|
||||
return str(intIds.getId(obj))
|
||||
|
||||
def getObjectForUid(uid, intIds=None):
|
||||
if intIds is None:
|
||||
intIds = component.getUtility(IIntIds)
|
||||
if isinstance(uid, str) and isdigit(uid):
|
||||
uid = int(uid)
|
||||
return intIds.getObject(uid)
|
||||
|
||||
|
|
|
@ -96,7 +96,7 @@ class OrderItems(object):
|
|||
criteria['runId'] = criteria.pop('run')
|
||||
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)
|
||||
existing = self.getCart(party, order, shop, run, product=product)
|
||||
options = kw.get('options')
|
||||
|
@ -114,7 +114,7 @@ class OrderItems(object):
|
|||
self.context.indexTrack(0, track, 'order')
|
||||
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:
|
||||
kw['run'] = run
|
||||
result = self.query(party=party, order=order, **kw)
|
||||
|
|
|
@ -1,35 +1,17 @@
|
|||
#
|
||||
# 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
|
||||
#
|
||||
# cybertools.pyscript.script
|
||||
|
||||
""" Simple implementation of Python scripts.
|
||||
|
||||
$Id$
|
||||
"""
|
||||
|
||||
import os, re
|
||||
import compiler.pycodegen
|
||||
from cStringIO import StringIO
|
||||
from io import StringIO
|
||||
from persistent import Persistent
|
||||
import RestrictedPython.RCompile
|
||||
from RestrictedPython.SelectCompiler import ast
|
||||
from zope.app.container.btree import BTreeContainer
|
||||
from zope.app.container.contained import Contained
|
||||
from zope.interface import implements
|
||||
from zope.interface import implementer
|
||||
from zope.proxy import removeAllProxies
|
||||
from zope.security.untrustedpython.builtins import SafeBuiltins
|
||||
from zope.security.untrustedpython.rcompile import RestrictionMutator as BaseRM
|
||||
|
@ -84,12 +66,11 @@ class RestrictionMutator(BaseRM):
|
|||
[node.expr, ast.Const(node.attrname)])
|
||||
|
||||
|
||||
@implementer(IPythonScript)
|
||||
class PythonScript(Contained, Persistent):
|
||||
"""Persistent Python Page - Content Type
|
||||
"""
|
||||
|
||||
implements(IPythonScript)
|
||||
|
||||
_v_compiled = None
|
||||
|
||||
title = u''
|
||||
|
@ -178,13 +159,13 @@ class Function(object):
|
|||
lines = []
|
||||
if parameters:
|
||||
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')
|
||||
for line in source.splitlines():
|
||||
lines.append(' ' + line)
|
||||
lines.append('script_result = dummy()')
|
||||
source = '\n'.join(lines)
|
||||
#print '*** source:', source
|
||||
#print('*** source:', source)
|
||||
self.code = compile(source, filename, 'exec')
|
||||
|
||||
def __call__(self, args, globals):
|
||||
|
@ -192,21 +173,21 @@ class Function(object):
|
|||
for idx, p in enumerate(self.parameters):
|
||||
# TODO: handle parameters with default values like ``attr=abc``
|
||||
globals[p] = args[idx]
|
||||
exec self.code in globals, None
|
||||
exec(self.code, globals, None)
|
||||
|
||||
|
||||
def _print_usrc(match):
|
||||
string = match.group(3)
|
||||
raw = match.group(2)
|
||||
if raw:
|
||||
return match.group(1)+'print '+`string`
|
||||
return match.group(1)+'print '+match.group(3).encode('unicode-escape')
|
||||
#return match.group(1)+'print '+`string`
|
||||
return match.group(1) + 'print(' + eval('string') + ')'
|
||||
return match.group(1) + 'print(' + match.group(3).encode('unicode-escape') + ')'
|
||||
|
||||
|
||||
@implementer(IScriptContainer)
|
||||
class ScriptContainer(BTreeContainer):
|
||||
|
||||
implements(IScriptContainer)
|
||||
|
||||
unrestricted_objects = ('rstat',) # not used (yet)
|
||||
|
||||
def getItems(self):
|
||||
|
|
|
@ -1,30 +1,11 @@
|
|||
#
|
||||
# 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
|
||||
#
|
||||
# cybertools.wiki.tracking.link
|
||||
|
||||
"""
|
||||
Store wiki links as tracks.
|
||||
|
||||
$Id$
|
||||
""" Store wiki links as tracks.
|
||||
"""
|
||||
|
||||
from zope import component
|
||||
from zope.component import adapts
|
||||
from zope.interface import implementer, implements
|
||||
from zope.interface import implementer
|
||||
from zope.traversing.api import getName, getParent
|
||||
|
||||
from cybertools.stateful.base import Stateful
|
||||
|
|
Loading…
Add table
Reference in a new issue