示例#1
0
def get_info(request):
    """
    Obtiene 

    """
    info = "Backend"
    if UserToken.get_headquar_id(request.session):
        try:
            sede = Headquar.objects.get(id=UserToken.get_headquar_id(request.session))
            info = "%s-%s" % (sede.enterprise.name, sede.name)
        except:
            messages.error(request, ("Sede no se encuentra en la base de datos."))

    return info
示例#2
0
def get_info(request):
    """
    Obtiene 

    """
    info = "DentalCool"
    if UserToken.get_headquar_id(request.session):
        try:
            sede = Headquar.objects.get(
                id=UserToken.get_headquar_id(request.session))
            info = "%s-%s" % (sede.enterprise.name, sede.name)
        except:
            messages.error(request,
                           ("Sede no se encuentra en la base de datos."))

    return info
示例#3
0
    def load(request, menu_module):
        """
        Carga el menu del usuario

        Entrada::

                menu_module=BACKEND

        Salida::

                menu_item_list[menu]
    """
        Menus.menu_list = []
        Menus.menu_item_list = {}
        Menus.menu_module = menu_module
        user = request.user

        print ("\n\n\n")
        # print 'Permisos del User a travez de sus Groups'
        # print user.get_group_permissions() # no sirve pk tambien debemos comparar con la sede
        # if not UserToken.get_headquar_id(request.session):
        # 	return HttpResponse("Sede no seleccionada, seleccione en la Página de inicio para cargar el menú")
        # los Grupos del User según su espacio actual
        permission_list = []
        if not request.user.is_superuser:
            try:
                headquar = Headquar.objects.get(
                    id=UserToken.get_headquar_id(request.session))
                group_id_list_by_user_and_headquar = list(col["id"] for col in Group.objects.values("id").filter(
                    userheadquar__headquar__id=headquar.id, userheadquar__user__id=user.id).distinct())
                group_id_list_by_user_and_enterprise = list(col["id"] for col in Group.objects.values("id").filter(
                    userenterprise__enterprise__id=headquar.enterprise.id, userenterprise__user__id=user.id).distinct())
                group_id_list_by_user_and_association = list(col["id"] for col in Group.objects.values("id").filter(
                    userassociation__association__id=headquar.association.id, userassociation__user__id=user.id).distinct())
                group_id_list_by_user_and_hea = list(
                    set(group_id_list_by_user_and_headquar + group_id_list_by_user_and_enterprise + group_id_list_by_user_and_association))

                # print 'Groups del User a travez de su espacio actual'
                # print group_id_list_by_user_and_hea

                # print 'Permisos del User a travez de su espacio actual'
                # compara con los Group del user
                permission_list = Permission.objects.filter(
                    group__in=group_id_list_by_user_and_hea).distinct()
            except:
                print ("Sede no seleccionado")
                # headquar=Headquar.objects.filter(userheadquar__user__id=request.user.id).distinct().first()
                pass

        if request.user.is_superuser:
            permission_list = []  # si es uperuser mostrarme todo los menús
        menu = Menu()
        #permission_list = []
        # obtengo los hijos y luego saco sus padres, esto es para no mostrar un
        # menu sin items
        menu_item_list_t = Menu.objects.filter(Q(permission__in=permission_list) | Q(
            id__isnull=True if permission_list else False), module=menu_module, is_active=True).order_by("pos")
        Menus.menu_list = Menu.objects.filter(
            menu__in=menu_item_list_t, module=menu_module, is_active=True).order_by("pos").distinct()
        #print Menus.menu_list
        if Menus.menu_list:
            for menu in Menus.menu_list:
                Menus.menu_item_list[menu.title] = Menu.objects.filter(Q(permission__in=permission_list) | Q(
                    id__isnull=True if permission_list else False), parent_id=menu.id, module=menu_module, is_active=True).order_by("pos")  # .lower().replace(" ","_")
        #print Menus.menu_item_list
        return ""
