Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

add FirstName and LastName proxies, update facebook_graph, fix crash …

…when unicode method requires complete object
  • Loading branch information...
commit 218580856b74291fc4f620ae23dc83606b5fa821 1 parent 66783ea
@sbaechler authored
View
9 README.rst
@@ -113,7 +113,10 @@ Contrib
-------
Crates a Custom Object. The backend class is the first parameter.
-The backend class has to inherit from Tube.
+The backend class has to inherit from Tube::
+
+ user = scaffolding.Contrib(FacebookTestUser, app_name='contest')
+
FacebookTestUser
----------------
@@ -123,3 +126,7 @@ If there aren't enough test users new ones are automatically created.
This requires the django-facebook-graph API.
https://github.com/feinheit/django-facebook-graph
+The module is in ``external.facebook_graph``.
+
+
+
View
6 scaffolding/__init__.py
@@ -7,12 +7,14 @@
from django.utils.importlib import import_module
from tubes import (Tube, Name, LoremIpsum, RandInt, Contrib, AlwaysTrue,
- AlwaysFalse, StaticValue, RandomValue, EveryValue, RandomInternetImage, ForeignKey)
+ AlwaysFalse, StaticValue, RandomValue, EveryValue, RandomInternetImage, ForeignKey,
+ FirstName, LastName
+ )
__all__ = ['Tube', 'Name', 'LoremIpsum', 'RandInt', 'Contrib', 'AlwaysTrue',
'AlwaysFalse', 'StaticValue', 'RandomValue', 'EveryValue',
- 'RandomInternetImage',
+ 'RandomInternetImage', 'FirstName', 'LastName',
'ForeignKey', 'register', 'scaffold_for_model']
View
16 scaffolding/external/facebook_graph.py
@@ -1,9 +1,9 @@
-""" This module still uses the master branch of the graph.
+""" This module uses the structured branch of the graph.
"""
-from facebook.api import GraphAPIError
-from facebook.models import TestUser, User
+from facebook.graph import GraphAPIError
+from facebook.fb import TestUser, User
from facebook.testusers import TestUsers
-from facebook.utils import get_app_dict, get_static_graph
+from facebook import get_app_dict, get_static_graph
from scaffolding.tubes import Tube
@@ -33,9 +33,9 @@ def set_up(self, cls, count, **kwargs):
pass
for i in range(remaining):
self.generate_new_user()
- self.user_for_testuser(testuser_list)
+ self._user_for_testuser(testuser_list)
- def user_for_testuser(self, testuser_list):
+ def _user_for_testuser(self, testuser_list):
try:
print u'Checking for Facebook Test users...:\n'
except IOError:
@@ -50,7 +50,7 @@ def user_for_testuser(self, testuser_list):
except IOError:
pass
- def generate_new_user(self):
+ def _generate_new_user(self):
newuser = self.testusers.generate_new_test_user(installed=True, permissions=['email'])
try:
print u'Generated new Testuser: %s\n' % newuser
@@ -67,7 +67,7 @@ def next(self):
if self.index == len(self.users)-1:
if self.unique:
try:
- return self.generate_new_user()
+ return self._generate_new_user()
except GraphAPIError:
raise StopIteration
else:
View
8 scaffolding/management/commands/scaffold.py
@@ -52,14 +52,16 @@ def make_factory(self, cls, count):
generator.set_up(cls, count)
fields[field_name] = generator
text.append(u'%s: %s; ' % (field_name, fields[field_name]))
-
- self.stdout.write(u'Generator for %s: %s\n' % (cls, u''.join(text)))
+ try:
+ self.stdout.write(u'Generator for %s: %s\n' % (cls, u''.join(text)))
+ except models.ObjectDoesNotExist:
+ self.stdout.write(u'Generator for %s\n' % u''.join(text))
return fields
def make_object(self, cls, fields):
obj = cls()
- self.stdout.write(u'\nCreated new %s: ' % obj)
+ self.stdout.write(u'\nCreated new %s: ' % obj.__class__.__name__)
for field_name, generator in fields.items():
# Some custom processing
View
18 scaffolding/tubes.py
@@ -69,7 +69,17 @@ def __init__(self, max_length=30, gender=None, **kwargs):
self.last_names = names.LastNames()
def next(self):
- return '%s %s'[:self.max_length] % (self.first_names.next(), self.last_names.next())
+ return u'%s %s'[:self.max_length] % (self.first_names.next(), self.last_names.next())
+
+class FirstName(Name):
+ """ Only returns first names. """
+ def next(self):
+ return u'%s'[:self.max_length] % self.first_names.next()
+
+class LastName(Name):
+ """ Only returns last names. """
+ def next(self):
+ return u'%s'[:self.max_length] % self.last_names.next()
class LoremIpsum(Tube):
@@ -120,6 +130,12 @@ def __iter__(self):
def next(self):
return self.backend.next()
+ def set_up(self, cls, count, **kwargs):
+ if hasattr(self.backend, 'set_up'):
+ self.backend.set_up(cls, count, **kwargs)
+ else:
+ pass
+
class AlwaysTrue(StaticValue):
""" Always returns True."""
Please sign in to comment.
Something went wrong with that request. Please try again.