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


Python simple_history.register函数代码示例

本文整理汇总了Python中simple_history.register函数的典型用法代码示例。如果您正苦于以下问题:Python register函数的具体用法?Python register怎么用?Python register使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: test_reregister

 def test_reregister(self):
     register(Restaurant, manager_name='again')
     register(User, manager_name='again')
     self.assertTrue(hasattr(Restaurant, 'updates'))
     self.assertFalse(hasattr(Restaurant, 'again'))
     self.assertTrue(hasattr(User, 'histories'))
     self.assertFalse(hasattr(User, 'again'))
开发者ID:dgreisen-cfpb,项目名称:django-simple-history,代码行数:7,代码来源:tests.py

示例2: setup_m2m_history

 def setup_m2m_history(self, cls):
     m2m_history_fields = self.m2m_fields
     if m2m_history_fields is ALL_M2M_FIELDS:
         for field in cls._meta.many_to_many:
             field = getattr(cls, field.name).field
             assert isinstance(field, models.fields.related.ManyToManyField), \
                 ('%s must be a ManyToManyField' % field.name)
             if not sum([
                     isinstance(item, HistoricalRecords) for item in field.remote_field.through.__dict__.values()
             ]):
                 through_model = field.remote_field.through
                 if through_model._meta.auto_created and not_registered(through_model):
                     through_model.history = HistoricalRecords()
                     register(through_model)
     elif m2m_history_fields:
         assert (isinstance(m2m_history_fields, list) or isinstance(m2m_history_fields, tuple)), \
             'm2m_history_fields must be a list or tuple'
         for field_name in m2m_history_fields:
             field = getattr(cls, field_name).field
             assert isinstance(field, models.fields.related.ManyToManyField), \
                 ('%s must be a ManyToManyField' % field_name)
             if not sum([
                     isinstance(item, HistoricalRecords) for item in field.remote_field.through.__dict__.values()
             ]):
                 through_model = field.remote_field.through
                 if through_model._meta.auto_created and not_registered(through_model):
                     through_model.history = HistoricalRecords()
                     register(through_model)
开发者ID:emergence,项目名称:django-simple-history,代码行数:28,代码来源:models.py

示例3: contribute_to_class

    def contribute_to_class(self, cls, name):
        self.manager_name = name
        self.module = cls.__module__
        models.signals.class_prepared.connect(self.finalize, sender=cls)
        setattr(cls, 'simple_history_manager', name)

        def save_without_historical_record(self, *args, **kwargs):
            """Caution! Make sure you know what you're doing before you use this method."""
            self.skip_history_when_saving = True
            ret = self.save(*args, **kwargs)
            del self.skip_history_when_saving
            return ret
        setattr(cls, 'save_without_historical_record', save_without_historical_record)

        # Injecting HistoricalRecords into ManyToManyFields' intermediate tables ('through' models)
        if hasattr(cls, 'm2m_history_fields'):
            m2m_history_fields = getattr(cls, 'm2m_history_fields', None)
            assert (isinstance(m2m_history_fields, list)
                or  isinstance(m2m_history_fields, tuple)), 'm2m_history_fields must be a list or tuple'
            for field_name in m2m_history_fields:
                field = getattr(cls, field_name).field
                assert isinstance(field, models.fields.related.ManyToManyField), ('%s must be a ManyToManyField' % field_name)
                if not sum([isinstance(item, HistoricalRecords) for item in field.rel.through.__dict__.values()]):
                    field.rel.through.history = HistoricalRecords()
                    simple_history.register(field.rel.through)
开发者ID:oramadev,项目名称:orama-django-simple-history,代码行数:25,代码来源:models.py

示例4: setup_m2m_history

 def setup_m2m_history(self, cls):
     m2m_history_fields = self.m2m_fields
     if m2m_history_fields:
         assert (isinstance(m2m_history_fields, list) or isinstance(m2m_history_fields, tuple)), 'm2m_history_fields must be a list or tuple'
         for field_name in m2m_history_fields:
             field = getattr(cls, field_name).field
             assert isinstance(field, models.fields.related.ManyToManyField), ('%s must be a ManyToManyField' % field_name)
             if not sum([isinstance(item, HistoricalRecords) for item in field.rel.through.__dict__.values()]):
                 field.rel.through.history = HistoricalRecords()
                 register(field.rel.through)
开发者ID:Kyruus,项目名称:django-simple-history,代码行数:10,代码来源:models.py

