Skip to content
Browse files

build generators

  • Loading branch information...
1 parent ef460a6 commit 469b494bd50a50b41f8072a508f6ab37cfd1a46d Simon Bächler committed
View
7 LICENCE
@@ -0,0 +1,7 @@
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+IN THE SOFTWARE.
View
6 README.rst
@@ -18,9 +18,9 @@ Create a Scaffolding class within your model which contains the callbacks to fil
...
class Scaffolding:
- first_name = scaffolding.first_name(max_length=32)
- last_name = scaffolding.last_name(max_length=32)
- comment = scaffolding.lorem(paragraphs=1)
+ first_name = scaffolding.FirstNname(max_length=32)
+ last_name = scaffolding.LastNname(max_length=32)
+ comment = scaffolding.LoremIpsum(paragraphs=1)
Run the management command to create the data::
View
66 scaffolding/__init__.py
@@ -1 +1,65 @@
-
+# -*- coding: utf-8 -*-
+import random
+from scaffolding import library
+from library.lorem_ipsum import LOREM_IPSUM
+
+class Name(object):
+ """ Generates a random name. gender can be 'male' or 'female' or 'm' or 'f'.
+ """
+ def __init__(self, max_length=30, gender=None, *args, **kwargs):
+ self.max_length = max_length
+ self.first_names = library.FirstNames(gender=gender)
+ self.last_names = library.LastNames()
+
+ def __iter__(self):
+ return self
+
+ def next(self):
+ return '%s %s'[:self.max_length] % (self.first_names.next(), self.last_names.next())
+
+
+class LoremIpsum(object):
+ """ Generates a Lorem Ipsum Text. The number of paragraphs is defined in paragraphs.
+ """
+ def __init__(self, paragraphs=7, max_length=None, text=LOREM_IPSUM, *args, **kwargs):
+ self.text = text
+ self.max_length = max_length
+ self.paragraphs = paragraphs
+ # TODO: Loop paragraphs.
+ if self.paragraphs > len(self.text):
+ raise AttributeError('The Text %s only has %s paragraphs' %(text, len(text)))
+
+ def __iter__(self):
+ return self
+
+ def next(self):
+ text = u'\n\n'.join(self.text[:self.paragraphs])
+ if self.max_length:
+ return text[:self.max_length]
+ return text
+
+
+class RandInt(object):
+ """ Generates a random integer between min and max """
+ def __init__(self, min, max, *args, **kwargs):
+ self.min = min
+ self.max = max
+
+ def __iter__(self):
+ return self
+
+ def next(self):
+ return random.randint(self.min, self.max)
+
+
+class Contrib(object):
+ """ Crates a Custom Object. The backend class is the first parameter.
+ """
+ def __init__(self, backend, *args, **kwargs):
+ self.backend = backend(*args, **kwargs)
+
+ def __iter__(self):
+ return self.backend
+
+ def next(self):
+ return self.backend.next()
View
BIN scaffolding/__init__.pyc
Binary file not shown.
View
1 scaffolding/contrib/__init__.py
@@ -0,0 +1 @@
+
View
BIN scaffolding/contrib/__init__.pyc
Binary file not shown.
View
33 scaffolding/contrib/facebook_graph.py
@@ -0,0 +1,33 @@
+""" This module still uses the master branch of the graph.
+"""
+from facebook.models import TestUser
+from facebook.testusers import TestUsers
+from facebook.utils import get_app_dict, get_static_graph
+
+
+class FacebookTestUser(object):
+ def __init__(self, app_name=None, count=None, unique=True):
+ self.app_name = app_name
+ self.count = count
+ self.unique = unique
+
+ #application = get_app_dict(self.app_name)
+ graph = get_static_graph(self.app_name)
+ testusers = TestUsers(graph)
+ self.users = testusers.get_test_users()
+ if self.count and count > len(self.users):
+ raise AttributeError('Not enough test users for app %s' % self.app_name)
+ self.index = 0
+
+ def __iter__(self):
+ return self
+
+ def next(self):
+ if self.index == len(self.users)-1:
+ if self.unique:
+ raise StopIteration
+ else:
+ self.index = 0
+ return self.users[self.index]
+ self.index += 1
+ return self.users[self.index]
View
BIN scaffolding/contrib/facebook_graph.pyc
Binary file not shown.
View
55 scaffolding/library/__init__.py
@@ -0,0 +1,55 @@
+# -*- coding: utf-8 -*-
+import random
+
+US_MALE_NAMES = ['Jacob', 'Ethan', 'Michael', 'Alexander', 'William', 'Joshua','Daniel',
+ 'Jayden', 'Noah', 'Anthony']
+US_FEMALE_NAMES = ['Isabella', 'Emma', 'Olivia', 'Sophia', 'Ava', 'Emily', 'Madison',
+ 'Abigail','Chloe', 'Mia']
+
+class FirstNames(object):
+ """ can iterate over names for the given gender.
+ """
+ def __init__(self, gender=None, male_names=US_MALE_NAMES,
+ female_names=US_FEMALE_NAMES, *args, **kwargs):
+ self.gender = gender
+ if gender in ['male', 'm']:
+ self.first_names = male_names
+ elif gender in ['female', 'f']:
+ self.first_names = female_names
+ else:
+ self.first_names = male_names + female_names
+ random.shuffle(self.first_names)
+ self.index = 0
+
+ def __iter__(self):
+ return self
+
+ def next(self):
+ # infinite iteration
+ if self.index == len(self.first_names)-1:
+ self.index = 0
+ return self.first_names[0]
+ self.index += 1
+ return self.first_names[self.index]
+
+
+GERMAN_LAST_NAMES = [u'Müller', u'Schmid', u'Schneider', u'Fischer', u'Weber', u'Meyer',
+ u'Wagner', u'Becker', u'Schutz', u'Hoffmann', u'Schäfer',
+ u'Koch', u'Bauer', u'Richter']
+
+class LastNames(object):
+ """ Keeps returning last names
+ """
+ def __init__(self, last_names=GERMAN_LAST_NAMES, *args, **kwargs):
+ self.last_names = last_names
+ self.index = 0
+
+ def __iter__(self):
+ return self
+
+ def next(self):
+ if self.index == len(self.last_names)-1:
+ self.index = 0
+ return self.last_names[0]
+ self.index += 1
+ return self.last_names[self.index]
View
BIN scaffolding/library/__init__.pyc
Binary file not shown.
View
8 scaffolding/library/lorem_ipsum.py
@@ -0,0 +1,8 @@
+LOREM_IPSUM = ["Lorem ipsum dolor sit amet, consectetur adipisici elit, sed eiusmod tempor incidunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquid ex ea commodi consequat. Quis aute iure reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint obcaecat cupiditat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.",
+ "Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.",
+ "Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi.",
+ "Nam liber tempor cum soluta nobis eleifend option congue nihil imperdiet doming id quod mazim placerat facer possim assum. Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat.",
+ "Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis.",
+ "At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, At accusam aliquyam diam diam dolore dolores duo eirmod eos erat, et nonumy sed tempor et et invidunt justo labore Stet clita ea et gubergren, kasd magna no rebum. sanctus sea sed takimata ut vero voluptua. est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat.",
+ "Consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet."]
+
View
BIN scaffolding/library/lorem_ipsum.pyc
Binary file not shown.
View
1 scaffolding/management/__init__.py
@@ -0,0 +1 @@
+
View
1 scaffolding/management/commands/__init__.py
@@ -0,0 +1 @@
+

0 comments on commit 469b494

Please sign in to comment.
Something went wrong with that request. Please try again.