예제 #1
0
 def change_view(self, request, params):
     '''
     Change protfolio date
     '''
     f = self.viewform(data = params, request = request)
     if f.is_valid():
         cd   = f.cleaned_data
         dt   = cd['date']
         url  = self.buildurl(dt)
         return jredirect(url)
     else:
         return jredirect(self.url)
예제 #2
0
 def change_view(self, request, params):
     '''
     Change protfolio view or date
     '''
     self.preprocess_default(request)
     f = self.viewform(request=request, data=params)
     if f.is_valid():
         cd = f.cleaned_data
         dt = cd['date']
         view = cd['view']
         url = self.buildurl(dt, view)
         return jredirect(url)
     else:
         return jredirect(self.url)
예제 #3
0
파일: views.py 프로젝트: OspreyX/flow
 def change_view(self, request, params):
     '''
     Change protfolio view or date
     '''
     self.preprocess_default(request)
     f = self.viewform(request = request, data = params)
     if f.is_valid():
         cd   = f.cleaned_data
         dt   = cd['date']
         view = cd['view']
         url  = self.buildurl(dt,view)
         return jredirect(url)
     else:
         return jredirect(self.url)
예제 #4
0
    def create_view(self, request, params):
        f = self.addform(request, data=params)
        if f.is_valid():
            cd = f.cleaned_data
            name = cd.get('name')
            des = cd.get('description')
            nview = PortfolioView(code=name,
                                  name=name,
                                  description=des,
                                  user=request.user,
                                  fund=self.fund)
            nview.save()
            if cd.get('default', False):
                nview.set_as_default(request.user)

            cfrom = cd.get('copy_from', None)
            if cfrom:
                folders = cfrom.portfolio_set.filter(Q(parent__isnull=True))
                for f in folders:
                    f.copytoview(nview)

            dt = datetime.date.today()
            url = self.buildurl(dt, nview)
            return jredirect(url)
        else:
            return f.jerrors
예제 #5
0
파일: views.py 프로젝트: OspreyX/flow
 def create_view(self, request, params):
     f = self.addform(request, data = params)
     if f.is_valid():
         cd   = f.cleaned_data
         name = cd.get('name')
         des  = cd.get('description')
         nview = PortfolioView(code = name,
                               name = name,
                               description = des,
                               user = request.user,
                               fund = self.fund)
         nview.save()
         if cd.get('default',False):
             nview.set_as_default(request.user)
         
         cfrom  = cd.get('copy_from',None)
         if cfrom:
             folders = cfrom.portfolio_set.filter(Q(parent__isnull=True))
             for f in folders:
                 f.copytoview(nview)
         
         dt   = datetime.date.today() 
         url  = self.buildurl(dt,nview)
         return jredirect(url)
     else:
         return f.jerrors
예제 #6
0
    def edit_view(self, request, params):
        f = self.editform(request, data=params)
        if f.is_valid():
            cd = f.cleaned_data
            obj = self.object
            if cd.get('default', False):
                obj.set_as_default(request.user)

            if self.object.user == request.user:
                obj.code = cd.get('code')
                obj.name = cd.get('name')
                obj.des = cd.get('description')
                obj.save()
            dt = datetime.date.today()
            url = self.buildurl(dt, obj)
            return jredirect(url)
        else:
            return f.jerrors
예제 #7
0
파일: views.py 프로젝트: OspreyX/flow
 def edit_view(self, request, params):
     f = self.editform(request, data = params)
     if f.is_valid():
         cd    = f.cleaned_data
         obj   = self.object
         if cd.get('default',False):
             obj.set_as_default(request.user)
         
         if self.object.user == request.user:
             obj.code  = cd.get('code')
             obj.name  = cd.get('name')
             obj.des   = cd.get('description')
             obj.save()            
         dt   = datetime.date.today()
         url  = self.buildurl(dt,obj)
         return jredirect(url)
     else:
         return f.jerrors
