コード例 #1
0
ファイル: __init__.py プロジェクト: adelsonllima/djangoplus
 def decorate(func):
     func._action = dict(
         verbose_name=verbose_name, can_execute=iterable(can_execute), help_text=help_text,
         input=input, group=category or verbose_name, style=style, condition=condition, view_name=func.__name__,
         message=message, initial=initial or '{}_initial'.format(func.__name__), function=func,
         choices=choices or '{}_choices'.format(func.__name__), inline=inline, subsets=iterable(subset), icon=icon,
         doc=func.__doc__, usecase=usecase, can_execute_by_organization=iterable(can_execute_by_organization),
         can_execute_by_unit=iterable(can_execute_by_unit), can_execute_by_role=iterable(can_execute_by_role),
         redirect_to=redirect_to, menu=menu, display=display, source='model', expose=iterable(expose)
     )
     return func
コード例 #2
0
    def decorate(function):
        def receive_function_args(request, *args, **kwargs):
            if can_execute and not permissions.check_group_or_permission(
                    request, '%s.%s' %
                (model._meta.app_label, function.func_name)):
                return HttpResponseRedirect('/admin/login/')
            f_return = function(request, *args, **kwargs)

            if type(f_return) == dict:
                if 'pdf' in style:
                    template_list = [
                        '%s.html' % function.func_name, 'report.html'
                    ]
                    return PdfResponse(
                        render_to_string(template_list,
                                         f_return,
                                         request=request))
                else:
                    template_list = [
                        '%s.html' % function.func_name, 'default.html'
                    ]
                    return render(request, template or template_list, f_return)

            else:
                return f_return

        d = dict(
            title=title,
            can_execute=iterable(can_execute),
            condition=condition,
            view_name=function.__name__,
            function=function,
            group=category,
            css=style,
            message=message,
            model=model,
            input=None,
            initial=None,
            choices=None,
            inline=inline,
            icon=icon,
            doc=function.__doc__,
            sequence=sequence,
            can_execute_by_organization=iterable(can_execute_by_organization),
            can_execute_by_unit=iterable(can_execute_by_unit),
            can_execute_by_role=iterable(can_execute_by_role),
            redirect_to=redirect_to,
            menu=None)

        receive_function_args._action = d

        return receive_function_args
コード例 #3
0
ファイル: views.py プロジェクト: adelsonllima/djangoplus
    def decorate(func):
        url = '/{}/{}/'.format(func.__module__.split('.')[-2], func.__name__)

        def receive_function_args(request, *args, **kwargs):
            without_permission = can_view and not permissions.check_group_or_permission(
                request, can_view)
            without_authentication = login_required and not request.user.is_authenticated
            if without_permission or without_authentication:
                return HttpResponseRedirect(
                    '/admin/login/?next={}'.format(url))
            f_return = func(request, *args, **kwargs)
            template_name = template or '{}.html'.format(func.__name__)
            return return_response(f_return, request, verbose_name, style,
                                   template_name)

        receive_function_args._view = dict(verbose_name=verbose_name,
                                           function=func,
                                           url=url,
                                           can_view=iterable(can_view),
                                           menu=menu,
                                           icon=icon,
                                           style=style,
                                           add_shortcut=shortcut,
                                           doc=func.__doc__,
                                           usecase=usecase)
        return receive_function_args
