def handle(self, *args, **options):
        verbosity = options.get('verbosity', 1)
        # First check if public schema is synced already
        write = self.stdout.write
        if len(args) == 0:
            raise CommandError('You need to specify schema names to sync!')

        if args[0] != conn.PUBLIC_SCHEMA:
            conn.schema = conn.PUBLIC_SCHEMA
            # There are no tables in public schema
            if not conn.introspection.table_names():
                raise CommandError('You should sync the public schema first!')

        for schema in args:
            conn.schema = schema
            if not conn.schema_exists(schema):
                conn.create_schema(schema)
            auth_user_not_in_tenant = 'auth.User' in FORCED_MODELS or 'auth' not in TENANT_APP_LABELS
            if (conn.schema_is_public() and not is_shared(auth_app.User) or
               (not conn.schema_is_public() and auth_user_not_in_tenant)):
                    if verbosity > 1:
                        write("Disconnect auth.User signal handlers, as it is not synced...")
                    post_syncdb.disconnect(create_permissions,
                                           dispatch_uid="django.contrib.auth.management.create_permissions")
                    post_syncdb.disconnect(create_superuser, sender=auth_app,
                                           dispatch_uid="django.contrib.auth.management.create_superuser")

            call_command('syncdb', **options)
Exemple #2
0
def set_signals():
    """
    Add load_data to amcat.models::post_syncdb to make sure data is loaded before
    auth, and unhook the django.auth create_superuser hook
    """
    post_syncdb.connect(initialize, sender=amcat.models)
    # From http://stackoverflow.com/questions/1466827/ --
    post_syncdb.disconnect(
        create_superuser,
        sender=auth_models,
        dispatch_uid='django.contrib.auth.management.create_superuser')
Exemple #3
0
def set_signals():
    """
    Add load_data to amcat.models::post_syncdb to make sure data is loaded before
    auth, and unhook the django.auth create_superuser hook
    """
    post_syncdb.connect(initialize, sender=amcat.models)
    # From http://stackoverflow.com/questions/1466827/ --
    post_syncdb.disconnect(
        auth_models.User.objects.create_superuser,
        sender=auth_models,
        dispatch_uid='django.contrib.auth.management.create_superuser'
    )
Exemple #4
0
def fix_auth_post_syncdb():
    """Disconnects post_syncdb signals so that syncdb doesn't attempt to call
       create_permissions or create_superuser before South migrations have had
       chance to run. Connects a new post_syncdb hook that creates permissions
       during tests.
       """
    # ensure signals have had a chance to be connected
    __import__('django.contrib.auth.management')
    post_syncdb.disconnect(
        dispatch_uid="django.contrib.auth.management.create_permissions")
    post_syncdb.disconnect(
        dispatch_uid="django.contrib.auth.management.create_superuser")
    post_syncdb.connect(
        create_permissions_for_tests,
        dispatch_uid="go.base.models.create_permissions_for_tests")
def is_tenant_user_model(sender):
    from .models import TenantModelBase

    if isinstance(sender, TenantModelBase):
        global TENANT_AUTH_USER_MODEL
        TENANT_AUTH_USER_MODEL = True
        # Disconnect the `create_superuser` post-syncdb signal receiver
        # since the swapped for user model is tenant specific
        post_syncdb.disconnect(
            create_superuser, sender=auth_app, dispatch_uid="django.contrib.auth.management.create_superuser"
        )
    else:
        # Make sure the `create_superuser` signal is correctly attached
        # since this module might be reloaded during testing
        post_syncdb.connect(
            create_superuser, sender=auth_app, dispatch_uid="django.contrib.auth.management.create_superuser"
        )
def is_tenant_user_model(sender):
    from .models import TenantModelBase
    if isinstance(sender, TenantModelBase):
        global TENANT_AUTH_USER_MODEL
        TENANT_AUTH_USER_MODEL = True
        # Disconnect the `create_superuser` post-syncdb signal receiver
        # since the swapped for user model is tenant specific
        post_syncdb.disconnect(
            create_superuser,
            sender=auth_app,
            dispatch_uid='django.contrib.auth.management.create_superuser'
        )
    else:
        # Make sure the `create_superuser` signal is correctly attached
        # since this module might be reloaded during testing
        post_syncdb.connect(
            create_superuser,
            sender=auth_app,
            dispatch_uid='django.contrib.auth.management.create_superuser',
        )
