예제 #1
0
 def update(self,
            title=None,
            author=None,
            publisher=None,
            copies=None,
            available=None):
     if title and not valid_name(title):
         return 'invalid title'
     if author and not valid_name(author):
         return 'invalid author'
     if publisher and not valid_name(publisher):
         return 'invalid publisher'
     if not isinstance(copies, int):
         return 'invalid copies no.'
     edits = {}
     edits['title'] = title if title else self.title
     edits['author'] = author if author else self.author
     edits['publisher'] = publisher if publisher else self.publisher
     edits['copies'] = copies if isinstance(copies, int) else self.copies
     edits['available'] = available if isinstance(available,
                                                  bool) else self.available
     with self.session() as session:
         entity = session.query(type(self)).filter(type(self).id == self.id)
         entity.update(edits)
         session.commit()
         session.expunge_all()
         return self
예제 #2
0
파일: models.py 프로젝트: oversoul/MeX-LMS
 def add(self,
         title=None,
         author=None,
         cat_id=None,
         cat_order=None,
         state=None,
         copies=None,
         available=None):
     cat_name = None
     cat_custom_id = None
     if not title:  # valid_name(title):
         return translate('dbModels', 'invalid title')
     if author and not valid_name(author):
         return translate('dbModels', 'invalid author')
     if cat_id:
         cat = Cat.by_id(cat_id)
         if not cat:
             return translate('dbModels', 'invalid category')
         cat_name = cat.name
         cat_custom_id = cat.custom_id
     if not isinstance(copies, int):
         return translate('dbModels', 'invalid copies no.')
     if not isinstance(available, bool):
         return translate('dbModels', 'invalid available value')
     # code to validate arguments
     new = self(title=title,
                author=author,
                cat_id=cat_id,
                cat_name=cat_name,
                cat_custom_id=cat_custom_id,
                cat_order=cat_order,
                state=state,
                copies=copies,
                available=available)
     return new.put()
예제 #3
0
파일: models.py 프로젝트: elshobaky/MeX-LMS
 def add(self, title=None, author=None,
         cat_id=None, cat_order=None, state=None,
         copies=None, available=None):
     cat_name = None
     cat_custom_id = None
     if not title:  # valid_name(title):
         return translate('dbModels', 'invalid title')
     if author and not valid_name(author):
         return translate('dbModels', 'invalid author')
     if cat_id:
         cat = Cat.by_id(cat_id)
         if not cat:
             return translate('dbModels', 'invalid category')
         cat_name = cat.name
         cat_custom_id = cat.custom_id
     if not isinstance(copies, int):
         return translate('dbModels', 'invalid copies no.')
     if not isinstance(available, bool):
         return translate('dbModels', 'invalid available value')
     # code to validate arguments
     new = self(title=title, author=author,
                cat_id=cat_id, cat_name=cat_name,
                cat_custom_id=cat_custom_id, cat_order=cat_order,
                state=state, copies=copies, available=available)
     return new.put()
예제 #4
0
파일: models.py 프로젝트: oversoul/MeX-LMS
 def update(self,
            title=None,
            author=None,
            cat_id=None,
            cat_order=None,
            state=None,
            copies=None,
            available=None):
     cat_name = None
     cat_custom_id = None
     if title and not valid_name(title):
         return translate('dbModels', 'invalid title')
     if author and not valid_name(author):
         return translate('dbModels', 'invalid author')
     if cat_id:
         cat = Cat.by_id(cat_id)
         if not cat:
             return translate('dbModels', 'invalid category')
         cat_name = cat.name
         cat_custom_id = cat.custom_id
     if copies is not None and not isinstance(copies, int):
         return translate('dbModels', 'invalid copies no.')
     edits = {}
     edits['title'] = title if title else self.title
     edits['author'] = author if author else self.author
     if cat_id:
         edits['cat_id'] = cat_id
         edits['cat_name'] = cat_name
         edits['cat_custom_id'] = cat_custom_id
     elif cat_id is not None:
         edits['cat_id'] = None
         edits['cat_name'] = None
         edits['cat_custom_id'] = None
     if cat_order:
         edits['cat_order'] = cat_order
     elif cat_order is not None:
         edits['cat_order'] = None
     edits['state'] = state if state else self.state
     edits['copies'] = copies if isinstance(copies, int) else self.copies
     edits['available'] = available if isinstance(available,
                                                  bool) else self.available
     with self.session() as session:
         entity = session.query(type(self)).filter(type(self).id == self.id)
         entity.update(edits)
         session.commit()
         session.expunge_all()
     return self