示例#4
0
    def load(request, menu_module):
        """
        Carga el menu del usuario

        Entrada::

                menu_module=BACKEND

        Salida::

                menu_item_list[menu]
    """
        Menus.menu_list = []
        Menus.menu_item_list = {}
        Menus.menu_module = menu_module
        user = request.user

        print "\n\n\n"
        # print 'Permisos del User a travez de sus Groups'
        # print user.get_group_permissions() # no sirve pk tambien debemos comparar con la sede
        # if not UserToken.get_headquar_id(request.session):
        # 	return HttpResponse("Sede no seleccionada, seleccione en la Página de inicio para cargar el menú")
        # los Grupos del User según su espacio actual
        permission_list = []
        if not request.user.is_superuser:
            try:
                headquar = Headquar.objects.get(
                    id=UserToken.get_headquar_id(request.session))
                group_id_list_by_user_and_headquar = list(col["id"] for col in Group.objects.values("id").filter(
                    userheadquar__headquar__id=headquar.id, userheadquar__user__id=user.id).distinct())
                group_id_list_by_user_and_enterprise = list(col["id"] for col in Group.objects.values("id").filter(
                    userenterprise__enterprise__id=headquar.enterprise.id, userenterprise__user__id=user.id).distinct())
                group_id_list_by_user_and_association = list(col["id"] for col in Group.objects.values("id").filter(
                    userassociation__association__id=headquar.association.id, userassociation__user__id=user.id).distinct())
                group_id_list_by_user_and_hea = list(
                    set(group_id_list_by_user_and_headquar + group_id_list_by_user_and_enterprise + group_id_list_by_user_and_association))

                # print 'Groups del User a travez de su espacio actual'
                # print group_id_list_by_user_and_hea

                # print 'Permisos del User a travez de su espacio actual'
                # compara con los Group del user
                permission_list = Permission.objects.filter(
                    group__in=group_id_list_by_user_and_hea).distinct()
            except:
                print "Sede no seleccionado"
                # headquar=Headquar.objects.filter(userheadquar__user__id=request.user.id).distinct().first()
                pass
            
        if request.user.is_superuser:
            permission_list = []  # si es uperuser mostrarme todo los menús
        menu = Menu()
        #permission_list = []
        # obtengo los hijos y luego saco sus padres, esto es para no mostrar un
        # menu sin items
        menu_item_list_t = Menu.objects.filter(Q(permission__in=permission_list) | Q(
            id__isnull=True if permission_list else False), module=menu_module, is_active=True).order_by("pos")
        Menus.menu_list = Menu.objects.filter(
            menu__in=menu_item_list_t, module=menu_module, is_active=True).order_by("pos").distinct()
        #print Menus.menu_list
        if Menus.menu_list:
            for menu in Menus.menu_list:
                Menus.menu_item_list[menu.title] = Menu.objects.filter(Q(permission__in=permission_list) | Q(
                    id__isnull=True if permission_list else False), parent_id=menu.id, module=menu_module, is_active=True).order_by("pos")  # .lower().replace(" ","_")
        #print Menus.menu_item_list
        return ""
