コード例 #1
0
def create_project():
    """Create a project"""
    data = {
        'email': request.json.get('email'),
        'password': request.json.get('password'),
        'name': request.json.get('name'),
        'description': request.json.get('description'),
        'contract_value': request.json.get('value'),
        'percentage_return': request.json.get('return'),
        'end_date': request.json.get('end_date'),
    }
    check_valid(CreateProjectSchema().validate(data))

    user = Users.get_user(data['email'], data['password'])
    project = Projects(
        name=data['name'], description=data['description'],
        contract_value=data['contract_value'],
        percentage_return=data['percentage_return'],
        start_date=datetime.date.today(), end_date=data['end_date'],
        user_email=user.email)
    project.save()

    data['project_id'] = project.id

    return jsonify({
        'message': 'Project Created Successfully.',
        'data': data,
        }), 201
コード例 #2
0
def new_proj(request):
    """添加一个项目"""
    name = request_post(request, 'pname', required=True)
    desc = request_post(request, 'pdesc', required=True)
    p = Projects.objects.filter(name=name).first()
    if not p:
        p = Projects()
        p.name = name
        p.desc = desc
        p.domain = 'http://' + request.META.get('HTTP_HOST')
        p.created_by = request.user
    p.name = name
    p.desc = desc
    p.save()
    return HttpResponseRedirect(reverse('index'))
コード例 #3
0
class BaseTestCase(TestCase):
    """A base test case for flask-tracking."""

    def setUp(self):
        self.app = create_app('testing')
        self.client = self.app.test_client()
        self.app.app_context().push()
        with self.app.app_context():
            db.create_all()
        self.user1 = Users(
            username='******', email='*****@*****.**',
            password='******')
        self.user1.save()
        self.user2 = Users(
            username='******', email='*****@*****.**',
            password='******')
        self.user2.save()
        self.project1 = Projects(
            name="User1's Project", description='sample project',
            contract_value='5000',
            percentage_return='22',
            start_date=datetime.date.today(),
            end_date=datetime.date.today()+datetime.timedelta(days=10),
            user_email=self.user1.email)
        self.project1.save()
        self.project2 = Projects(
            name="User2's Project", description='sample project',
            contract_value='3000',
            percentage_return='10',
            start_date=datetime.date.today(),
            end_date=datetime.date.today()+datetime.timedelta(days=10),
            user_email=self.user2.email)
        self.project2.save()
        self.bid = Bids(
            amount='200', date=datetime.date.today(),
            user_email=self.user1.email, project_id=self.project2.id,)
        self.bid.save()

    def tearDown(self):
        with self.app.app_context():
            db.session.remove()
            db.drop_all()