예제 #1
0
 def rollback_due_lock_lost(self, env, item, silent=False):
     '''rollbacks request.db and flashes failure message'''
     env.db.rollback()
     if not silent:
         flash(env, u'Объект (%s) не был сохранен из-за '
                    u'перехваченной блокировки' % (item,),
                    'failure')
예제 #2
0
    def revert(self, env, data):
        self.stream.insure_has_permission(env, 'p')
        if data.lock_message:
            self.stream.rollback_due_lock_lost(env, data.item)
            return env.json({
                'success': False,
                'error': 'item_lock',
                'lock_message': data.lock_message
            })

        log = self.stream.create_log_entry(env, data.item, 'revert')
        if log is not None:
            log.before = self._clean_item_data(self.stream, env, data.item)
            env.db.add(log)

        data.item.revert_to_published()

        DraftForm = getattr(env, 'draft_form_model', None)
        if DraftForm is not None:
            draft = DraftForm.get_for_item(env.db, self.stream.uid(env),
                                           data.item, env.user)
            if draft is not None:
                env.db.delete(draft)

        flash(env,
              u'Объект «%s» восстановлен из опубликованной версии' % data.item,
              'success')
        env.db.commit()

        if log is not None:
            log.after = self._clean_item_data(self.stream, env, data.item)
            env.db.commit()

        url = self.stream.url_for(env, 'item', item=data.item.id)
        return env.json({'success': True, 'location': url})
예제 #3
0
 def commit_item_transaction(self, env, item, silent=False):
     '''commits request.db and flashes success message'''
     env.db.commit()
     if not silent:
         flash(
             env,
             six.u('Объект (%s) сохранен') % (item.__title__,),
             'success',
         )
예제 #4
0
 def rollback_due_form_errors(self, env, item, silent=False):
     env.db.rollback()
     if not silent:
         flash(
             env,
             six.u(
                 'Объект (%s) не был сохранен из-за ошибок',
             ) % (item.__title__,),
             'failure',
         )
예제 #5
0
파일: stream.py 프로젝트: Lehych/iktomi-cms
    def unpublish(self, env, data):
        self.stream.insure_has_permission(env, 'p')
        if data.lock_message:
            self.stream.rollback_due_lock_lost(env, data.item)
            return env.json({'success': False,
                             'error': 'item_lock',
                             'lock_message': data.lock_message})

        log = self.stream.create_log_entry(env, data.item, 'unpublish')
        if log is not None:
            env.db.add(log)

        data.item.unpublish()
        flash(env, u'Объект «%s» снят с публикации' % data.item, 'success')
        env.db.commit()

        url = self.stream.url_for(env, 'item', item=data.item.id)
        return env.json({'success': True,
                         'location': url})
예제 #6
0
    def revert(self, env, data):
        self.stream.insure_has_permission(env, 'p')
        if data.lock_message:
            self.stream.rollback_due_lock_lost(env, data.item)
            return env.json({})

        EditLog = getattr(env, 'edit_log_model', None)
        log_enabled = EditLog is not None and self.stream.edit_log
        if log_enabled:
            before = self._clean_item_data(self.stream, env, data.item)
            log = EditLog(stream_name=self.stream.uid(env),
                          type="revert",
                          object_id=data.item.id,
                          global_id=ItemLock.item_global_id(data.item),
                          before=before,
                          users=[env.user])
            env.db.add(log)

        data.item.revert_to_published()

        DraftForm = getattr(env, 'draft_form_model', None)
        if DraftForm is not None:
            draft = DraftForm.get_for_item(env.db,
                                           self.stream.uid(env),
                                           data.item, env.user)
            if draft is not None:
                env.db.delete(draft)

        flash(env, u'Объект «%s» восстановлен из фронтальной версии' 
                    % data.item, 'success')
        env.db.commit()

        if log_enabled:
            log.after = self._clean_item_data(self.stream, env, data.item)
            env.db.commit()


        url = self.stream.url_for(env, 'item', item=data.item.id)
        return env.json({'result': 'success',
                         'location': url})
예제 #7
0
    def unpublish(self, env, data):
        self.stream.insure_has_permission(env, 'p')
        if data.lock_message:
            self.stream.rollback_due_lock_lost(env, data.item)
            return env.json({})

        EditLog = getattr(env, 'edit_log_model', None)
        log_enabled = EditLog is not None and self.stream.edit_log
        if log_enabled:
            log = EditLog(stream_name=self.stream.uid(env),
                          type="unpublish",
                          object_id=data.item.id,
                          global_id=ItemLock.item_global_id(data.item),
                          users=[env.user])
            env.db.add(log)

        data.item.unpublish()
        flash(env, u'Объект «%s» снят с публикации' % data.item, 'success')
        env.db.commit()

        url = self.stream.url_for(env, 'item', item=data.item.id)
        return env.json({'result': 'success',
                         'location': url})
예제 #8
0
파일: stream.py 프로젝트: Lehych/iktomi-cms
    def revert(self, env, data):
        self.stream.insure_has_permission(env, 'p')
        if data.lock_message:
            self.stream.rollback_due_lock_lost(env, data.item)
            return env.json({'success': False,
                             'error': 'item_lock',
                             'lock_message': data.lock_message})


        log = self.stream.create_log_entry(env, data.item, 'revert')
        if log is not None:
            log.before = self._clean_item_data(self.stream, env, data.item)
            env.db.add(log)

        data.item.revert_to_published()

        DraftForm = getattr(env, 'draft_form_model', None)
        if DraftForm is not None:
            draft = DraftForm.get_for_item(env.db,
                                           self.stream.uid(env),
                                           data.item, env.user)
            if draft is not None:
                env.db.delete(draft)

        flash(env, u'Объект «%s» восстановлен из опубликованной версии'
                    % data.item, 'success')
        env.db.commit()

        if log is not None:
            log.after = self._clean_item_data(self.stream, env, data.item)
            env.db.commit()


        url = self.stream.url_for(env, 'item', item=data.item.id)
        return env.json({'success': True,
                         'location': url})
예제 #9
0
    def unpublish(self, env, data):
        self.stream.insure_has_permission(env, 'p')
        if data.lock_message:
            self.stream.rollback_due_lock_lost(env, data.item)
            return env.json({
                'success': False,
                'error': 'item_lock',
                'lock_message': data.lock_message
            })

        log = self.stream.create_log_entry(env, data.item, 'unpublish')
        if log is not None:
            env.db.add(log)

        data.item.unpublish()
        flash(env, u'Объект «%s» снят с публикации' % data.item, 'success')
        env.db.commit()

        url = self.stream.url_for(env, 'item', item=data.item.id)
        return env.json({
            'success': True,
            'item_id': data.item.id,
            'location': url
        })
예제 #10
0
 def rollback_due_form_errors(self, env, item, silent=False):
     env.db.rollback()
     if not silent:
         flash(env, u'Объект (%s) не был сохранен из-за ошибок' % (item,),
                    'failure')
예제 #11
0
 def commit_item_transaction(self, env, item, silent=False):
     '''commits request.db and flashes success message'''
     env.db.commit()
     if not silent:
         flash(env, u'Объект (%s) сохранен' % (item,), 'success')