Commit ef76e0904b5e619f0c32bd8fd64f914c1c29c208
1 parent
21973244
Exists in
master
and in
39 other branches
Fix flake8 warnings
Signed-off-by: Gustavo Jaruga <darksshades@gmail.com> Signed-off-by: Rodrigo Siqueira <rodrigosiqueiramelo@gmail.com>
Showing
5 changed files
with
41 additions
and
41 deletions
Show diff stats
colab/accounts/views.py
1 | #!/usr/bin/env python | 1 | #!/usr/bin/env python |
2 | # encoding: utf-8 | 2 | # encoding: utf-8 |
3 | -import importlib | ||
4 | -import inspect | ||
5 | - | ||
6 | from collections import OrderedDict | 3 | from collections import OrderedDict |
7 | 4 | ||
8 | from haystack.exceptions import SearchBackendError | 5 | from haystack.exceptions import SearchBackendError |
@@ -17,19 +14,16 @@ from django.shortcuts import render, redirect, get_object_or_404 | @@ -17,19 +14,16 @@ from django.shortcuts import render, redirect, get_object_or_404 | ||
17 | from django.core.urlresolvers import reverse | 14 | from django.core.urlresolvers import reverse |
18 | from django.core.exceptions import PermissionDenied | 15 | from django.core.exceptions import PermissionDenied |
19 | from django.views.generic import DetailView, UpdateView, TemplateView | 16 | from django.views.generic import DetailView, UpdateView, TemplateView |
20 | -from django.apps import apps | ||
21 | 17 | ||
22 | from conversejs import xmpp | 18 | from conversejs import xmpp |
23 | from conversejs.models import XMPPAccount | 19 | from conversejs.models import XMPPAccount |
24 | -from haystack.query import SearchQuerySet | ||
25 | 20 | ||
26 | from colab.super_archives.models import (EmailAddress, Message, | 21 | from colab.super_archives.models import (EmailAddress, Message, |
27 | EmailAddressValidation) | 22 | EmailAddressValidation) |
28 | from colab.search.utils import trans, getCollaborationData | 23 | from colab.search.utils import trans, getCollaborationData |
29 | -# from proxy.trac.models import WikiCollabCount, TicketCollabCount | 24 | + |
30 | from .forms import (UserCreationForm, UserForm, ListsForm, | 25 | from .forms import (UserCreationForm, UserForm, ListsForm, |
31 | UserUpdateForm, ChangeXMPPPasswordForm) | 26 | UserUpdateForm, ChangeXMPPPasswordForm) |
32 | -# from .errors import XMPPChangePwdException | ||
33 | from .utils import mailman | 27 | from .utils import mailman |
34 | 28 | ||
35 | 29 | ||
@@ -81,7 +75,8 @@ class UserProfileDetailView(UserProfileBaseMixin, DetailView): | @@ -81,7 +75,8 @@ class UserProfileDetailView(UserProfileBaseMixin, DetailView): | ||
81 | collaborations, count_types_extras = getCollaborationData(user) | 75 | collaborations, count_types_extras = getCollaborationData(user) |
82 | collaborations.extend(messages) | 76 | collaborations.extend(messages) |
83 | 77 | ||
84 | - collaborations = sorted(collaborations, key=lambda elem : elem.modified, reverse=True) | 78 | + collaborations = sorted(collaborations, |
79 | + key=lambda elem: elem.modified, reverse=True) | ||
85 | 80 | ||
86 | count_types.update(count_types_extras) | 81 | count_types.update(count_types_extras) |
87 | 82 | ||
@@ -101,6 +96,7 @@ class UserProfileDetailView(UserProfileBaseMixin, DetailView): | @@ -101,6 +96,7 @@ class UserProfileDetailView(UserProfileBaseMixin, DetailView): | ||
101 | context.update(kwargs) | 96 | context.update(kwargs) |
102 | return super(UserProfileDetailView, self).get_context_data(**context) | 97 | return super(UserProfileDetailView, self).get_context_data(**context) |
103 | 98 | ||
99 | + | ||
104 | def signup(request): | 100 | def signup(request): |
105 | BROWSERID_ENABLED = getattr(settings, 'BROWSERID_ENABLED', False) | 101 | BROWSERID_ENABLED = getattr(settings, 'BROWSERID_ENABLED', False) |
106 | 102 |
colab/home/views.py
1 | -from collections import OrderedDict | ||
2 | - | ||
3 | from django.conf import settings | 1 | from django.conf import settings |
4 | -from django.core.cache import cache | ||
5 | from django.shortcuts import render | 2 | from django.shortcuts import render |
6 | from django.http import HttpResponse, Http404 | 3 | from django.http import HttpResponse, Http404 |
7 | 4 | ||
8 | -from haystack.query import SearchQuerySet | ||
9 | - | ||
10 | -<<<<<<< HEAD | ||
11 | -# from proxy.trac.models import WikiCollabCount, TicketCollabCount | ||
12 | -from colab.search.utils import trans | ||
13 | -from colab.super_archives.models import Thread | ||
14 | -======= | ||
15 | from colab.search.utils import trans, getCollaborationData | 5 | from colab.search.utils import trans, getCollaborationData |
16 | -from colab.super_archives.models import Thread, Message | ||
17 | -from colab.search.preview_block import PreviewBlock | ||
18 | -from colab.accounts.models import User | ||
19 | ->>>>>>> Remove haystack search from dashboard an profile | 6 | +from colab.super_archives.models import Thread |
20 | 7 | ||
21 | 8 | ||
22 | def dashboard(request): | 9 | def dashboard(request): |
@@ -37,7 +24,7 @@ def dashboard(request): | @@ -37,7 +24,7 @@ def dashboard(request): | ||
37 | 24 | ||
38 | latest_results.extend(messages) | 25 | latest_results.extend(messages) |
39 | latest_results = sorted(latest_results, | 26 | latest_results = sorted(latest_results, |
40 | - key=lambda elem : elem.modified, reverse=True) | 27 | + key=lambda elem: elem.modified, reverse=True) |
41 | 28 | ||
42 | for key in count_types.keys(): | 29 | for key in count_types.keys(): |
43 | count_types[trans(key)] = count_types.pop(key) | 30 | count_types[trans(key)] = count_types.pop(key) |
@@ -50,6 +37,7 @@ def dashboard(request): | @@ -50,6 +37,7 @@ def dashboard(request): | ||
50 | } | 37 | } |
51 | return render(request, 'home.html', context) | 38 | return render(request, 'home.html', context) |
52 | 39 | ||
40 | + | ||
53 | def robots(request): | 41 | def robots(request): |
54 | if getattr(settings, 'ROBOTS_NOINDEX', False): | 42 | if getattr(settings, 'ROBOTS_NOINDEX', False): |
55 | return HttpResponse('User-agent: *\nDisallow: /', | 43 | return HttpResponse('User-agent: *\nDisallow: /', |
colab/proxy/gitlab/apps.py
@@ -3,6 +3,7 @@ from django.utils.translation import ugettext_lazy as _ | @@ -3,6 +3,7 @@ from django.utils.translation import ugettext_lazy as _ | ||
3 | 3 | ||
4 | from ..utils.apps import ColabProxiedAppConfig | 4 | from ..utils.apps import ColabProxiedAppConfig |
5 | 5 | ||
6 | + | ||
6 | class ProxyGitlabAppConfig(ColabProxiedAppConfig): | 7 | class ProxyGitlabAppConfig(ColabProxiedAppConfig): |
7 | ''' | 8 | ''' |
8 | You can define a collaboration_models list to tell colab which | 9 | You can define a collaboration_models list to tell colab which |
@@ -12,9 +13,11 @@ class ProxyGitlabAppConfig(ColabProxiedAppConfig): | @@ -12,9 +13,11 @@ class ProxyGitlabAppConfig(ColabProxiedAppConfig): | ||
12 | 13 | ||
13 | Field model refers to the model to be displayed. | 14 | Field model refers to the model to be displayed. |
14 | Field model_verbose is the human name to be displayed in charts. | 15 | Field model_verbose is the human name to be displayed in charts. |
15 | - Field collaborator_username tells which user(username) is associated with this collaboration. | 16 | + Field collaborator_username tells which user(username) is |
17 | + associated with this collaboration. | ||
16 | 18 | ||
17 | - The value of the hashes maps the attribute or method of the model to be put in those positions. | 19 | + The value of the hashes maps the attribute or method of the model |
20 | + to be put in those positions. | ||
18 | 21 | ||
19 | collaboration_models = [ | 22 | collaboration_models = [ |
20 | { | 23 | { |
@@ -53,3 +56,4 @@ class ProxyGitlabAppConfig(ColabProxiedAppConfig): | @@ -53,3 +56,4 @@ class ProxyGitlabAppConfig(ColabProxiedAppConfig): | ||
53 | } | 56 | } |
54 | 57 | ||
55 | collaboration_models = [] | 58 | collaboration_models = [] |
59 | + |
colab/search/preview_block.py
1 | class PreviewBlock(): | 1 | class PreviewBlock(): |
2 | + ''' | ||
3 | + Class to define the fields of the collaboration block | ||
4 | + that are displayed at dashboard and profile pages. | ||
5 | + ''' | ||
2 | tag = None | 6 | tag = None |
3 | title = None | 7 | title = None |
4 | description = None | 8 | description = None |
5 | fullname = None | 9 | fullname = None |
6 | modified = None | 10 | modified = None |
7 | modified_by = None | 11 | modified_by = None |
8 | - url = None | 12 | + url = None |
9 | type = None | 13 | type = None |
10 | modified_by_url = None | 14 | modified_by_url = None |
11 | collaborator_username = None | 15 | collaborator_username = None |
colab/search/utils.py
@@ -7,7 +7,7 @@ from django.core.cache import cache | @@ -7,7 +7,7 @@ from django.core.cache import cache | ||
7 | from django.utils.translation import ugettext as _ | 7 | from django.utils.translation import ugettext as _ |
8 | from django.apps import apps | 8 | from django.apps import apps |
9 | from django.conf import settings | 9 | from django.conf import settings |
10 | -from colab.super_archives.models import Thread, Message | 10 | +from colab.super_archives.models import Thread |
11 | from colab.search.preview_block import PreviewBlock | 11 | from colab.search.preview_block import PreviewBlock |
12 | 12 | ||
13 | 13 | ||
@@ -23,16 +23,17 @@ def trans(key): | @@ -23,16 +23,17 @@ def trans(key): | ||
23 | app_names = settings.PROXIED_APPS.keys() | 23 | app_names = settings.PROXIED_APPS.keys() |
24 | 24 | ||
25 | for app_name in app_names: | 25 | for app_name in app_names: |
26 | - collaboration_models = apps.get_app_config(app_name).collaboration_models | 26 | + collaboration_models = \ |
27 | + apps.get_app_config(app_name).collaboration_models | ||
27 | 28 | ||
28 | for collaboration in collaboration_models: | 29 | for collaboration in collaboration_models: |
29 | - module = importlib.import_module('colab.proxy.{}.models'.format(app_name)) | ||
30 | - elements = eval("module." + collaboration['model']).objects.all() | ||
31 | - translations[ collaboration['model'].lower() ] = collaboration['model_verbose'] | 30 | + translations[collaboration['model'].lower()] = \ |
31 | + collaboration['model_verbose'] | ||
32 | 32 | ||
33 | return translations.get(key, key) | 33 | return translations.get(key, key) |
34 | 34 | ||
35 | -def getCollaborationData(filter_by_user = None): | 35 | + |
36 | +def getCollaborationData(filter_by_user=None): | ||
36 | 37 | ||
37 | latest_results = [] | 38 | latest_results = [] |
38 | count_types = cache.get('home_chart') | 39 | count_types = cache.get('home_chart') |
@@ -46,11 +47,16 @@ def getCollaborationData(filter_by_user = None): | @@ -46,11 +47,16 @@ def getCollaborationData(filter_by_user = None): | ||
46 | app_names = settings.PROXIED_APPS.keys() | 47 | app_names = settings.PROXIED_APPS.keys() |
47 | 48 | ||
48 | for app_name in app_names: | 49 | for app_name in app_names: |
49 | - collaboration_models = apps.get_app_config(app_name).collaboration_models | 50 | + collaboration_models = \ |
51 | + apps.get_app_config(app_name).collaboration_models | ||
50 | 52 | ||
51 | for collaboration in collaboration_models: | 53 | for collaboration in collaboration_models: |
52 | - module = importlib.import_module('colab.proxy.{}.models'.format(app_name)) | ||
53 | - elements = eval("module." + collaboration['model']).objects | 54 | + module = importlib |
55 | + module = \ | ||
56 | + module.import_module('colab.proxy.{}.models'.format(app_name)) | ||
57 | + | ||
58 | + module = eval("module." + collaboration['model']) | ||
59 | + elements = module.objects | ||
54 | 60 | ||
55 | if filter_by_user: | 61 | if filter_by_user: |
56 | dic = {} | 62 | dic = {} |
@@ -62,16 +68,17 @@ def getCollaborationData(filter_by_user = None): | @@ -62,16 +68,17 @@ def getCollaborationData(filter_by_user = None): | ||
62 | latest_results.extend(parsePreviewBlock(elements, collaboration)) | 68 | latest_results.extend(parsePreviewBlock(elements, collaboration)) |
63 | 69 | ||
64 | if populate_count_types: | 70 | if populate_count_types: |
65 | - count_types[ collaboration['model'].lower() ] = elements.count() | 71 | + count_types[collaboration['model'].lower()] = elements.count() |
66 | 72 | ||
67 | if populate_count_types: | 73 | if populate_count_types: |
68 | - cache.set('home_chart', count_types) | 74 | + cache.set('home_chart', count_types, 30) |
69 | 75 | ||
70 | for key in count_types.keys(): | 76 | for key in count_types.keys(): |
71 | count_types[trans(key)] = count_types.pop(key) | 77 | count_types[trans(key)] = count_types.pop(key) |
72 | 78 | ||
73 | return latest_results, count_types | 79 | return latest_results, count_types |
74 | 80 | ||
81 | + | ||
75 | def parsePreviewBlock(elements, collaboration): | 82 | def parsePreviewBlock(elements, collaboration): |
76 | results = [] | 83 | results = [] |
77 | for element in elements: | 84 | for element in elements: |
@@ -79,14 +86,15 @@ def parsePreviewBlock(elements, collaboration): | @@ -79,14 +86,15 @@ def parsePreviewBlock(elements, collaboration): | ||
79 | attributes = collaboration.keys() | 86 | attributes = collaboration.keys() |
80 | 87 | ||
81 | for keyname in attributes: | 88 | for keyname in attributes: |
82 | - if keyname == 'model' or keyname == 'model_verbose' or len(collaboration[keyname].strip()) == 0: | 89 | + if keyname == 'model' or keyname == 'model_verbose' \ |
90 | + or len(collaboration[keyname].strip()) == 0: | ||
83 | continue | 91 | continue |
84 | value = getattr(element, collaboration[keyname]) | 92 | value = getattr(element, collaboration[keyname]) |
85 | if(inspect.ismethod(value)): | 93 | if(inspect.ismethod(value)): |
86 | - setattr(previewblock, keyname, value() ) | 94 | + setattr(previewblock, keyname, value()) |
87 | else: | 95 | else: |
88 | - setattr(previewblock, keyname, value ) | 96 | + setattr(previewblock, keyname, value) |
89 | 97 | ||
90 | results.append(previewblock) | 98 | results.append(previewblock) |
91 | 99 | ||
92 | - return results | ||
93 | \ No newline at end of file | 100 | \ No newline at end of file |
101 | + return results |