Пример #1
0
    def post(self):
        f = profile_form()
        data = self.get_arguments()
        user = self.current_user
        accounts = extract_input_array(self.request.arguments, 'acc_')
        accounts = User.filter_valid_accounts(accounts)
        
        _ = self._
        
        try:
            attachments = self.get_argument('attachments', None)
            if attachments:
                data['attachments'] = parse_attachments(data['attachments'], True)

            if f.validates(tornado.web._O(data)):
                data['bank_accounts'] = accounts
                if data.get('password', None):
                    data['password_hashed'] = hashlib.sha1(data.get('password')).hexdigest()
                user.save(data, user)

                if attachments:
                    user['attachments'] = move_attachments(self.settings.upload_path, data['attachments'])
                    user.update_html()
                    user.save()
                
                self.set_flash(_("Profile saved."))
                self.redirect("/profile/%s" % user.username)
                return
            raise InvalidFormDataError(_("Form still have errors. Please correct them before saving."))
        except Exception, e:
            if not isinstance(e, InvalidFormDataError): raise
            f.note = f.note if f.note else e
            self.render('profile/edit', f=f, user=user, accounts=accounts)
Пример #2
0
 def post(self, slug=None):
     f = page_form()
     data = self.get_arguments()
     is_edit = data.has_key('ori_slug')
     _ = self._
     try:
         attachments = self.get_argument('attachments', None)
         if attachments:
             data['attachments'] = parse_attachments(data['attachments'], is_edit) 
             
         if f.validates(tornado.web._O(data)):
             page = Page.one({'type': 'Page', 'slug': data['ori_slug']}) \
                     if is_edit else Page()
             page.save(data, user=self.current_user)
             
             if attachments:
                 page['attachments'] = move_attachments(self.settings.upload_path, data['attachments'])
                 page.update_html()
                 page.save()
                 
             self.set_flash(_("Page has been saved."))
             self.redirect(page.get_url())
             return
         page = Page()
         raise Exception(_("Invalid form data."))
     except Exception, e:
         if attachments:
             page['attachments'] = data['attachments']
         f.note = f.note if f.note else e
         self.render("page-edit", f=f, page=page, user=self.current_user)
Пример #3
0
    def post(self, slug=None):
        f = project_form()
        data = self.get_arguments()
        attachments = self.get_argument('attachments', None)
        is_edit = bool(slug)
        
        _ = self._
        
        try:
            if attachments:
                data['attachments'] = parse_attachments(data['attachments'], is_edit)
                
            project = Project.one({'slug': slug}) \
                    if is_edit else Project()
            
            if f.validates(tornado.web._O(data)):
                project.save(data, user=self.current_user)

                if attachments and not is_edit:
                    project['attachments'] = move_attachments(self.settings.upload_path, data['attachments'])
                    project.update_html()
                    project.save()

                self.set_flash(_("Project has been saved."))
                url =  project.get_url() if project.status == 'published' else '/dashboard'
                self.redirect(url)
                return
            raise Exception(_("Form still have errors. Please check for required fields."))
        except EditDisallowedError:
            self.set_flash(_("You are not allowed to edit the project."))
            self.redirect(project.get_url())
        except Exception, e:
            if attachments:
                project['attachments'] = data['attachments']
            f.note = f.note if f.note else e
            self.render("project-edit", f=f, project=project, user=self.current_user)