Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add a new EveryValue tube

  • Loading branch information...
commit 00b83f7a3af20c44de3f74feda0e170e0aa0a497 1 parent 27bdb9d
@matthiask matthiask authored
Showing with 17 additions and 2 deletions.
  1. +3 −2 scaffolding/__init__.py
  2. +14 −0 scaffolding/tubes.py
View
5 scaffolding/__init__.py
@@ -7,11 +7,12 @@
from django.utils.importlib import import_module
from tubes import (Tube, Name, LoremIpsum, RandInt, Contrib, AlwaysTrue,
- AlwaysFalse, StaticValue, RandomValue, RandomInternetImage, ForeignKey)
+ AlwaysFalse, StaticValue, RandomValue, EveryValue, RandomInternetImage, ForeignKey)
__all__ = ['Tube', 'Name', 'LoremIpsum', 'RandInt', 'Contrib', 'AlwaysTrue',
- 'AlwaysFalse', 'StaticValue', 'RandomValue', 'RandomInternetImage',
+ 'AlwaysFalse', 'StaticValue', 'RandomValue', 'EveryValue',
+ 'RandomInternetImage',
'ForeignKey', 'register', 'scaffold_for_model']
View
14 scaffolding/tubes.py
@@ -113,6 +113,20 @@ def next(self):
return random.choice(self.lst)
+class EveryValue(Tube):
+ """
+ Yields values from the passed iterable in order, looping into infinity.
+ """
+ def __init__(self, values, **kwargs):
+ self.index = -1
+ self.values = list(values)
+ self.length = len(self.values)
+
+ def next(self):
+ self.index += 1
+ return self.values[self.index % self.length]
+
+
class RandomInternetImage(Tube):
""" Creates a random image for an ImageField using an internet source.
"""
Please sign in to comment.
Something went wrong with that request. Please try again.