def post(self): args = self.parser.parse_args() slug = str(args.slug or args.name.replace(' ', '-').lower()) match = Project.query.filter( Project.slug == slug, ).first() if match: return '{"error": "Project with slug %r already exists"}' % (slug,), 400 repository = Repository.get(args.repository) if repository is None: repository = Repository( url=args.repository, ) db.session.add(repository) project = Project( name=args.name, slug=slug, repository=repository, ) db.session.add(project) db.session.commit() return self.respond(project)
def post(self, project_id): project = Project.get(project_id) if project is None: return '', 404 args = self.post_parser.parse_args() if args.name: project.name = args.name if args.slug: match = Project.query.filter( Project.slug == args.slug, Project.id != project.id, ).first() if match: return '{"error": "Project with slug %r already exists"}' % (args.slug,), 400 project.slug = args.slug if args.repository: repository = Repository.get(args.repository) if repository is None: return '{"error": "Repository with url %r does not exist"}' % (args.repository,), 400 project.repository = repository db.session.add(project) data = self.serialize(project) data['repository'] = self.serialize(project.repository) return self.respond(data, serialize=False)
def post(self, project_id): project = Project.get(project_id) if project is None: return '', 404 args = self.post_parser.parse_args() if args.name: project.name = args.name if args.slug: match = Project.query.filter( Project.slug == args.slug, Project.id != project.id, ).first() if match: return '{"error": "Project with slug %r already exists"}' % ( args.slug, ), 400 project.slug = args.slug if args.repository: repository = Repository.get(args.repository) if repository is None: return '{"error": "Repository with url %r does not exist"}' % ( args.repository, ), 400 project.repository = repository if args.status == 'inactive': project.status = ProjectStatus.inactive elif args.status == 'active': project.status = ProjectStatus.active db.session.add(project) data = self.serialize(project) data['repository'] = self.serialize(project.repository) return self.respond(data, serialize=False)
def post(self): args = self.post_parser.parse_args() slug = str(args.slug or args.name.replace(' ', '-').lower()) match = Project.query.filter(Project.slug == slug, ).first() if match: return '{"error": "Project with slug %r already exists"}' % ( slug, ), 400 repository = Repository.get(args.repository) if repository is None: return '{"error": "Repository with url %r does not exist"}' % ( args.repository, ), 400 project = Project( name=args.name, slug=slug, repository=repository, ) db.session.add(project) db.session.commit() return self.respond(project)