working on lists in python
Posted
by owca
on Stack Overflow
See other posts from Stack Overflow
or by owca
Published on 2010-04-09T22:16:12Z
Indexed on
2010/04/09
22:43 UTC
Read the original article
Hit count: 337
I'm trying to make a small modification to django lfs project, that will allow me to deactivate products with no stocks. Unfortunatelly I'm just beginning to learn python, so I have big trouble with its syntax. That's what I'm trying to do. I'm using method 'has_variants' which returns true if product has any. Then I'm building a list from variants for this product. Next for every product in this list (I've called it 'set') I check it's stock and set bool variable 'inactive' to true if product has no stocks and to false if there are any. Finally if 'inactive' is false I'm setting self.active to 0. Code fails in line with:
set[] = s
How to correct it ?
def deactivate(self):
"""If there are no stocks, deactivate the product. Used in last step of checkout.
"""
if self.has_variants():
for s in self.variants.filter(active=True):
set[] = s
for var in set:
if var.get_stock_amount() == 0:
inactive = True
else:
inactive = False
else:
if self.get_stock_amount() == 0:
inactive = True
if inactive:
self.active = False
return 0
error log :
Traceback (most recent call last):
File "manage.py", line 11, in <module>
execute_manager(settings)
File "/home/purplecow/rails/purpledev/site-packages/django/core/management/__i nit__.py", line 362, in execute_manager
utility.execute()
File "/home/purplecow/rails/purpledev/site-packages/django/core/management/__i nit__.py", line 303, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/purplecow/rails/purpledev/site-packages/django/core/management/bas e.py", line 195, in run_from_argv
self.execute(*args, **options.__dict__)
File "/home/purplecow/rails/purpledev/site-packages/django/core/management/bas e.py", line 213, in execute
translation.activate('en-us')
File "/home/purplecow/rails/purpledev/site-packages/django/utils/translation/_ _init__.py", line 73, in activate
return real_activate(language)
File "/home/purplecow/rails/purpledev/site-packages/django/utils/translation/_ _init__.py", line 43, in delayed_loader
return g['real_%s' % caller](*args, **kwargs)
File "/home/purplecow/rails/purpledev/site-packages/django/utils/translation/t rans_real.py", line 205, in activate
_active[currentThread()] = translation(language)
File "/home/purplecow/rails/purpledev/site-packages/django/utils/translation/t rans_real.py", line 194, in translation
default_translation = _fetch(settings.LANGUAGE_CODE)
File "/home/purplecow/rails/purpledev/site-packages/django/utils/translation/t rans_real.py", line 180, in _fetch
app = import_module(appname)
File "/home/purplecow/rails/purpledev/site-packages/django/utils/importlib.py" , line 35, in import_module
__import__(name)
File "/home/purplecow/rails/purpledev/lfs/caching/__init__.py", line 1, in <mo dule>
from listeners import *
File "/home/purplecow/rails/purpledev/lfs/caching/listeners.py", line 10, in < module>
from lfs.cart.models import Cart
File "/home/purplecow/rails/purpledev/lfs/cart/models.py", line 8, in <module>
from lfs.catalog.models import Product
File "/home/purplecow/rails/purpledev/lfs/catalog/__init__.py", line 1, in <mo dule>
from listeners import *
File "/home/purplecow/rails/purpledev/lfs/catalog/listeners.py", line 5, in <m odule>
from lfs.catalog.models import PropertyGroup
File "/home/purplecow/rails/purpledev/lfs/catalog/models.py", line 589
set[] = s
^
SyntaxError: invalid syntax
© Stack Overflow or respective owner