Exemplo n.º 1
0
Arquivo: store.py Projeto: NewRGB/lino
 def parse_form_value(self, v, obj):
     """
     Ext.ensible CalendarPanel sends boolean values as
     """
     return constants.parse_boolean(v)
Exemplo n.º 2
0
 def parse_form_value(self, v, obj):
     """
     Ext.ensible CalendarPanel sends boolean values as 
     """
     #~ print "20110717 parse_form_value", self.field.name, v, obj
     return constants.parse_boolean(v)
Exemplo n.º 3
0
    def get(self, request, app_label=None, actor=None):
        ar = action_request(app_label, actor, request, request.GET, True)
        ar.renderer = settings.SITE.kernel.extjs_renderer
        rh = ar.ah

        fmt = request.GET.get(constants.URL_PARAM_FORMAT,
                              ar.bound_action.action.default_format)

        if fmt == constants.URL_FORMAT_JSON:
            rows = [
                rh.store.row2list(ar, row) for row in ar.sliced_data_iterator
            ]
            total_count = ar.get_total_count()
            for row in ar.create_phantom_rows():
                d = rh.store.row2list(ar, row)
                rows.append(d)
                total_count += 1
            kw = dict(count=total_count,
                      rows=rows,
                      success=True,
                      no_data_text=ar.no_data_text,
                      title=str(ar.get_title()))
            if ar.actor.parameters:
                kw.update(param_values=ar.actor.params_layout.params_store.
                          pv2dict(ar.param_values))
            return json_response(kw)

        if fmt == constants.URL_FORMAT_HTML:
            after_show = ar.get_status()

            sp = request.GET.get(constants.URL_PARAM_SHOW_PARAMS_PANEL, None)
            if sp is not None:
                #~ after_show.update(show_params_panel=sp)
                after_show.update(
                    show_params_panel=constants.parse_boolean(sp))

            # if isinstance(ar.bound_action.action, actions.ShowInsert):
            #     elem = ar.create_instance()
            #     rec = ar.elem2rec_insert(rh, elem)
            #     after_show.update(data_record=rec)

            kw = dict(on_ready=ar.renderer.action_call(
                ar.request, ar.bound_action, after_show))
            #~ print '20110714 on_ready', params
            kw.update(title=ar.get_title())
            return http.HttpResponse(ar.renderer.html_page(request, **kw))

        if fmt == 'csv':
            #~ response = HttpResponse(mimetype='text/csv')
            charset = settings.SITE.csv_params.get('encoding', 'utf-8')
            response = http.HttpResponse(content_type='text/csv;charset="%s"' %
                                         charset)
            if False:
                response['Content-Disposition'] = \
                    'attachment; filename="%s.csv"' % ar.actor
            else:
                #~ response = HttpResponse(content_type='application/csv')
                response['Content-Disposition'] = \
                    'inline; filename="%s.csv"' % ar.actor

            #~ response['Content-Disposition'] = 'attachment; filename=%s.csv' % ar.get_base_filename()
            w = ucsv.UnicodeWriter(response, **settings.SITE.csv_params)
            w.writerow(ar.ah.store.column_names())
            if True:  # 20130418 : also column headers, not only internal names
                column_names = None
                fields, headers, cellwidths = ar.get_field_info(column_names)
                w.writerow(headers)

            for row in ar.data_iterator:
                w.writerow([str(v) for v in rh.store.row2list(ar, row)])
            return response

        if fmt == constants.URL_FORMAT_PRINTER:
            if ar.get_total_count() > MAX_ROW_COUNT:
                raise Exception(
                    _("List contains more than %d rows") % MAX_ROW_COUNT)
            response = http.HttpResponse(
                content_type='text/html;charset="utf-8"')
            doc = xghtml.Document(force_text(ar.get_title()))
            doc.body.append(E.h1(doc.title))
            t = doc.add_table()
            #~ settings.SITE.kernel.ar2html(ar,t,ar.data_iterator)
            ar.dump2html(t, ar.data_iterator)
            doc.write(response, encoding='utf-8')
            return response

        return settings.SITE.kernel.run_action(ar)
