diff --git a/beat/web/team/models.py b/beat/web/team/models.py index 6158ee3a65faeabaae57eff75d92d44dc9b9def8..e8e4e8ff27d4f989cc110095792d6b73f173c376 100644 --- a/beat/web/team/models.py +++ b/beat/web/team/models.py @@ -93,23 +93,48 @@ class Team(models.Model): return (self.owner.username, self.name) - def total_shares(self): + def total_shares(self, user=None): + '''Count number of objects shared with this team + + If ``user`` is passed, counts objects shared with this team that the + given user has access to. + ''' used_at = 0 - used_at += self.shared_algorithms.count() - used_at += self.shared_databases.count() - used_at += self.shared_dataformats.count() - used_at += self.shared_environments.count() - used_at += self.shared_experiments.count() - used_at += self.shared_librarys.count() - used_at += self.shared_plotterparameters.count() - used_at += self.shared_plotters.count() - used_at += self.shared_searchs.count() - used_at += self.shared_toolchains.count() - used_at += self.usable_algorithms.count() - used_at += self.usable_librarys.count() - used_at += self.usable_plotterparameters.count() - used_at += self.usable_plotters.count() + + if user is None: + + used_at += self.shared_algorithms.count() + used_at += self.shared_databases.count() + used_at += self.shared_dataformats.count() + used_at += self.shared_environments.count() + used_at += self.shared_experiments.count() + used_at += self.shared_librarys.count() + used_at += self.shared_plotterparameters.count() + used_at += self.shared_plotters.count() + used_at += self.shared_searchs.count() + used_at += self.shared_toolchains.count() + used_at += self.usable_algorithms.count() + used_at += self.usable_librarys.count() + used_at += self.usable_plotterparameters.count() + used_at += self.usable_plotters.count() + + else: + + used_at += self.shared_algorithms.for_user(user, add_public=True).count() + used_at += self.shared_databases.for_user(user, add_public=True).count() + used_at += self.shared_dataformats.for_user(user, add_public=True).count() + used_at += self.shared_environments.for_user(user, add_public=True).count() + used_at += self.shared_experiments.for_user(user, add_public=True).count() + used_at += self.shared_librarys.for_user(user, add_public=True).count() + used_at += self.shared_plotterparameters.for_user(user, add_public=True).count() + used_at += self.shared_plotters.for_user(user, add_public=True).count() + used_at += self.shared_searchs.for_user(user, add_public=True).count() + used_at += self.shared_toolchains.for_user(user, add_public=True).count() + used_at += self.usable_algorithms.for_user(user, add_public=True).count() + used_at += self.usable_librarys.for_user(user, add_public=True).count() + used_at += self.usable_plotterparameters.for_user(user, add_public=True).count() + used_at += self.usable_plotters.for_user(user, add_public=True).count() return used_at diff --git a/beat/web/team/templates/team/panels/actions.html b/beat/web/team/templates/team/panels/actions.html index 75e9e51c80c02520f8a29b3a87b527329548679c..434d1ece2953da50516feade12ad021efb30546d 100644 --- a/beat/web/team/templates/team/panels/actions.html +++ b/beat/web/team/templates/team/panels/actions.html @@ -1,34 +1,39 @@ {% comment %} * Copyright (c) 2016 Idiap Research Institute, http://www.idiap.ch/ * Contact: beat.support@idiap.ch - * + * * This file is part of the beat.web module of the BEAT platform. - * + * * Commercial License Usage * Licensees holding valid commercial BEAT licenses may use this file in * accordance with the terms contained in a written agreement between you * and Idiap. For further information contact tto@idiap.ch - * + * * Alternatively, this file may be used under the terms of the GNU Affero * Public License version 3 as published by the Free Software and appearing * in the file LICENSE.AGPL included in the packaging of this file. * The BEAT platform is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. - * + * * You should have received a copy of the GNU Affero Public License along * with the BEAT platform. If not, see http://www.gnu.org/licenses/. {% endcomment %} +{% load team_tags %} <div class="btn-group btn-group-sm action-buttons pull-right"> {% if display_count %} - <a class="btn btn-default btn-references" href="{% url 'teams:view' object.owner.username object.name %}" data-toggle="tooltip" data-placement="bottom" title="Number of members in this team"><span class="badge">{{ object.members.count }}</span></a> + <a class="btn btn-default btn-references" href="{% url 'teams:view' object.owner.username object.name %}" data-toggle="tooltip" data-placement="bottom" title="Number of objects shared through this team"><span class="badge">{% total_shares_for_user object %}</span></a> + + <a class="btn btn-default btn-references" href="{% url 'teams:view' object.owner.username object.name %}" data-toggle="tooltip" data-placement="bottom" title="Number of members in this team">{{ object.members.count }} <i class="fa fa-group"></i></a> {% endif %} {% ifequal request.user object.owner %} <!-- Delete, needs to be the owner --> + {% if object.deletable %} <a class="btn btn-default btn-delete" onclick="modal_delete('team', '{{ object.name }}', '{% url 'api_teams:user_teamlist' request.user.username %}', '{% url 'teams:list' request.user.username %}');" data-toggle="tooltip" data-placement="bottom" title="Delete"><i class="fa fa-times fa-lg"></i></a> + {% endif %} <!-- Edit --> <a class="btn btn-default btn-edit" href="{% url 'teams:edit' object.owner.username object.name %}" data-toggle="tooltip" data-placement="bottom" title="Edit"><i class="fa fa-edit fa-lg"></i></a> diff --git a/beat/web/team/templatetags/team_tags.py b/beat/web/team/templatetags/team_tags.py index 1fc422d73f0cdf126f31d8dfa5ec3079820209d6..bc8acad19942b8ef845233ce9934ae583151b8db 100644 --- a/beat/web/team/templatetags/team_tags.py +++ b/beat/web/team/templatetags/team_tags.py @@ -86,10 +86,21 @@ def team_actions(context, obj, display_count): } -register.inclusion_tag('ui/contribution_list.html') +#-------------------------------------------------- + + +@register.inclusion_tag('ui/contribution_list.html') def user_list(id): return { 'panel_id': id, 'URL_PREFIX': settings.URL_PREFIX, 'finder_placeholder': 'Find an User...', 'owner': False, } + + +#-------------------------------------------------- + + +@register.simple_tag(takes_context=True) +def total_shares_for_user(context, team): + return team.total_shares(context['request'].user)