Commit c792331e8ce28151b0788f8ef74c35841af39e7b
Committed by
Sergio Oliveira
1 parent
a1c9a273
Create example of plugin using signals structure
Using the gitlab plugin structure to test the signal structure created by using a GitlabProject method to send a dummy signal. Signed-off-by: Lucas Moura <lucas.moura128@gmail.com> Signed-off-by: Gustavo Jaruga <darksshades@gmail>
Showing
5 changed files
with
45 additions
and
1 deletions
Show diff stats
colab/plugins/gitlab/apps.py
@@ -2,11 +2,16 @@ | @@ -2,11 +2,16 @@ | ||
2 | from django.utils.translation import ugettext_lazy as _ | 2 | from django.utils.translation import ugettext_lazy as _ |
3 | 3 | ||
4 | from ..utils.apps import ColabProxiedAppConfig | 4 | from ..utils.apps import ColabProxiedAppConfig |
5 | +from colab.signals.tasks import register_signal, connect_signal | ||
6 | +from colab.plugins.gitlab.tasks import handling_method | ||
5 | 7 | ||
6 | 8 | ||
7 | class ProxyGitlabAppConfig(ColabProxiedAppConfig): | 9 | class ProxyGitlabAppConfig(ColabProxiedAppConfig): |
8 | name = 'colab.plugins.gitlab' | 10 | name = 'colab.plugins.gitlab' |
9 | verbose_name = 'Gitlab Proxy' | 11 | verbose_name = 'Gitlab Proxy' |
12 | + short_name = 'gitlab' | ||
13 | + | ||
14 | + signals_list = ['gitlab_create_project'] | ||
10 | 15 | ||
11 | menu = { | 16 | menu = { |
12 | 'title': _('Code'), | 17 | 'title': _('Code'), |
@@ -23,3 +28,9 @@ class ProxyGitlabAppConfig(ColabProxiedAppConfig): | @@ -23,3 +28,9 @@ class ProxyGitlabAppConfig(ColabProxiedAppConfig): | ||
23 | 28 | ||
24 | ), | 29 | ), |
25 | } | 30 | } |
31 | + | ||
32 | + | ||
33 | + def __init__(self, app_name, app_module): | ||
34 | + super(ProxyGitlabAppConfig, self).__init__(app_name, app_module) | ||
35 | + register_signal(self.short_name, self.signals_list) | ||
36 | + connect_signal(self.signals_list[0], self.short_name, handling_method) |
@@ -0,0 +1,22 @@ | @@ -0,0 +1,22 @@ | ||
1 | +from __future__ import absolute_import | ||
2 | + | ||
3 | +import os | ||
4 | + | ||
5 | +from celery import Celery | ||
6 | + | ||
7 | +# set the default Django settings module for the 'celery' program. | ||
8 | +os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'colab.settings') | ||
9 | + | ||
10 | +from django.conf import settings | ||
11 | + | ||
12 | +app = Celery('colab') | ||
13 | + | ||
14 | +app.config_from_object('django.conf:settings') | ||
15 | +app.autodiscover_tasks(lambda: settings.INSTALLED_APPS) | ||
16 | + | ||
17 | +app.conf.update( | ||
18 | + CELERY_RESULT_BACKEND='djcelery.backends.database:DatabaseBackend', | ||
19 | +) | ||
20 | +app.conf.update( | ||
21 | + CELERY_RESULT_BACKEND='djcelery.backends.cache:CacheBackend', | ||
22 | +) |
colab/plugins/gitlab/models.py
@@ -2,6 +2,7 @@ from django.db import models | @@ -2,6 +2,7 @@ from django.db import models | ||
2 | from django.utils.translation import ugettext_lazy as _ | 2 | from django.utils.translation import ugettext_lazy as _ |
3 | from colab.plugins.utils.models import Collaboration | 3 | from colab.plugins.utils.models import Collaboration |
4 | from hitcounter.models import HitCounterModelMixin | 4 | from hitcounter.models import HitCounterModelMixin |
5 | +from colab.signals.tasks import send | ||
5 | 6 | ||
6 | 7 | ||
7 | class GitlabProject(models.Model, HitCounterModelMixin): | 8 | class GitlabProject(models.Model, HitCounterModelMixin): |
@@ -17,6 +18,7 @@ class GitlabProject(models.Model, HitCounterModelMixin): | @@ -17,6 +18,7 @@ class GitlabProject(models.Model, HitCounterModelMixin): | ||
17 | 18 | ||
18 | @property | 19 | @property |
19 | def url(self): | 20 | def url(self): |
21 | + send('gitlab_create_project', 'colab.plugins.gitlab') | ||
20 | return u'/gitlab/{}'.format(self.path_with_namespace) | 22 | return u'/gitlab/{}'.format(self.path_with_namespace) |
21 | 23 | ||
22 | class Meta: | 24 | class Meta: |
colab/signals/tasks.py
@@ -33,6 +33,6 @@ def connect_signal(signal_name, sender, handling_method): | @@ -33,6 +33,6 @@ def connect_signal(signal_name, sender, handling_method): | ||
33 | 33 | ||
34 | def send(signal_name, sender, **kwargs): | 34 | def send(signal_name, sender, **kwargs): |
35 | if signal_name in signal_instances: | 35 | if signal_name in signal_instances: |
36 | - signal_instances[signal_name].send(sender=sender) | 36 | + signal_instances[signal_name].send(sender=sender, **kwargs) |
37 | else: | 37 | else: |
38 | raise Exception("Signal does not exist!") | 38 | raise Exception("Signal does not exist!") |