コード例 #4
0
ファイル: __init__.py プロジェクト: adelsonllima/djangoplus
    def __init__(self, request, *args, **kwargs):
        metaclass = hasattr(self.__class__, 'Meta') and self.__class__.Meta or None
        self.request = request
        self.method = kwargs.pop('method', None) or metaclass and hasattr(
            metaclass, 'method') and metaclass.method or 'post'
        self.horizontal = True
        self.id = self.__class__.__name__.lower()
        self.inline = kwargs.pop('inline', False)
        self.partial = kwargs.pop('partial', False)
        self.perm_or_group = ()
        self.str_hidden = ''
        self.inner_forms = []
        self.configured_fieldsets = []
        self.submit_label = _('Send')
        self.title = _('Form')
        self.is_inner = False
        self.captcha = False
        self.component = kwargs.pop('component', None)

        if self.method.lower() == 'post':
            kwargs['data'] = request.POST or None
            kwargs['files'] = request.FILES or None
        else:
            kwargs['data'] = request.GET or None

        if request.GET.get('popup'):
            prefix = kwargs.get('prefix', '')
            prefix = 'popup{}'.format(prefix)
            kwargs.update(prefix=prefix)

        super(Form, self).__init__(*args, **kwargs)

        if hasattr(self, 'instance') and not self.fieldsets and not self.inline:
            self.fieldsets = copy.deepcopy(get_metadata(self._meta.model, 'fieldsets', ()))

        if metaclass:
            self.title = hasattr(metaclass, 'title') and metaclass.title or ''
            self.icon = hasattr(metaclass, 'icon') and metaclass.icon or ''
            self.note = hasattr(metaclass, 'note') and metaclass.note or ''
            self.is_inner = hasattr(metaclass, 'is_inner') and metaclass.is_inner or False
            self.horizontal = hasattr(metaclass, 'horizontal') and metaclass.horizontal or False
            self.perm_or_group = hasattr(metaclass, 'perm_or_group') and iterable(
                metaclass.perm_or_group) or self.perm_or_group
            self.captcha = hasattr(metaclass, 'captcha') and metaclass.captcha or False

            if hasattr(metaclass, 'submit_label'):
                self.submit_label = metaclass.submit_label
            elif hasattr(self, 'instance'):
                self.submit_label = _('Save')

            self.submit_style = hasattr(metaclass, 'submit_style') and metaclass.submit_style or 'default'
            self.cancel_style = hasattr(metaclass, 'cancel_style') and metaclass.cancel_style or 'default'
            self.cancel_button = not hasattr(metaclass, 'cancel_button') and True or metaclass.cancel_button
            self.method = hasattr(metaclass, 'method') and metaclass.method or 'post'

        for field_name in self.fields:
            if self.method.lower() == 'post' and field_name in self.request.GET:
                # field.widget = django_forms.HiddenInput()
                self.initial[field_name] = self.request.GET[field_name]
コード例 #5
0
ファイル: views.py プロジェクト: allysonbarros/djangoplus
    def decorate(function):
        url = '/{}/{}/'.format(
            function.__module__.split('.')[-2], function.__name__)

        def receive_function_args(request, *args, **kwargs):
            without_permission = can_view and not permissions.check_group_or_permission(
                request, can_view)
            without_authentication = login_required and not request.user.is_authenticated
            if without_permission or without_authentication:
                return HttpResponseRedirect(
                    '/admin/login/?next={}'.format(url))
            f_return = function(request, *args, **kwargs)
            if 'title' not in f_return:
                f_return['title'] = title
            if type(f_return) == dict:
                for key in f_return:
                    if hasattr(f_return[key], 'process_request'):
                        f_return[key].process_request()
                if 'pdf' in style:
                    request.GET._mutable = True
                    request.GET['pdf'] = 1
                    request.GET._mutable = False
                    from datetime import datetime
                    from djangoplus.admin.models import Settings
                    app_settings = Settings.default()
                    f_return[
                        'logo'] = app_settings.logo_pdf and app_settings.logo_pdf or app_settings.logo
                    f_return['project_name'] = app_settings.initials
                    f_return['project_description'] = app_settings.name
                    f_return['today'] = datetime.now()
                    template_list = [
                        '{}.html'.format(function.__name__), 'report.html'
                    ]
                    return PdfResponse(
                        render_to_string(template_list,
                                         f_return,
                                         request=request))
                else:
                    template_list = [
                        template or '{}.html'.format(function.__name__),
                        'default.html'
                    ]
                    return render(request, template_list, f_return)
            return f_return

        receive_function_args._view = dict(title=title,
                                           function=function,
                                           url=url,
                                           can_view=iterable(can_view),
                                           menu=menu,
                                           icon=icon,
                                           style=style,
                                           add_shortcut=add_shortcut,
                                           doc=function.__doc__,
                                           usecase=usecase)
        return receive_function_args
