def get(self, request, *args, **kwargs): pk = self.kwargs['pk'] periodo = self.kwargs['periodo'] station = Station.objects.get(pk=pk) dataidx = station.climateindexdata_set.filter(periodo=periodo, climate_index__sezione='index')\ .order_by('-climate_index__type', 'climate_index__rank') title = 'Indici climatici %s' % station.stname periodo_rif = '%s' % 'Periodo di riferimento ' + periodo if self.kwargs['tipo_export'] == 'pdf': return render_to_pdf(self.template_name, {'tabella': dataidx, 'pagesize': 'A4 landscape', 'title': title, 'periodo_rif': periodo_rif}) elif self.kwargs['tipo_export'] == 'xls': fields = ["climate_index__name", "gen", "feb", "mar", "apr", "mag", "giu", "lug", "ago", "sett", "ott", "nov", "dic", "nota"] col_name = ["indice", "gen", "feb", "mar", "apr", "mag", "giu", "lug", "ago", "sett", "ott", "nov", "dic", "unione di due serie"] queryset = dataidx filename = title try: return export_xlwt(filename, col_name, queryset.values_list(*fields)) except Exception, e: raise e
def get(self, request, *args, **kwargs): pk = self.kwargs['pk'] periodo = self.kwargs['periodo'] station = Station.objects.get(pk=pk) dataext = station.climateextremesdata_set.filter(climate_index__sezione='extreme')\ .order_by('climate_index__resolution', 'climate_index__type', 'climate_index__rank') title = 'Estremi climatici %s' % station.stname periodo_rif = '%s' % 'Periodo di riferimento ' + periodo if self.kwargs['tipo_export'] == 'pdf': return render_to_pdf(self.template_name, {'tabella': dataext, 'pagesize': 'A4 landscape', 'title': title, 'periodo_rif': periodo_rif}) elif self.kwargs['tipo_export'] == 'xls': fields = ["climate_index__name","anno_inizio", "gen", "gen_data", "feb", "feb_data", "mar", "mar_data", "apr", "apr_data", "mag", "mag_data", "giu", "giu_data", "lug", "lug_data", "ago", "ago_data", "sett", "sett_data", "ott", "nov", "nov_data", "dic", "dic_data", "annua", "annua_data", "inverno", "inverno_data", "primavera", "primavera_data", "estate", "estate_data", "autunno", "autunno_data"] col_name = ["estremo climatico","anno_inizio", "gen", "gen_data", "feb", "feb_data", "mar", "mar_data", "apr", "apr_data", "mag", "mag_data", "giu", "giu_data", "lug", "lug_data", "ago", "ago_data", "sett", "sett_data", "ott", "nov", "nov_data", "dic", "dic_data", "annua", "annua_data", "DGF", "DGF_data", "MAM", "MAM_data", "GLA", "GLA_data", "SON", "SON_data"] fields += ["station__note_omogen"] col_name += ["note"] queryset = dataext filename = title try: return export_xlwt(filename, col_name, queryset.values_list(*fields)) except Exception, e: raise e
def get(self, request, *args, **kwargs): self.index = get_object_or_404(ClimateIndex, r_name=self.kwargs['r_name']) data = ClimateExtremesData.objects.filter(climate_index=self.index).order_by('station__stname') title = '%s' % (self.index.name) if self.kwargs['tipo_export'] == 'pdf': return render_to_pdf(self.template_name, {'tabella': data, 'estremo': self.index, 'pagesize': 'A4 landscape', 'title': title}) elif self.kwargs['tipo_export'] == 'xls': fields = ["station__stname", "station__elevation", "anno_inizio", "gen", "gen_data", "feb", "feb_data", "mar", "mar_data", "apr", "apr_data", "mag", "mag_data", "giu", "giu_data", "lug", "lug_data", "ago", "ago_data", "sett", "sett_data", "ott", "nov", "nov_data", "dic", "dic_data"] col_name = ["station__stname", "station__elevation", "anno_inizio", "gen", "gen_data", "feb", "feb_data", "mar", "mar_data", "apr", "apr_data", "mag", "mag_data", "giu", "giu_data", "lug", "lug_data", "ago", "ago_data", "sett", "sett_data", "ott", "nov", "nov_data", "dic", "dic_data"] if self.index.resolution == 'mensili': fields += ["annua", "annua_data", "inverno", "inverno_data", "primavera", "primavera_data", "estate", "estate_data", "autunno", "autunno_data"] col_name += ["annua", "annua_data", "DGF", "DGF_data", "MAM", "MAM_data", "GLA", "GLA_data", "SON", "SON_data"] fields += ["station__note_omogen"] col_name += ["note"] queryset = data filename = title try: return export_xlwt(filename, col_name, queryset.values_list(*fields)) except Exception, e: raise e
def export_xls(request): from export_xls.views import export_xlwt fields = ["username", "birthday", "random_number"] filename = MyUser._meta.verbose_name_plural.lower() queryset = MyUser.objects.all() try: return export_xlwt(filename, fields, queryset.values_list(*fields)) except Exception, e: raise e
def export_xls(request, id_user=False): from export_xls.views import export_xlwt fields = ["id", "name", "author", "price"] if id_user: from django.contrib.auth.models import User _user = User.objects.get(pk=id_user) queryset = Book.objects.filter(author=_user) filename = "%ss-%s" %(_user.username, Book._meta.verbose_name_plural.lower()) else: queryset = Book.objects.all() filename = Book._meta.verbose_name_plural.lower() try: return export_xlwt(filename, fields, queryset.values_list(*fields)) except Exception, e: raise e
def get(self, request, *args, **kwargs): self.index = get_object_or_404(ClimateIndex, r_name=self.kwargs['r_name']) if self.kwargs['periodo'] not in self.index.get_climateindex_periodo_list: raise Http404('No %s matches the given query.' ) data = ClimateIndexData.objects.filter(periodo=self.kwargs['periodo'], climate_index=self.index).exclude(gen=None, feb=None, mar=None, apr=None, mag=None, giu=None, lug=None, ago=None, sett=None, ott=None, nov=None, dic=None, annua=None, autunno=None, primavera=None, inverno=None, estate=None).order_by('station__stname') title = '%s' % self.index.name periodo_rif = '%s' % 'Periodo di riferimento ' + self.kwargs['periodo'] if self.kwargs['tipo_export'] == 'pdf': return render_to_pdf(self.template_name, {'tabella': data, 'pagesize': 'A4 landscape', 'title': title, 'periodo_rif': periodo_rif}) elif self.kwargs['tipo_export'] == 'xls': fields = ["station__stname", "station__elevation", "gen", "feb", "mar", "apr", "mag", "giu", "lug", "ago", "sett", "ott", "nov", "dic", "inverno", "primavera", "estate", "autunno", "station__note_omogen"] col_name = ["station__stname", "station__elevation", "gen", "feb", "mar", "apr", "mag", "giu", "lug", "ago", "sett", "ott", "nov", "dic", "DGF", "MAM", "GLA", "SON", "note"] queryset = data filename = title try: return export_xlwt(filename, col_name, queryset.values_list(*fields)) except Exception, e: raise e
def list_production_orders(request): if request.method == 'POST': form = ListProductionOrderForm(request.POST) if form.is_valid(): date_from = form.cleaned_data['date_from'] date_to = form.cleaned_data['date_to'] type_date = form.cleaned_data['type_date'] if type_date == 'added': object_list = ProductionOrder.objects.filter(date_added__gt = date_from).filter(date_added__lt = date_to).order_by('-date_added').annotate(total_filling=Sum("fillingproord__filling_filling_pro_ord__value")) elif type_date == 'modified': object_list = ProductionOrder.objects.filter(date_modified__gt = date_from).filter(date_modified__lt = date_to).order_by('-date_added').annotate(total_filling=Sum("fillingproord__filling_filling_pro_ord__value")) elif type_date == 'filling': object_list = ProductionOrder.objects.filter(fillingproord__date_modified__gt = date_from).filter(fillingproord__date_modified__lt = date_to).order_by('-date_added').annotate(total_filling=Sum("fillingproord__filling_filling_pro_ord__value")) else: print "Error in list_production_orders" if '_excel' in request.POST: from export_xls.views import export_xlwt values_list =[] fields=["#","Actividad", "Lugar", "Estado", "Fecha de creacion","Cantidad", "Calificacion"] for obj in object_list: total_filling = obj.total_filling if obj.total_filling else 0 values_list.append( ( obj.pk, obj.activity.name, obj.place.name, get_str_status(obj), str(obj.date_added.strftime('%Y-%m-%d_%H-%M')), total_filling, get_str_qualification_pro_ord(obj) ) ) name_file = str(datetime.datetime.now().strftime('%Y-%m-%d_%H-%M')) return export_xlwt("op_"+(name_file), fields, values_list) else: disable_excel_button = True else: form = ListProductionOrderForm() disable_excel_button = True return render_to_response('list_production_orders.html', locals(), context_instance=RequestContext(request))
def generate_xls_payroll(request, payroll_pk): """Show the history, the list of employees with values of activities, general discounts applied and legal discounts applied.""" pr_obj = Payroll.objects.get(pk=payroll_pk) payroll_list =[] obj_list = MyUser.objects.filter(userprofile__user_type__pk__in=[7,8]) filling_list = Filling.objects.filter(filling_pro_ord__production_order__payroll=pr_obj) filling_list2 = Filling.objects.filter(filling_pro_ord__production_order__payroll=pr_obj).aggregate(total=Sum('value')) discounts_list = DiscountsApplied.objects.filter(payroll = pr_obj, is_active=False) increases_list = IncreasesApplied.objects.filter(payroll = pr_obj, is_active=False) legal_discounts = LegalDiscounts.objects.filter(is_active=True) global_payroll = 0 values_list =[] for obj in obj_list: total_payroll = 0 #total activities activities = filling_list.filter(user=obj, filling_pro_ord__production_order__qualificationproord__status=1, filling_pro_ord__production_order__status=4) total_activities = 0 for a in activities: a1 = a.filling_pro_ord.production_order.activity.value activity_value = a.value * a1 total_activities += activity_value # total_payroll=total_activities total_activities = int(round(total_activities,0)) #aumentos increases = increases_list.filter(employee=obj) total_increases = increases.aggregate(t= Sum('value')) total_increases_value = total_increases["t"] if total_increases["t"] != None else 0 # total_payroll = total_payroll+total_increases_value total_accrued = total_activities + total_increases_value legal_discount_value = int(round((total_accrued/float(100))*8,0)) #General discount discounts = discounts_list.filter(employee=obj) total_discounts = discounts.aggregate(t= Sum('value')) total_discounts_value = total_discounts["t"] if total_discounts["t"] != None else 0 total_payroll = total_accrued-total_discounts_value-legal_discount_value global_payroll += total_payroll #payroll payroll_list.append({"user": obj, "activities": activities, "total_activities": total_activities, "discounts": discounts, "total_discounts": total_discounts_value, "increases": increases, "total_increases": total_increases_value, "total_payroll": total_payroll, "legal_discount_type": "Seguridad social 8%", #"%s %s%%"%(ld.name, ld.value), "legal_discount_value": legal_discount_value, "total_accrued": total_accrued #"adjust": adjust }) values_list.append( ( str(obj.get_full_name()), str(obj.userprofile.dni), str(obj.userprofile.user_type.name), total_payroll, ) ) last_payroll=True from export_xls.views import export_xlwt fields=["Nombre Completo","Cedula", "Tipo de usuario", "Valor"] name_file = str(datetime.datetime.now().strftime('%Y-%m-%d_%H-%M')) return export_xlwt("op_"+(name_file), fields, values_list)
def export_xls(self, request, queryset): from export_xls.views import export_xlwt fields = ["id", "parent", "name", "external_id"] filename = "category_list" return export_xlwt(filename, fields, queryset.values_list(*fields))
def generate_xls(filename, fields, values_list): from export_xls.views import export_xlwt return export_xlwt(filename, fields, values_list, save=True, folder="xls/")