Esempio n. 1
0
    def update(self, id):
        """PUT /repos_groups/id: Update an existing item"""
        # Forms posted to this method should contain a hidden field:
        #    <input type="hidden" name="_method" value="PUT" />
        # Or using helpers:
        #    h.form(url('repos_group', id=ID),
        #           method='put')
        # url('repos_group', id=ID)

        self.__load_defaults()
        c.repos_group = Group.get(id)

        repos_group_model = ReposGroupModel()
        repos_group_form = ReposGroupForm(edit=True,
                                          old_data=c.repos_group.get_dict(),
                                          available_groups=
                                            c.repo_groups_choices)()
        try:
            form_result = repos_group_form.to_python(dict(request.POST))
            repos_group_model.update(id, form_result)
            h.flash(_('updated repos group %s') \
                    % form_result['group_name'], category='success')
            #TODO: in futureaction_logger(, '', '', '', self.sa)
        except formencode.Invalid, errors:

            return htmlfill.render(
                render('admin/repos_groups/repos_groups_edit.html'),
                defaults=errors.value,
                errors=errors.error_dict or {},
                prefix_error=False,
                encoding="UTF-8")