Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Move FirstNames and LastNames into their own library module for inter…

…nal consistency
  • Loading branch information...
commit 829ac1ee2d2964c1f7357bea478929a2e40c4c2d 1 parent f94ff40
Matthias K matthiask authored
49 scaffolding/library/__init__.py
View
@@ -1,50 +1 @@
-# -*- 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
- self.length = len(self.first_names)
-
- def __iter__(self):
- return self
-
- def next(self):
- self.index += 1
- return self.first_names[self.index % self.length]
-
-
-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
- self.length = len(self.last_names)
-
- def __iter__(self):
- return self
-
- def next(self):
- self.index += 1
- return self.last_names[self.index % self.length]
50 scaffolding/library/names.py
View
@@ -0,0 +1,50 @@
+# -*- 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
+ self.length = len(self.first_names)
+
+ def __iter__(self):
+ return self
+
+ def next(self):
+ self.index += 1
+ return self.first_names[self.index % self.length]
+
+
+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
+ self.length = len(self.last_names)
+
+ def __iter__(self):
+ return self
+
+ def next(self):
+ self.index += 1
+ return self.last_names[self.index % self.length]
13 scaffolding/tubes.py
View
@@ -1,9 +1,10 @@
+from __future__ import absolute_import
+
import os
import random
-import gc
-from scaffolding import library
-from library.lorem_ipsum import LOREM_IPSUM
import urllib
+
+from library import lorem_ipsum, names
from django.core.files import File
class Tube(object):
@@ -57,8 +58,8 @@ class Name(Tube):
def __init__(self, max_length=30, gender=None, **kwargs):
super(Name, self).__init__(**kwargs)
self.max_length = max_length
- self.first_names = library.FirstNames(gender=gender)
- self.last_names = library.LastNames()
+ self.first_names = names.FirstNames(gender=gender)
+ self.last_names = names.LastNames()
def next(self):
return '%s %s'[:self.max_length] % (self.first_names.next(), self.last_names.next())
@@ -67,7 +68,7 @@ def next(self):
class LoremIpsum(Tube):
""" Generates a Lorem Ipsum Text. The number of paragraphs is defined in paragraphs.
"""
- def __init__(self, paragraphs=7, max_length=None, text=LOREM_IPSUM, **kwargs):
+ def __init__(self, paragraphs=7, max_length=None, text=lorem_ipsum.LOREM_IPSUM, **kwargs):
super(LoremIpsum, self).__init__(**kwargs)
self.text = text
self.max_length = max_length
Please sign in to comment.
Something went wrong with that request. Please try again.