当前位置: 首页>>代码示例>>Python>>正文


Python reversion.models方法代码示例

本文整理汇总了Python中reversion.models方法的典型用法代码示例。如果您正苦于以下问题:Python reversion.models方法的具体用法?Python reversion.models怎么用?Python reversion.models使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在reversion的用法示例。


在下文中一共展示了reversion.models方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: setUp

# 需要导入模块: import reversion [as 别名]
# 或者: from reversion import models [as 别名]
def setUp(self):
        # Unregister all registered models.
        self.initial_registered_models = []
        for registered_model in reversion.get_registered_models():
            self.initial_registered_models.append((registered_model, reversion.get_adapter(registered_model).__class__))
            reversion.unregister(registered_model)
        # Register the test models.
        reversion.register(ReversionTestModel1)
        reversion.register(ReversionTestModel2)
        # Create some test data.
        self.test11 = ReversionTestModel1.objects.create(
            name = "model1 instance1 version1",
        )
        self.test12 = ReversionTestModel1.objects.create(
            name = "model1 instance2 version1",
        )
        self.test21 = ReversionTestModel2.objects.create(
            name = "model2 instance1 version1",
        )
        self.test22 = ReversionTestModel2.objects.create(
            name = "model2 instance2 version1",
        )
        self.user = User.objects.create(
            username = "user1",
        ) 
开发者ID:osess,项目名称:mes,代码行数:27,代码来源:tests.py

示例2: tearDown

# 需要导入模块: import reversion [as 别名]
# 或者: from reversion import models [as 别名]
def tearDown(self):
        # Unregister the test models.
        reversion.unregister(ReversionTestModel1)
        reversion.unregister(ReversionTestModel2)
        # Delete the test models.
        ReversionTestModel1.objects.all().delete()
        ReversionTestModel2.objects.all().delete()
        User.objects.all().delete()
        del self.test11
        del self.test12
        del self.test21
        del self.test22
        del self.user
        # Delete the revisions index.
        Revision.objects.all().delete()
        # Unregister all remaining models.
        for registered_model in reversion.get_registered_models():
            reversion.unregister(registered_model)
        # Re-register initial registered models.
        for initial_model, adapter in self.initial_registered_models:
            reversion.register(initial_model, adapter_cls=adapter)
        del self.initial_registered_models 
开发者ID:osess,项目名称:mes,代码行数:24,代码来源:tests.py

示例3: testRevertWithDelete

# 需要导入模块: import reversion [as 别名]
# 或者: from reversion import models [as 别名]
def testRevertWithDelete(self):
        with reversion.create_revision():
            test23 = ReversionTestModel2.objects.create(
                name = "model2 instance3 version1",
            )
            self.follow1.test_model_2s.add(test23)
            self.follow1.save()
        self.assertEqual(reversion.get_for_object(test23).count(), 1)
        self.assertEqual(self.follow1.test_model_2s.all().count(), 3)
        # Test that a revert with delete works.
        test23_pk = test23.pk
        self.assertEqual(ReversionTestModel2.objects.count(), 3)
        with reversion.create_revision():
            reversion.get_for_object(self.follow1)[1].revision.revert(delete=True)
        self.assertEqual(ReversionTestModel1.objects.get(id=self.test11.pk).name, "model1 instance1 version1")
        self.assertEqual(ReversionTestModel2.objects.get(id=self.test22.pk).name, "model2 instance2 version1")
        self.assertEqual(ReversionTestModel2.objects.get(id=self.test22.pk).name, "model2 instance2 version1")
        self.assertEqual(ReversionTestModel2.objects.count(), 2)
        self.assertRaises(ReversionTestModel2.DoesNotExist, lambda: ReversionTestModel2.objects.get(id=test23_pk))
        # Roll back to the revision where all models were present.
        reversion.get_for_object(self.follow1)[1].revision.revert()
        self.assertEqual(self.follow1.test_model_2s.all().count(), 3)
        # Roll back to a revision where a delete flag is present.
        reversion.get_for_object(self.follow1)[0].revision.revert(delete=True)
        self.assertEqual(self.follow1.test_model_2s.all().count(), 2) 
开发者ID:osess,项目名称:mes,代码行数:27,代码来源:tests.py

示例4: register_draft_only

# 需要导入模块: import reversion [as 别名]
# 或者: from reversion import models [as 别名]
def register_draft_only(model_class, fields, follow, format):
    """
    version of the reversion register function that only registers drafts and
    ignores public models
    """
    if revision_manager.is_registered(model_class):
        raise RegistrationError(
            "%r has already been registered with Reversion." % model_class)

    # Ensure the parent model of proxy models is registered.
    if (model_class._meta.proxy and
        not revision_manager.is_registered(list(model_class._meta.parents.keys())[0])): # turn KeysView into list
        raise RegistrationError(
            '%r is a proxy model, and its parent has not been registered with'
            'Reversion.' % model_class)

    # Calculate serializable model fields.
    opts = model_class._meta
    local_fields = opts.local_fields + opts.local_many_to_many
    if fields is None:
        fields = [field.name for field in local_fields]
    fields = tuple(fields)

    # Register the generated registration information.
    follow = tuple(follow)
    registration_info = VersionAdapter(model_class)
    registration_info.fields = fields
    registration_info.follow = follow
    registration_info.format = format
    if hasattr(revision_manager, '_registration_key_for_model'):
        model_key = revision_manager._registration_key_for_model(model_class)
    else:
        model_key = model_class
    revision_manager._registered_models[model_key] = registration_info
    # Do not connect to the post save signal of the model. 
开发者ID:farhan711,项目名称:DjangoCMS,代码行数:37,代码来源:reversion_hacks.py