Exemplo n.º 4
0
 def parse_req(self,request,rqdata,**kw):
     """
     Handle the request parameters issued by Ext.ensible CalendarPanel.
     """
     #~ filter = kw.get('filter',{})
     assert not kw.has_key('filter')
     fkw = {}
     #~ logger.info("20120118 filter is %r", filter)
     endDate = rqdata.get(constants.URL_PARAM_END_DATE,None)
     if endDate:
         d = parsedate(endDate)
         fkw.update(start_date__lte=d)
     startDate = rqdata.get(constants.URL_PARAM_START_DATE,None)
     if startDate:
         d = parsedate(startDate)
         #~ logger.info("startDate is %r", d)
         fkw.update(start_date__gte=d)
     #~ logger.info("20120118 filter is %r", filter)
     
     #~ subs = Subscription.objects.filter(user=request.user).values_list('calendar__id',flat=True)
     #~ filter.update(calendar__id__in=subs)
     
     flt = models.Q(**fkw)
     
     """
     If you override `parse_req`, then keep in mind that it will
     be called *before* Lino checks the requirements. 
     For example the user may be AnonymousUser even if 
     the requirements won't let it be executed.
     
     `request.subst_user.profile` may be None e.g. when called 
     from `find_appointment` in :ref:`welfare.pcsw.Clients`.
     """
     if not request.user.profile.authenticated: 
         raise exceptions.PermissionDenied(
             _("As %s you have no permission to run this action.") % request.user.profile)
         
     # who am i ?
     me = request.subst_user or request.user
     
     # show all my events
     for_me = models.Q(user__isnull=True)
     for_me |= models.Q(user=me)
     
     # also show events to which i am invited
     if me.partner:
         #~ me_as_guest = Guest.objects.filter(partner=request.user.partner)
         #~ for_me = for_me | models.Q(guest_set__count__gt=0)
         #~ for_me = for_me | models.Q(guest_count__gt=0)
         for_me = for_me | models.Q(guest__partner=me.partner)
     
     if False:
         # in team view, show also events of all my team members
         tv = rqdata.get(constants.URL_PARAM_TEAM_VIEW,False)
         if tv and constants.parse_boolean(tv):
             # positive list of ACLs for events of team members
             team_classes = (None,AccessClasses.public,AccessClasses.show_busy)
             my_teams = Membership.objects.filter(user=me)
             we = settings.SITE.user_model.objects.filter(users_membership_set_by_user__team__in=my_teams)
             #~ team_ids = Membership.objects.filter(user=me).values_list('watched_user__id',flat=True)
             #~ for_me = for_me | models.Q(user__id__in=team_ids,access_class__in=team_classes)
             for_me = for_me | models.Q(user__in=we,access_class__in=team_classes)
     flt = flt & for_me
     #~ logger.info('20120710 %s', flt)
     kw.update(filter=flt)
     #~ logger.info('20130808 %s %s', tv,me)
     return kw
Exemplo n.º 5
0
 def parse_form_value(self, v, obj):
     """
     Ext.ensible CalendarPanel sends boolean values as
     """
     return constants.parse_boolean(v)
