<commit_before>from django.contrib.contenttypes.models import ContentType

from flexi_auth.models import ParamRole, Param

from gasistafelice.lib.formsets import BaseFormSetWithRequest
from gasistafelice.base.forms import BaseRoleForm
from gasistafelice.consts import GAS_MEMBER
from gasistafelice.supplier.models import Supplier

class GASRoleForm(BaseRoleForm):

    def __init__(self, request, *args, **kw):
        super(GASRoleForm, self).__init__(request, *args, **kw)
        self._gas = request.resource.gas
        self.fields['person'].queryset = \
            self._gas.persons.filter(gasmember__isnull=False)
        self.fields['role'].queryset = self.fields['role'].queryset.exclude(role__name=GAS_MEMBER)
        
        self.fields['role'].queryset |= self._get_additional_roles()

    def _get_additional_roles(self):
        """
        Return a QuerySet containing all parametric roles manageable by the GAS
        (i.e: by GAS_REFERRER_TECH)
        """

        # Roles MUST BE a property because roles are bound to a User 
        # with `add_principal()` and not directly to a GAS member
        # costruct the result set by joining partial QuerySets

        ctype = ContentType.objects.get_for_model(Supplier)
        params = Param.objects.filter(content_type=ctype, object_id__in=map(lambda x: x['id'], self._gas.suppliers.values('id')))
        # get all parametric roles assigned to the GAS;
        return ParamRole.objects.filter(param_set__in=params)

#--------------------------------------------------------------------------------
<commit_msg>Added GAS_REFERRER_SUPPLIER in tech_referrer manegeable roles<commit_after>from django.contrib.contenttypes.models import ContentType

from flexi_auth.models import ParamRole, Param

from gasistafelice.lib.formsets import BaseFormSetWithRequest
from gasistafelice.base.forms import BaseRoleForm
from gasistafelice.consts import GAS_MEMBER
from gasistafelice.gas.models import GASSupplierSolidalPact

import logging
log = logging.getLogger(__name__)

class GASRoleForm(BaseRoleForm):

    def __init__(self, request, *args, **kw):
        super(GASRoleForm, self).__init__(request, *args, **kw)
        self._gas = request.resource.gas
        self.fields['person'].queryset = \
            self._gas.persons.filter(gasmember__isnull=False)
        self.fields['role'].queryset = self.fields['role'].queryset.exclude(role__name=GAS_MEMBER)
        self.fields['role'].queryset |= self._get_additional_roles()

    def _get_additional_roles(self):
        """
        Return a QuerySet containing all parametric roles manageable by the GAS
        (i.e: by GAS_REFERRER_TECH)
        """

        # Roles MUST BE a property because roles are bound to a User 
        # with `add_principal()` and not directly to a GAS member
        # costruct the result set by joining partial QuerySets

        ctype = ContentType.objects.get_for_model(GASSupplierSolidalPact)
        params = Param.objects.filter(content_type=ctype, object_id__in=map(lambda x: x['pk'], self._gas.pacts.values('pk')))
        qs = ParamRole.objects.filter(param_set__in=params)
        log.debug("PACT selectable roles %s" % qs.values())
        return qs

#--------------------------------------------------------------------------------

{'fraction_non_alphanumeric': 0.13777372262773724, 'fraction_numerical': 0.0, 'mean_word_length': 2.9818401937046004, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6864227', 'n_tokens_mistral': 974, 'n_tokens_neox': 950, 'n_words': 222}