Exemplo n.º 1
0
 def addTermToTaxonomy(term, taxonomy, description=None, parent_id=0):
     """
     Add a Term to a Taxonomy by creating and adding a TaxonomyTerm to the DB
     Arguments:
         term - a Term object, the term you want to add to the taxonomy
         taxonomy - a Taxonomy object, the taxonomy you want to add the term to
         description - a unicode string, the description of the term in the context
         [parent_id] - an integer, the id of the parent TaxonomyTerm object
     Returns:
         taxonomy - the Taxonomy object with the newly added TaxonomyTerm
     """
     taxonomy_term = taxonomy_model.TaxonomyTerm()
     taxonomy_term.term_id = term.id
     taxonomy_term.taxonomy_id = taxonomy.id
     if not description:
         description = term.name + " " + taxonomy.name
     taxonomy_term.description = description
     taxonomy_term.parent_id = parent_id
     db_add(taxonomy_term)
     return taxonomy
Exemplo n.º 2
0
 def addUser(email, hashed_password, first_name, last_name, image_url=None):
     """
     Create and add a User to the DB.  Also creates Email/Credential pairs.
     Arguments:
         email - a unicode string, the email address of the user you wish to add
         hashed_password - a unicode string, the password hash string, hashed with bcrypt
         first_name - a unicode string, the user's first name
         last_name - a unicode string, the user's last name
         [image_url] - a unicode string, the URL of the user's image picture (Usually a CDN URL) [None]
     Returns:
         user - a User, the newly created User
                 None on failure
     Notes:
         There is no additional business logic.
         A controller/call should check the following independenly:
             - is the email address valid?
             - does the email address already exist?
     """
     # Create the credentials
     usercred = UserPrivateDAL.createUserCredentials(email)
     db_add(usercred, commit=False)
     # Create the user, hooking the credentials in
     user = UserPrivateDAL.createUser(usercred.id, first_name, last_name, image_url)
     db_add(user, commit=False)
     # Tie the user to a password now
     user_passwd = UserPrivateDAL.createUserPassword(user.id, hashed_password)
     db_add(user_passwd, commit=False)
     db.session.commit()
     return user
Exemplo n.º 3
0
 def addRole(role_name):
     """
     Create a new role and add it to the DB for use System wide.
     These roles should also be replicated in the __init__ role dictionary.
     Arguments:
         role_name - a string, the name of the Role you want to create (eg: admin, author, user)
     Returns:
         role - a Role object, the freshly created and persisted role
     Notes:
         There is no additional business logic/sanity check to see if the role exists
         If it does, a unique constraint exception will be thrown
     """
     role = UserPrivateDAL.createRole(role_name)
     return db_add(role)
Exemplo n.º 4
0
 def addTaxonomy(name):
     """
     """
     taxonomy = TaxonomyPrivateDAL.createTaxonomy(name)
     return db_add(taxonomy)
Exemplo n.º 5
0
 def addTerm(name):
     """
     """
     term = TaxonomyPrivateDAL.createTerm(name)
     return db_add(term)
Exemplo n.º 6
0
 def addWork(post_id, subtitle, summary, cover_image_url=None, meta_data=None):
     """
     """
     work = PostPrivateDAL.createWork(post_id, subtitle, summary, cover_image_url, meta_data)
     return db_add(work)
Exemplo n.º 7
0
 def addPost(author_id, title, excerpt, content, status, comment_status, password):
     """
     """
     post = PostPrivateDAL.createPost(author_id, title, excerpt, content, status, comment_status, password)
     return db_add(post)