本文整理汇总了Python中mptt.register函数的典型用法代码示例。如果您正苦于以下问题:Python register函数的具体用法?Python register怎么用?Python register使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了register函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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()
开发者ID:CSIS-iLab,项目名称:new-silk-road,代码行数:7,代码来源:0024_organization_mission_rendered.py
示例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()
开发者ID:00WhengWheng,项目名称:shuup,代码行数:7,代码来源:0004_add_parents.py
示例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()
开发者ID:kingsdigitallab,项目名称:dprr-django,代码行数:7,代码来源:0054_rebuild_provinces_tree.py
示例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()
开发者ID:City-of-Helsinki,项目名称:linkedevents,代码行数:8,代码来源:0041_rebuild_organization_mptt_index.py
示例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()
开发者ID:GETLIMS,项目名称:LIMS-Backend,代码行数:8,代码来源:0017_auto_20170131_1430.py
示例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)
开发者ID:Inboxen,项目名称:infrastructure,代码行数:54,代码来源:0003_data_jig.py
示例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'])
开发者ID:cmc333333,项目名称:regulations-core,代码行数:12,代码来源:0012_migrate_documents.py
示例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()
开发者ID:cmc333333,项目名称:regulations-core,代码行数:15,代码来源:0012_migrate_documents.py
示例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)
开发者ID:cmc333333,项目名称:regulations-core,代码行数:20,代码来源:0003_mptt_copy_children.py
示例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
开发者ID:hien,项目名称:dpaste.de,代码行数:30,代码来源:models.py
示例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',))
开发者ID:MCGallaspy,项目名称:django-mptt,代码行数:28,代码来源:models.py
示例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')
开发者ID:amakhnach,项目名称:django-blog-zinnia,代码行数:30,代码来源:models.py
示例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')),
开发者ID:EnTeQuAk,项目名称:django-filer,代码行数:31,代码来源:foldermodels.py
示例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
开发者ID:rklancer,项目名称:mssm,代码行数:31,代码来源:models.py
示例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)
开发者ID:MaistrenkoAnton,项目名称:organizator,代码行数:31,代码来源:models.py
示例16: _
return self.get_caption_formatted(escape=False)
get_caption_formatted_unescaped.allow_tags = True
get_caption_formatted_unescaped.short_description = _('displayed metadata')
@property
def alt(self):
"""Returns object metadata suitable for use as the HTML ``alt``
attribute. You can use this method in templates::
<img src="{{ node.file.url }}" alt="{{ node.alt }}" />
"""
if self.override_alt != '' and self.override_alt is not None:
return self.override_alt
elif self.override_caption != '' and self.override_caption is not None:
return self.override_caption
else:
return self.get_metadata_display()
# Legacy mptt support
if ModelBase == models.Model:
FileNode._mptt_meta = FileNode._meta
try:
mptt.register(FileNode,
order_insertion_by=FileNode.MPTTMeta.order_insertion_by)
except mptt.AlreadyRegistered:
pass
from media_tree.utils import autodiscover_media_extensions
autodiscover_media_extensions()
开发者ID:SebCorbin,项目名称:django-media-tree,代码行数:30,代码来源:models.py
示例17: MultiOrder
class MultiOrder(models.Model):
name = models.CharField(max_length=50)
size = models.PositiveIntegerField()
date = models.DateField()
parent = models.ForeignKey('self', null=True, blank=True, related_name='children')
def __unicode__(self):
return self.name
class Node(models.Model):
parent = models.ForeignKey('self', null=True, blank=True, related_name='children')
class OrderedInsertion(models.Model):
name = models.CharField(max_length=50)
parent = models.ForeignKey('self', null=True, blank=True, related_name='children')
def __unicode__(self):
return self.name
class Tree(models.Model):
parent = models.ForeignKey('self', null=True, blank=True, related_name='children')
mptt.register(Category)
mptt.register(Genre)
mptt.register(Insert)
mptt.register(MultiOrder, order_insertion_by=['name', 'size', 'date'])
mptt.register(Node, left_attr='does', right_attr='zis', level_attr='madness',
tree_id_attr='work')
mptt.register(OrderedInsertion, order_insertion_by=['name'])
mptt.register(Tree)
开发者ID:cortextual,项目名称:django-mptt,代码行数:30,代码来源:models.py
示例18: Topic
conflicts[obj.name] = obj
for child in children:
if child.name in conflicts:
squash.append((child.id, conflicts[child.name].id))
examine.append((child, conflicts[child.name]))
else:
to_move.append((child, merge_node))
if squash:
signals.pre_merge.send(sender=self, merge_pairs=squash)
if to_move:
signals.pre_move.send(sender=self, moving=to_move)
for child, new_parent in to_move:
# Need to refresh the instance, as previous moves might have
# changed the "lft" and "rght" attributes.
new_parent = manager.get(id=new_parent.id)
child.move_to(new_parent)
self.delete()
class Topic(AbstractTopic):
"""
The basic concrete class for a topic node. API details are defined by the
AbstractTopic base class.
"""
pass
mptt.register(Topic, order_insertion_by=["name"])
开发者ID:pombredanne,项目名称:django-acacia,代码行数:30,代码来源:models.py
示例19: get_root_menu
def get_root_menu(self):
return self.parent
def get_children(self):
return CMSMenu.objects.get_children(self)
name = property(get_name)
status = property(get_page_status)
def get_controller(self):
if hasattr(self.content_object, 'get_controller'):
return self.content_object.get_controller()
return None
mptt.register(CMSMenu, order_insertion_by=['object_id'])
class MenuLocalLink(models.Model):
""" MenuLocalLink is to link static page dynamicaly into the menu """
name = models.CharField(max_length=100, unique=False, help_text=_('Max 100 characters.'))
local_link = models.CharField(max_length=200, null=True, blank=True,
help_text="Link on this web site. ex. /www/page/")
class Meta:
app_label = "www"
verbose_name = 'Menu - Local Link'
verbose_name_plural = 'Menu - Local Link'
def __unicode__(self):
return self.name
开发者ID:francisl,项目名称:vcms,代码行数:30,代码来源:menu.py
示例20: NewsAndEventsPlugin
event = kwargs['instance']
event.get_root().check_date()
post_save.connect(receiver_function, sender = Event)
class NewsAndEventsPlugin(CMSPlugin, UniversalPluginOptions):
DISPLAY = (
("news & events", u"News and events"),
("news", u"News only"),
("events", u"Events only"),
)
display = models.CharField("Show", max_length=25,choices = DISPLAY, default = "news_and_events")
entity = models.ForeignKey(Entity, null=True, blank=True,
help_text="Leave blank for autoselect",
related_name="news_events_plugin")
show_previous_events = models.BooleanField()
news_heading_text = models.CharField(max_length=25, default="News")
events_heading_text = models.CharField(max_length=25, default="Events")
try:
mptt.register(Event)
except mptt.AlreadyRegistered:
pass
'''
entity: ('name',)
building: ('name', 'number', 'street', 'postcode', 'site__site_name',)
website: ('title_set__title',)
'''
开发者ID:airtonix,项目名称:Arkestra,代码行数:30,代码来源:models.py
注:本文中的mptt.register函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论