示例#1
0
文件: views.py 项目: Arpaso/ETS
    def form_valid(self, form):
        start_date = form.cleaned_data['start_date'] 
        end_date = form.cleaned_data['end_date']

        queryset = waybill_user_related_filter(Waybill.objects.all(), self.request.user)
        data = compress_waybills(queryset, start_date, end_date)
        
        return data_to_file_response(data, self.file_name % {
            'start_date': start_date, 
            'end_date': end_date,
        }, type="data")
示例#2
0
文件: views.py 项目: Arpaso/ETS
def export_compas_file(request, compas=None, warehouse=None, data_type="json"):
    """Returns a file with all COMPAS data in response"""
    template = 'ets_data-%s' % ("compress" if data_type=="data" else data_type,)
    if compas:
        compas = get_object_or_404(ets.models.Compas, pk=compas)
        template = "-".join([template, compas.pk])
    if warehouse:
        warehouse = get_object_or_404(ets.models.Warehouse, pk=warehouse)
        template = "-".join([template, warehouse.pk])

    data = serializers.serialize('json', get_compas_data(compas=compas, warehouse=warehouse), use_decimal=False)
    template = "-".join([template, "%s"])

    if data_type == "data":
        data = compress_json(data)
        
    return data_to_file_response(data, file_name=template % datetime.date.today(), type=data_type)