本文整理汇总了Python中mptt.register函数的典型用法代码示例。如果您正苦于以下问题:Python register函数的具体用法?Python register怎么用?Python register使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了register函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: render_organization_missions
def render_organization_missions(apps, schema_editor):
Organization = apps.get_model("facts", "Organization")
mptt.register(Organization)
db_alias = schema_editor.connection.alias
for obj in Organization.objects.using(db_alias).exclude(mission=''):
obj.mission_rendered = render_markdown(obj.mission)
obj.save()
示例2: rebuild_pages
def rebuild_pages(apps, schema_editor):
manager = mptt.managers.TreeManager()
page_model = apps.get_model("shoop_simple_cms", "Page")
manager.model = page_model
mptt.register(page_model, order_insertion_by=["-available_from"])
manager.contribute_to_class(page_model, 'objects')
manager.rebuild()
示例3: rebuild_province_mptt
def rebuild_province_mptt(apps, schema_editor):
manager = mptt.managers.TreeManager()
Province = apps.get_model("promrep", "Province")
manager.model = Province
mptt.register(Province, order_insertion_by=['name'])
manager.contribute_to_class(Province, 'objects')
manager.rebuild()
示例4: forward
def forward(apps, schema_editor):
# the zero mptt fields won't do, we need a treemanager to build the mptt tree
manager = mptt.managers.TreeManager()
Organization = apps.get_model("events", "Organization")
manager.model = Organization
mptt.register(Organization)
manager.contribute_to_class(Organization, 'objects')
manager.rebuild()
示例5: rebuild_trees
def rebuild_trees(apps, schema_editor):
for tree in ['Location', 'ItemType']:
manager = mptt.managers.TreeManager()
Object = apps.get_model('inventory', tree)
manager.model = Object
mptt.register(Object, order_insertion_by=['display_order', 'id'])
manager.contribute_to_class(Object, 'objects')
manager.rebuild()
示例6: forwards
def forwards(self, orm):
# Note: Don't use "from appname.models import ModelName".
# Use orm.ModelName to refer to models in this application,
# and orm['appname.ModelName'] for models in other applications.
# Take PartList and "extend" it with mtpp stuff
# http://django-mptt.github.io/django-mptt/models.html#registration-of-existing-models
mptt.register(orm.PartList)
for email in orm.Email.objects.all():
self.flag_setter(email)
try:
if email.body is not None:
body = email.body.encode("utf8")
else:
body = ""
except UnicodeError:
body = email.body
body = self.make_body(orm, data=body)
first_part = orm.PartList(email=email, body=body, parent=None)
first_part.save()
ordinal = 0
for header in email.headers.all():
self.make_header(orm, name=header.name, data=header.data, part=first_part, ordinal=ordinal)
ordinal = ordinal + 1
old_attachments = email.attachments.all()
if len(old_attachments) > 0:
self.make_header(orm, name="Content-Type", data="multipart/mixed", part=first_part, ordinal=ordinal)
for attachment in old_attachments:
try:
if attachment._data is not None:
data = attachment._data.encode("utf8")
else:
data = ""
except UnicodeError:
data = attachment._data
try:
data = base64.decodestring(data)
except binascii.Error:
pass
body = self.make_body(orm, data=data, path=attachment.path)
part = orm.PartList(email=email, body=body, parent=first_part)
part.save()
self.make_header(orm, name="Content-Type", data=attachment.content_type, part=part, ordinal=0)
self.make_header(orm, name="Content-Disposition", data=attachment.content_disposition, part=part, ordinal=1)
示例7: copy_preambles
def copy_preambles(apps, schema_editor):
Preamble = apps.get_model('regcore', 'Preamble')
Document = apps.get_model('regcore', 'Document')
# Bind manager
manager = mptt.managers.TreeManager()
manager.model = Document
mptt.register(Document)
manager.contribute_to_class(Document, 'objects')
for pre in Preamble.objects.all():
write_node(Document, pre.data, 'preamble', pre.data['label'])
示例8: uncopy_preambles
def uncopy_preambles(apps, schema_editor):
Preamble = apps.get_model('regcore', 'Preamble')
Document = apps.get_model('regcore', 'Document')
# Bind manager
manager = mptt.managers.TreeManager()
manager.model = Document
mptt.register(Document)
manager.contribute_to_class(Document, 'objects')
for doc in Document.objects.filter(doc_type='preamble', root=True):
nodes = doc.get_descendants(include_self=True)
data = serialize(nodes[0], build_adjacency_map(nodes))
pre = Preamble(document_number=doc.label_string, data=data)
pre.save()
示例9: rebuild
def rebuild(apps, schema_editor):
Regulation = apps.get_model('regcore', 'Regulation')
Regulation.objects.filter(root=False).delete()
# Bind manager
manager = mptt.managers.TreeManager()
manager.model = Regulation
mptt.register(Regulation)
manager.contribute_to_class(Regulation, 'objects')
for root in Regulation.objects.all():
serialized = {
'text': root.text,
'title': root.title,
'label': root.label_string.split('-'),
'node_type': root.node_type,
'children': root.children,
}
root.delete()
write_node(Regulation, serialized, root.version, root.label_string)
示例10: content_splitted
def content_splitted(self):
return self.content_highlighted.splitlines()
def save(self, *args, **kwargs):
if not self.pk:
self.published = datetime.datetime.now()
self.secret_id = generate_secret_id()
self.content_highlighted = self.content
super(Snippet, self).save(*args, **kwargs)
def get_absolute_url(self):
return reverse('snippet_details', kwargs={'snippet_id': self.secret_id})
def __unicode__(self):
return '%s' % self.secret_id
mptt.register(Snippet, order_insertion_by=['content'])
class SpamwordManager(models.Manager):
def get_regex(self):
return re.compile(r'|'.join((i[1] for i in self.values_list())),
re.MULTILINE)
class Spamword(models.Model):
word = models.CharField(max_length=100)
objects = SpamwordManager()
def __unicode__(self):
return self.word
示例11: SingleProxyModel
# 4. proxy models
class SingleProxyModel(ConcreteModel):
objects = CustomTreeManager()
class Meta:
proxy = True
class DoubleProxyModel(SingleProxyModel):
class Meta:
proxy = True
class AutoNowDateFieldModel(MPTTModel):
parent = TreeForeignKey('self', null=True, blank=True, related_name='children')
now = models.DateTimeField(auto_now_add=True)
class MPTTMeta:
order_insertion_by = ('now',)
# test registering of remote model
class Group(models.Model):
name = models.CharField(max_length=100)
TreeForeignKey(Group, blank=True, null=True).contribute_to_class(Group, 'parent')
mptt.register(Group, order_insertion_by=('name',))
示例12: getattr
dot = ENTRY_BASE_MODEL.rindex('.')
module_name = ENTRY_BASE_MODEL[:dot]
class_name = ENTRY_BASE_MODEL[dot + 1:]
try:
_class = getattr(import_module(module_name), class_name)
return _class
except (ImportError, AttributeError):
warnings.warn('%s cannot be imported' % ENTRY_BASE_MODEL,
RuntimeWarning)
return EntryAbstractClass
class Entry(get_base_model()):
"""Final Entry model"""
class Meta:
"""Entry's Meta"""
ordering = ['-creation_date']
verbose_name = _('entry')
verbose_name_plural = _('entries')
permissions = (('can_view_all', 'Can view all'),
('can_change_author', 'Can change author'), )
moderator.register(Entry, EntryCommentModerator)
mptt.register(Category, order_insertion_by=['title'])
post_save.connect(ping_directories_handler, sender=Entry,
dispatch_uid='zinnia.entry.post_save.ping_directories')
post_save.connect(ping_external_urls_handler, sender=Entry,
dispatch_uid='zinnia.entry.post_save.ping_external_urls')
示例13: _
return True
except Folder.DoesNotExist:
return False
class Meta:
unique_together = (('parent', 'name'),)
ordering = ('name',)
permissions = (("can_use_directory_listing",
"Can use directory listing"),)
app_label = 'filer'
verbose_name = _("Folder")
verbose_name_plural = _("Folders")
# MPTT registration
try:
mptt.register(Folder)
except mptt.AlreadyRegistered:
pass
@python_2_unicode_compatible
class FolderPermission(models.Model):
ALL = 0
THIS = 1
CHILDREN = 2
ALLOW = 1
DENY = 0
TYPES = (
(ALL, _('all items')),
示例14: Clade
class Meta:
unique_together = ('column', 'row')
class Clade(models.Model):
alignment = models.ForeignKey(Alignment, related_name='clades', db_index=True)
num = models.IntegerField(editable=False)
cumulative_branch_length = models.FloatField(default=0.0, editable=False)
local_branch_length = models.FloatField(editable=False)
row = models.OneToOneField(Row, null=True) # leaf nodes only
parent = models.ForeignKey('self', null=True, related_name='children')
# use django-mptt to manage tree structure of Clades. Possibly this should be in __init__.py?
try:
mptt.register(Clade, order_insertion_by=["num"])
except mptt.AlreadyRegistered:
pass
class ThresholdGrouping(models.Model):
alignment = models.ForeignKey(Alignment, related_name='threshold_groupings')
root_clades = models.ManyToManyField(Clade, related_name='threshold_groupings')
threshold = models.FloatField()
class RowGroup(models.Model):
# issue. Would like to have a 'Group' table against which to score relatedness.
# ThresholdGroupings are currently
示例15: Genre
from mptt.models import MPTTModel, TreeForeignKey
import mptt
class Genre(MPTTModel):
name = models.CharField(max_length=50)
parent = TreeForeignKey('self', null=True, blank=True, related_name='children', db_index=True)
user = models.ForeignKey(User)
class MPTTMeta:
level_attr = 'mptt_level'
order_insertion_by = ['name']
def __str__(self):
return self.name
mptt.register(Genre, order_insertion_by=['name'])
class Icon(models.Model):
icon_name = models.CharField(max_length=50)
def __str__(self):
return self.icon_name
class Note(models.Model):
note_name = models.CharField(max_length=50)
note_text = models.TextField()
icon_name = models.ManyToManyField(Icon)
user = models.ForeignKey(User)
parent = models.ForeignKey(Genre)