예제 #1
0
 def isValid(self):
     institution = self.institution_key.get()
     sender = self.sender_key.urlsafe()
     if not sender:
         raise FieldException("The request require sender_key")
     if RequestUser.senderIsMember(sender, institution):
         raise FieldException("The sender is already a member")
     if RequestUser.senderIsInvited(sender, institution.key):
         raise FieldException("The sender is already invited")
예제 #2
0
파일: event.py 프로젝트: RonnyldoSilva/web
    def isValid(self, is_patch=False):
        """Check if is valid event."""
        date_now = datetime.datetime.today()

        if (self.end_time is None) or (self.start_time is None):
            raise FieldException("Event must contains start time and end time")
        if self.end_time < self.start_time:
            raise FieldException("The end time can not be before the start time")
        if date_now > self.end_time and not is_patch:
            raise FieldException("The end time must be after the current time")
예제 #3
0
 def isValid(self):
     institution_key = self.institution_key
     sender = self.sender_key
     institution_requested = self.institution_requested_key.get()
     if not sender:
         raise FieldException("The request require sender_key")
     if not institution_requested:
         raise FieldException("The request require institution_requested")
     if Request.isLinked(institution_key, institution_requested):
         raise FieldException(
             "The institutions has already been connected.")
     if Request.isRequested(institution_key, institution_requested.key):
         raise FieldException(
             "The requested institution has already been invited")
예제 #4
0
파일: event.py 프로젝트: RonnyldoSilva/web
    def verify_patch(self, patch):
        """Check if the patch is valid."""
        INDEX_AFTER_SLASH = 1
        has_ended = datetime.datetime.today() > self.end_time
        forbidden_props = ["title", "official_site", "address", "local"]
        patch_props = [update['path'][INDEX_AFTER_SLASH:] for update in json.loads(patch)]

        for p in patch_props:
            p = "address" if "address" in p else p
            if has_ended and p in forbidden_props:
                raise FieldException("The event basic data can not be changed after it has ended")
예제 #5
0
    def create(post, data, author_key, institution_key):
        """Create a post and check required fields."""
        post = post.createSharing(data)

        if (post.isCommonPost(data)):
            if not data.get('title'):
                raise FieldException("Title can not be empty")
            if not data.get('text'):
                raise FieldException("Text can not be empty")

        post.title = data.get('title')
        post.photo_url = data.get('photo_url')
        post.text = data.get('text')
        post.pdf_files = Utils.toJson(data.get('pdf_files'))
        post.last_modified_by = author_key
        post.author = author_key
        post.institution = institution_key
        post.video_url = data.get('video_url')
        post.subscribers = [author_key]

        return post
예제 #6
0
    def create(data, author):
        """Create a comment and check required fields."""
        if not data.get('text'):
            raise FieldException("Text can not be empty")
        if not data.get('institution_key'):
            raise FieldException("Institution can not be empty")

        institution = ndb.Key(urlsafe=data['institution_key']).get()
        Utils._assert(not institution.is_active(),
                      "This institution is not active",
                      NotAuthorizedException)
        comment = Comment()
        comment.text = data['text']
        comment.author_key = author.key.urlsafe()
        comment.author_name = author.name
        comment.author_img = author.photo_url
        comment.publication_date = datetime.datetime.now().isoformat()
        comment.institution_name = institution.name
        comment.id = Utils.getHash(comment)

        comment.replies = {}
        comment.likes = []

        return comment
예제 #7
0
    def create(data):
        """Create an institution profile model instance."""
        for prop in [
                'office', 'institution_name', 'institution_key',
                'institution_photo_url'
        ]:
            if (not data.get(prop)):
                raise FieldException(
                    "The %s property is missing in data profile" % prop)

        profile = InstitutionProfile()
        profile.office = data.get('office')
        profile.email = data.get('email')
        profile.phone = data.get('phone')
        profile.branch_line = data.get('branch_line')
        profile.institution_name = data.get('institution_name')
        profile.institution_photo_url = data.get('institution_photo_url')
        profile.institution_key = data.get('institution_key')

        return profile
예제 #8
0
 def isValid(self):
     sender = self.sender_key
     if not sender:
         raise FieldException("The request require sender_key")
예제 #9
0
 def check_is_invite_institution_valid(data):
     """Check if invite for institution is valid."""
     if data.get('suggestion_institution_name') is None:
         raise FieldException(
             "The invite for institution have to specify the suggestion institution name"
         )