Commit d1f1b014af5fdc9e1b94d989d3e7bf05b6905395
1 parent
0a74c018
Exists in
master
and in
39 other branches
Fixed MR suggestions
Signed-off-by: Gustavo Jaruga <darksshades@gmail.com> Signed-off-by: Siqueira Melo <rodrigosiqueiramelo@gmail.com>
Showing
4 changed files
with
33 additions
and
52 deletions
Show diff stats
colab/accounts/views.py
| @@ -65,12 +65,7 @@ class UserProfileDetailView(UserProfileBaseMixin, DetailView): | @@ -65,12 +65,7 @@ class UserProfileDetailView(UserProfileBaseMixin, DetailView): | ||
| 65 | 65 | ||
| 66 | count_types = OrderedDict() | 66 | count_types = OrderedDict() |
| 67 | 67 | ||
| 68 | - # TODO: remove when mailman becomes a proxied plugin | ||
| 69 | - messages = Message.objects.filter(from_address__user__pk=user.pk) | ||
| 70 | - count_types[_('Emails')] = messages.count() | ||
| 71 | - | ||
| 72 | collaborations, count_types_extras = get_collaboration_data(user) | 68 | collaborations, count_types_extras = get_collaboration_data(user) |
| 73 | - collaborations.extend(messages) | ||
| 74 | 69 | ||
| 75 | collaborations.sort(key=lambda elem: elem.modified, reverse=True) | 70 | collaborations.sort(key=lambda elem: elem.modified, reverse=True) |
| 76 | 71 | ||
| @@ -84,6 +79,7 @@ class UserProfileDetailView(UserProfileBaseMixin, DetailView): | @@ -84,6 +79,7 @@ class UserProfileDetailView(UserProfileBaseMixin, DetailView): | ||
| 84 | query = query.order_by('-received_time') | 79 | query = query.order_by('-received_time') |
| 85 | context['emails'] = query[:10] | 80 | context['emails'] = query[:10] |
| 86 | 81 | ||
| 82 | + messages = Message.objects.filter(from_address__user__pk=user.pk) | ||
| 87 | count_by = 'thread__mailinglist__name' | 83 | count_by = 'thread__mailinglist__name' |
| 88 | context['list_activity'] = dict(messages.values_list(count_by) | 84 | context['list_activity'] = dict(messages.values_list(count_by) |
| 89 | .annotate(Count(count_by)) | 85 | .annotate(Count(count_by)) |
colab/home/views.py
| @@ -14,12 +14,8 @@ def dashboard(request): | @@ -14,12 +14,8 @@ def dashboard(request): | ||
| 14 | hottest_threads = [t.latest_message for t in highest_score_threads] | 14 | hottest_threads = [t.latest_message for t in highest_score_threads] |
| 15 | 15 | ||
| 16 | latest_threads = Thread.objects.all()[:6] | 16 | latest_threads = Thread.objects.all()[:6] |
| 17 | - latest_results, count_types = get_collaboration_data() | ||
| 18 | 17 | ||
| 19 | - # NOTE: This code will cease to exist when super_archives | ||
| 20 | - # become a plugin | ||
| 21 | - messages = [t.latest_message for t in latest_threads] | ||
| 22 | - latest_results.extend(messages) | 18 | + latest_results, count_types = get_collaboration_data() |
| 23 | latest_results.sort(key=lambda elem: elem.modified, reverse=True) | 19 | latest_results.sort(key=lambda elem: elem.modified, reverse=True) |
| 24 | 20 | ||
| 25 | context = { | 21 | context = { |
colab/proxy/utils/models.py
| @@ -3,35 +3,21 @@ from django.conf import settings | @@ -3,35 +3,21 @@ from django.conf import settings | ||
| 3 | from colab.accounts.models import User | 3 | from colab.accounts.models import User |
| 4 | 4 | ||
| 5 | 5 | ||
| 6 | -class CollaborationModel(models.Model): | 6 | +class Collaboration(models.Model): |
| 7 | ''' | 7 | ''' |
| 8 | Class to define the fields of the collaboration block | 8 | Class to define the fields of the collaboration block |
| 9 | that are displayed at dashboard and profile pages. | 9 | that are displayed at dashboard and profile pages. |
| 10 | ''' | 10 | ''' |
| 11 | 11 | ||
| 12 | - @property | ||
| 13 | - def verbose_name(self): | ||
| 14 | - raise NotImplemented | ||
| 15 | - | ||
| 16 | - @property | ||
| 17 | - def tag(self): | ||
| 18 | - return None | ||
| 19 | - | ||
| 20 | - @property | ||
| 21 | - def title(self): | ||
| 22 | - raise NotImplemented | ||
| 23 | - | ||
| 24 | - @property | ||
| 25 | - def description(self): | ||
| 26 | - return None | ||
| 27 | - | ||
| 28 | - @property | ||
| 29 | - def url(self): | ||
| 30 | - return None | 12 | + tag = None |
| 13 | + title = None | ||
| 14 | + description = None | ||
| 15 | + url = None | ||
| 16 | + modified = None | ||
| 17 | + type = None | ||
| 31 | 18 | ||
| 32 | - @property | ||
| 33 | - def modified(self): | ||
| 34 | - return None | 19 | + user = models.ForeignKey(settings.AUTH_USER_MODEL, null=True, |
| 20 | + on_delete=models.SET_NULL) | ||
| 35 | 21 | ||
| 36 | @property | 22 | @property |
| 37 | def modified_by(self): | 23 | def modified_by(self): |
| @@ -45,15 +31,11 @@ class CollaborationModel(models.Model): | @@ -45,15 +31,11 @@ class CollaborationModel(models.Model): | ||
| 45 | return self.user.get_absolute_url() | 31 | return self.user.get_absolute_url() |
| 46 | return None | 32 | return None |
| 47 | 33 | ||
| 48 | - @property | ||
| 49 | - def type(self): | ||
| 50 | - return None | ||
| 51 | - | ||
| 52 | - user = models.ForeignKey(settings.AUTH_USER_MODEL, null=True, | ||
| 53 | - on_delete=models.SET_NULL) | ||
| 54 | - | ||
| 55 | def update_user(self, user_name): | 34 | def update_user(self, user_name): |
| 56 | - self.user = User.objects.filter(username=user_name).last() | 35 | + try: |
| 36 | + self.user = User.objects.get(username=user_name) | ||
| 37 | + except User.DoesNotExist: | ||
| 38 | + self.user = None | ||
| 57 | 39 | ||
| 58 | class Meta: | 40 | class Meta: |
| 59 | abstract = True | 41 | abstract = True |
colab/search/utils.py
| @@ -6,8 +6,8 @@ from collections import OrderedDict | @@ -6,8 +6,8 @@ from collections import OrderedDict | ||
| 6 | from django.core.cache import cache | 6 | 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.conf import settings | 8 | from django.conf import settings |
| 9 | -from colab.super_archives.models import Thread | ||
| 10 | -from colab.proxy.utils.models import CollaborationModel | 9 | +from colab.super_archives.models import Thread, Message |
| 10 | +from colab.proxy.utils.models import Collaboration | ||
| 11 | 11 | ||
| 12 | 12 | ||
| 13 | def get_collaboration_data(filter_by_user=None): | 13 | def get_collaboration_data(filter_by_user=None): |
| @@ -20,29 +20,36 @@ def get_collaboration_data(filter_by_user=None): | @@ -20,29 +20,36 @@ def get_collaboration_data(filter_by_user=None): | ||
| 20 | count_types = OrderedDict() | 20 | count_types = OrderedDict() |
| 21 | count_types[_('Emails')] = Thread.objects.count() | 21 | count_types[_('Emails')] = Thread.objects.count() |
| 22 | 22 | ||
| 23 | + if filter_by_user: | ||
| 24 | + messages = Message.objects.filter(from_address__user__pk=filter_by_user.pk) | ||
| 25 | + else: | ||
| 26 | + latest_threads = Thread.objects.all()[:6] | ||
| 27 | + messages = [t.latest_message for t in latest_threads] | ||
| 28 | + | ||
| 29 | + latest_results.extend(messages) | ||
| 30 | + | ||
| 23 | app_names = settings.PROXIED_APPS.keys() | 31 | app_names = settings.PROXIED_APPS.keys() |
| 24 | 32 | ||
| 25 | for app_name in app_names: | 33 | for app_name in app_names: |
| 26 | - module = importlib | ||
| 27 | - module = \ | ||
| 28 | - module.import_module('colab.proxy.{}.models'.format(app_name)) | 34 | + module = importlib \ |
| 35 | + .import_module('colab.proxy.{}.models'.format(app_name)) | ||
| 29 | 36 | ||
| 30 | for module_item_name in dir(module): | 37 | for module_item_name in dir(module): |
| 31 | module_item = getattr(module, module_item_name) | 38 | module_item = getattr(module, module_item_name) |
| 32 | if not inspect.isclass(module_item): | 39 | if not inspect.isclass(module_item): |
| 33 | continue | 40 | continue |
| 34 | - if not issubclass(module_item, CollaborationModel): | 41 | + if not issubclass(module_item, Collaboration): |
| 35 | continue | 42 | continue |
| 36 | - if module_item == CollaborationModel: | 43 | + if module_item == Collaboration: |
| 37 | continue | 44 | continue |
| 38 | 45 | ||
| 39 | - elements = module_item.objects | 46 | + queryset = module_item.objects |
| 40 | 47 | ||
| 41 | if filter_by_user: | 48 | if filter_by_user: |
| 42 | - elements = elements.filter( | 49 | + elements = queryset.filter( |
| 43 | user__username=filter_by_user) | 50 | user__username=filter_by_user) |
| 44 | else: | 51 | else: |
| 45 | - elements = elements.all() | 52 | + elements = queryset.all() |
| 46 | 53 | ||
| 47 | latest_results.extend(elements) | 54 | latest_results.extend(elements) |
| 48 | elements_count = elements.count() | 55 | elements_count = elements.count() |
| @@ -50,7 +57,7 @@ def get_collaboration_data(filter_by_user=None): | @@ -50,7 +57,7 @@ def get_collaboration_data(filter_by_user=None): | ||
| 50 | if elements_count > 1: | 57 | if elements_count > 1: |
| 51 | verbose_name = module_item._meta.verbose_name_plural.title() | 58 | verbose_name = module_item._meta.verbose_name_plural.title() |
| 52 | else: | 59 | else: |
| 53 | - verbose_name = module_item._meta.verbose_name_plural.title() | 60 | + verbose_name = module_item._meta.verbose_name.title() |
| 54 | 61 | ||
| 55 | if populate_count_types: | 62 | if populate_count_types: |
| 56 | count_types[verbose_name] = elements_count | 63 | count_types[verbose_name] = elements_count |