Created
June 7, 2011 15:24
-
-
Save ntoll/1012469 to your computer and use it in GitHub Desktop.
Dynamic creation of tags for a FOM class
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Untested and the result of a brain dump | |
from fom.mapping import Object, tag_value | |
# the list of users I'm interested in | |
users = ['ntoll', 'gridaphobe', 'terrycojones', 'jkakar', ] | |
# they all should have a username/foo/bar tag | |
path_template = '%s/foo/bar' | |
# the dict will have the key (for attribute name) and tag_value (for the tag) | |
userTags = {} | |
# the inevitable iteration | |
for user in users: | |
# you could create the tags here if they don't exist already and | |
# assuming you have privs | |
userTags[user] = tag_value(path_template % user) | |
# dynamically create the class | |
myCustomClass = type('fom_class', (Object, ), userTags) | |
# instantiate it | |
x = myCustomClass(about='foo') | |
x.ntoll = "this" # ntoll/foo/bar = "this" | |
x.gridaphobe = "should" # gridaphobe/foo/bar = "should" | |
x.terrycojones = "just" # etc... | |
x.jkakar = "work!" | |
# push to fluidinfo | |
x.save() # famous last words ;-) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment