当前位置: 首页>>代码示例>>Python>>正文


Python User.add_project方法代码示例

本文整理汇总了Python中models.User.User.add_project方法的典型用法代码示例。如果您正苦于以下问题:Python User.add_project方法的具体用法?Python User.add_project怎么用?Python User.add_project使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在models.User.User的用法示例。


在下文中一共展示了User.add_project方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: post

# 需要导入模块: from models.User import User [as 别名]
# 或者: from models.User.User import add_project [as 别名]
    def post(self, username):
        mode = self.request.get('mode')
        if mode == 'add_project':
            blob_info = None
            fileerror = 'Screenshot is mandatory'
            upload_files = self.get_uploads('screenshot')
            if upload_files:
                blob_info = upload_files[0]
                if 'image' in blob_info.content_type:
                    screenshot = blob_info.key()
                    screenshot_url = images.get_serving_url(screenshot)
                    fileerror = ''
                else:
                    # uploaded file wasn't an images, hence remove from the blobstore
                    blobstore.delete(blob_info.key())
                    fileerror = 'Invalid image type'
            else:
                fileerror = 'Please provide a screenshot of your project (max size: 1MB)'

            title = self.request.get('title').strip()
            titleerror = validate_project_title(title)

            url = self.request.get('url').strip()
            urlerror = validate_project_url(url)

            short_description = self.request.get('short_description').strip()
            sderror = validate_project_short_description(short_description)
            
            if titleerror or urlerror or sderror or fileerror:
                if blob_info and not fileerror:
                    # blob was okay but validation of some other field failed
                    # hence remove it to avoid orphaned entry
                    # also remove the serving url
                    Project.remove_screenshot_blob(blob_info.key())

                user = User.get_user(username)
                template = 'profile/add_project.html'
                upload_url = blobstore.create_upload_url('/' + username, max_bytes_per_blob=self.MAX_IMG_SIZE)
                context = { 'user': user,
                            'username': username,
                            'title': title,
                            'url': url,
                            'short_description': short_description,
                            'upload_url': upload_url,
                            'titleerror': titleerror,
                            'urlerror': urlerror,
                            'sderror': sderror,
                            'fileerror': fileerror}
                self.render(template, context)
                return
            else:
                user = User.get_user(username)
                project_id = Project.add_project(title=title, screenshot=screenshot,
                    screenshot_url=screenshot_url, url=url, short_description=short_description, 
                    author=user.key)

                User.add_project(username, project_id)
                
        elif mode == 'edit_project':
            blob_info = None
            screenshot = None
            screenshot_url = None
            fileerror = ''

            upload_files = self.get_uploads('screenshot')
            if upload_files:
                blob_info = upload_files[0]
                if 'image' in blob_info.content_type:
                    screenshot = blob_info.key()
                    screenshot_url = images.get_serving_url(screenshot)
                else:
                    # uploaded file wasn't an images, hence remove from the blobstore
                    blobstore.delete(blob_info.key())
                    fileerror = 'Invalid image type'

            project_id = self.request.get('projects_dropdown')

            title = self.request.get('title').strip()
            titleerror = validate_project_title(title)

            url = self.request.get('url').strip()
            urlerror = validate_project_url(url)

            short_description = self.request.get('short_description').strip()
            sderror = validate_project_short_description(short_description)

            if titleerror or urlerror or sderror or fileerror:
                if blob_info and not fileerror:
                    # same as above
                    Project.remove_screenshot_blob(blob_info.key())
                
                user = User.get_user(username)
                projects = Project.get_projects_by_ids(user.projects)
                upload_url = blobstore.create_upload_url('/' + username, max_bytes_per_blob=self.MAX_IMG_SIZE)
                template = 'profile/edit_project.html'
                context = { 'user': user,
                            'username': username,
                            'title': title,
                            'url': url,
                            'short_description': short_description,
#.........这里部分代码省略.........
开发者ID:nitishparkar,项目名称:udacityplus,代码行数:103,代码来源:profile.py


注:本文中的models.User.User.add_project方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。