Commit ef76e0904b5e619f0c32bd8fd64f914c1c29c208

Authored by Gust
1 parent 21973244

Fix flake8 warnings

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