Skip to content

Instantly share code, notes, and snippets.

@ntoll
Created June 7, 2011 15:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ntoll/1012469 to your computer and use it in GitHub Desktop.
Save ntoll/1012469 to your computer and use it in GitHub Desktop.
Dynamic creation of tags for a FOM class
# 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