コード例 #6
0
ファイル: views.py プロジェクト: adelsonllima/djangoplus
    def decorate(func):
        def receive_function_args(request, *args, **kwargs):
            if can_execute and not permissions.check_group_or_permission(
                    request, can_execute):
                return HttpResponseRedirect('/admin/login/')
            f_return = func(request, *args, **kwargs)
            template_name = '{}.html'.format(func.__name__)
            return return_response(f_return, request, verbose_name, style,
                                   template_name)

        _action = dict(
            verbose_name=verbose_name,
            can_execute=iterable(can_execute),
            condition=condition,
            help_text=help_text,
            view_name=func.__name__,
            function=func,
            group=category,
            style=style,
            message=message,
            model=model,
            input=None,
            initial=None,
            choices=None,
            inline=inline,
            subsets=iterable(subset),
            icon=icon,
            doc=func.__doc__,
            usecase=usecase,
            can_execute_by_organization=iterable(can_execute_by_organization),
            can_execute_by_unit=iterable(can_execute_by_unit),
            can_execute_by_role=iterable(can_execute_by_role),
            redirect_to=None,
            menu=menu,
            display=None,
            source='view',
            expose=('web', ))

        receive_function_args._action = _action
        func._view_action = _action

        return receive_function_args
コード例 #7
0
ファイル: __init__.py プロジェクト: adelsonllima/djangoplus
 def decorate(func):
     set_metadata(func, 'type', 'attr')
     set_metadata(func, 'verbose_name', verbose_name)
     set_metadata(func, 'can_view', can_view)
     set_metadata(func, 'help_text', help_text)
     set_metadata(func, 'formatter', formatter)
     set_metadata(func, 'dashboard', dashboard)
     set_metadata(func, 'shortcut', shortcut)
     set_metadata(func, 'icon', icon)
     set_metadata(func, 'expose', iterable(expose))
     return func
コード例 #8
0
ファイル: __init__.py プロジェクト: adelsonllima/djangoplus
 def decorate(func):
     from djangoplus import next_number
     set_metadata(func, 'type', 'subset')
     set_metadata(func, 'tab', True)
     set_metadata(func, 'verbose_name', verbose_name)
     set_metadata(func, 'alert', can_alert)
     set_metadata(func, 'notify', can_notify)
     set_metadata(func, 'menu', menu)
     set_metadata(func, 'help_text', help_text)
     set_metadata(func, 'usecase', usecase)
     set_metadata(func, 'can_view', iterable(can_view))
     set_metadata(func, 'name', func.__name__)
     set_metadata(func, 'order', next_number())
     set_metadata(func, 'dashboard', dashboard)
     set_metadata(func, 'list_display', list_display)
     set_metadata(func, 'list_filter', list_filter)
     set_metadata(func, 'search_fields', search_fields)
     set_metadata(func, 'template', template)
     set_metadata(func, 'formatter', None)
     set_metadata(func, 'expose', iterable(expose))
     return func
コード例 #9
0
ファイル: __init__.py プロジェクト: allysonbarros/djangoplus
 def decorate(function):
     function._action = dict(
         title=title,
         can_execute=iterable(can_execute),
         input=input,
         group=category or title,
         css=style,
         condition=condition,
         view_name=function.__name__,
         message=message,
         initial=initial or '{}_initial'.format(function.__name__),
         function=function,
         choices=choices or '{}_choices'.format(function.__name__),
         inline=inline,
         icon=icon,
         doc=function.__doc__,
         usecase=usecase,
         can_execute_by_organization=iterable(can_execute_by_organization),
         can_execute_by_unit=iterable(can_execute_by_unit),
         can_execute_by_role=iterable(can_execute_by_role),
         redirect_to=redirect_to,
         menu=menu)
     return function
コード例 #10
0
ファイル: __init__.py プロジェクト: allysonbarros/djangoplus
 def decorate(function):
     set_metadata(function, 'type', 'subset')
     set_metadata(function, 'tab', True)
     set_metadata(function, 'title', title)
     set_metadata(function, 'alert', alert)
     set_metadata(function, 'notify', notify)
     set_metadata(function, 'menu', menu)
     set_metadata(function, 'help_text', help_text)
     set_metadata(function, 'usecase', usecase)
     set_metadata(function, 'can_view', iterable(can_view))
     set_metadata(function, 'name', function.__name__)
     set_metadata(function, 'order', cache.next_number())
     set_metadata(function, 'dashboard', dashboard)
     set_metadata(function, 'list_display', list_display)
     set_metadata(function, 'list_filter', list_filter)
     set_metadata(function, 'search_fields', search_fields)
     return function
