Commit 2abb487945ede57261122c2edd2b77e403ec2f2e
1 parent
31d4ac82
Exists in
startplugin
Implemented startplugin command
startplugin it's a command that generates the base of a Colab plugin. Just like django's startapp and startproject. Signed-off-by: Sergio Oliveira <sergio@tracy.com.br>
Showing
16 changed files
with
225 additions
and
0 deletions
Show diff stats
| @@ -0,0 +1,37 @@ | @@ -0,0 +1,37 @@ | ||
| 1 | +#!/usr/bin/env python | ||
| 2 | +""" | ||
| 3 | +{{ app_name_verbose }} Colab plugin | ||
| 4 | +=================================== | ||
| 5 | +""" | ||
| 6 | +from setuptools import setup, find_packages | ||
| 7 | + | ||
| 8 | +install_requires = ['colab'] | ||
| 9 | + | ||
| 10 | +tests_require = ['mock'] | ||
| 11 | + | ||
| 12 | + | ||
| 13 | +setup( | ||
| 14 | + name="{{ app_name_dash }}", | ||
| 15 | + version='0.1.0', | ||
| 16 | + author='<<Author Name>>', | ||
| 17 | + author_email='<<Author email>>', | ||
| 18 | + url='<< project url/repo url >>', | ||
| 19 | + description='{{ app_name_verbose }} Colab plugin', | ||
| 20 | + long_description=__doc__, | ||
| 21 | + license='<< project license >>', | ||
| 22 | + package_dir={'': 'src'}, | ||
| 23 | + packages=find_packages('src'), | ||
| 24 | + zip_safe=False, | ||
| 25 | + install_requires=install_requires, | ||
| 26 | + test_suite="tests.runtests.run", | ||
| 27 | + tests_require=tests_require, | ||
| 28 | + extras_require={'test': tests_require}, | ||
| 29 | + include_package_data=True, | ||
| 30 | + classifiers=[ | ||
| 31 | + 'Framework :: Django', | ||
| 32 | + 'Intended Audience :: Developers', | ||
| 33 | + 'Intended Audience :: System Administrators', | ||
| 34 | + 'Operating System :: OS Independent', | ||
| 35 | + 'Topic :: Software Development' | ||
| 36 | + ], | ||
| 37 | +) |
colab/conf/plugin_template/src/app_name/data_importer.py
0 → 100644
| @@ -0,0 +1 @@ | @@ -0,0 +1 @@ | ||
| 1 | +# Your models here. |
colab/conf/plugin_template/src/app_name/search_indexes.py
0 → 100644
| @@ -0,0 +1,55 @@ | @@ -0,0 +1,55 @@ | ||
| 1 | + | ||
| 2 | +## Set to false in production | ||
| 3 | +DEBUG = True | ||
| 4 | +TEMPLATE_DEBUG = False | ||
| 5 | + | ||
| 6 | +## System admins | ||
| 7 | +ADMINS = [['John Foo', 'john@example.com'], ['Mary Bar', 'mary@example.com']] | ||
| 8 | + | ||
| 9 | +MANAGERS = ADMINS | ||
| 10 | + | ||
| 11 | +COLAB_FROM_ADDRESS = '"Colab" <noreply@example.com>' | ||
| 12 | +SERVER_EMAIL = '"Colab" <noreply@example.com>' | ||
| 13 | + | ||
| 14 | +EMAIL_HOST = 'localhost' | ||
| 15 | +EMAIL_PORT = 25 | ||
| 16 | +EMAIL_SUBJECT_PREFIX = '[colab]' | ||
| 17 | + | ||
| 18 | +SECRET_KEY = 'not-a-secret' | ||
| 19 | + | ||
| 20 | +ALLOWED_HOSTS = [ | ||
| 21 | + 'localhost', | ||
| 22 | +# 'example.com', | ||
| 23 | +# 'example.org', | ||
| 24 | +# 'example.net', | ||
| 25 | +] | ||
| 26 | + | ||
| 27 | +### Uncomment to enable social networks fields profile | ||
| 28 | +SOCIAL_NETWORK_ENABLED = True | ||
| 29 | + | ||
| 30 | +## Disable indexing | ||
| 31 | +ROBOTS_NOINDEX = True | ||
| 32 | + | ||
| 33 | +LOGGING = { | ||
| 34 | + 'version': 1, | ||
| 35 | + | ||
| 36 | + 'handlers': { | ||
| 37 | + 'null': { | ||
| 38 | + 'level': 'DEBUG', | ||
| 39 | + 'class': 'logging.NullHandler', | ||
| 40 | + }, | ||
| 41 | + }, | ||
| 42 | + | ||
| 43 | + 'loggers': { | ||
| 44 | + 'colab.mailman': { | ||
| 45 | + 'handlers': ['null'], | ||
| 46 | + 'propagate': False, | ||
| 47 | + }, | ||
| 48 | + 'haystack': { | ||
| 49 | + 'handlers': ['null'], | ||
| 50 | + 'propagate': False, | ||
| 51 | + }, | ||
| 52 | + }, | ||
| 53 | +} | ||
| 54 | + | ||
| 55 | +STATICFILES_STORAGE = 'django.contrib.staticfiles.storage.StaticFilesStorage' |
| @@ -0,0 +1,32 @@ | @@ -0,0 +1,32 @@ | ||
| 1 | + | ||
| 2 | +from django.utils.translation import ugettext_lazy as _ | ||
| 3 | +from colab.plugins.utils.menu import colab_url_factory | ||
| 4 | + | ||
| 5 | +name = '{{ app_name }}' | ||
| 6 | +verbose_name = '{{ app_name_verbose }} Plugin' | ||
| 7 | + | ||
| 8 | +upstream = 'localhost' | ||
| 9 | +# middlewares = [] | ||
| 10 | + | ||
| 11 | +urls = { | ||
| 12 | + 'include': '{{ app_name }}.urls', | ||
| 13 | + 'namespace': '{{ app_name }}', | ||
| 14 | + 'prefix': '^{{ app_name }}/', | ||
| 15 | +} | ||
| 16 | + | ||
| 17 | +menu_title = _('{{ app_name }}') | ||
| 18 | + | ||
| 19 | +url = colab_url_factory('{{ app_name }}') | ||
| 20 | + | ||
| 21 | +# Extra data to be exposed to plugin app config | ||
| 22 | +extra = {} | ||
| 23 | + | ||
| 24 | +menu_urls = ( | ||
| 25 | +# Example of menu URL: | ||
| 26 | +# url(display=_('Public Projects'), viewname='gitlab', | ||
| 27 | +# kwargs={'path': 'public/projects'}, auth=False), | ||
| 28 | + | ||
| 29 | +# Example of authenticated user menu URL: | ||
| 30 | +# url(display=_('Profile'), viewname='gitlab', | ||
| 31 | +# kwargs={'path': 'profile'}, auth=True), | ||
| 32 | +) |
| @@ -0,0 +1,22 @@ | @@ -0,0 +1,22 @@ | ||
| 1 | +#!/usr/bin/env python | ||
| 2 | +import os | ||
| 3 | +import sys | ||
| 4 | + | ||
| 5 | +import django | ||
| 6 | +from django.conf import settings | ||
| 7 | +from django.test.utils import get_runner | ||
| 8 | + | ||
| 9 | + | ||
| 10 | +def run(): | ||
| 11 | + os.environ['DJANGO_SETTINGS_MODULE'] = 'colab.settings' | ||
| 12 | + os.environ['COLAB_PLUGINS'] = 'tests/plugins.d' | ||
| 13 | + os.environ['COLAB_SETTINGS'] = 'tests/colab_settings.py' | ||
| 14 | + django.setup() | ||
| 15 | + TestRunner = get_runner(settings) | ||
| 16 | + test_runner = TestRunner() | ||
| 17 | + failures = test_runner.run_tests(["tests"]) | ||
| 18 | + sys.exit(bool(failures)) | ||
| 19 | + | ||
| 20 | + | ||
| 21 | +if __name__ == "__main__": | ||
| 22 | + run() |
| @@ -0,0 +1,25 @@ | @@ -0,0 +1,25 @@ | ||
| 1 | + | ||
| 2 | +import os | ||
| 3 | + | ||
| 4 | +import colab | ||
| 5 | + | ||
| 6 | +from django.core.management.commands.startapp import Command as StartAppCommand | ||
| 7 | + | ||
| 8 | + | ||
| 9 | +class Command(StartAppCommand): | ||
| 10 | + help = ("Creates a Colab plugin directory structure for the given " | ||
| 11 | + "plugin name in the current directory or optionally in the " | ||
| 12 | + "plugin directory.") | ||
| 13 | + missing_args_message = "You must provide a plugin name" | ||
| 14 | + | ||
| 15 | + def handle_template(self, template, subdir): | ||
| 16 | + if template is None: | ||
| 17 | + return os.path.join(colab.__path__[0], 'conf', 'plugin_template') | ||
| 18 | + | ||
| 19 | + return super(Command, self).handle_template(template, subdir) | ||
| 20 | + | ||
| 21 | + def handle(self, name, **kwargs): | ||
| 22 | + kwargs['app_name_dash'] = name.replace('_', '-') | ||
| 23 | + kwargs['app_name_camel'] = name.title().replace('_', '') | ||
| 24 | + kwargs['app_name_verbose'] = name.replace('_', ' ').title() | ||
| 25 | + super(Command, self).handle(name, **kwargs) |
-
Nas linhas 26 e 30 do arquivo colab/conf/plugin_template/tests/plugins.d/app_name.py,
gitlabestá hardcoded. -
A definição da classe de teste do plugin não deveria ser {{ app_name_camel }}PluginTest? Em colab/conf/plugin_template/tests/test_plugin.py.