diff --git a/colab/accounts/views.py b/colab/accounts/views.py index 9bf04b0..81b0ab4 100644 --- a/colab/accounts/views.py +++ b/colab/accounts/views.py @@ -1,8 +1,5 @@ #!/usr/bin/env python # encoding: utf-8 -import importlib -import inspect - from collections import OrderedDict from haystack.exceptions import SearchBackendError @@ -17,19 +14,16 @@ from django.shortcuts import render, redirect, get_object_or_404 from django.core.urlresolvers import reverse from django.core.exceptions import PermissionDenied from django.views.generic import DetailView, UpdateView, TemplateView -from django.apps import apps from conversejs import xmpp from conversejs.models import XMPPAccount -from haystack.query import SearchQuerySet from colab.super_archives.models import (EmailAddress, Message, EmailAddressValidation) from colab.search.utils import trans, getCollaborationData -# from proxy.trac.models import WikiCollabCount, TicketCollabCount + from .forms import (UserCreationForm, UserForm, ListsForm, UserUpdateForm, ChangeXMPPPasswordForm) -# from .errors import XMPPChangePwdException from .utils import mailman @@ -81,7 +75,8 @@ class UserProfileDetailView(UserProfileBaseMixin, DetailView): collaborations, count_types_extras = getCollaborationData(user) collaborations.extend(messages) - collaborations = sorted(collaborations, key=lambda elem : elem.modified, reverse=True) + collaborations = sorted(collaborations, + key=lambda elem: elem.modified, reverse=True) count_types.update(count_types_extras) @@ -101,6 +96,7 @@ class UserProfileDetailView(UserProfileBaseMixin, DetailView): context.update(kwargs) return super(UserProfileDetailView, self).get_context_data(**context) + def signup(request): BROWSERID_ENABLED = getattr(settings, 'BROWSERID_ENABLED', False) diff --git a/colab/home/views.py b/colab/home/views.py index 90cd32a..2799230 100644 --- a/colab/home/views.py +++ b/colab/home/views.py @@ -1,22 +1,9 @@ -from collections import OrderedDict - from django.conf import settings -from django.core.cache import cache from django.shortcuts import render from django.http import HttpResponse, Http404 -from haystack.query import SearchQuerySet - -<<<<<<< HEAD -# from proxy.trac.models import WikiCollabCount, TicketCollabCount -from colab.search.utils import trans -from colab.super_archives.models import Thread -======= from colab.search.utils import trans, getCollaborationData -from colab.super_archives.models import Thread, Message -from colab.search.preview_block import PreviewBlock -from colab.accounts.models import User ->>>>>>> Remove haystack search from dashboard an profile +from colab.super_archives.models import Thread def dashboard(request): @@ -37,7 +24,7 @@ def dashboard(request): latest_results.extend(messages) latest_results = sorted(latest_results, - key=lambda elem : elem.modified, reverse=True) + key=lambda elem: elem.modified, reverse=True) for key in count_types.keys(): count_types[trans(key)] = count_types.pop(key) @@ -50,6 +37,7 @@ def dashboard(request): } return render(request, 'home.html', context) + def robots(request): if getattr(settings, 'ROBOTS_NOINDEX', False): return HttpResponse('User-agent: *\nDisallow: /', diff --git a/colab/proxy/gitlab/apps.py b/colab/proxy/gitlab/apps.py index f92d3e9..fb253b6 100644 --- a/colab/proxy/gitlab/apps.py +++ b/colab/proxy/gitlab/apps.py @@ -3,6 +3,7 @@ from django.utils.translation import ugettext_lazy as _ from ..utils.apps import ColabProxiedAppConfig + class ProxyGitlabAppConfig(ColabProxiedAppConfig): ''' You can define a collaboration_models list to tell colab which @@ -12,9 +13,11 @@ class ProxyGitlabAppConfig(ColabProxiedAppConfig): Field model refers to the model to be displayed. Field model_verbose is the human name to be displayed in charts. - Field collaborator_username tells which user(username) is associated with this collaboration. + Field collaborator_username tells which user(username) is + associated with this collaboration. - The value of the hashes maps the attribute or method of the model to be put in those positions. + The value of the hashes maps the attribute or method of the model + to be put in those positions. collaboration_models = [ { @@ -53,3 +56,4 @@ class ProxyGitlabAppConfig(ColabProxiedAppConfig): } collaboration_models = [] + diff --git a/colab/search/preview_block.py b/colab/search/preview_block.py index 5876af0..d5e9778 100644 --- a/colab/search/preview_block.py +++ b/colab/search/preview_block.py @@ -1,11 +1,15 @@ class PreviewBlock(): + ''' + Class to define the fields of the collaboration block + that are displayed at dashboard and profile pages. + ''' tag = None title = None description = None fullname = None modified = None modified_by = None - url = None + url = None type = None modified_by_url = None collaborator_username = None diff --git a/colab/search/utils.py b/colab/search/utils.py index dfe28f4..ce8f458 100644 --- a/colab/search/utils.py +++ b/colab/search/utils.py @@ -7,7 +7,7 @@ from django.core.cache import cache from django.utils.translation import ugettext as _ from django.apps import apps from django.conf import settings -from colab.super_archives.models import Thread, Message +from colab.super_archives.models import Thread from colab.search.preview_block import PreviewBlock @@ -23,16 +23,17 @@ def trans(key): app_names = settings.PROXIED_APPS.keys() for app_name in app_names: - collaboration_models = apps.get_app_config(app_name).collaboration_models + collaboration_models = \ + apps.get_app_config(app_name).collaboration_models for collaboration in collaboration_models: - module = importlib.import_module('colab.proxy.{}.models'.format(app_name)) - elements = eval("module." + collaboration['model']).objects.all() - translations[ collaboration['model'].lower() ] = collaboration['model_verbose'] + translations[collaboration['model'].lower()] = \ + collaboration['model_verbose'] return translations.get(key, key) -def getCollaborationData(filter_by_user = None): + +def getCollaborationData(filter_by_user=None): latest_results = [] count_types = cache.get('home_chart') @@ -46,11 +47,16 @@ def getCollaborationData(filter_by_user = None): app_names = settings.PROXIED_APPS.keys() for app_name in app_names: - collaboration_models = apps.get_app_config(app_name).collaboration_models + collaboration_models = \ + apps.get_app_config(app_name).collaboration_models for collaboration in collaboration_models: - module = importlib.import_module('colab.proxy.{}.models'.format(app_name)) - elements = eval("module." + collaboration['model']).objects + module = importlib + module = \ + module.import_module('colab.proxy.{}.models'.format(app_name)) + + module = eval("module." + collaboration['model']) + elements = module.objects if filter_by_user: dic = {} @@ -62,16 +68,17 @@ def getCollaborationData(filter_by_user = None): latest_results.extend(parsePreviewBlock(elements, collaboration)) if populate_count_types: - count_types[ collaboration['model'].lower() ] = elements.count() + count_types[collaboration['model'].lower()] = elements.count() if populate_count_types: - cache.set('home_chart', count_types) + cache.set('home_chart', count_types, 30) for key in count_types.keys(): count_types[trans(key)] = count_types.pop(key) return latest_results, count_types + def parsePreviewBlock(elements, collaboration): results = [] for element in elements: @@ -79,14 +86,15 @@ def parsePreviewBlock(elements, collaboration): attributes = collaboration.keys() for keyname in attributes: - if keyname == 'model' or keyname == 'model_verbose' or len(collaboration[keyname].strip()) == 0: + if keyname == 'model' or keyname == 'model_verbose' \ + or len(collaboration[keyname].strip()) == 0: continue value = getattr(element, collaboration[keyname]) if(inspect.ismethod(value)): - setattr(previewblock, keyname, value() ) + setattr(previewblock, keyname, value()) else: - setattr(previewblock, keyname, value ) + setattr(previewblock, keyname, value) results.append(previewblock) - return results \ No newline at end of file + return results -- libgit2 0.21.2