Commit 704b65a297b73d2e71859628b2bae490670382ec

Authored by Matheus de Sousa Faria
Committed by Gust
1 parent a98dc763

Refactoring widget system with flake8

colab/utils/conf.py
... ... @@ -156,8 +156,7 @@ def load_widgets_settings():
156 156 importlib.import_module(settings_module)
157 157  
158 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 160 logger.info('Widgets Settings directory: %s', settings_dir)
162 161 sys.path = original_path
163 162  
... ...
colab/widgets/admin.py
1   -from django.contrib import admin
  1 +# from django.contrib import admin
2 2  
3 3 # Register your models here.
... ...
colab/widgets/models.py
1   -from django.db import models
  1 +# from django.db import models
2 2  
3 3 # Create your models here.
... ...
colab/widgets/tests/test_widget_manager.py
... ... @@ -2,22 +2,25 @@ from django.test import TestCase
2 2  
3 3 from colab.widgets.widget_manager import WidgetManager, Widget
4 4  
  5 +
5 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 9 widget_area = 'profile'
9 10 widget_id = 'widget_id'
10 11  
11 12 def custom_widget_instance(self, content):
  13 +
12 14 class CustomWidget(Widget):
13 15 identifier = 'widget_id'
  16 +
14 17 def generate_content(self, request=None):
15 18 self.content = content
16 19 return CustomWidget()
17 20  
18 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 25 def tearDown(self):
23 26 WidgetManager.unregister_widget(self.widget_area, self.widget_id)
... ... @@ -38,7 +41,7 @@ class WidgetManagerTest(TestCase):
38 41 customWidget = self.custom_widget_instance(self.html_content)
39 42  
40 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 46 def test_get_header(self):
44 47 customWidget = self.custom_widget_instance(self.html_content)
... ...
colab/widgets/views.py
1   -from django.shortcuts import render
  1 +# from django.shortcuts import render
2 2  
3 3 # Create your views here.
... ...
colab/widgets/widget_manager.py
1 1 from django.utils.safestring import mark_safe
2 2  
  3 +
3 4 class Widget(object):
4 5 identifier = None
5 6 name = None
... ... @@ -36,21 +37,21 @@ class WidgetManager(object):
36 37  
37 38 @staticmethod
38 39 def register_widget(category, widget):
39   - if not WidgetManager.widget_categories.has_key(category):
  40 + if category not in WidgetManager.widget_categories:
40 41 WidgetManager.widget_categories[category] = []
41 42  
42 43 WidgetManager.widget_categories[category].append(widget)
43 44  
44 45 @staticmethod
45 46 def unregister_widget(category, widget_identifier):
46   - if WidgetManager.widget_categories.has_key(category):
  47 + if category in WidgetManager.widget_categories:
47 48 for widget in WidgetManager.widget_categories[category]:
48 49 if widget.identifier == widget_identifier:
49 50 WidgetManager.widget_categories[category].remove(widget)
50 51  
51 52 @staticmethod
52 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 55 return []
55 56  
56 57 widgets = WidgetManager.widget_categories[category]
... ...