コード例 #11
0
    def decorate(function):
        url = '/%s/%s/' % (function.__module__.split('.')[-2],
                           function.func_name)

        def receive_function_args(request, *args, **kwargs):
            without_permission = can_view and not permissions.check_group_or_permission(
                request, 'admin.%s' % function.func_name)
            without_authentication = login_required and not request.user.is_authenticated(
            )
            if without_permission or without_authentication:
                return HttpResponseRedirect('/admin/login/?next=%s' % url)
            f_return = function(request, *args, **kwargs)
            if type(f_return) == dict:
                f_return['title'] = title % f_return
                if 'pdf' in style:
                    template_list = [
                        '%s.html' % function.func_name, 'report.html'
                    ]
                    return PdfResponse(
                        render_to_string(template_list,
                                         f_return,
                                         request=request))
                else:
                    template_list = [
                        template or '%s.html' % function.func_name,
                        'default.html'
                    ]
                    return render(request, template_list, f_return)
            return f_return

        receive_function_args._view = dict(title=title,
                                           function=function,
                                           url=url,
                                           can_view=iterable(can_view),
                                           menu=menu,
                                           icon=icon,
                                           style=style,
                                           add_shortcut=add_shortcut,
                                           doc=function.__doc__,
                                           sequence=sequence)
        return receive_function_args
コード例 #12
0
    def configure(self):

        from djangoplus.ui.components.forms import factory

        hidden_fields = []

        one_to_one_fields = dict()
        one_to_many_fields = dict()
        for name in list(self.fields.keys()):
            field = self.fields[name]
            if type(field) == OneToOneField:
                one_to_one_fields[name] = field
                del (self.fields[name])
            elif type(field) == OneToManyField:
                one_to_many_fields[name] = field
                del (self.fields[name])

        if not self.fieldsets:
            fields = list(self.fields.keys()) + list(
                one_to_one_fields.keys()) + list(one_to_many_fields.keys())
            if self.inline:
                self.fieldsets = (('', {'fields': (fields, )}), )
            else:
                self.fieldsets = (('', {'fields': fields}), )

        fieldset_field_names = []
        extra_fieldset_field_names = []
        for title, fieldset in self.fieldsets:
            field_names = fieldset.get('fields', ())
            relation_names = fieldset.get('relations', ())
            for name_or_tuple in tuple(field_names) + tuple(relation_names):
                for name in iterable(name_or_tuple):
                    fieldset_field_names.append(name)
        for field_name in list(self.fields.keys()):
            if field_name not in fieldset_field_names:
                extra_fieldset_field_names.append(field_name)
        if extra_fieldset_field_names:
            self.fieldsets += ('Outros', {
                'fields': extra_fieldset_field_names,
            }),

        for title, fieldset in self.fieldsets:
            title = '::' in title and title.split('::')[1] or title.split(
                '::')[0]
            field_names = fieldset.get('fields', ())
            relation_names = fieldset.get('relations', ())

            configured_fieldset = dict(title=title,
                                       tuples=[],
                                       one_to_one=[],
                                       one_to_many=[])

            for name_or_tuple in tuple(field_names) + tuple(relation_names):
                fields = []
                for name in iterable(name_or_tuple):
                    if name in self.fields:
                        field = self.fields[name]
                        bf = BoundField(self, field, name)
                        if bf.is_hidden:
                            hidden_fields.append(bf)
                        else:
                            if bf.label:
                                label = conditional_escape(str(bf.label))
                                if self.label_suffix:
                                    if label[-1] not in ':?.!':
                                        label += self.label_suffix
                                label = label or ''
                            else:
                                label = ''

                            help_text = field.help_text or ''
                            label = str(label)[0:-1]
                            label = field.required and '{}<span class="text-danger">*</span>'.format(
                                label) or label

                            d = dict(name=name,
                                     request=self.request,
                                     label=label,
                                     widget=bf,
                                     help_text=help_text)
                            fields.append(d)

                    elif name in one_to_one_fields:
                        field = one_to_one_fields[name]
                        one_to_one_id = getattr(self.instance,
                                                '{}_id'.format(name))
                        form = factory.get_one_to_one_form(self.request,
                                                           self.instance,
                                                           name,
                                                           one_to_one_id,
                                                           partial=True,
                                                           prefix=name)
                        required = field.required or form.data.get(
                            form.prefix, None)
                        save = form.data.get(form.prefix, None)
                        if not required:
                            for field_name in form.fields:
                                form.fields[field_name].required = False
                        configured_fieldset['one_to_one'].append(
                            (field, form, required, save))
                        self.inner_forms.append(form)
                    elif name in one_to_many_fields:
                        field = one_to_many_fields[name]
                        one_to_many_forms = []

                        if self.instance.pk:
                            qs = getattr(self.instance, name).all()
                        else:
                            qs = field.queryset.filter(pk=0)
                        count = qs.count()
                        for i in range(0, field.one_to_many_max):
                            instance = i < count and qs[i] or None
                            form = factory.get_one_to_many_form(
                                self.request,
                                self.instance,
                                name,
                                partial=True,
                                inline=True,
                                prefix='{}{}'.format(name, i),
                                instance=instance)
                            form.id = '{}-{}'.format(name, i)
                            form.hidden = i > count or field.one_to_many_count
                            required = form.data.get(form.prefix, None)
                            if not required:
                                for field_name in form.fields:
                                    form.fields[field_name].required = False
                            one_to_many_forms.append(form)
                            self.inner_forms.append(form)
                        one_to_many_count = None
                        if field.one_to_many_count:
                            if type(field.one_to_many_count) is int:
                                one_to_many_count = field.one_to_many_count
                            else:
                                app_label = get_metadata(qs.model, 'app_label')
                                if '__' in field.one_to_many_count:
                                    tokens = field.one_to_many_count.split(
                                        '__')
                                    model_name = self.fields[tokens[
                                        0]].queryset.model.__name__.lower()
                                    model_lookup = '__'.join(tokens[1:])
                                    one_to_many_count = '{}:/view/{}/{}/PK/?one_to_many_count={}'.format(
                                        tokens[0], app_label, model_name,
                                        model_lookup)
                                else:
                                    one_to_many_count = field.one_to_many_count
                        configured_fieldset['one_to_many'].append(
                            (name, field, one_to_many_forms,
                             one_to_many_count))

                if len(fields) > 2 or mobile(self.request):
                    self.horizontal = False

                configured_fieldset['tuples'].append(fields)

            self.configured_fieldsets.append(configured_fieldset)
        self.str_hidden = ''.join([str(x) for x in hidden_fields])
