class QSub(Document): name = StringField() dbname = get_mongo_dbname_from_collection("qsub") if dbname: meta = {'allow_inheritance': True, 'db_alias': dbname} @classmethod def remove(cls, name): element = cls.find(name) element.delete() @classmethod def find(cls, name): try: return cls.objects(name=name)[0] except: None @classmethod def reset(cls): for element in cls.objects: element.delete() @classmethod def connect(cls): get_mongo_db("qsub", DBConnFactory.TYPE_MONGOENGINE)
class ExperimentGroup(Document): name = StringField(required=True) userid = StringField(required=True) description = StringField(max_length=50) tags = ListField(StringField(max_length=30)) dbname = get_mongo_dbname_from_collection("experiment") if dbname: meta = {'db_alias': dbname}
class ExperimentBase(Document): cm_kind = StringField(default="experiment") cm_label = StringField() cm_userid = StringField() dbname = get_mongo_dbname_from_collection("experiment") if dbname: meta = {'allow_inheritance': True, 'db_alias': dbname} else: meta = {'allow_inheritance': True}
class GroupItem(Document): group = ReferenceField(ExperimentGroup, reverse_delete_rule=CASCADE) tags = ListField(StringField(max_length=30)) comments = ListField(EmbeddedDocumentField(Comment)) dbname = get_mongo_dbname_from_collection("experiment") if dbname: meta = {'allow_inheritance': True, 'db_alias': dbname} else: meta = {'allow_inheritance': True}
def __init__(self): config = ConfigDict(filename=config_file("/cloudmesh_server.yaml")) port = config['cloudmesh']['server']['mongo']['port'] # db = connect('manage', port=port) self.users = User.objects() dbname = get_mongo_dbname_from_collection("manage") if dbname: meta = {'db_alias': dbname}
def __init__(self): config = ConfigDict(filename=config_file("/cloudmesh_server.yaml")) port = config["cloudmesh"]["server"]["mongo"]["port"] # db = connect('manage', port=port) self.users = User.objects() dbname = get_mongo_dbname_from_collection("manage") if dbname: meta = {"db_alias": dbname}
class Project(CloudmeshObject): # named connection (not 'default') dbname = get_mongo_dbname_from_collection("manage") if dbname: meta = {'db_alias': dbname} ''' The project object with its fields. The current fields include Attributes: title abstract intellectual_merit broader_impact use_of_fg scale_of_use categories keywords primary_discipline orientation contact url comment active projectid status lead managers members alumnis grant_orgnization grant_id grant_url results aggreement_use aggreement_slides aggreement_support aggreement_sotfware aggreement_documentation comments join_open join_notification resources_services resources_software resources_clusters resources_provision ''' # ------------------------------------------------------------------- # Project Information # ------------------------------------------------------------------- title = StringField(required=REQUIRED) # ------------------------------------------------------------------- # Project Vocabulary # ------------------------------------------------------------------- categories = ListField(StringField(choices=CATEGORY), required=REQUIRED) keywords = ListField(StringField(), required=REQUIRED) # ------------------------------------------------------------------- # Project Contact # ------------------------------------------------------------------- # lead_institutional_role = StringField(choices=INSTITUTE_ROLE, required=REQUIRED) lead = ReferenceField(User) managers = ListField(StringField()) members = ListField(ReferenceField(User)) alumnis = ListField(StringField()) contact = StringField(required=REQUIRED) # active_members = lead u managers u members - alumnis # if not active : active_members = None # ------------------------------------------------------------------- # Project Details # ------------------------------------------------------------------- orientation = StringField(required=REQUIRED) primary_discipline = StringField(choices=DISCIPLINE, required=REQUIRED) abstract = StringField(required=REQUIRED) intellectual_merit = StringField(required=REQUIRED) broader_impact = StringField(required=REQUIRED) url = URLField(required=REQUIRED) results = StringField() # ------------------------------------------------------------------- # Agreements # ------------------------------------------------------------------- agreement_use = BooleanField() agreement_slides = BooleanField() agreement_support = BooleanField() agreement_software = BooleanField() agreement_documentation = BooleanField() # ------------------------------------------------------------------- # Grant Information # ------------------------------------------------------------------- grant_organization = StringField(choices=GRANT_ORG) grant_id = StringField() grant_url = URLField() # ------------------------------------------------------------------- # Resources # ------------------------------------------------------------------- resources_services = ListField( StringField(choices=SERVICES), required=REQUIRED) resources_software = ListField( StringField(choices=SOFTWARE), required=REQUIRED) resources_clusters = ListField( StringField(choices=CLUSTERS), required=REQUIRED) resources_provision = ListField( StringField(choices=PROVISIONING), required=REQUIRED) comment = StringField() use_of_fg = StringField(required=REQUIRED) scale_of_use = StringField(required=REQUIRED) # ------------------------------------------------------------------- # Other # ------------------------------------------------------------------- comments = StringField() # ------------------------------------------------------------------- # Project Membership Management # ------------------------------------------------------------------- join_open = BooleanField() join_notification = BooleanField() # ------------------------------------------------------------------- # Location # ------------------------------------------------------------------- loc_name = StringField() loc_street = StringField() loc_additional = StringField() loc_state = StringField() loc_country = StringField() # example search in a list field # Project.objects(categories__contains='education') active = BooleanField(required=REQUIRED) projectid = UUIDField() status = StringField(choices=STATUS, required=REQUIRED) # maybe we do not need active as this may be covered in status # ------------------------------------------------------------------- # Project Comittee: contains all the information about the projects committee # ------------------------------------------------------------------- # comittee = ReferenceField(Committee) # BUG how can we add also arbitray info in case of other, mabe ommit # choices def to_json(self): """prints the project as a json object""" d = { "title": self.title, "abstract": self.abstract, "intellectual_merit": self.intellectual_merit, "broader_impact": self.broader_impact, "use_of_fg": self.use_of_fg, "scale_of_use": self.scale_of_use, "categories": self.categories, "keywords": self.keywords, "primary_discipline": self.primary_discipline, "orientation": self.orientation, "contact": self.contact, "url": self.url, "active": self.active, "status": self.status, "lead": self.lead, "members": self.members, "resources_services": self.resources_services, "resources_software": self.resources_software, "resources_clusters": self.resources_clusters, "resources_provision": self.resources_provision } return d def __str__(self): ''' printing the object as a string ''' d = self.to_json() return str(d)
class Comment(EmbeddedDocument): content = StringField() name = StringField(max_length=120) dbname = get_mongo_dbname_from_collection("experiment") if dbname: meta = {'db_alias': dbname}
class User(CloudmeshObject): """ This class is used to represent a Cloudmesh User """ dbname = get_mongo_dbname_from_collection("manage") if dbname: meta = {'db_alias': dbname} # # defer the connection to where the object is instantiated # get_mongo_db("manage", DBConnFactory.TYPE_MONGOENGINE) """ User fields """ username = StringField(required=True) email = EmailField(required=True) password = StringField(required=True) confirm = StringField(required=True) title = StringField(required=True) firstname = StringField(required=True) lastname = StringField(required=True) phone = StringField(required=True) url = StringField(required=True) citizenship = StringField(required=True) bio = StringField(required=True) institution = StringField(required=True) institutionrole = StringField(required=True) department = StringField(required=True) address = StringField(required=True) advisor = StringField(required=True) country = StringField(required=True) """ Hidden fields """ status = StringField(required=True, default='pending') userid = UUIDField() projects = StringField() """ Message received from either reviewers, committee or other users. It is a list because there might be more than one message """ message = ListField(StringField()) def order(self): """ Order the attributes to be printed in the display method """ try: return [ ("username", self.username), ("status", self.status), ("title", self.title), ("firstname", self.firstname), ("lastname", self.lastname), ("email", self.email), ("url", self.url), ("citizenship", self.citizenship), ("bio", self.bio), ("password", self.password), ("phone", self.phone), ("projects", self.projects), ("institution", self.institution), ("department", self.department), ("address", self.address), ("country", self.country), ("advisor", self.advisor), ("date_modified", self.date_modified), ("date_created", self.date_created), ("date_approved", self.date_approved), ("date_deactivated", self.date_deactivated), ] except: return None @classmethod def hidden(cls): """ Hidden attributes """ return [ "userid", "active", "message", ] # def save(self,db): # db.put({"firname":user.firname,...}) def is_active(self): ''' check if the user is active ''' """finds if a user is active or not""" d1 = datetime.datetime.now() return (self.active and (datetime.datetime.now() < self.date_deactivate)) @classmethod def set_password(cls, password): ''' not implemented :param password: :type password: ''' # self.password_hash = generate_password_hash(password) pass @classmethod def check_password(cls, password): ''' not implemented :param password: :type password: ''' # return check_password_hash(self.password_hash, password) pass def json(self): ''' returns a json representation of the object ''' """prints the user as a json object""" d = {} for (field, value) in self.order(): try: d[field] = value except: pass return d def yaml(self): ''' returns the yaml object of the object. ''' """prints the user as a json object""" return self.__str__(fields=True, all=True) """
class Committee(Document): status = StringField(choices=STATUS) projects = ListField(StringField()) reviewers = ListField(ReferenceField(User), default=[]) reviews = StringField() # -------------------------------------------------------------------- # Default value showing if this is the first time the project is being applied for or not # -------------------------------------------------------------------- default = StringField(choices=CHOICES, default='Yes') message = StringField() dbname = get_mongo_dbname_from_collection("manage") if dbname: meta = {'db_alias': dbname} def __str__(self): return "{0} {1} {2} {3}".format(self.status, self.reviewers) def set_committee(self): pass def get_project(self, title): """This function wold be deleted later after we have been able call this class from the project class, hence this is a sample""" _project = projects.find_by_title("Django") def get_reviewer(self, user_name): """This function adds reviewers to the project committee. It first checks if the default attribute is 'Yes' or 'No', if 'Yes' it adds the default reviewers and if 'No' it does otherwise""" if self.default == 'Yes': for _username in DEFAULT_REVIEWERS: default_reviewer = users.find_user(_username) self.add_reviewers(default_reviewer) self.default == 'No' elif self.default == 'No': _reviewer = users.find_user(user_name) self.add_reviewers(_reviewer) def add_reviewers(self, user): """This function adds users to the reviewers list""" self.reviewers.append(user) def set_review(self, project, user, msg): """by set_review, do you mean to state whether approved or not and what type of message am I meant to pass into this function""" IMPLEMENT() def delete_reviewer(self, project, user): """This function accepts a user and removes the user from the committee list""" self.reviewers.remove(user) def notify_project_management(self, project, msg): IMPLEMENT() def notify_project_members(self, project, msg): IMPLEMENT() def notify_project_alumni(self, project, msg): IMPLEMENT() def notify_reviewers(self, project, msg): IMPLEMENT() def notify_all_reviewers(self, msg): IMPLEMENT() def enable(self, bool): """enables or disables reviews, useful for maintenance""" IMPLEMENT() def pending_projects(self): return self.get_by_status("pending") def approved_projects(self): return self.get_by_status("approved") def disproved_projects(self): return self.get_by_status("disproved") def completed_projects(self): return self.get_by_status("completed") def get_by_status(self, status): if status in STATUS: IMPLEMENT() else: print "ERROR: wrong status", status return None