Commit 1607da034dcfc8aec528c6cac0f8a16653e50a55

Authored by Sergio Oliveira
Committed by Gust
1 parent 83dc32cc

Added support to install apps arbitrary apps

Now apps can be installed from settings.yml
colab/plugins/__init__.py 0 → 100644
colab/plugins/urls.py 0 → 100644
... ... @@ -0,0 +1,21 @@
  1 +
  2 +from django.conf import settings
  3 +from django.conf.urls import patterns, url, include
  4 +from django.core.exceptions import ImproperlyConfigured
  5 +
  6 +undef_url_include_msg = (u'COLAB_APP with urls must define '
  7 + 'the `include` attribute')
  8 +
  9 +urlpatterns = patterns('')
  10 +
  11 +for app_name, app in settings.COLAB_APPS.items():
  12 + if not app or 'urls' not in app:
  13 + continue
  14 +
  15 + urls = app.get('urls')
  16 + if not urls.get('include'):
  17 + raise ImproperlyConfigured(undef_url_include_msg)
  18 + urlpatterns += patterns('',
  19 + url(urls.get('prefix', r''), include(urls['include'],
  20 + namespace=urls.get('namespace'))),
  21 + )
... ...
colab/settings.py
... ... @@ -50,7 +50,6 @@ INSTALLED_APPS = (
50 50 'hitcounter',
51 51 'i18n_model',
52 52 'mptt',
53   - 'dpaste',
54 53 'taggit',
55 54  
56 55 # Own apps
... ... @@ -292,19 +291,6 @@ CONVERSEJS_SHOW_ONLY_ONLINE_USERS = True
292 291 # Tastypie settings
293 292 TASTYPIE_DEFAULT_FORMATS = ['json', ]
294 293  
295   -# Dpaste settings
296   -DPASTE_EXPIRE_CHOICES = (
297   - ('onetime', _(u'One Time Snippet')),
298   - (3600, _(u'In one hour')),
299   - (3600 * 24 * 7, _(u'In one week')),
300   - (3600 * 24 * 30, _(u'In one month')),
301   - ('never', _(u'Never')),
302   -)
303   -DPASTE_EXPIRE_DEFAULT = DPASTE_EXPIRE_CHOICES[4][0]
304   -DPASTE_DEFAULT_GIST_DESCRIPTION = 'Gist created from Colab DPaste'
305   -DPASTE_DEFAULT_GIST_NAME = 'colab_paste'
306   -DPASTE_LEXER_DEFAULT = 'text'
307   -
308 294 from .utils.conf import load_yaml_settings
309 295 locals().update(load_yaml_settings())
310 296  
... ... @@ -328,3 +314,8 @@ PROXIED_APPS = locals().get('PROXIED_APPS') or {}
328 314  
329 315 for app_label in PROXIED_APPS.keys():
330 316 INSTALLED_APPS += ('colab.proxy.{}'.format(app_label),)
  317 +
  318 +COLAB_APPS = locals().get('COLAB_APPS') or {}
  319 +
  320 +for app in COLAB_APPS:
  321 + INSTALLED_APPS += (app,)
... ...
colab/urls.py
... ... @@ -7,8 +7,7 @@ from django.views.generic import RedirectView
7 7  
8 8 admin.autodiscover()
9 9  
10   -urlpatterns = patterns(
11   - '',
  10 +urlpatterns = patterns('',
12 11 url(r'^robots.txt$', 'colab.home.views.robots', name='robots'),
13 12 url(r'^dashboard$', 'colab.home.views.dashboard', name='dashboard'),
14 13 url(r'^$', RedirectView.as_view(url=settings.COLAB_HOME_URL), name='home'),
... ... @@ -35,8 +34,6 @@ urlpatterns = patterns(
35 34  
36 35 url(r'^planet/', include('feedzilla.urls')),
37 36  
38   - url(r'paste/', include('dpaste.urls.dpaste')),
39   -
40 37 # Uncomment the next line to enable the admin:
41 38 url(r'^colab/admin/', include(admin.site.urls)),
42 39  
... ... @@ -44,6 +41,8 @@ urlpatterns = patterns(
44 41 url(r'^gitlab/', include('colab.proxy.gitlab.urls')),
45 42 url(r'^social/', include('colab.proxy.noosfero.urls')),
46 43 url(r'^ci/', include('colab.proxy.jenkins.urls')),
  44 +
  45 + url(r'', include('colab.plugins.urls')),
47 46 )
48 47  
49 48 if settings.DEBUG:
... ...
colab/utils/conf.py
... ... @@ -2,6 +2,8 @@
2 2 import os
3 3 import yaml
4 4  
  5 +import yamlordereddictloader
  6 +
5 7 from django.core.exceptions import ImproperlyConfigured
6 8  
7 9  
... ... @@ -14,7 +16,8 @@ class InaccessibleYAMLSettings(ImproperlyConfigured):
14 16 def _load_yaml_file(yaml_path):
15 17 try:
16 18 with open(yaml_path) as yaml_file:
17   - yaml_settings = yaml.load(yaml_file.read())
  19 + yaml_settings = yaml.load(yaml_file.read(),
  20 + yamlordereddictloader.Loader)
18 21 except IOError:
19 22 msg = ('Could not open settings file {}. Please '
20 23 'check if the file exists and if user '
... ...