Ejemplo n.º 1
0
    def handle(self, *args, **options):
        app_name = args[0]
        module = importlib.import_module(app_name)
        path = os.path.dirname(module.__file__) + os.sep
        
        project_path = os.path.dirname(os.path.normpath(os.sys.modules[settings.SETTINGS_MODULE].__file__))
        
        install_app('social_auth')

        copy_tree(os.path.dirname(djangobp.__file__) + os.sep + 'scaffold/socialauth/templates/accounts', path + '/templates/accounts', update=True)

        copy_file(os.path.dirname(djangobp.__file__) + os.sep + 'scaffold/socialauth/controllers/accounts.py', path + '/controllers', update=True)
        copy_file(os.path.dirname(djangobp.__file__) + os.sep + 'scaffold/scaffold/socialauthsettings.py', project_path, update=True)

        urls_edit = CodeEditor(path + 'urls.py')
        urls_edit.insert_line("url(r'', include('social_auth.urls')),", 'urlpatterns')
        urls_edit.commit()

        settings_edit = CodeEditor(project_path + os.sep + 'settings.py')
        settings_edit.append_line("from socialauthsettings import *")
        settings_edit.commit()
        
        # TODO copy controllers/accounts.py
        # TODO copy templates/accounts/login.html
        # TODO urls social auth
        # TODO django-social-auth settings
        
        
Ejemplo n.º 2
0
    def test_edit(self):
        source = '''
INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'djangobp',
    # Uncomment the next line to enable the admin:
    'django.contrib.admin',
    # Uncomment the next line to enable admin documentation:
    # 'django.contrib.admindocs',
)'''

        expected = '''
INSTALLED_APPS = (
    'sampleapp',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'djangobp',
    # Uncomment the next line to enable the admin:
    'django.contrib.admin',
    # Uncomment the next line to enable admin documentation:
    # 'django.contrib.admindocs',
)'''

        editor = CodeEditor(source)
        editor.insert_tuple_element('INSTALLED_APPS', 'sampleapp')
        self.assertEqual(expected, editor.to_source())
        
Ejemplo n.º 3
0
    def handle(self, *args, **options):
        app_name = args[0].split('.')[0]
        module = importlib.import_module(app_name)
        path = os.path.dirname(module.__file__) + os.sep
        model_class = get_class(args[0])
        controller = model_class.__name__.lower()

        copy_tree(os.path.dirname(djangobp.__file__) + os.sep + 'scaffold/model/templates/sample', path + '/templates/' + controller , update=True)
        copy_tree(os.path.dirname(djangobp.__file__) + os.sep + 'scaffold/model/templates/common', path + '/templates/common', update=True)
        copy_file(os.path.dirname(djangobp.__file__) + os.sep + 'scaffold/model/controllers/sample.py', path + '/controllers/' + controller + '.py', update=True)

        controller_edit = CodeEditor(path + '/controllers/' + controller + '.py')
        controller_edit.replace_all('from djangobp.scaffold.model.models import Sample', 'from %s import %s' % (model_class.__module__, model_class.__name__))
        controller_edit.replace_all('Sample',  model_class.__name__)
        controller_edit.commit()
Ejemplo n.º 4
0
    def handle(self, *args, **options):
        app_name = args[0]
        module = importlib.import_module(app_name)
        path = os.path.dirname(module.__file__) + os.sep
        
        copy_tree(os.path.dirname(djangobp.__file__) + os.sep + 'scaffold/app/controllers', path + 'controllers', update=True)
        copy_tree(os.path.dirname(djangobp.__file__) + os.sep + 'scaffold/app/templates', path + '/templates', update=True)
        copy_tree(os.path.dirname(djangobp.__file__) + os.sep + 'scaffold/app/static', path + '/static', update=True)
        
        copy_file(os.path.dirname(djangobp.__file__) + os.sep + 'scaffold/app/urls.py', path, update=True)
        
        urls_edit = CodeEditor(path + 'urls.py')
        urls_edit.replace_all('app', app_name)
        urls_edit.commit()
        project_path = os.path.dirname(os.path.normpath(os.sys.modules[settings.SETTINGS_MODULE].__file__))
        main_urls_edit = CodeEditor(project_path + os.sep + 'urls.py')
        main_urls_edit.insert_line("    (r'', include('%s'))," % (app_name + '.urls'), after='urlpatterns')
        main_urls_edit.commit()
        
        settings_edit = CodeEditor(project_path + os.sep + 'settings.py')
        settings_edit.insert_line("    '%s'," % app_name, 'INSTALLED_APPS')
        settings_edit.commit()
        # TODO urls.py edit: urlpatterns += (controller_method_resource_pattern, route(controller))
        # TODO settings.py edit: app

        
Ejemplo n.º 5
0
    def handle(self, *args, **options):
        database = args[0]
        user = args[1]
        password = args[2]
#        if 'superuser' in options: user = options['superuser']

        db = MySQLdb.connect(user=user, passwd=password)
        cursor = db.cursor()
        print 'CREATE SCHEMA `%s` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci' % database
        cursor.execute('CREATE SCHEMA `%s` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci' % database)
        cursor.close()
        db.close()
        print 'database %s created.' % database

        project_path = os.path.dirname(os.path.normpath(os.sys.modules[settings.SETTINGS_MODULE].__file__))
        edit = CodeEditor(project_path + os.sep + 'settings.py')
        edit.go_line('DATABASES = {')
        edit.go_line("'default': {")
        edit.replace_line("'ENGINE': 'django.db.backends.'", "'ENGINE': 'django.db.backends.mysql'")
        edit.replace_line("'NAME': ''", "'NAME': '%s'" % database)
        edit.replace_line("'USER': ''", "'USER': '******'" % user)
        edit.replace_line("'PASSWORD': ''", "'PASSWORD': '******'" % password)
        edit.commit()
        
        print "edited settings.py"