Exemplo n.º 6
0
Arquivo: views.py Projeto: raffas/lino
    def get(self, request, app_label=None, actor=None):
        ar = action_request(app_label, actor, request, request.GET, True)
        ar.renderer = settings.SITE.ui.extjs_renderer
        rh = ar.ah

        fmt = request.GET.get(
            ext_requests.URL_PARAM_FORMAT,
            ar.bound_action.action.default_format)

        if fmt == ext_requests.URL_FORMAT_JSON:
            rows = [rh.store.row2list(ar, row)
                    for row in ar.sliced_data_iterator]
            total_count = ar.get_total_count()
            for row in ar.create_phantom_rows():
                d = rh.store.row2list(ar, row)
                rows.append(d)
                total_count += 1
            kw = dict(count=total_count,
                      rows=rows,
                      success=True,
                      no_data_text=ar.no_data_text,
                      title=unicode(ar.get_title()))
            if ar.actor.parameters:
                kw.update(
                    param_values=ar.actor.params_layout.params_store.pv2dict(
                        ar.param_values))
            return json_response(kw)

        if fmt == ext_requests.URL_FORMAT_HTML:
            after_show = ar.get_status()

            sp = request.GET.get(
                ext_requests.URL_PARAM_SHOW_PARAMS_PANEL, None)
            if sp is not None:
                #~ after_show.update(show_params_panel=sp)
                after_show.update(
                    show_params_panel=ext_requests.parse_boolean(sp))

            if isinstance(ar.bound_action.action, actions.InsertRow):
                elem = ar.create_instance()
                #~ print 20120630
                #~ print elem.national_id
                rec = ar.elem2rec_insert(rh, elem)
                after_show.update(data_record=rec)

            kw = dict(on_ready=
                      ar.renderer.action_call(
                          ar.request,
                          ar.bound_action, after_show))
            #~ print '20110714 on_ready', params
            kw.update(title=ar.get_title())
            return http.HttpResponse(ar.renderer.html_page(request, **kw))

        if fmt == 'csv':
            #~ response = HttpResponse(mimetype='text/csv')
            charset = settings.SITE.csv_params.get('encoding', 'utf-8')
            response = http.HttpResponse(
                content_type='text/csv;charset="%s"' % charset)
            if False:
                response['Content-Disposition'] = \
                    'attachment; filename="%s.csv"' % ar.actor
            else:
                #~ response = HttpResponse(content_type='application/csv')
                response['Content-Disposition'] = \
                    'inline; filename="%s.csv"' % ar.actor

            #~ response['Content-Disposition'] = 'attachment; filename=%s.csv' % ar.get_base_filename()
            w = ucsv.UnicodeWriter(response, **settings.SITE.csv_params)
            w.writerow(ar.ah.store.column_names())
            if True:  # 20130418 : also column headers, not only internal names
                column_names = None
                fields, headers, cellwidths = ar.get_field_info(column_names)
                w.writerow(headers)

            for row in ar.data_iterator:
                w.writerow([unicode(v) for v in rh.store.row2list(ar, row)])
            return response

        if fmt == ext_requests.URL_FORMAT_PRINTER:
            if ar.get_total_count() > MAX_ROW_COUNT:
                raise Exception(_("List contains more than %d rows") %
                                MAX_ROW_COUNT)
            response = http.HttpResponse(
                content_type='text/html;charset="utf-8"')
            doc = xghtml.Document(force_unicode(ar.get_title()))
            doc.body.append(E.h1(doc.title))
            t = doc.add_table()
            #~ settings.SITE.ui.ar2html(ar,t,ar.data_iterator)
            ar.dump2html(t, ar.data_iterator)
            doc.write(response, encoding='utf-8')
            return response

        return settings.SITE.ui.run_action(ar)
