Ejemplo n.º 1
0
def create_main_tree(sender, **kwargs):
    Tree = get_tree_model()
    TreeItem = get_tree_item_model()
    main, c = Tree.objects.get_or_create(title='Menu principal', alias='main')
    TreeItem.objects.get_or_create(title='Início', url='home', alias='home',
                                   urlaspattern=True, inmenu=True,
                                   insitetree=True, tree=main)
Ejemplo n.º 2
0
def G3Wtree(alias, title='', items=None, **kwargs):
    """Dynamically creates and returns a sitetree.
    `items` - dynamic sitetree items objects created by `item` function.
    REPLACE SITETREE tree()  UTILS FUNCTION TO ADD CUSTOM FILED IN TREE CUSTOM MODEL.
    """
    tree_obj = get_tree_model()(alias=alias, title=title, **kwargs)
    tree_obj.id = generate_id_for(tree_obj)
    tree_obj.is_dynamic = True


    if items is not None:
        tree_obj.dynamic_items = []
        def traverse(items):
            for item in items:
                item.tree = tree_obj
                tree_obj.dynamic_items.append(item)
                if hasattr(item, 'dynamic_children'):
                    traverse(item.dynamic_children)

        traverse(items)
    return tree_obj
Ejemplo n.º 3
0
from optparse import make_option

from django.core.management.base import BaseCommand
from django.db import DEFAULT_DB_ALIAS

from sitetree.utils import get_tree_model, import_project_sitetree_modules
from sitetree.settings import APP_MODULE_NAME
from sitetree.sitetreeapp import Cache

MODEL_TREE_CLASS = get_tree_model()


class Command(BaseCommand):

    help = 'Places sitetrees of the project applications (defined in `app_name.sitetree.py`) into DB, ' \
           'replacing old ones if any.'

    args = '[app_name app_name ...]'

    option_list = BaseCommand.option_list + (make_option(
        '--database',
        action='store',
        dest='database',
        default=DEFAULT_DB_ALIAS,
        help=
        'Nominates a specific database to place trees and items into. Defaults to the "default" database.'
    ), )

    def handle(self, *apps, **options):
        using = options.get('database', DEFAULT_DB_ALIAS)
Ejemplo n.º 4
0
from django.core import serializers
from django.core.management.base import BaseCommand, CommandError
from django.db import DEFAULT_DB_ALIAS

from sitetree.utils import get_tree_model, get_tree_item_model
from sitetree.compat import CommandOption, options_getter


MODEL_TREE_CLASS = get_tree_model()
MODEL_TREE_ITEM_CLASS = get_tree_item_model()


get_options = options_getter((
    CommandOption(
        '--indent', default=None, dest='indent', type=int,
        help='Specifies the indent level to use when pretty-printing output.'),

    CommandOption('--items_only', action='store_true', dest='items_only', default=False,
         help='Export tree items only.'),

    CommandOption('--database', action='store', dest='database', default=DEFAULT_DB_ALIAS,
         help='Nominates a specific database to export fixtures from. Defaults to the "default" database.'),
))


class Command(BaseCommand):

    option_list = get_options()
    help = 'Output sitetrees from database as a fixture in JSON format.'
    args = '[tree_alias tree_alias ...]'