示例5: finalize

    def finalize(self, sender, **kwargs):
        try:
            hint_class = self.cls
        except AttributeError:  # called via `register`
            pass
        else:
            if hint_class is not sender:  # set in concrete
                if not (self.inherit and issubclass(sender, hint_class)):
                    return  # set in abstract
        if hasattr(sender._meta, 'simple_history_manager_attribute'):
            raise exceptions.MultipleRegistrationsError(
                '{}.{} registered multiple times for history tracking.'.format(
                    sender._meta.app_label,
                    sender._meta.object_name,
                )
            )
        if sender._meta.proxy:
            original_class = [base_class for base_class in sender.__bases__ if base_class._meta.abstract is False][0]
            # Parent model must be registered before the proxy model is
            if not_registered(original_class):
                # Ignore the `app` kwarg, since the proxy model may be in a different app than the original model
                register_kwargs = {
                    'manager_name': self.manager_name,
                    'records_class': self.__class__,
                    'verbose_name': self.user_set_verbose_name,
                    'bases': self.bases,
                    'user_related_name': self.user_related_name,
                    'm2m_fields': self.m2m_fields,
                }
                register(original_class, **register_kwargs)
            # Proxy models use their parent's history model
            history_model = getattr(sender, self.manager_name).model
        else:
            history_model = self.create_history_model(sender)
            module = importlib.import_module(self.module)
            setattr(module, history_model.__name__, history_model)
        # The HistoricalRecords object will be discarded,
        # so the signal handlers can't use weak references.
        models.signals.post_save.connect(self.post_save, sender=sender,
                                         weak=False)
        models.signals.pre_delete.connect(self.pre_delete, sender=sender,
                                          weak=False)
        models.signals.post_delete.connect(self.post_delete, sender=sender,
                                           weak=False)
        models.signals.m2m_changed.connect(self.m2m_changed, sender=sender, weak=False)

        descriptor = HistoryDescriptor(history_model)
        setattr(sender, self.manager_name, descriptor)
        sender._meta.simple_history_manager_attribute = self.manager_name
开发者ID:emergence,项目名称:django-simple-history,代码行数:49,代码来源:models.py

示例6: Poll

from simple_history import register


class Poll(models.Model):
    question = models.CharField(max_length=200)
    pub_date = models.DateTimeField('date published')

    history = HistoricalRecords()


class Choice(models.Model):
    poll = models.ForeignKey(Poll)
    choice = models.CharField(max_length=200)
    votes = models.IntegerField()

register(Choice)


class Place(models.Model):
    name = models.CharField(max_length=100)


class Restaurant(Place):
    rating = models.IntegerField()

    updates = HistoricalRecords()


class Person(models.Model):
    name = models.CharField(max_length=100)
开发者ID:dgreisen-cfpb,项目名称:django-simple-history,代码行数:30,代码来源:models.py

示例7: HistoricalRecords

    level = models.IntegerField()
    date = models.DateTimeField()

    history = HistoricalRecords()

    @property
    def _history_date(self):
        return self.date


class Choice(models.Model):
    poll = models.ForeignKey(Poll)
    choice = models.CharField(max_length=200)
    votes = models.IntegerField()

register(Choice)


class Voter(models.Model):
    user = models.ForeignKey(User)
    choice = models.ForeignKey(Choice, related_name='voters')


class HistoricalRecordsVerbose(HistoricalRecords):
    def get_extra_fields(self, model, fields):
        def verbose_str(self):
            return '%s changed by %s as of %s' % (
                self.history_object, self.history_user, self.history_date)

        extra_fields = super(
            HistoricalRecordsVerbose, self).get_extra_fields(model, fields)
开发者ID:g10f,项目名称:django-simple-history,代码行数:31,代码来源:models.py

示例8: institutionAdmin

class institutionAdmin (SimpleHistoryAdmin):
    list_display = ('user', 'department')
    class Meta:
        model = Institution

class patientIdAdmin (SimpleHistoryAdmin):
    list_display = ('user', 'patient_id')
    class Meta:
        model = Patient_id

class aggregateAdmin (SimpleHistoryAdmin):
    list_display = ('center_id','name_of_center', 'author', 'pub_date')
    class Meta:
        model = Ext_centers

register(User, inherit=True)
register(Group, inherit=True)