示例#5
0
    def __init__(self, *args, **kwargs):
        self.request = kwargs.pop('request', None)
        self.object = kwargs.pop('object', None)

        super(UserForm, self).__init__(*args, **kwargs)
        # print self.request.user
        #self.fields['hidden_field'] = forms.CharField(widget=forms.HiddenInput())
        # print self.hidden_field

        headquar = Headquar.objects.get(
            id=UserToken.get_headquar_id(self.request.session))
        solution_enterprise = Solution.objects.get(
            id=headquar.enterprise.solution.id)
        solution_association = Solution.objects.get(
            id=headquar.association.solution.id)
        module_list = Module.objects.filter(Q(solutions=solution_enterprise) | Q(
            solutions=solution_association), is_active=True).distinct()
        # trae los objetos relacionados sad.Module
        group_perm_list = Group.objects.filter(
            module_set__in=module_list).order_by("-id").distinct()
        # print group_perm_list
        # print "====================="
        # pero hay que adornarlo de la forma Module>Group
        group_list_by_module = []
        # solo para verificar que el Group no se repita si este está en dos o
        # más módulos
        group_list_by_module_unique_temp = []
        for module in module_list:
            for group in Group.objects.filter(module_set=module).distinct():
                if len(group_list_by_module) == 0:
                    group_list_by_module.append({
                                                "group": group,
                                                "module": module,
                                                })
                    group_list_by_module_unique_temp.append(group)
                else:
                    if group not in group_list_by_module_unique_temp:
                        group_list_by_module.append({
                                                    "group": group,
                                                    "module": module,
                                                    })
                        group_list_by_module_unique_temp.append(group)
        groups_final = {}
        for perm in group_list_by_module:
            groups_final[perm['group'].id] = '%s> %s' % (
                perm['module'].name,  perm['group'].name)

        # print groups_final.items()
        '''
        self.fields['hgroups'] = forms.ModelMultipleChoiceField(
            queryset=Group.objects.filter(module_set__in=module_list).order_by("-id").distinct()

            )
        self.fields['hgroups'].initial=Group.objects.filter(userheadquar__headquar__id=headquar.id, userheadquar__user__id=2).distinct() 
        
        '''
        self.fields['hgroups'] = forms.MultipleChoiceField(
            label=u'%s %s' % (capfirst(_(u'groups')), capfirst(_(u'Headquar'))), required=False,
            choices=groups_final.items(),
            help_text=u'<small class="help-error"></small> %s' % _(
                u' '),
        )
        if self.object:
            self.fields['hgroups'].initial = [(e.id) for e in Group.objects.filter(
                userheadquar__headquar__id=headquar.id, userheadquar__user__id=self.object.id).distinct()]

        self.fields['egroups'] = forms.MultipleChoiceField(
            label=u'%s %s' % (capfirst(_(u'groups')), capfirst(_(u'Enterprise'))), required=False,
            choices=groups_final.items(),
            help_text=u'<small class="help-error"></small> %s' % _(
                u' '),
        )
        if self.object:
            self.fields['egroups'].initial = [(e.id) for e in Group.objects.filter(
                userenterprise__enterprise__id=headquar.enterprise.id, userenterprise__user__id=self.object.id).distinct()]

        self.fields['agroups'] = forms.MultipleChoiceField(
            label=u'%s %s' % (capfirst(_(u'groups')), capfirst(_(u'Association'))), required=False,
            choices=groups_final.items(),
            help_text=u'<small class="help-error"></small> %s' % _(
                u' '),
        )
        if self.object:
            self.fields['agroups'].initial = [(e.id) for e in Group.objects.filter(
                userassociation__association__id=headquar.association.id, userassociation__user__id=self.object.id).distinct()]

        self.fields['password1'] = forms.CharField(
            label=capfirst(_(u'Password')), required=False,
            widget=forms.PasswordInput, initial='',
            help_text=u'<small class="help-error"></small> %s' % _(
                u' '),
        )
        self.fields['password2'] = forms.CharField(
            label=capfirst(_(u'Password confirmation')), required=False,
            widget=forms.PasswordInput, initial='',
            help_text=u'<small class="help-error"></small> %s' % _(
                u'Enter the same password as above, for verification.'),
        )

        self.fields['first_name'] = forms.CharField(
            label=capfirst(_(u'first name')), required=True,
            help_text=u'<small class="help-error"></small> %s' % _(
                u' '),
        )
        self.fields['last_name'] = forms.CharField(
            label=capfirst(_(u'last name')), required=True,
            help_text=u'<small class="help-error"></small> %s' % _(
                u' '),
        )
        self.fields['identity_type'] = forms.ChoiceField(
            label=capfirst(_(u'Identity type')), required=True,
            # widget=forms.RadioSelect(),
            choices=IDENTITY_TYPE_CHOICES,

            help_text=u'<small class="help-error"></small> %s' % _(
                u' '),
        )
        self.fields['identity_num'] = forms.CharField(
            label=capfirst(_(u'number')), required=False,
            help_text=u'<small class="help-error"></small> %s' % _(
                u' '),
        )
        self.fields['photo'] = forms.ImageField(
            label=capfirst(_(u'Photo')), required=False,
            initial='persons/default.png',
            help_text=u'<small class="help-error"></small> %s' % _(
                u'Available formats are JPG, GIF, and PNG.'),
        )

        self.helper = FormHelper()
        self. helper.layout = Layout(
            Field('person_id',),
            TabHolder(
                Tab(_('Personal Info'),
                    Row(
                        Div(Field('first_name',),
                    css_class='col-md-6'),
                        Div(Field('last_name', ),
                    css_class='col-md-6'),
                    ),
                    Row(
                        Div(Field('identity_type',),
                                    css_class='col-md-6'),
                        Div(Field('identity_num',),
                                    css_class='col-md-6'),
                    ),
                    ),
                Tab(_('Account Info'),
                    Row(
                        Div(Field('username', autofocus=True, autocomplete='off', css_class='input-required'),
                    css_class='col-md-6'),
                        Div(Field('email', ),
                    css_class='col-md-6'),
                    ),
                    Row(
                        Div(Field('password1', autocomplete='off'),
                                    css_class='col-md-6'),
                        Div(Field('password2', autocomplete='off'),
                                    css_class='col-md-6'),
                    ),
                    Row(
                        Div(Field('hgroups'),
                                    css_class='col-md-6'),
                    ),
                    Row(
                        Div(Field('egroups'),
                                    css_class='col-md-6'),
                        Div(Field('agroups'),
                                    css_class='col-md-6'),
                    ),

                    ),

                Tab(_('Image'),
                    Row(
                        Div(Field('photo'),
                                    css_class='col-md-6'),
                    ),
                    ),
            ),
            Row(
                FormActions(
                    smtSave(),
                    btnCancel(),
                    btnReset(),
                ),
            ),
        )