示例5: test_no_comparison

# 需要导入模块: import reversion [as 别名]
# 或者: from reversion import models [as 别名]
def test_no_comparison(admin_client):
    """If there are no models in the database anymore, we can't compare."""
    policy, version = policy_with_version()
    policy.delete()

    resp = admin_client.get('/admin/reqs/policy/recover/{0}/'.format(
        version.pk)).content.decode('utf-8')
    assert revision_admin.CERTAIN_WARNING not in resp
    assert revision_admin.HEDGED_WARNING in resp 
开发者ID:18F,项目名称:omb-eregs,代码行数:11,代码来源:revision_admin_tests.py

示例6: testProxyRegistration

# 需要导入模块: import reversion [as 别名]
# 或者: from reversion import models [as 别名]
def testProxyRegistration(self):
        # Test error if registering proxy models.
        self.assertRaises(RegistrationError, lambda: reversion.register(ReversionTestModel1Proxy)) 
开发者ID:osess,项目名称:mes,代码行数:5,代码来源:tests.py

示例7: list_filters_my

# 需要导入模块: import reversion [as 别名]
# 或者: from reversion import models [as 别名]
def list_filters_my( request ): # {{{1
    """ View that lists the filters of the logged-in user
    """
    list_of_filters = Filter.objects.filter( user = request.user )
    if list_of_filters is None or len( list_of_filters ) == 0:
        messages.error( request, _( "You do not have any filters" ) )
        return main( request )
    else:
        return render(request, 'list_filters_my.html',
            {'title': _( u'list of my filters' ), 'filters': list_of_filters})

# not used for now because of privacy concerns:
#def list_events_of_user( request, username ): # {{{1
#    """ View that lists the events of a user
#
#    >>> from django.test import Client
#    >>> from django.core.urlresolvers import reverse
#    >>> from django.contrib.auth.models import User
#    >>> u = User.objects.create_user('l_e_o_u', '[email protected]', 'p')
#    >>> e = Event.objects.create(
#    ...         title = 'lefu_test', tags = 'berlin',
#    ...         start = datetime.date.today(), user = u )
#    >>> client = Client()
#    >>> client.login(username = u.username, password = 'p')
#    True
#    >>> client.get(reverse('list_events_of_user',
#    ...         kwargs={'username': u.username,})).status_code
#    200
#    >>> e.delete()
#    """
#    if ( ( not request.user.is_authenticated() ) or
#            ( request.user.id is None ) ):
#        try:
#            user = User.objects.get( username__exact = username )
#            useridtmp = user.id
#            events = Event.objects.filter( user = useridtmp ) # FIXME: what is this?
#            if len( events ) == 0:
#                return _error( request,
#                        _( "Your search didn't get any result" ) )
#            else:
#                return render(request, 'events/list_user.html',
#                    {'events': events, 'username': username})
#        except User.DoesNotExist:
#            return _error( request, _( "User does not exist" ) )
#    else:
#        try:
#            user = User.objects.get( username__exact = username )
#            useridtmp = user.id
#            events = Event.objects.filter( user = useridtmp )
#            if len( events ) == 0:
#                return _error(
#                        request,
#                        _( "Your search didn't get any result" ) )
#            else:
#                return render(request, 'events/list_user.html',
#                    {'events': events, 'username': username})
#        except User.DoesNotExist:
#            return _error( request, ( "User does not exist" ) ) 
开发者ID:wikical,项目名称:grical,代码行数:60,代码来源:views.py

示例8: _ical_http_response_from_event_list

# 需要导入模块: import reversion [as 别名]
# 或者: from reversion import models [as 别名]
def _ical_http_response_from_event_list( elist, filename, calname = None ):#{{{2
    """ returns an ical file with the events in ``elist`` and the name
    ``filename`` """
    if len(elist) == 1:
        icalstream = elist[0].icalendar().serialize()
    else:
        ical = vobject.iCalendar()
        ical.add('METHOD').value = 'PUBLISH' # IE/Outlook needs this
        ical.add('PRODID').value = settings.PRODID
        if calname:
            ical.add('X-WR-CALNAME').value = calname
        for event in elist:
            event.icalendar(ical)
        icalstream = ical.serialize()
    response = HttpResponse( icalstream,
            content_type = 'text/calendar;charset=UTF-8' )
    filename = unicodedata.normalize('NFKD', filename).encode('ascii','ignore')
    filename = filename.replace(' ','_')
    if not filename[-4:] == '.ics':
        filename = filename + '.ics'
    response['Filename'] = filename  # IE needs this
    response['Content-Disposition'] = 'attachment; filename=' + filename
    return response

# def all_events_text ( request ): #{{{1
#     """ returns a text file with all events.
#
#     >>> from django.test import Client
#     >>> from django.core.urlresolvers import reverse
#     >>> from grical.events.models import Event
#     >>> e = Event.objects.create(
#     ...         title = 'aet_test', tags = 'berlin',
#     ...         start = datetime.date.today() )
#     >>> Client().get(reverse('all_events_text')).status_code
#     200
#     >>> e.delete()
#     """
#     # TODO: stream it, see https://code.djangoproject.com/ticket/7581
#     elist = Event.objects.all()
#     text = Event.list_as_text( elist )
#     response = HttpResponse( text, content_type = 'text/text;charset=UTF-8' )
#     filename =  Site.objects.get_current().name + '_' + \
#             datetime.datetime.now().isoformat() + '.txt'
#     response['Filename'] = filename
#     response['Content-Disposition'] = 'attachment; filename=' + filename
#     return response 
开发者ID:wikical,项目名称:grical,代码行数:48,代码来源:views.py


注:本文中的reversion.models方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。