Пример #1
0
 def __init__(self, request, app_name, base_class, mutable, guard):
     self.request = request
     self.app_name = app_name
     self.base_class = base_class
     self.mutable = mutable
     self.guard = guard
     AuthenticationGuard(self.guard, self.request).guard()
 def __init__(self,
              request,
              permission=AuthenticationGuardType.PUBLIC_GUARD,
              **kwargs):
     super().__init__(request)
     self.context = self._setContext()
     AuthenticationGuard(permission, self.request, self.context).guard()
Пример #3
0
    def dispatch(self, form_path):
        self.form_path = form_path

        def generalViewDisplay():
            def actionView():
                action_type = dict(table=True)
                table = Table(currentClass, self.form_path).makeTable()
                content = [table]
                return dict(page_title=page_title, type=action_type, context=content)

            def actionAdd():
                self.request.session[self.session_name] = MiscFunctions.getViewJSON(action, None)
                action_type = dict(form=True)
                content = Form('_add_form', form_path, action, self.destination,
                               self.view_dispatcher.get(self.form_path)["form"]())
                return dict(page_title=page_title, type=action_type, context=content)

            def actionEditDelete(choice):
                choiceDict = {"edit": "_edit_form", "delete": "_delete_form"}
                if element_id is None:
                    return HttpResponse('{"Response": "Error: No Element ID Provided"}')
                else:
                    self.request.session[self.session_name] = MiscFunctions.getViewJSON(action, element_id)
                    element = currentClass.objects.get(pk=int(element_id))
                    action_type = dict(form=True)
                    content = Form(choiceDict[choice], form_path, action, self.destination,
                                   self.view_dispatcher.get(self.form_path)["form"](instance=element))
                    return dict(page_title=page_title, type=action_type, context=content)

            def setFunctionDispatcher():
                dispatcher = Dispatcher()
                dispatcher.add('view', actionView())
                dispatcher.add('add', actionAdd())
                dispatcher.add('edit', actionEditDelete('edit'))
                dispatcher.add('delete', actionEditDelete('delete'))
                return dispatcher

            action = (lambda x: x if x else 'view')(self.request.GET.get("action"))
            element_id = self.request.GET.get("element_id")

            page_title = (self.form_path + " " + action).title()
            currentData = (lambda x: x if x else None)(self.view_dispatcher.get(self.form_path))
            currentClass = currentData["class"]

            functionDispatch = setFunctionDispatcher()

            return (
                lambda x: render(
                    self.request, self.page_path, MiscFunctions.updateDict(
                        x, dict(auth=self.permission_obj().getIdentifier(), template_base=self.template_base)
                    )
                ) if x else HttpResponse(
                    '{"Response": "Error: Insufficient Parameters"}')
            )(functionDispatch.get(action))

        def generalViewLogic():
            def actionAdd():
                form = self.view_dispatcher.get(self.form_path)["form"](self.request.POST)
                temp = form.save()
                LogFunctions.generateLog(
                    self.request, 'admin', LogFunctions.makeLogQuery(currentClass, action.title(), id=temp.id))

            def actionEdit():
                element = get_object_or_404(currentClass, pk=element_id)
                form = self.view_dispatcher.get(self.form_path)["form"](self.request.POST, instance=element)
                temp = form.save()
                LogFunctions.generateLog(
                    self.request, 'admin', LogFunctions.makeLogQuery(currentClass, action.title(), id=temp.id))

            def actionDelete():
                element = get_object_or_404(currentClass, pk=element_id)
                LogFunctions.generateLog(
                    self.request, 'admin', LogFunctions.makeLogQuery(currentClass, action.title(), id=element.id))
                element.delete()

            def setFunctionDispatcher():
                dispatcher = Dispatcher()
                dispatcher.add('add', actionAdd)
                dispatcher.add('edit', actionEdit)
                dispatcher.add('delete', actionDelete)
                return dispatcher

            currentData = (lambda x: x if x else None)(self.view_dispatcher.get(self.form_path))
            currentClass = currentData["class"]

            self.request_variables = self.request.session[self.session_name]
            self.request.session[self.session_name] = None
            action = self.request_variables["action"]
            element_id = self.request_variables["id"]

            functionDispatch = setFunctionDispatcher()
            functionDispatch.get(action)()

            return HttpResponseRedirect(self.destination)

        return AuthenticationGuard(AuthenticationGuardType.LOGIN_GUARD, self.request).guard(
            api=False,
            rend=(lambda x: generalViewLogic() if x else generalViewDisplay())(self.request.method == 'POST')
        )
    def dispatch(self, form_path):
        self.form_path = form_path

        def CustomViewDisplay():
            def loadView(actionClass):
                return (lambda x: render(
                    self.request, self.page_path,
                    MiscFunctions.updateDict(
                        x(
                            currentClass(self.request).grabData(
                                action, form_path, element_id)),
                        dict(auth=self.permission_obj().getIdentifier(),
                             template_base=self.template_base)))
                        if x else HttpResponse(
                            '{"Response": "Error: Insufficient Parameters"}')
                        )(actionClass)

            def loadViewChecker():
                return loadView(functionDispatch.get(action)) if currentClass(
                    self.request).dispatcher.get(action) else redirect(
                        'panel.module.management_data.view_dispatch_param',
                        form_path, 'custom')

            def actionView(data):
                action_type = dict(table=True)
                return dict(page_title=page_title,
                            type=action_type,
                            context=data)

            def actionAdd(data):
                self.request.session[
                    self.session_name] = MiscFunctions.getViewJSON(
                        action, None)
                page_type = dict(form=True)
                content = Form(
                    '_add_form', form_path, action, self.destination,
                    self.view_dispatcher.get(
                        self.form_path)["form"](data=data['data']))
                specialContent = data['special_field']
                return dict(page_title=page_title,
                            type=page_type,
                            context=content,
                            special_context=specialContent)

            def actionEdit(data):
                if element_id is None:
                    return HttpResponse(
                        '{"Response": "Error: No Element ID Provided"}')
                else:
                    self.request.session[
                        self.session_name] = MiscFunctions.getViewJSON(
                            action, element_id)
                    page_type = dict(form=True)
                    content = Form(
                        '_edit_form', form_path, action, self.destination,
                        self.view_dispatcher.get(
                            self.form_path)["form"](data=data['data']))
                    specialContent = data['special_field']
                    return dict(page_title=page_title,
                                type=page_type,
                                context=content,
                                special_context=specialContent)

            def actionDelete(data):
                if element_id is None:
                    return HttpResponse(
                        '{"Response": "Error: No Element ID Provided"}')
                else:
                    self.request.session[
                        self.session_name] = MiscFunctions.getViewJSON(
                            action, element_id)
                    page_type = dict(form=True)
                    content = Form(
                        '_delete_form', form_path, action, self.destination,
                        self.view_dispatcher.get(
                            self.form_path)["form"](data=data['data']))
                    specialContent = data['special_field']
                    return dict(page_title=page_title,
                                type=page_type,
                                context=content,
                                special_context=specialContent)

            def setFunctionDispatcher():
                dispatcher = Dispatcher()
                dispatcher.add('view', actionView)
                dispatcher.add('add', actionAdd)
                dispatcher.add('edit', actionEdit)
                dispatcher.add('delete', actionDelete)
                return dispatcher

            action = (lambda x: x
                      if x else 'view')(self.request.GET.get("action"))
            element_id = self.request.GET.get("element_id")
            page_title = (self.form_path + " " + action).title()
            currentData = (lambda x: x if x else None)(
                self.view_dispatcher.get(self.form_path))
            currentClass = currentData["class"]

            functionDispatch = setFunctionDispatcher()

            return loadViewChecker()

        def CustomViewLogic():
            def actionAdd():
                currentClass(self.request).add()

            def actionEdit():
                currentClass(self.request).edit(element_id)

            def actionDelete():
                currentClass(self.request).delete(element_id)

            def setFunctionDispatcher():
                dispatcher = Dispatcher()
                dispatcher.add('add', actionAdd)
                dispatcher.add('edit', actionEdit)
                dispatcher.add('delete', actionDelete)
                return dispatcher

            currentData = (lambda x: x if x else None)(
                self.view_dispatcher.get(self.form_path))
            currentClass = currentData["class"]

            self.request_variables = self.request.session[self.session_name]
            self.request.session[self.session_name] = None
            action = self.request_variables["action"]
            element_id = self.request_variables["id"]

            functionDispatch = setFunctionDispatcher()
            functionDispatch.get(action)()
            return HttpResponseRedirect(self.destination)

        return AuthenticationGuard(
            AuthenticationGuardType.LOGIN_GUARD,
            self.request).guard(api=False,
                                rend=(lambda x: CustomViewLogic()
                                      if x else CustomViewDisplay())(
                                          self.request.method == 'POST'))
Пример #5
0
 def verifyRequest(self, module, callback, failure):
     AuthenticationGuard(AuthenticationGuardType.LOGIN_GUARD, self.module_request).guard()
     if self.__checkModulePermission(module):
         return callback()
     else:
         return redirect(reverse(self.module_base_redirect_route)) if failure is None else failure()
Пример #6
0
def index(request):
    return AuthenticationGuard(AuthenticationGuardType.LOGIN_GUARD,
                               request).guard(api=False,
                                              rend=render(
                                                  request,
                                                  'platform/index.html'))
 def view(request):
     return AuthenticationGuard(AuthenticationGuardType.PUBLIC_GUARD,
                                request).guard(api=False,
                                               rend=render(
                                                   request,
                                                   'permission/login.html'))