Exemple #7
0
                confirm = raw_input("Please enter either 'yes' or 'no': ")
        if verbosity >= 1:
            print
            print(
                "Creating initial content "
                "(About page, Blog, Contact form, Gallery) ...")
            print
        call_command("loaddata", "mezzanine.json")
        zip_name = "gallery.zip"
        copy_test_to_media("mezzanine.core", zip_name)
        gallery = Gallery.objects.get()
        gallery.zip_import = zip_name
        gallery.save()


def create_site(app, created_models, verbosity, interactive, **kwargs):
    if settings.DEBUG and Site in created_models:
        domain = "127.0.0.1:8000"
        if verbosity >= 1:
            print
            print "Creating default Site %s ... " % domain
            print
        Site.objects.create(name="Local development", domain=domain)


if not settings.TESTING:
    post_syncdb.connect(create_user, sender=auth_app)
    post_syncdb.connect(create_pages, sender=pages_app)
    post_syncdb.connect(create_site, sender=sites_app)
    post_syncdb.disconnect(create_default_site, sender=sites_app)
Exemple #8
0
                                "'domain:port'. For example 'localhost:8000' "
                                "or 'www.example.com'. Hit enter to use the "
                                "default (%s): " % domain)
            if entered:
                domain = entered.strip("': ")
        if verbosity >= 1:
            print
            print "Creating default Site %s ... " % domain
            print
        Site.objects.create(name="Default", domain=domain)


def install_optional_data(verbosity):
    call_command("loaddata", "mezzanine_optional.json")
    zip_name = "gallery.zip"
    copy_test_to_media("mezzanine.core", zip_name)
    gallery = Gallery.objects.get()
    gallery.zip_import = zip_name
    gallery.save()
    if verbosity >= 1:
        print
        print ("Creating demo content "
               "(About page, Blog, Contact form, Gallery) ...")
        print

if not settings.TESTING:
    post_syncdb.connect(create_user, sender=auth_app)
    post_syncdb.connect(create_pages, sender=pages_app)
    post_syncdb.connect(create_site, sender=sites_app)
    post_syncdb.disconnect(create_default_site, sender=sites_app)
Exemple #9
0
from django.db.models.signals import post_syncdb

from djangoplugins import models as plugins_app
from djangoplugins.management import sync_plugins

post_syncdb.disconnect(sync_plugins, sender=plugins_app)
Exemple #10
0
        for codename, name in _get_all_permissions(klass._meta):
            p, created = Permission.objects.get_or_create(
                codename=codename,
                content_type__pk=ctype.id,
                defaults={
                    'name': name,
                    'content_type': ctype
                })
            if created and verbosity >= 2:
                print("Adding permission '%s'" % p)


# Replace the original handling with our modified one if
# CONTENTTYPE_NO_TRAVERSE_PROXY is set.
# This is needed if you want to use proper permissions for proxy models
# that are tied to the proxy application.
# See also: http://code.djangoproject.com/ticket/11154
try:
    settings.CONTENTTYPE_NO_TRAVERSE_PROXY
except AttributeError:
    pass
else:
    if settings.CONTENTTYPE_NO_TRAVERSE_PROXY:
        from django.db.models.signals import post_syncdb
        post_syncdb.disconnect(
            create_permissions,
            dispatch_uid='django.contrib.auth.management.create_permissions')
        post_syncdb.connect(
            create_permissions_respecting_proxy,
            dispatch_uid='django.contrib.auth.management.create_permissions')
Exemple #11
0
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