예제 #8
0
파일: site.py 프로젝트: pombredanne/djpcms
    def handle_error(self, request, response):
        '''Render an error into text or Html depending on *content_type*.
This function can be overwritten by user implementation.'''
        exc_info = request.exc_info
        settings = request.settings
        status = 500
        if exc_info and exc_info[0] is not None:
            status = getattr(exc_info[1], 'status', status)
        else:
            exc_info = None
        # 302 is a special case, we redirect
        content_type = request.content_type
        if status in REDIRECT_CODES:
            location = dict(exc_info[1].headers)['location']
            if request.is_xhr:
                content = ajax.jredirect(request.environ, location)
            else:
                content_type = None
                response.headers['Location'] = iri_to_uri(location)
                content = ''
        else:
            err_cls = '%s%s' % (classes.error, status)
            err_title = '%s %s' % (status, error_title(status))
            if content_type == 'text/plain':
                content = err_title
                if settings.DEBUG:
                    content += '\n\n' + html_trace(exc_info, plain=True)
            else:
                inner = Widget('div', cn=(classes.error, err_cls))
                if settings.DEBUG:
                    inner.addClass('debug')
                    inner.add(Widget('h2', err_title))
                    inner.add(Widget('a', request.path, href=request.path))
                    inner.add(html_trace(exc_info))
                else:
                    func_name = 'render_error_%s' % status
                    if hasattr(self, func_name):
                        text = getattr(self, func_name)(request, status)
                    else:
                        text = error_title
                    inner.add(text)
                if request.is_xhr:
                    content = ajax.jservererror(request.environ,
                                                inner.render(request))
                else:
                    try:
                        layout = request.view.root.get_page_layout(err_cls,
                                                                   classes.error,
                                                                   'default')
                        outer = layout()
                        content = outer.render(request,
                                               context={'content': inner})
                    except:
                        logger.error('Could not render %s error on %s layout',
                                     status, layout, exc_info=True)
                        content = inner.render(request)
        if is_renderer(content):
            response.status_code = 200
            response.content_type = content.content_type()
            content = content.render(request)
        else:
            response.content_type = content_type
            response.status_code = status
        if status == 500:
            logger.critical('Interval server error', exc_info=exc_info)
        return content
예제 #9
0
파일: site.py 프로젝트: pombredanne/djpcms
    def handle_error(self, request, response):
        '''Render an error into text or Html depending on *content_type*.
This function can be overwritten by user implementation.'''
        exc_info = request.exc_info
        settings = request.settings
        status = 500
        if exc_info and exc_info[0] is not None:
            status = getattr(exc_info[1], 'status', status)
        else:
            exc_info = None
        # 302 is a special case, we redirect
        content_type = request.content_type
        if status in REDIRECT_CODES:
            location = dict(exc_info[1].headers)['location']
            if request.is_xhr:
                content = ajax.jredirect(request.environ, location)
            else:
                content_type = None
                response.headers['Location'] = iri_to_uri(location)
                content = ''
        else:
            err_cls = '%s%s' % (classes.error, status)
            err_title = '%s %s' % (status, error_title(status))
            if content_type == 'text/plain':
                content = err_title
                if settings.DEBUG:
                    content += '\n\n' + html_trace(exc_info, plain=True)
            else:
                inner = Widget('div', cn=(classes.error, err_cls))
                if settings.DEBUG:
                    inner.addClass('debug')
                    inner.add(Widget('h2', err_title))
                    inner.add(Widget('a', request.path, href=request.path))
                    inner.add(html_trace(exc_info))
                else:
                    func_name = 'render_error_%s' % status
                    if hasattr(self, func_name):
                        text = getattr(self, func_name)(request, status)
                    else:
                        text = error_title
                    inner.add(text)
                if request.is_xhr:
                    content = ajax.jservererror(request.environ,
                                                inner.render(request))
                else:
                    try:
                        layout = request.view.root.get_page_layout(
                            err_cls, classes.error, 'default')
                        outer = layout()
                        content = outer.render(request,
                                               context={'content': inner})
                    except:
                        logger.error('Could not render %s error on %s layout',
                                     status,
                                     layout,
                                     exc_info=True)
                        content = inner.render(request)
        if is_renderer(content):
            response.status_code = 200
            response.content_type = content.content_type()
            content = content.render(request)
        else:
            response.content_type = content_type
            response.status_code = status
        if status == 500:
            logger.critical('Interval server error', exc_info=exc_info)
        return content