コード例 #13
0
ファイル: views.py プロジェクト: allysonbarros/djangoplus
    def decorate(function):
        def receive_function_args(request, *args, **kwargs):
            if can_execute and not permissions.check_group_or_permission(
                    request, '{}.{}'.format(model._meta.app_label,
                                            function.__name__)):
                return HttpResponseRedirect('/admin/login/')
            f_return = function(request, *args, **kwargs)
            if 'title' not in f_return:
                f_return['title'] = title
            if type(f_return) == dict:
                if 'pdf' in style:
                    request.GET._mutable = True
                    request.GET['pdf'] = 1
                    request.GET._mutable = False
                    from datetime import datetime
                    from djangoplus.admin.models import Settings
                    app_settings = Settings.default()
                    f_return[
                        'logo'] = app_settings.logo_pdf and app_settings.logo_pdf or app_settings.logo
                    f_return['project_name'] = app_settings.initials
                    f_return['project_description'] = app_settings.name
                    f_return['today'] = datetime.now()
                    template_list = [
                        '{}.html'.format(function.__name__), 'report.html'
                    ]
                    return PdfResponse(
                        render_to_string(template_list,
                                         f_return,
                                         request=request))
                else:
                    template_list = [
                        '{}.html'.format(function.__name__), 'default.html'
                    ]
                    return render(request, template or template_list, f_return)
            else:
                return f_return

        d = dict(
            title=title,
            can_execute=iterable(can_execute),
            condition=condition,
            view_name=function.__name__,
            function=function,
            group=category,
            css=style,
            message=message,
            model=model,
            input=None,
            initial=None,
            choices=None,
            inline=inline,
            icon=icon,
            doc=function.__doc__,
            usecase=usecase,
            can_execute_by_organization=iterable(can_execute_by_organization),
            can_execute_by_unit=iterable(can_execute_by_unit),
            can_execute_by_role=iterable(can_execute_by_role),
            redirect_to=redirect_to,
            menu=None)

        receive_function_args._action = d

        return receive_function_args