Exemplo n.º 7
0
    def get(self,request,app_label=None,actor=None):
        #~ ar = action_request(app_label,actor,request,request.GET,limit=PLAIN_PAGE_LENGTH)
        ar = action_request(app_label,actor,request,request.GET,True)
        ar.renderer = settings.SITE.ui.ext_renderer
        rh = ar.ah
        
        #~ print 20120630, 'api_list_view'
        fmt = request.GET.get(
            ext_requests.URL_PARAM_FORMAT,
            ar.bound_action.action.default_format)
            
        #~ logger.info("20121203 views.ApiList.get() %s",ar.bound_action.full_name())
      
        if fmt == ext_requests.URL_FORMAT_JSON:
            #~ ar.renderer = ui.ext_renderer
            rows = [ rh.store.row2list(ar,row) for row in ar.sliced_data_iterator]
            #~ return json_response_kw(msg="20120124")
            #~ total_count = len(ar.data_iterator)
            total_count = ar.get_total_count()
            #~ if ar.create_rows:
            for row in ar.create_phantom_rows():
                d = rh.store.row2list(ar,row)
                rows.append(d)
                total_count += 1
            #~ 20120918
            kw = dict(count=total_count,
              rows=rows,
              success=True,
              no_data_text=ar.no_data_text, 
              #~ status=ar.get_status(ar.ui),
              title=unicode(ar.get_title()))
              #~ disabled_actions=rpt.disabled_actions(ar,None),
              #~ gc_choices=[gc.data for gc in ar.actor.grid_configs])
            if ar.actor.parameters:
                #~ kw.update(param_values=ar.actor.params_layout.params_store.pv2dict(settings.SITE.ui,ar.param_values))
                kw.update(param_values=ar.actor.params_layout.params_store.pv2dict(ar.param_values))
            return json_response(kw) 
                
        if fmt == ext_requests.URL_FORMAT_HTML:
            #~ ar.renderer = ui.ext_renderer
            #~ after_show = ar.get_status(ar.ui)
            after_show = ar.get_status()
            
            sp = request.GET.get(ext_requests.URL_PARAM_SHOW_PARAMS_PANEL,None)
            if sp is not None: 
                #~ after_show.update(show_params_panel=sp)
                after_show.update(show_params_panel=ext_requests.parse_boolean(sp))
            
            
            if isinstance(ar.bound_action.action,actions.InsertRow):
                elem = ar.create_instance()
                #~ print 20120630
                #~ print elem.national_id
                rec = elem2rec_insert(ar,rh,elem)
                after_show.update(data_record=rec)

            kw = dict(on_ready=
                ar.renderer.action_call(ar.request,ar.bound_action,after_show))
                #~ ui.ext_renderer.action_call(ar.request,ar.action,after_show))
            #~ print '20110714 on_ready', params
            kw.update(title=ar.get_title())
            return http.HttpResponse(ar.renderer.html_page(request,**kw))
        
        if fmt == 'csv':
            #~ response = HttpResponse(mimetype='text/csv')
            charset = settings.SITE.csv_params.get('encoding','utf-8')
            response = http.HttpResponse(
              content_type='text/csv;charset="%s"' % charset)
            if False:
                response['Content-Disposition'] = \
                    'attachment; filename="%s.csv"' % ar.actor
            else:
                #~ response = HttpResponse(content_type='application/csv')
                response['Content-Disposition'] = \
                    'inline; filename="%s.csv"' % ar.actor
              
            #~ response['Content-Disposition'] = 'attachment; filename=%s.csv' % ar.get_base_filename()
            w = ucsv.UnicodeWriter(response,**settings.SITE.csv_params)
            w.writerow(ar.ah.store.column_names())
            if True: # 20130418 : also column headers, not only internal names
                column_names = None
                fields, headers, cellwidths = ar.get_field_info(column_names)
                w.writerow(headers)
                
            for row in ar.data_iterator:
                w.writerow([unicode(v) for v in rh.store.row2list(ar,row)])
            return response
            
        #~ if fmt in (ext_requests.URL_FORMAT_PDF,ext_requests.URL_FORMAT_ODT):
            #~ mf = TmpMediaFile(ar,fmt)
            #~ settings.SITE.makedirs_if_missing(os.path.dirname(mf.name))
            #~ ar.appy_render(mf.name)
            #~ return http.HttpResponseRedirect(mf.url)
            
        if fmt == ext_requests.URL_FORMAT_PRINTER:
            if ar.get_total_count() > MAX_ROW_COUNT:
                raise Exception(_("List contains more than %d rows") % MAX_ROW_COUNT)
            #~ ar.renderer = ui.ext_renderer
            response = http.HttpResponse(content_type='text/html;charset="utf-8"')
            doc = xghtml.Document(force_unicode(ar.get_title()))
            doc.body.append(E.h1(doc.title))
            t = doc.add_table()
            #~ settings.SITE.ui.ar2html(ar,t,ar.data_iterator)
            ar.dump2html(t,ar.data_iterator)
            doc.write(response,encoding='utf-8')
            return response
            
        return settings.SITE.ui.run_action(ar)