Python flask_mongoengine.Document() Examples
The following are 2
code examples of flask_mongoengine.Document().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
flask_mongoengine
, or try the search function
.
Example #1
Source File: user.py From vulyk with BSD 3-Clause "New" or "Revised" License | 6 votes |
def pre_save(cls, sender: Type, document: Document, **kwargs: Dict) -> Document: """ A signal handler which will put a new member into a default group if any hasn't been assigned yet. :param sender: Type of signal emitter. :type sender: Type :param document: New instance of User model. :type document: User :param kwargs: Additional parameters :type kwargs: Dict :return: Modified User instance. :rtype: User """ if all(map(lambda x: x.id != 'default', document.groups)): try: document.groups = [Group.objects.get(id='default')] except Group.DoesNotExist: raise Group.DoesNotExist('Please run \'manage.py init ...\'') return document
Example #2
Source File: user.py From vulyk with BSD 3-Clause "New" or "Revised" License | 5 votes |
def get_by_id(cls, user_id: str) -> Optional[Document]: """ :param user_id: Needed user ID :type user_id: str :return: The user :rtype: Optional[User] """ try: return cls.objects.get(id=user_id) except (cls.DoesNotExist, ValidationError): return None