예제 #1
0
파일: model.py 프로젝트: devkhan/SDK
    def __init__(self, c_id):
        inst = utils.Database().biodb.find_one({"_id": ObjectId(c_id)})
        self.k = False

        if inst is not None:
            self.k = True
            self._meta = inst
예제 #2
0
파일: model.py 프로젝트: devkhan/SDK
    def add(self, software_name, tags, primary_link, one_liner, paid, primary_ref = "N.A", remarks = "N.A", meta = None):
        """
        Adds the software into the Database. Any additional properties should
        only be added into `meta`.
        """
        if all([
            type(software_name) is str,
            type(tags) is list,
            type(primary_link) is str,
            type(one_liner) is str,
            type(paid) is bool,
            type(primary_ref) is str,
            type(remarks) is str,
            type(meta) is dict or meta is None
        ]):
            sw = {
                "software_name": software_name,
                "tags": tags,
                "primary_link": primary_link,
                "one_liner": one_liner,
                "paid": paid,
                "primary_ref": primary_ref,
                "remarks": remarks,
                "meta": meta
            }

            # Add document to collection and return the objectId.
            return utils.Database().biodb.insert_one(sw).inserted_id

        return False
예제 #3
0
파일: model.py 프로젝트: devkhan/SDK
 def __init__(self, user_name):
     """
     Initializes the Instance Object. Its status should be checked through the
     property `k`.
     """
     if _Utils.user_exists(user_name) is False:
         self.k = False
         return None
     self.k = True
     self.udb = utils.Database().user
     self._user_dat = self.udb.find_one({"user_name": user_name})
     self._updates = set()
예제 #4
0
파일: model.py 프로젝트: devkhan/SDK
    def update(
        self,
        software_id,
        software_name = None,
        primary_link = None,
        one_liner = None,
        paid = None,
        primary_ref = None,
        remarks = None,
        meta = None
        ):

        update = {}

        def __update_macro(key, val, _type):
            if all([
                val is not None,
                type(val) is _type
            ]):
                update[key] = val

        __update_macro('software_name', software_name, str)
        __update_macro('primary_link', primary_link, str)
        __update_macro('one_liner', one_liner, str)
        __update_macro('paid', paid, bool)
        __update_macro('primary_ref', primary_ref, str)
        __update_macro('remarks', remarks, str)
        __update_macro('meta', meta, dict)

        if len(update) is not 0:
            utils.Database().biodb.update(
                {'_id': ObjectId(software_id)},
                {'$set': update},
                upsert = False,
                multi = False
            )
            return True

        return False
예제 #5
0
파일: model.py 프로젝트: devkhan/SDK
    def add(user_name, password, confirm_password, email_id):
        """Adds the User into Database."""
        errors = []

        if _Utils.validate_username(user_name) is False:
            errors.append("BadUserName")

        if _Utils.validate_email(email_id) is False:
            errors.append("BadEmailID")

        if _Utils.validate_password(password) is False:
            errors.append("ShortPassword")

        if _Utils.user_exists(user_name):
            errors.append("UsernameExist")

        if _Utils.email_exists(email_id):
            errors.append("EmailExist")

        if password != confirm_password:
            errors.append("PasswordNoMatch")

        if len(errors) is not 0:
            return (False, errors)
        else:
            user = {
                'user_name': user_name,
                'pswd': Password.get_hashed_password(password),
                'email': email_id,
                'status': 1,
                'meta': {
                    'added': datetime.datetime.utcnow()
                }
            }

            utils.Database().user.insert_one(user).inserted_id

            return (True, )
예제 #6
0
파일: model.py 프로젝트: devkhan/SDK
 def search(self, query_string):
     results = utils.Database().biodb.find({"cell_name":{"$regex": query_string}})
     serialized_results = [json.dumps(result, default=json_util.default, separators=(',', ':')) for result in results]
     results = utils.Database().biodb.find({"function":{"$regex": query_string}})
     serialized_results = [json.dumps(result, default=json_util.default, separators=(',', ':')) for result in results]
     return serialized_results
예제 #7
0
파일: model.py 프로젝트: devkhan/SDK
 def delete(self, cell_id):
     "Deletes a software from Database."
     return utils.Database().biodb.remove({"_id": ObjectId(cell_id)})['n'] > 0
예제 #8
0
파일: model.py 프로젝트: devkhan/SDK
 def email_exists(email_id):
     """
     Checks if the Email exists in Database.
     """
     return utils.Database().user.find_one({"email": email_id})
예제 #9
0
파일: model.py 프로젝트: devkhan/SDK
 def user_exists(user_name):
     """
     Checks if the User exists in Database.
     """
     return utils.Database().user.find_one({"user_name":
                                            user_name}) is not None