Commit 704b65a297b73d2e71859628b2bae490670382ec
Committed by
Gust
1 parent
a98dc763
Exists in
master
and in
4 other branches
Refactoring widget system with flake8
Showing
6 changed files
with
15 additions
and
12 deletions
Show diff stats
colab/utils/conf.py
| @@ -156,8 +156,7 @@ def load_widgets_settings(): | @@ -156,8 +156,7 @@ def load_widgets_settings(): | ||
| 156 | importlib.import_module(settings_module) | 156 | importlib.import_module(settings_module) |
| 157 | 157 | ||
| 158 | # Read settings from widgets.d | 158 | # Read settings from widgets.d |
| 159 | - settings_dir = os.getenv('COLAB_WIDGETS', | ||
| 160 | - '/etc/colab/widgets.d') | 159 | + settings_dir = os.getenv('COLAB_WIDGETS', '/etc/colab/widgets.d') |
| 161 | logger.info('Widgets Settings directory: %s', settings_dir) | 160 | logger.info('Widgets Settings directory: %s', settings_dir) |
| 162 | sys.path = original_path | 161 | sys.path = original_path |
| 163 | 162 |
colab/widgets/admin.py
colab/widgets/models.py
colab/widgets/tests/test_widget_manager.py
| @@ -2,22 +2,25 @@ from django.test import TestCase | @@ -2,22 +2,25 @@ from django.test import TestCase | ||
| 2 | 2 | ||
| 3 | from colab.widgets.widget_manager import WidgetManager, Widget | 3 | from colab.widgets.widget_manager import WidgetManager, Widget |
| 4 | 4 | ||
| 5 | + | ||
| 5 | class WidgetManagerTest(TestCase): | 6 | class WidgetManagerTest(TestCase): |
| 6 | 7 | ||
| 7 | - html_content = "<head><meta charset='UTF-8'></head><body><p>test</p></body>" | 8 | + html_content = "<head><meta charset='UTF-8'></head><body><p>T</p></body>" |
| 8 | widget_area = 'profile' | 9 | widget_area = 'profile' |
| 9 | widget_id = 'widget_id' | 10 | widget_id = 'widget_id' |
| 10 | 11 | ||
| 11 | def custom_widget_instance(self, content): | 12 | def custom_widget_instance(self, content): |
| 13 | + | ||
| 12 | class CustomWidget(Widget): | 14 | class CustomWidget(Widget): |
| 13 | identifier = 'widget_id' | 15 | identifier = 'widget_id' |
| 16 | + | ||
| 14 | def generate_content(self, request=None): | 17 | def generate_content(self, request=None): |
| 15 | self.content = content | 18 | self.content = content |
| 16 | return CustomWidget() | 19 | return CustomWidget() |
| 17 | 20 | ||
| 18 | def setUp(self): | 21 | def setUp(self): |
| 19 | - WidgetManager.register_widget(self.widget_area, \ | ||
| 20 | - self.custom_widget_instance(self.html_content)) | 22 | + custom_widget = self.custom_widget_instance(self.html_content) |
| 23 | + WidgetManager.register_widget(self.widget_area, custom_widget) | ||
| 21 | 24 | ||
| 22 | def tearDown(self): | 25 | def tearDown(self): |
| 23 | WidgetManager.unregister_widget(self.widget_area, self.widget_id) | 26 | WidgetManager.unregister_widget(self.widget_area, self.widget_id) |
| @@ -38,7 +41,7 @@ class WidgetManagerTest(TestCase): | @@ -38,7 +41,7 @@ class WidgetManagerTest(TestCase): | ||
| 38 | customWidget = self.custom_widget_instance(self.html_content) | 41 | customWidget = self.custom_widget_instance(self.html_content) |
| 39 | 42 | ||
| 40 | customWidget.generate_content() | 43 | customWidget.generate_content() |
| 41 | - self.assertEqual(customWidget.get_body(), "<p>test</p>") | 44 | + self.assertEqual(customWidget.get_body(), "<p>T</p>") |
| 42 | 45 | ||
| 43 | def test_get_header(self): | 46 | def test_get_header(self): |
| 44 | customWidget = self.custom_widget_instance(self.html_content) | 47 | customWidget = self.custom_widget_instance(self.html_content) |
colab/widgets/views.py
colab/widgets/widget_manager.py
| 1 | from django.utils.safestring import mark_safe | 1 | from django.utils.safestring import mark_safe |
| 2 | 2 | ||
| 3 | + | ||
| 3 | class Widget(object): | 4 | class Widget(object): |
| 4 | identifier = None | 5 | identifier = None |
| 5 | name = None | 6 | name = None |
| @@ -36,21 +37,21 @@ class WidgetManager(object): | @@ -36,21 +37,21 @@ class WidgetManager(object): | ||
| 36 | 37 | ||
| 37 | @staticmethod | 38 | @staticmethod |
| 38 | def register_widget(category, widget): | 39 | def register_widget(category, widget): |
| 39 | - if not WidgetManager.widget_categories.has_key(category): | 40 | + if category not in WidgetManager.widget_categories: |
| 40 | WidgetManager.widget_categories[category] = [] | 41 | WidgetManager.widget_categories[category] = [] |
| 41 | 42 | ||
| 42 | WidgetManager.widget_categories[category].append(widget) | 43 | WidgetManager.widget_categories[category].append(widget) |
| 43 | 44 | ||
| 44 | @staticmethod | 45 | @staticmethod |
| 45 | def unregister_widget(category, widget_identifier): | 46 | def unregister_widget(category, widget_identifier): |
| 46 | - if WidgetManager.widget_categories.has_key(category): | 47 | + if category in WidgetManager.widget_categories: |
| 47 | for widget in WidgetManager.widget_categories[category]: | 48 | for widget in WidgetManager.widget_categories[category]: |
| 48 | if widget.identifier == widget_identifier: | 49 | if widget.identifier == widget_identifier: |
| 49 | WidgetManager.widget_categories[category].remove(widget) | 50 | WidgetManager.widget_categories[category].remove(widget) |
| 50 | 51 | ||
| 51 | @staticmethod | 52 | @staticmethod |
| 52 | def get_widgets(category, request=None): | 53 | def get_widgets(category, request=None): |
| 53 | - if not WidgetManager.widget_categories.has_key(category): | 54 | + if category not in WidgetManager.widget_categories: |
| 54 | return [] | 55 | return [] |
| 55 | 56 | ||
| 56 | widgets = WidgetManager.widget_categories[category] | 57 | widgets = WidgetManager.widget_categories[category] |