Пример #1
0
class ProjectAddView(BaseAddView, TreeMixin):
    title = u"Ajout d'un nouveau projet"
    schema = get_add_project_schema()
    msg = u"Le projet a été ajouté avec succès"
    named_form_grid = ADD_STEP1_FORM_GRID
    factory = Project
    route_name = COMPANY_PROJECTS_ROUTE

    def before(self, form):
        BaseAddView.before(self, form)
        self.populate_navigation()
        # If there's no customer, redirect to customer view
        if len(self.request.context.customers) == 0:
            redirect_to_customerslist(self.request, self.request.context)

    def redirect(self, new_model):
        return HTTPFound(
            self.request.route_path(
                PROJECT_ITEM_ROUTE,
                id=new_model.id,
                _query={'action': 'addstep2'},
            ))

    def on_add(self, new_model, appstruct):
        """
        On add, set the project's company
        """
        new_model.company = self.context
Пример #2
0
def test_add_project_schema(customer, project_type):
    from autonomie.forms.project import get_add_project_schema
    schema = get_add_project_schema()

    args = {
        "name": u"Test project",
        "project_type_id": str(project_type.id),
        "customers": [str(customer.id)]
    }
    result = schema.deserialize(args)
    assert result['name'] == u"Test project"
    assert result['project_type_id'] == project_type.id
    assert result['customers'] == [customer.id]

    for field in 'name', 'customers', "project_type_id":
        wrong = args.copy()
        wrong.pop(field)
        with pytest.raises(colander.Invalid):
            schema.deserialize(wrong)