Esempio n. 1
0
File: page.py Progetto: apit/rinjani
 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)
Esempio n. 2
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)
Esempio n. 3
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)
Esempio n. 4
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)
Esempio n. 5
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)
Esempio n. 6
0
    def post(self, slug=None):
        f = article_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)

            if f.validates(tornado.web._O(data)):
                article = Article.one({'slug':slug}) if is_edit else Article()
                article.save(data, user=self.current_user)

                if attachments:
                    # ganti sama $push nih
                    article['attachments'] = move_attachments(self.settings.upload_path, data['attachments'])
                    article.update_html()
                    article.save()

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