mirror of
				https://gitlab.crans.org/bde/nk20
				synced 2025-11-04 01:12:08 +01:00 
			
		
		
		
	Add tab for user list
This commit is contained in:
		@@ -170,10 +170,13 @@ class UserListView(ProtectQuerysetMixin, LoginRequiredMixin, SingleTableView):
 | 
				
			|||||||
        else:
 | 
					        else:
 | 
				
			||||||
            qs = qs.none()
 | 
					            qs = qs.none()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        return qs
 | 
					        return qs[:20]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def get_context_data(self, **kwargs):
 | 
					    def get_context_data(self, **kwargs):
 | 
				
			||||||
        context = super().get_context_data(**kwargs)
 | 
					        context = super().get_context_data(**kwargs)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        context["title"] = _("Search user")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        return context
 | 
					        return context
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -46,12 +46,14 @@ class TransactionTemplate(models.Model):
 | 
				
			|||||||
        unique=True,
 | 
					        unique=True,
 | 
				
			||||||
        error_messages={'unique': _("A template with this name already exist")},
 | 
					        error_messages={'unique': _("A template with this name already exist")},
 | 
				
			||||||
    )
 | 
					    )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    destination = models.ForeignKey(
 | 
					    destination = models.ForeignKey(
 | 
				
			||||||
        NoteClub,
 | 
					        NoteClub,
 | 
				
			||||||
        on_delete=models.PROTECT,
 | 
					        on_delete=models.PROTECT,
 | 
				
			||||||
        related_name='+',  # no reverse
 | 
					        related_name='+',  # no reverse
 | 
				
			||||||
        verbose_name=_('destination'),
 | 
					        verbose_name=_('destination'),
 | 
				
			||||||
    )
 | 
					    )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    amount = models.PositiveIntegerField(
 | 
					    amount = models.PositiveIntegerField(
 | 
				
			||||||
        verbose_name=_('amount'),
 | 
					        verbose_name=_('amount'),
 | 
				
			||||||
        help_text=_('in centimes'),
 | 
					        help_text=_('in centimes'),
 | 
				
			||||||
@@ -62,9 +64,12 @@ class TransactionTemplate(models.Model):
 | 
				
			|||||||
        verbose_name=_('type'),
 | 
					        verbose_name=_('type'),
 | 
				
			||||||
        max_length=31,
 | 
					        max_length=31,
 | 
				
			||||||
    )
 | 
					    )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    display = models.BooleanField(
 | 
					    display = models.BooleanField(
 | 
				
			||||||
        default=True,
 | 
					        default=True,
 | 
				
			||||||
 | 
					        verbose_name=_("display"),
 | 
				
			||||||
    )
 | 
					    )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    description = models.CharField(
 | 
					    description = models.CharField(
 | 
				
			||||||
        verbose_name=_('description'),
 | 
					        verbose_name=_('description'),
 | 
				
			||||||
        max_length=255,
 | 
					        max_length=255,
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -118,7 +118,8 @@ class AliasTable(tables.Table):
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    delete_col = tables.TemplateColumn(template_code=DELETE_TEMPLATE,
 | 
					    delete_col = tables.TemplateColumn(template_code=DELETE_TEMPLATE,
 | 
				
			||||||
                                       extra_context={"delete_trans": _('delete')},
 | 
					                                       extra_context={"delete_trans": _('delete')},
 | 
				
			||||||
                                       attrs={'td': {'class': 'col-sm-1'}})
 | 
					                                       attrs={'td': {'class': 'col-sm-1'}},
 | 
				
			||||||
 | 
					                                       verbose_name=_("Delete"),)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class ButtonTable(tables.Table):
 | 
					class ButtonTable(tables.Table):
 | 
				
			||||||
@@ -134,17 +135,20 @@ class ButtonTable(tables.Table):
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        model = TransactionTemplate
 | 
					        model = TransactionTemplate
 | 
				
			||||||
 | 
					        exclude = ('id',)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    edit = tables.LinkColumn('note:template_update',
 | 
					    edit = tables.LinkColumn('note:template_update',
 | 
				
			||||||
                             args=[A('pk')],
 | 
					                             args=[A('pk')],
 | 
				
			||||||
                             attrs={'td': {'class': 'col-sm-1'},
 | 
					                             attrs={'td': {'class': 'col-sm-1'},
 | 
				
			||||||
                                    'a': {'class': 'btn btn-sm btn-primary'}},
 | 
					                                    'a': {'class': 'btn btn-sm btn-primary'}},
 | 
				
			||||||
                             text=_('edit'),
 | 
					                             text=_('edit'),
 | 
				
			||||||
                             accessor='pk')
 | 
					                             accessor='pk',
 | 
				
			||||||
 | 
					                             verbose_name=_("Edit"),)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    delete_col = tables.TemplateColumn(template_code=DELETE_TEMPLATE,
 | 
					    delete_col = tables.TemplateColumn(template_code=DELETE_TEMPLATE,
 | 
				
			||||||
                                       extra_context={"delete_trans": _('delete')},
 | 
					                                       extra_context={"delete_trans": _('delete')},
 | 
				
			||||||
                                       attrs={'td': {'class': 'col-sm-1'}})
 | 
					                                       attrs={'td': {'class': 'col-sm-1'}},
 | 
				
			||||||
 | 
					                                       verbose_name=_("Delete"),)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def render_amount(self, value):
 | 
					    def render_amount(self, value):
 | 
				
			||||||
        return pretty_money(value)
 | 
					        return pretty_money(value)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -4,6 +4,7 @@
 | 
				
			|||||||
from django.contrib.contenttypes.models import ContentType
 | 
					from django.contrib.contenttypes.models import ContentType
 | 
				
			||||||
from django.template.defaultfilters import stringfilter
 | 
					from django.template.defaultfilters import stringfilter
 | 
				
			||||||
from django import template
 | 
					from django import template
 | 
				
			||||||
 | 
					from note.models import Transaction
 | 
				
			||||||
from note_kfet.middlewares import get_current_authenticated_user, get_current_session
 | 
					from note_kfet.middlewares import get_current_authenticated_user, get_current_session
 | 
				
			||||||
from permission.backends import PermissionBackend
 | 
					from permission.backends import PermissionBackend
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -21,9 +22,7 @@ def not_empty_model_list(model_name):
 | 
				
			|||||||
        return True
 | 
					        return True
 | 
				
			||||||
    if session.get("not_empty_model_list_" + model_name, None):
 | 
					    if session.get("not_empty_model_list_" + model_name, None):
 | 
				
			||||||
        return session.get("not_empty_model_list_" + model_name, None) == 1
 | 
					        return session.get("not_empty_model_list_" + model_name, None) == 1
 | 
				
			||||||
    spl = model_name.split(".")
 | 
					    qs = model_list(model_name)
 | 
				
			||||||
    ct = ContentType.objects.get(app_label=spl[0], model=spl[1])
 | 
					 | 
				
			||||||
    qs = ct.model_class().objects.filter(PermissionBackend.filter_queryset(user, ct, "view")).all()
 | 
					 | 
				
			||||||
    session["not_empty_model_list_" + model_name] = 1 if qs.exists() else 2
 | 
					    session["not_empty_model_list_" + model_name] = 1 if qs.exists() else 2
 | 
				
			||||||
    return session.get("not_empty_model_list_" + model_name) == 1
 | 
					    return session.get("not_empty_model_list_" + model_name) == 1
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -41,18 +40,55 @@ def not_empty_model_change_list(model_name):
 | 
				
			|||||||
        return True
 | 
					        return True
 | 
				
			||||||
    if session.get("not_empty_model_change_list_" + model_name, None):
 | 
					    if session.get("not_empty_model_change_list_" + model_name, None):
 | 
				
			||||||
        return session.get("not_empty_model_change_list_" + model_name, None) == 1
 | 
					        return session.get("not_empty_model_change_list_" + model_name, None) == 1
 | 
				
			||||||
    spl = model_name.split(".")
 | 
					    qs = model_list(model_name, "change")
 | 
				
			||||||
    ct = ContentType.objects.get(app_label=spl[0], model=spl[1])
 | 
					 | 
				
			||||||
    qs = ct.model_class().objects.filter(PermissionBackend.filter_queryset(user, ct, "change"))
 | 
					 | 
				
			||||||
    session["not_empty_model_change_list_" + model_name] = 1 if qs.exists() else 2
 | 
					    session["not_empty_model_change_list_" + model_name] = 1 if qs.exists() else 2
 | 
				
			||||||
    return session.get("not_empty_model_change_list_" + model_name) == 1
 | 
					    return session.get("not_empty_model_change_list_" + model_name) == 1
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					@stringfilter
 | 
				
			||||||
 | 
					def model_list(model_name, t="view"):
 | 
				
			||||||
 | 
					    """
 | 
				
			||||||
 | 
					    Return the queryset of all visible instances of the given model.
 | 
				
			||||||
 | 
					    """
 | 
				
			||||||
 | 
					    user = get_current_authenticated_user()
 | 
				
			||||||
 | 
					    if user is None:
 | 
				
			||||||
 | 
					        return False
 | 
				
			||||||
 | 
					    spl = model_name.split(".")
 | 
				
			||||||
 | 
					    ct = ContentType.objects.get(app_label=spl[0], model=spl[1])
 | 
				
			||||||
 | 
					    qs = ct.model_class().objects.filter(PermissionBackend.filter_queryset(user, ct, t)).all()
 | 
				
			||||||
 | 
					    return qs
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def has_perm(perm, obj):
 | 
					def has_perm(perm, obj):
 | 
				
			||||||
    return PermissionBackend().has_perm(get_current_authenticated_user(), perm, obj)
 | 
					    return PermissionBackend().has_perm(get_current_authenticated_user(), perm, obj)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					def can_create_transaction():
 | 
				
			||||||
 | 
					    """
 | 
				
			||||||
 | 
					    :return: True iff the authenticated user can create a transaction.
 | 
				
			||||||
 | 
					    """
 | 
				
			||||||
 | 
					    user = get_current_authenticated_user()
 | 
				
			||||||
 | 
					    session = get_current_session()
 | 
				
			||||||
 | 
					    if user is None:
 | 
				
			||||||
 | 
					        return False
 | 
				
			||||||
 | 
					    elif user.is_superuser and session.get("permission_mask", 0) >= 42:
 | 
				
			||||||
 | 
					        return True
 | 
				
			||||||
 | 
					    if session.get("can_create_transaction", None):
 | 
				
			||||||
 | 
					        return session.get("can_create_transaction", None) == 1
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    empty_transaction = Transaction(
 | 
				
			||||||
 | 
					        source=user.note,
 | 
				
			||||||
 | 
					        destination=user.note,
 | 
				
			||||||
 | 
					        quantity=1,
 | 
				
			||||||
 | 
					        amount=0,
 | 
				
			||||||
 | 
					        reason="Check permissions",
 | 
				
			||||||
 | 
					    )
 | 
				
			||||||
 | 
					    session["can_create_transaction"] = PermissionBackend().has_perm(user, "note.add_transaction", empty_transaction)
 | 
				
			||||||
 | 
					    return session.get("can_create_transaction") == 1
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
register = template.Library()
 | 
					register = template.Library()
 | 
				
			||||||
register.filter('not_empty_model_list', not_empty_model_list)
 | 
					register.filter('not_empty_model_list', not_empty_model_list)
 | 
				
			||||||
register.filter('not_empty_model_change_list', not_empty_model_change_list)
 | 
					register.filter('not_empty_model_change_list', not_empty_model_change_list)
 | 
				
			||||||
 | 
					register.filter('model_list', model_list)
 | 
				
			||||||
register.filter('has_perm', has_perm)
 | 
					register.filter('has_perm', has_perm)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -25,7 +25,7 @@
 | 
				
			|||||||
                <dt class="col-xl-6">{% trans 'end date'|capfirst %}</dt>
 | 
					                <dt class="col-xl-6">{% trans 'end date'|capfirst %}</dt>
 | 
				
			||||||
                <dd class="col-xl-6">{{ activity.date_end }}</dd>
 | 
					                <dd class="col-xl-6">{{ activity.date_end }}</dd>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                {% if "view_"|has_perm:activity.creater %}
 | 
					                {% if ".view_"|has_perm:activity.creater %}
 | 
				
			||||||
                    <dt class="col-xl-6">{% trans 'creater'|capfirst %}</dt>
 | 
					                    <dt class="col-xl-6">{% trans 'creater'|capfirst %}</dt>
 | 
				
			||||||
                    <dd class="col-xl-6"><a href="{% url "member:user_detail" pk=activity.creater.pk %}">{{ activity.creater }}</a></dd>
 | 
					                    <dd class="col-xl-6"><a href="{% url "member:user_detail" pk=activity.creater.pk %}">{{ activity.creater }}</a></dd>
 | 
				
			||||||
                {% endif %}
 | 
					                {% endif %}
 | 
				
			||||||
@@ -53,17 +53,17 @@
 | 
				
			|||||||
        </div>
 | 
					        </div>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        <div class="card-footer text-center">
 | 
					        <div class="card-footer text-center">
 | 
				
			||||||
            {% if activity.open and "change__open"|has_perm:activity %}
 | 
					            {% if activity.open and ".change__open"|has_perm:activity %}
 | 
				
			||||||
                <a class="btn btn-warning btn-sm my-1" href="{% url 'activity:activity_entry' pk=activity.pk %}"> {% trans "Entry page" %}</a>
 | 
					                <a class="btn btn-warning btn-sm my-1" href="{% url 'activity:activity_entry' pk=activity.pk %}"> {% trans "Entry page" %}</a>
 | 
				
			||||||
            {% endif %}
 | 
					            {% endif %}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            {% if activity.valid and "change__open"|has_perm:activity %}
 | 
					            {% if activity.valid and ".change__open"|has_perm:activity %}
 | 
				
			||||||
                <a class="btn btn-warning btn-sm my-1" id="open_activity"> {% if activity.open %}{% trans "close"|capfirst %}{% else %}{% trans "open"|capfirst %}{% endif %}</a>
 | 
					                <a class="btn btn-warning btn-sm my-1" id="open_activity"> {% if activity.open %}{% trans "close"|capfirst %}{% else %}{% trans "open"|capfirst %}{% endif %}</a>
 | 
				
			||||||
            {% endif %}
 | 
					            {% endif %}
 | 
				
			||||||
            {% if not activity.open and "change__valid"|has_perm:activity %}
 | 
					            {% if not activity.open and ".change__valid"|has_perm:activity %}
 | 
				
			||||||
                <a class="btn btn-success btn-sm my-1" id="validate_activity"> {% if activity.valid %}{% trans "invalidate"|capfirst %}{% else %}{% trans "validate"|capfirst %}{% endif %}</a>
 | 
					                <a class="btn btn-success btn-sm my-1" id="validate_activity"> {% if activity.valid %}{% trans "invalidate"|capfirst %}{% else %}{% trans "validate"|capfirst %}{% endif %}</a>
 | 
				
			||||||
            {% endif %}
 | 
					            {% endif %}
 | 
				
			||||||
            {% if "view_"|has_perm:activity %}
 | 
					            {% if ".view_"|has_perm:activity %}
 | 
				
			||||||
                <a class="btn btn-primary btn-sm my-1" href="{% url 'activity:activity_update' pk=activity.pk %}"> {% trans "edit"|capfirst %}</a>
 | 
					                <a class="btn btn-primary btn-sm my-1" href="{% url 'activity:activity_update' pk=activity.pk %}"> {% trans "edit"|capfirst %}</a>
 | 
				
			||||||
            {% endif %}
 | 
					            {% endif %}
 | 
				
			||||||
            {% if activity.activity_type.can_invite and not activity_started %}
 | 
					            {% if activity.activity_type.can_invite and not activity_started %}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -84,6 +84,11 @@ SPDX-License-Identifier: GPL-3.0-or-later
 | 
				
			|||||||
                        <a class="nav-link" href="{% url 'note:transfer' %}"><i class="fa fa-exchange"></i>{% trans 'Transfer' %} </a>
 | 
					                        <a class="nav-link" href="{% url 'note:transfer' %}"><i class="fa fa-exchange"></i>{% trans 'Transfer' %} </a>
 | 
				
			||||||
                    </li>
 | 
					                    </li>
 | 
				
			||||||
                {% endif %}
 | 
					                {% endif %}
 | 
				
			||||||
 | 
					                {% if "auth.user"|model_list|length >= 2 %}
 | 
				
			||||||
 | 
					                    <li class="nav-item active">
 | 
				
			||||||
 | 
					                        <a class="nav-link" href="{% url 'member:user_list' %}"><i class="fa fa-user"></i> {% trans 'Users' %}</a>
 | 
				
			||||||
 | 
					                    </li>
 | 
				
			||||||
 | 
					                {% endif %}
 | 
				
			||||||
                {% if "member.club"|not_empty_model_list %}
 | 
					                {% if "member.club"|not_empty_model_list %}
 | 
				
			||||||
                    <li class="nav-item active">
 | 
					                    <li class="nav-item active">
 | 
				
			||||||
                        <a class="nav-link" href="{% url 'member:club_list' %}"><i class="fa fa-users"></i> {% trans 'Clubs' %}</a>
 | 
					                        <a class="nav-link" href="{% url 'member:club_list' %}"><i class="fa fa-users"></i> {% trans 'Clubs' %}</a>
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user