# Copyright 2014, Cercle Informatique ASBL. All rights reserved.
#
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or (at
# your option) any later version.
#
# This software was made by hast, C4, ititou at UrLab, ULB's hackerspace

from django.db.models.signals import post_syncdb
from django.contrib.auth.management import create_superuser
from django.contrib.auth import models as auth_app


# when create the DB with these models, don't create a super user
post_syncdb.disconnect(create_superuser, sender=auth_app, dispatch_uid="django.contrib.auth.management.create_superuser")
Exemple #12
0
import guardian
guardian.management.create_anonymous_user = new_create_anonymous_user

# ------------------------------------------------------------------------

# Prevent interactive question about wanting a superuser created.  (This code
# has to go in this "models" module so that it gets processed by the "syncdb"
# command during database creation.)
#
# From http://stackoverflow.com/questions/1466827/ --

from django.contrib.auth import models as auth_models
from django.contrib.auth.management import create_superuser

post_syncdb.disconnect(
    create_superuser,
    sender=auth_models,
    dispatch_uid='django.contrib.auth.management.create_superuser')

# ------------------------------------------------------------------------

# Include models for deprecated PHP-only tables, just so that we can
# remove them with South in a later migration.

class DeprecatedAppliedMigrations(models.Model):
    class Meta:
        db_table = "applied_migrations"
    id = models.CharField(max_length=32, primary_key=True)

class DeprecatedSession(models.Model):
    class Meta:
        db_table = "sessions"
Exemple #13
0
        # If the permissions exists, move on.
        if (ctype.pk, codename) in all_perms:
            continue
        print 'Create perm: %s' % codename
        p = auth_app.Permission.objects.create(
            codename=codename,
            name=name,
            content_type=ctype
        )
        if verbosity >= 2:
            print "Adding permission '%s'" % p


# check for all model to create extra permissions after a syncdb
from django.contrib.auth.management import create_permissions
post_syncdb.disconnect(create_permissions, dispatch_uid='django.contrib.auth.management.create_permissions')
post_syncdb.connect(create_permissions_respecting_proxy, dispatch_uid='django.contrib.auth.management.create_permissions')


#dynamic check view permission actions
def check_view_readonly_action(obj):
    bool_list = []
    if not isinstance(obj, PermissionReadonlyView):
        return False

    action_items = obj.get_view_readonly_actions()
    if not action_items:
        return False

    for func in action_items:
        if callable(func):
Exemple #14
0
def _run_init_sql(**kwargs):
    connection.cursor().execute(
        (read_file(PATSAK_SQL_PATH) +
         read_file(CHATLANIAN_SQL_PATH)).replace('%', '%%'))
    post_syncdb.disconnect(_run_init_sql, sender=models)
Exemple #15
0
from bricks.models import Brick
from bricks.collections.models import Collection

from .fields import CropImageField

from django.db.models import get_models
from django.db.models.signals import post_syncdb
from django.utils.encoding import smart_unicode

from django.contrib.auth.management import create_permissions, _get_all_permissions

# Hack the postsyncdb signal, so we can fix the misbehavior of the
# content_type
# assignment to the proxy models.
# see http://code.djangoproject.com/ticket/11154
"""
def create_permissions_respecting_proxy(app, created_models, verbosity, **kwargs):

    if not kwargs['sender'].__name__ == 'bricks.images.models':
        # if not in 'customer' app, then use the original function
        create_permissions(app, created_models, verbosity, **kwargs)
        return

    from django.contrib.contenttypes.models import ContentType
    from django.contrib.auth import models as auth_app
    app_models = get_models(app)
    searched_perms = list()
    ctypes = set()
    for klass in app_models:
        # this is where the difference is: the original create_permissions
        # use ctype = ContentType.objects.get_for_model(klass)
Exemple #16
0
    # have run and if there are really no users.
    if (app == 'storybase_user' and kwargs.get('interactive', True)
            and User.objects.filter(is_superuser=True).count() == 0):
        msg = (
            "\nYou just installed Django's auth system, which means you "
            "don't have any superusers defined.\nWould you like to create one "
            "now? (yes/no): ")
        confirm = raw_input(msg)
        while 1:
            if confirm not in ('yes', 'no'):
                confirm = raw_input('Please enter either "yes" or "no": ')
                continue
            if confirm == 'yes':
                call_command("createsuperuser", interactive=True)
            break


if 'south' in settings.INSTALLED_APPS:
    # We have to wait until the user profile model is created before
    # creating the initial superuser.  Otherwise, the post_save handler
    # that creates the profile fails
    #from south.signals import post_migrate
    post_syncdb.disconnect(
        default_create_superuser,
        sender=auth_app,
        dispatch_uid="django.contrib.auth.management.create_superuser")
    # TODO: Figure out if there's a way to successfully connect this.
    # Unfortunately, it's being called during unit tests, so I'm just
    # disabling the new user creation prompt altogether.
    #post_migrate.connect(create_superuser)
Exemple #17
0
def _run_init_sql(**kwargs):
    connection.cursor().execute(
        (read_file(PATSAK_SQL_PATH) + read_file(CHATLANIAN_SQL_PATH)).replace(
            '%', '%%'))
    post_syncdb.disconnect(_run_init_sql, sender=models)