#admin.site.register(User, SimpleHistoryAdmin)
admin.site.register(Institution, institutionAdmin)
admin.site.register(Patient_id, patientIdAdmin)
admin.site.register(Demographic, DemographicsAdmin)
admin.site.register(Diagnosis, DiagnosisAdmin)
admin.site.register(DiagnosisOption,diag_optAdmin)
admin.site.register(A_b_sickle_thal,a_b_sickle_Admin)
admin.site.register(Redcell_enzyme_dis,redcell_enzAdmin)
admin.site.register(Redcell_membrane_dis,redcell_memb_Admin)
admin.site.register(Cong_dyseryth_anaemia,cong_dyserAdmin)
admin.site.register(icd_10, icd10Admin)
admin.site.register(orphaCodes, orphaAdmin)
admin.site.register(Pregnancy,pregnancyAdmin)
开发者ID:zinonas,项目名称:project_myTIF,代码行数:31,代码来源:admin.py

示例9: HistoricalRecords

    level = models.IntegerField()
    date = models.DateTimeField()

    history = HistoricalRecords()

    @property
    def _history_date(self):
        return self.date


class Choice(models.Model):
    poll = models.ForeignKey(Poll)
    choice = models.CharField(max_length=200)
    votes = models.IntegerField()

register(Choice)


class Place(models.Model):
    name = models.CharField(max_length=100)


class Restaurant(Place):
    rating = models.IntegerField()

    updates = HistoricalRecords()


class Person(models.Model):
    name = models.CharField(max_length=100)
开发者ID:DAV3HIT3,项目名称:django-simple-history,代码行数:30,代码来源:models.py

示例10: actual_decorator

 def actual_decorator(model):
     simple_history.register(model, **kwargs)
     return model
开发者ID:gitter-badger,项目名称:chcemvediet,代码行数:3,代码来源:history.py

示例11: test_registering_with_tracked_abstract_base

    def test_registering_with_tracked_abstract_base(self):
        class TrackedWithAbstractBaseToRegister(TrackedAbstractBaseA):
            pass

        with self.assertRaises(exceptions.MultipleRegistrationsError):
            register(TrackedWithAbstractBaseToRegister)
开发者ID:StepicOrg,项目名称:django-simple-history,代码行数:6,代码来源:test_models.py

示例12: ExternalModel4

from __future__ import unicode_literals

from django.db import models
from simple_history import register


class ExternalModel4(models.Model):
    name = models.CharField(max_length=100)

    class Meta:
        app_label = 'external'

register(ExternalModel4, app='simple_history.tests',
         manager_name='histories')
开发者ID:DAV3HIT3,项目名称:django-simple-history,代码行数:14,代码来源:model4.py

示例13: test_registering_with_tracked_abstract_base

 def test_registering_with_tracked_abstract_base(self):
     with self.assertRaises(exceptions.MultipleRegistrationsError):
         register(InheritTracking4)
开发者ID:emergence,项目名称:django-simple-history,代码行数:3,代码来源:tests.py

示例14: HistoricalRecords

    date = models.DateTimeField()

    history = HistoricalRecords(cascade_delete_history=True)

    @property
    def _history_date(self):
        return self.date


class Choice(models.Model):
    poll = models.ForeignKey(Poll, on_delete=models.CASCADE)
    choice = models.CharField(max_length=200)
    votes = models.IntegerField()


register(Choice)


class Voter(models.Model):
    user = models.ForeignKey(User, on_delete=models.CASCADE)
    choice = models.ForeignKey(Choice, on_delete=models.CASCADE, related_name="voters")

    def __str__(self):
        return "Voter object"


class HistoricalRecordsVerbose(HistoricalRecords):
    def get_extra_fields(self, model, fields):
        def verbose_str(self):
            return "%s changed by %s as of %s" % (
                self.history_object,
开发者ID:treyhunner,项目名称:django-simple-history,代码行数:31,代码来源:models.py

示例15: register

from django.db import models
from django.utils import timezone
from django.utils.http import urlquote
from django.utils.translation import ugettext_lazy as _
from django.contrib.auth.models import AbstractBaseUser, PermissionsMixin, BaseUserManager
from django.contrib.auth.models import User

from django.core.urlresolvers import reverse
from django.template.defaultfilters import slugify

from .choices import SEX_TYPE 
from simple_history import register

register(User)


class CustomUserManager(BaseUserManager):

    def _create_user(self, email, password, is_staff, is_superuser, **extra_fields):
        now = timezone.now()
        if not email:
            raise ValueError('The given email must be set')
        email = self.normalize_email(email)
        user = self.model(email=email, is_staff=is_staff, is_superuser=is_superuser, last_login=now, date_joined=now, **extra_fields)
        user.set_password(password)
        user.save(using=self._db)
        return user

    def create_user(self,  password=None, **extra_fields):
        return self._create_user(email, password, False, False, **extra_fields)
开发者ID:makudesu,项目名称:bnhsproject,代码行数:30,代码来源:models.py


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