Пример #1
0
    def post(self):

        user_id = int(self.request.get("user_id"))
        user = UserData.get_by_id(user_id)
        user = user or UserData.get_current_user()
        if user is None:
            return

        resource_id = self.request.get("resource_id")
        resource = Resource.get_by_id(int(resource_id))
        content = self.request.get("content")

        new_comment = Comment(parent=resource.key, comment_user=user.key, comment_content=content)
        new_comment.put()
        return
Пример #2
0
    def get(self, resource_id):

        user = UserData.get_current_user()
        resource = Resource.get_by_id(int(resource_id))
        if not resource.is_visible_to_user(user):
            return self.render("resource/show-resource-no-auth.html")

        else:
            contents = [key.get() for key in resource.contents]
            admins = [key.get().user_nickname for key in resource.admins]
            is_admin = user and user.key in resource.admins

            comments = Comment.get_by_resource(resource)
            comments.sort(key=lambda x: x.created_time, reverse=False)
            for comment in comments:
                comment.created_time = comment.created_time + timedelta(hours=8)
                comment.user_nickname = comment.comment_user.get().user_nickname

            data = {
                "resource": resource,
                "keywords": ", ".join(resource.keywords),
                "admins": ", ".join(admins),
                "contents": contents,
                "is_admin": is_admin,
                "comments": comments,
            }

            return self.render("resource/show-resource.html", data)
Пример #3
0
    def get(self, course_id):

        user = UserData.get_current_user()
        course = Resource.get_by_id(int(course_id))
        if not course.is_visible_to_user(user):
            return self.render('course/show-course-no-auth.html')

        else:
            materials = [key.get() for key in course.materials]
            admins = [key.get().user_nickname for key in course.admins]
            is_admin = user and user.key in course.admins

            comments = Comment.get_by_course(course)
            comments.sort(key=lambda x: x.created_time, reverse=False)
            for comment in comments:
                comment.created_time = comment.created_time + timedelta(hours=8)
                comment.user_nickname = comment.comment_user.get().user_nickname

            data = {
                'course': course,
                'keywords': ', '.join(course.keywords),
                'admins': ', '.join(admins),
                'materials': materials,
                'is_admin': is_admin,
                'comments': comments
            }

            return self.render('course/show-course.html', data)
Пример #4
0
    def post(self):

        user_id = int(self.request.get('user_id'))
        user = UserData.get_by_id(user_id)
        user = user or UserData.get_current_user()
        if user is None:
            return

        comment_parent_key = self.request.get('comment_parent_key')
        parent = "# get by key"
        comment_content = self.request.get('content')

        new_comment = Comment(parent=parent.key,
                              comment_user=user.key,
                              comment_content=content)
        new_comment.put()
        return
Пример #5
0
    def post(self):

        user_id = int(self.request.get('user_id'))
        user = UserData.get_by_id(user_id)
        user = user or UserData.get_current_user()
        if user is None:
            return

        comment_parent_key = self.request.get('comment_parent_key')
        parent =  "# get by key"
        comment_content = self.request.get('content')

        new_comment = Comment(parent=parent.key,
                              comment_user=user.key,
                              comment_content=content
                             )
        new_comment.put()
        return
Пример #6
0
    def post(self):

        user_id = int(self.request.get('user_id'))
        user = UserData.get_by_id(user_id)
        user = user or UserData.get_current_user()
        if user is None:
            return

        course_id = self.request.get('course_id')
        course = Resource.get_by_id(int(course_id))
        content = self.request.get('content')

        new_comment = Comment(parent=course.key,
                              comment_user=user.key,
                              comment_content=content
                             )
        new_comment.put()
        return