示例#6
0
文件: forms.py 项目: cpaja/dentalcool
    def __init__(self, *args, **kwargs):
        self.request = kwargs.pop('request', None)
        self.object = kwargs.pop('object', None)

        super(UserForm, self).__init__(*args, **kwargs)
        # print self.request.user
        #self.fields['hidden_field'] = forms.CharField(widget=forms.HiddenInput())
        # print self.hidden_field

        headquar = Headquar.objects.get(
            id=UserToken.get_headquar_id(self.request.session))
        solution_enterprise = Solution.objects.get(
            id=headquar.enterprise.solution.id)
        solution_association = Solution.objects.get(
            id=headquar.association.solution.id)
        module_list = Module.objects.filter(
            Q(solutions=solution_enterprise)
            | Q(solutions=solution_association),
            is_active=True).distinct()
        # trae los objetos relacionados sad.Module
        group_perm_list = Group.objects.filter(
            module_set__in=module_list).order_by("-id").distinct()
        # print group_perm_list
        # print "====================="
        # pero hay que adornarlo de la forma Module>Group
        group_list_by_module = []
        # solo para verificar que el Group no se repita si este está en dos o
        # más módulos
        group_list_by_module_unique_temp = []
        for module in module_list:
            for group in Group.objects.filter(module_set=module).distinct():
                if len(group_list_by_module) == 0:
                    group_list_by_module.append({
                        "group": group,
                        "module": module,
                    })
                    group_list_by_module_unique_temp.append(group)
                else:
                    if group not in group_list_by_module_unique_temp:
                        group_list_by_module.append({
                            "group": group,
                            "module": module,
                        })
                        group_list_by_module_unique_temp.append(group)
        groups_final = {}
        for perm in group_list_by_module:
            groups_final[perm['group'].id] = '%s> %s' % (perm['module'].name,
                                                         perm['group'].name)

        # print groups_final.items()
        '''
        self.fields['hgroups'] = forms.ModelMultipleChoiceField(
            queryset=Group.objects.filter(module_set__in=module_list).order_by("-id").distinct()

            )
        self.fields['hgroups'].initial=Group.objects.filter(userheadquar__headquar__id=headquar.id, userheadquar__user__id=2).distinct() 
        
        '''
        self.fields['hgroups'] = forms.MultipleChoiceField(
            label=u'%s %s' %
            (capfirst(_(u'groups')), capfirst(_(u'Headquar'))),
            required=False,
            choices=groups_final.items(),
            help_text=u'<small class="help-error"></small> %s' % _(u' '),
        )
        if self.object:
            self.fields['hgroups'].initial = [
                (e.id) for e in Group.objects.filter(
                    userheadquar__headquar__id=headquar.id,
                    userheadquar__user__id=self.object.id).distinct()
            ]

        self.fields['egroups'] = forms.MultipleChoiceField(
            label=u'%s %s' %
            (capfirst(_(u'groups')), capfirst(_(u'Enterprise'))),
            required=False,
            choices=groups_final.items(),
            help_text=u'<small class="help-error"></small> %s' % _(u' '),
        )
        if self.object:
            self.fields['egroups'].initial = [
                (e.id) for e in Group.objects.filter(
                    userenterprise__enterprise__id=headquar.enterprise.id,
                    userenterprise__user__id=self.object.id).distinct()
            ]

        self.fields['agroups'] = forms.MultipleChoiceField(
            label=u'%s %s' %
            (capfirst(_(u'groups')), capfirst(_(u'Association'))),
            required=False,
            choices=groups_final.items(),
            help_text=u'<small class="help-error"></small> %s' % _(u' '),
        )
        if self.object:
            self.fields['agroups'].initial = [
                (e.id) for e in Group.objects.filter(
                    userassociation__association__id=headquar.association.id,
                    userassociation__user__id=self.object.id).distinct()
            ]

        self.fields['password1'] = forms.CharField(
            label=capfirst(_(u'Password')),
            required=False,
            widget=forms.PasswordInput,
            initial='',
            help_text=u'<small class="help-error"></small> %s' % _(u' '),
        )
        self.fields['password2'] = forms.CharField(
            label=capfirst(_(u'Password confirmation')),
            required=False,
            widget=forms.PasswordInput,
            initial='',
            help_text=u'<small class="help-error"></small> %s' %
            _(u'Enter the same password as above, for verification.'),
        )

        self.fields['first_name'] = forms.CharField(
            label=capfirst(_(u'first name')),
            required=True,
            help_text=u'<small class="help-error"></small> %s' % _(u' '),
        )
        self.fields['last_name'] = forms.CharField(
            label=capfirst(_(u'last name')),
            required=True,
            help_text=u'<small class="help-error"></small> %s' % _(u' '),
        )
        self.fields['identity_type'] = forms.ChoiceField(
            label=capfirst(_(u'Identity type')),
            required=True,
            # widget=forms.RadioSelect(),
            choices=IDENTITY_TYPE_CHOICES,
            help_text=u'<small class="help-error"></small> %s' % _(u' '),
        )
        self.fields['identity_num'] = forms.CharField(
            label=capfirst(_(u'number')),
            required=False,
            help_text=u'<small class="help-error"></small> %s' % _(u' '),
        )
        self.fields['photo'] = forms.ImageField(
            label=capfirst(_(u'Photo')),
            required=False,
            initial='persons/default.png',
            help_text=u'<small class="help-error"></small> %s' %
            _(u'Available formats are JPG, GIF, and PNG.'),
        )

        self.helper = FormHelper()
        self.helper.layout = Layout(
            Field('person_id', ),
            TabHolder(
                Tab(
                    _('Personal Info'),
                    Row(
                        Div(Field('first_name', ), css_class='col-md-6'),
                        Div(Field('last_name', ), css_class='col-md-6'),
                    ),
                    Row(
                        Div(Field('identity_type', ), css_class='col-md-6'),
                        Div(Field('identity_num', ), css_class='col-md-6'),
                    ),
                ),
                Tab(
                    _('Account Info'),
                    Row(
                        Div(Field('username',
                                  autofocus=True,
                                  autocomplete='off',
                                  css_class='input-required'),
                            css_class='col-md-6'),
                        Div(Field('email', ), css_class='col-md-6'),
                    ),
                    Row(
                        Div(Field('password1', autocomplete='off'),
                            css_class='col-md-6'),
                        Div(Field('password2', autocomplete='off'),
                            css_class='col-md-6'),
                    ),
                    Row(Div(Field('hgroups'), css_class='col-md-6'), ),
                    Row(
                        Div(Field('egroups'), css_class='col-md-6'),
                        Div(Field('agroups'), css_class='col-md-6'),
                    ),
                ),
                Tab(
                    _('Image'),
                    Row(Div(Field('photo'), css_class='col-md-6'), ),
                ),
            ),
            Row(FormActions(
                smtSave(),
                btnCancel(),
                btnReset(),
            ), ),
        )