Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add two new tubes, StaticValue and RandomValue

  • Loading branch information...
commit 23fc5de56d9c070f6675214d847559285c6a0059 1 parent e057fdc
Matthias K matthiask authored
Showing with 22 additions and 5 deletions.
  1. +3 −3 scaffolding/__init__.py
  2. +19 −2 scaffolding/tubes.py
6 scaffolding/__init__.py
View
@@ -7,12 +7,12 @@
from django.utils.importlib import import_module
from tubes import (Tube, Name, LoremIpsum, RandInt, Contrib, AlwaysTrue,
- AlwaysFalse, RandomInternetImage, ForeignKey)
+ AlwaysFalse, StaticValue, RandomValue, RandomInternetImage, ForeignKey)
__all__ = ['Tube', 'Name', 'LoremIpsum', 'RandInt', 'Contrib', 'AlwaysTrue',
- 'AlwaysFalse', 'RandomInternetImage', 'ForeignKey', 'register',
- 'scaffold_for_model']
+ 'AlwaysFalse', 'StaticValue', 'RandomValue', 'RandomInternetImage',
+ 'ForeignKey', 'register', 'scaffold_for_model']
def generic_autodiscover(module_name):
21 scaffolding/tubes.py
View
@@ -10,8 +10,7 @@ class Tube(object):
""" The base class for scaffolding objects.
"""
def __init__(self, **kwargs):
- self.count = kwargs.get('count')
- self.cls = kwargs.get('cls')
+ pass
def __iter__(self):
return self
@@ -97,6 +96,23 @@ def next(self):
return False
+class StaticValue(Tube):
+ """Always returns the same value"""
+
+ def __init__(self, value):
+ self.value = value
+ def next(self):
+ return self.value
+
+
+class RandomValue(Tube):
+ """Returns random values from the passed list"""
+ def __init__(self, lst):
+ self.lst = lst
+ def next(self):
+ return random.choice(self.lst)
+
+
class RandomInternetImage(Tube):
""" Creates a random image for an ImageField using an internet source.
"""
@@ -110,6 +126,7 @@ def next(self):
temp_image = urllib.urlretrieve(url)
return os.path.basename(url), File(open(temp_image[0]))
+
class ForeignKey(Tube):
""" Creates a foreign key assigning the queryset.
"""
Please sign in to comment.
Something went wrong with that request. Please try again.