예제 #5
0
파일: models.py 프로젝트: elshobaky/MeX-LMS
 def update(self, title=None, author=None,
            cat_id=None, cat_order=None, state=None,
            copies=None, available=None):
     cat_name = None
     cat_custom_id = None
     if title and not valid_name(title):
         return translate('dbModels', 'invalid title')
     if author and not valid_name(author):
         return translate('dbModels', 'invalid author')
     if cat_id:
         cat = Cat.by_id(cat_id)
         if not cat:
             return translate('dbModels', 'invalid category')
         cat_name = cat.name
         cat_custom_id = cat.custom_id
     if copies is not None and not isinstance(copies, int):
         return translate('dbModels', 'invalid copies no.')
     edits = {}
     edits['title'] = title if title else self.title
     edits['author'] = author if author else self.author
     if cat_id:
         edits['cat_id'] = cat_id
         edits['cat_name'] = cat_name
         edits['cat_custom_id'] = cat_custom_id
     elif cat_id is not None:
         edits['cat_id'] = None
         edits['cat_name'] = None
         edits['cat_custom_id'] = None
     if cat_order:
         edits['cat_order'] = cat_order
     elif cat_order is not None:
         edits['cat_order'] = None
     edits['state'] = state if state else self.state
     edits['copies'] = copies if isinstance(copies, int) else self.copies
     edits['available'] = available if isinstance(available, bool) else self.available
     with self.session() as session:
         entity = session.query(type(self)).filter(type(self).id == self.id)
         entity.update(edits)
         session.commit()
         session.expunge_all()
     return self
예제 #6
0
	def update(self, title=None, author=None, publisher=None, copies=None, available=None):
		if title and not valid_name(title):
			return 'invalid title'
		if author and not valid_name(author):
			return 'invalid author'
		if publisher and not valid_name(publisher):
			return 'invalid publisher'
		if not isinstance(copies, int):
			return 'invalid copies no.'
		edits = {}
		edits['title'] = title if title else self.title
		edits['author'] = author if author else self.author
		edits['publisher'] = publisher if publisher else self.publisher
		edits['copies'] = copies if isinstance(copies, int) else self.copies
		edits['available'] = available if isinstance(available, bool) else self.available
		with self.session() as session:
			entity = session.query(type(self)).filter(type(self).id==self.id)
			entity.update(edits)
			session.commit()
			session.expunge_all()
			return self
예제 #7
0
파일: models.py 프로젝트: oversoul/MeX-LMS
 def add(self, name, email=None, mob=None, note=None):
     if not valid_name(name):
         return translate('dbModels', 'invalid name')
     if email and not valid_email(email):
         return translate('dbModels', 'invalid email')
     if email and self.by_email(email):
         return translate('dbModels', "email exists")
     if mob and not valid_phone(mob):
         return translate('dbModels', 'invalid mob no.')
     if mob and self.by_mob(mob):
         return translate('dbModels', "mob no. exists")
     self = self(name=name, email=email, mob=mob, note=note)
     return self.put()
예제 #8
0
 def add(self, name, email=None, mob=None):
     if not valid_name(name):
         return 'invalid name'
     if email and not valid_email(email):
         return 'invalid email'
     if email and self.by_email(email):
         return "email exists"
     if mob and not valid_phone(mob):
         return 'invalid mob no.'
     if mob and self.by_mob(mob):
         return "mob no. exists"
     self = self(name=name, email=email, mob=mob)
     return self.put()
예제 #9
0
파일: models.py 프로젝트: elshobaky/MeX-LMS
 def add(self, name, email=None, mob=None, note=None):
     if not valid_name(name):
         return translate('dbModels', 'invalid name')
     if email and not valid_email(email):
         return translate('dbModels', 'invalid email')
     if email and self.by_email(email):
         return translate('dbModels', "email exists")
     if mob and not valid_phone(mob):
         return translate('dbModels', 'invalid mob no.')
     if mob and self.by_mob(mob):
         return translate('dbModels', "mob no. exists")
     self = self(name=name, email=email, mob=mob, note=note)
     return self.put()
예제 #10
0
	def add(self, name, email=None, mob=None):
		if not valid_name(name):
			return 'invalid name'
		if email and not valid_email(email):
			return 'invalid email'
		if email and self.by_email(email):
			return "email exists"
		if mob and not valid_phone(mob):
			return 'invalid mob no.'
		if mob and self.by_mob(mob):
			return "mob no. exists"
		self = self(name=name, email=email, mob=mob)
		return self.put()
예제 #11
0
 def update(self, name=None, email=None, mob=None, fine=None):
     if name and not valid_name(name):
         return 'invalid name'
     if email and self.by_email(email):
         return "email exists"
     if email and not valid_email(email):
         return 'invalid email'
     if mob and self.by_mob(mob):
         return "mob exists"
     if mob and not valid_phone(mob):
         return 'invalid mob no.'
     edits = {}
     edits['name'] = name if name else self.name
     edits['email'] = email if email else self.email
     edits['mob'] = mob if mob else self.mob
     edits['fine'] = fine if fine else self.fine
     with self.session() as session:
         entity = session.query(type(self)).filter(type(self).id == self.id)
         entity.update(edits)
         session.commit()
         session.expunge_all()
         return self
예제 #12
0
	def update(self, name=None, email=None, mob=None, fine=None):
		if name and not valid_name(name):
			return 'invalid name'
		if email and self.by_email(email):
			return "email exists"
		if email and not valid_email(email):
			return 'invalid email'
		if mob and self.by_mob(mob):
			return "mob exists"
		if mob and not valid_phone(mob):
			return 'invalid mob no.'
		edits = {}
		edits['name'] = name if name else self.name
		edits['email'] = email if email else self.email
		edits['mob'] = mob if mob else self.mob
		edits['fine'] = fine if fine else self.fine
		with self.session() as session:
			entity = session.query(type(self)).filter(type(self).id==self.id)
			entity.update(edits)
			session.commit()
			session.expunge_all()
			return self