Exemplo n.º 1
0
    def post(self, item_id=None):
        from page.models import StaticBlock
        form = model_form(StaticBlock,
                          StaticBlock.session,
                          base_class=Form,
                          exclude=['content'])

        class StaticBlockForm(form):
            content = FormField(TextEditorFieldForm, '_')

        self._form = StaticBlockForm
        if item_id is None:
            block = StaticBlock()
            msg = "created a new"
        else:
            block = StaticBlock.get_by_id(item_id)
            msg = "updated a"
        data = self.get_form_data()
        block.name = data['name']
        block.content = data['content']['content']
        block.block_id = data['block_id']
        if block.save():
            flash(msg + " static_block with id: {}".format(block.block_id))
            return self.redirect('admin.index')
        else:
            flash("Error")
        return self.render()
Exemplo n.º 2
0
 def get(self):
     from page.models import StaticBlock
     name = request.args.get('name')
     block_id = request.args.get('block_id')
     content = request.args.get('content')
     block = StaticBlock.get_by_block_id(block_id)
     if block is None:
         block = StaticBlock()
         block.name = name
         block.block_id = block_id
     block.content = content
     try:
         block.save()
         return jsonify({'success': True, 'error': False})
     except:
         return jsonify({'error': True, 'success': False})
Exemplo n.º 3
0
 def get(self):
     from page.models import StaticBlock
     block = StaticBlock.get_by_block_id(request.args.get('block_id',None))
     if block is None:
         self._response['success'] = False
         self._response['error'] = 'No block found with id: ' + request.args.get('block_id','ERROR')
         self.flash("no block found?")
     else:
         try:
             bname = block.name
             block.delete()
             self.flash('Deleted: ' + bname)
         except Exception, e:
             self._response['success'] = False
             self._response['error'] = 'Error while deleting block with id: ' + request.args.get('block_id','ERROR')
             self.flash("error deleting:\n" + str(e))
Exemplo n.º 4
0
    def get(self):
        from page.models import StaticBlock

        name = request.args.get("name")
        block_id = request.args.get("block_id")
        content = request.args.get("content")
        block = StaticBlock.get_by_block_id(block_id)
        if block is None:
            block = StaticBlock()
            block.name = name
            block.block_id = block_id
        block.content = content
        try:
            block.save()
            return jsonify({"success": True, "error": False})
        except:
            return jsonify({"error": True, "success": False})
Exemplo n.º 5
0
 def get(self,item_id=None):
     from page.models import StaticBlock
     from .forms import AddStaticBlockForm
     form = AddStaticBlockForm #model_form(StaticBlock,db.session,base_class=Form,exclude=['content'])
     if 'list' in request.endpoint:
         self._template = 'sort_list.html'
         self._context['list_items'] = StaticBlock.query.all() or []
     elif 'add' in request.endpoint:            
         class StaticBlockForm(form):
             content = FormField(TextEditorFieldForm,'_')
         self._form = form #StaticBlockForm
     elif 'edit' in request.endpoint:
         self._template = 'add_block.html'
         class StaticBlockForm(form):
             content = FormField(TextEditorFieldForm,'_')
         self._form = form # form StaticBlockForm
         self._form_obj = StaticBlock.get_by_id(item_id)
         self._context['content'] = self._form_obj.content[:]
         self._context['obj'] = self._form_obj
     return self.render()
Exemplo n.º 6
0
 def post(self,item_id=None):
     from page.models import StaticBlock
     form = model_form(StaticBlock,db.session,base_class=Form,exclude=['content'])
     class StaticBlockForm(form):
         content = FormField(TextEditorFieldForm,'_')
     self._form = StaticBlockForm
     if item_id is None:
         block = StaticBlock()
         msg = "created a new"
     else:
         block = StaticBlock.get_by_id(item_id)
         msg = "updated a"
     data = self.get_form_data()
     block.name = data['name']
     block.content = data['content']['content']
     block.block_id = data['block_id']
     if block.save():
         flash(msg + " static_block with id: {}".format(block.block_id))
         return self.redirect('admin.index')
     else:
         flash("Error")
     return self.render()