Exemplo n.º 1
0
    def preview(self, env, data):
        insure_is_xhr(env)

        item = data.item

        tdata = dict(filter_form=data.filter_form,
                     roles=env.user.roles,
                     item=item,
                     item_url=self.item_url(env, data, item),
                     stream=self.stream,
                     stream_url=self.stream.url_for(env),
                     stream_title=self.stream.config.title,
                     title=unicode(item),
                     menu=self.stream.module_name,
                     actions=[x for x in self.stream.actions 
                              if x.for_item and x.is_visible(env, item)
                                and x.action not in ('preview', 'delete')])
        if self.item_lock:
            tdata = dict(tdata,
                         item_lock=self.item_lock,
                         item_global_id=ItemLock.item_global_id(item),
                         lock_message=data.lock_message,
                         edit_session=data.edit_session or data.owner_session,
                         lock_timeout=env.cfg.MODEL_LOCK_RENEW)
        return env.render_to_response('preview', tdata)
Exemplo n.º 2
0
 def create_log_entry(self, env, item, type_):
     EditLog = getattr(env, 'edit_log_model', None)
     log_enabled = EditLog is not None and \
                   self.edit_log_action is not None
     if log_enabled:
         return EditLog(stream_name=self.uid(env),
                        type=type_,
                        object_id=item.id,
                        global_id=ItemLock.item_global_id(item),
                        users=[env.user])
Exemplo n.º 3
0
 def create_log_entry(self, env, item, type_):
     EditLog = getattr(env, 'edit_log_model', None)
     log_enabled = EditLog is not None and \
                   self.edit_log_action is not None
     if log_enabled:
         return EditLog(stream_name=self.uid(env),
                        type=type_,
                        object_id=item.id,
                        global_id=ItemLock.item_global_id(item),
                        users=[env.user])
Exemplo n.º 4
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})
Exemplo n.º 5
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})
Exemplo n.º 6
0
 def item_global_id(self):
     gid = ItemLock.item_global_id(self, view_in_obj=False)
     assert gid.startswith(self.__class__.__module__)
     return gid.replace(self.__class__.__module__, 
                        self._admin_model.__class__.__module__, 1)
Exemplo n.º 7
0
 def query_for_item(cls, db, item):
     ''''''
     global_id = ItemLock.item_global_id(item)
     return db.query(cls).filter_by(global_id=global_id)
Exemplo n.º 8
0
 def item_global_id(self):
     return ItemLock.item_global_id(self._admin_item)
Exemplo n.º 9
0
 def query_for_item(cls, db, item):
     ''''''
     global_id = ItemLock.item_global_id(item)
     return db.query(cls).filter_by(global_id=global_id)
Exemplo n.º 10
0
 def item_lock(storage):
     return ItemLock(storage)