def run(self, model, fields, file_name, **kwargs): """Create the xls file""" if issubclass(model, TendenciBaseModel): fields = fields + ( 'allow_anonymous_view', 'allow_user_view', 'allow_member_view', 'allow_user_edit', 'allow_member_edit', 'create_dt', 'update_dt', 'creator', 'creator_username', 'owner', 'owner_username', 'status', 'status_detail', ) items = model.objects.filter(status=True) data_row_list = [] for item in items: # get the available fields from the model's meta opts = item._meta d = {} for f in opts.fields + opts.many_to_many: if f.name in fields: # include specified fields only if isinstance(f, ManyToManyField): value = [ "%s" % obj for obj in f.value_from_object(item) ] if isinstance(f, ForeignKey): value = getattr(item, f.name) if isinstance(f, generic.GenericRelation): generics = f.value_from_object(item).all() value = ["%s" % obj for obj in generics] if isinstance(f, DateTimeField): if f.value_from_object(item): value = f.value_from_object(item).strftime( "%Y-%m-%d %H:%M") else: value = f.value_from_object(item) d[f.name] = value # append the accumulated values as a data row # keep in mind the ordering of the fields data_row = [] for field in fields: # clean the derived values into unicode value = unicode(d[field]).rstrip() data_row.append(value) data_row_list.append(data_row) return render_csv(file_name, fields, data_row_list)
def run(self, model, fields, file_name, **kwargs): """Create the xls file""" if issubclass(model, TendenciBaseModel): fields = fields + ( 'allow_anonymous_view', 'allow_user_view', 'allow_member_view', 'allow_user_edit', 'allow_member_edit', 'create_dt', 'update_dt', 'creator', 'creator_username', 'owner', 'owner_username', 'status', 'status_detail', ) items = model.objects.filter(status=True) data_row_list = [] for item in items: # get the available fields from the model's meta opts = item._meta d = {} for f in opts.fields + opts.many_to_many: if f.name in fields: # include specified fields only if isinstance(f, ManyToManyField): value = ["%s" % obj for obj in f.value_from_object(item)] if isinstance(f, ForeignKey): value = getattr(item, f.name) if isinstance(f, generic.GenericRelation): generics = f.value_from_object(item).all() value = ["%s" % obj for obj in generics] if isinstance(f, DateTimeField): if f.value_from_object(item): value = f.value_from_object(item).strftime("%Y-%m-%d %H:%M") else: value = f.value_from_object(item) d[f.name] = value # append the accumulated values as a data row # keep in mind the ordering of the fields data_row = [] for field in fields: # clean the derived values into unicode value = unicode(d[field]).rstrip() data_row.append(value) data_row_list.append(data_row) return render_csv(file_name, fields, data_row_list)
def run(self, **kwargs): """Create the xls file""" nav_fields = [ 'title', 'description', 'megamenu', 'allow_anonymous_view', 'allow_user_view', 'allow_member_view', 'allow_user_edit', 'allow_member_edit', 'create_dt', 'update_dt', 'creator', 'creator_username', 'owner', 'owner_username', 'status', 'status_detail', ] nav_item_fields = [ 'label', 'title', 'new_window', 'css', 'ordering', 'level', 'page', 'url', ] navs = Nav.objects.filter(status=True) max_nav_items = navs.annotate(num_navitems=Count('navitem')).aggregate(Max('num_navitems'))['num_navitems__max'] file_name = 'navs.csv' data_row_list = [] for nav in navs: data_row = [] # nav setup nav_d = full_model_to_dict(nav) for field in nav_fields: value = nav_d[field] value = unicode(value).replace(os.linesep, ' ').rstrip() data_row.append(value) if nav.navitem_set.all(): # nav_item setup for nav_item in nav.navitem_set.all(): nav_item_d = full_model_to_dict(nav_item) for field in nav_item_fields: value = nav_item_d[field] value = unicode(value).replace(os.linesep, ' ').rstrip() data_row.append(value) # fill out the rest of the nav_item columns if nav.navitem_set.all().count() < max_nav_items: for i in range(0, max_nav_items - nav.navitem_set.all().count()): for field in nav_item_fields: data_row.append('') data_row_list.append(data_row) fields = nav_fields for i in range(0, max_nav_items): fields = fields + ["nav_item %s %s" % (i, f) for f in nav_item_fields] return render_csv(file_name, fields, data_row_list)
def run(self, **kwargs): """Create the xls file""" event_fields = [ 'entity', 'type', 'title', 'description', 'all_day', 'start_dt', 'end_dt', 'timezone', 'private', 'password', 'on_weekend', 'external_url', 'image', 'tags', 'allow_anonymous_view', 'allow_user_view', 'allow_member_view', 'allow_anonymous_edit', 'allow_user_edit', 'allow_member_edit', 'create_dt', 'update_dt', 'creator', 'creator_username', 'owner', 'owner_username', 'status', 'status_detail', ] place_fields = [ 'name', 'description', 'address', 'city', 'state', 'zip', 'country', 'url', ] configuration_fields = [ 'payment_method', 'payment_required', 'limit', 'enabled', 'is_guest_price', 'use_custom_reg_form', 'reg_form', 'bind_reg_form_to_conf_only', ] speaker_fields = [ 'name', 'description', ] organizer_fields = [ 'name', 'description', ] pricing_fields = [ 'title', 'quantity', 'group', 'price', 'reg_form', 'start_dt', 'end_dt', 'allow_anonymous', 'allow_user', 'allow_member', 'status', ] events = Event.objects.filter(status=True) max_speakers = events.annotate(num_speakers=Count('speaker')).aggregate(Max('num_speakers'))['num_speakers__max'] max_organizers = events.annotate(num_organizers=Count('organizer')).aggregate(Max('num_organizers'))['num_organizers__max'] max_pricings = events.annotate(num_pricings=Count('registration_configuration__regconfpricing')).aggregate(Max('num_pricings'))['num_pricings__max'] file_name = 'events.csv' data_row_list = [] for event in events: data_row = [] # event setup event_d = full_model_to_dict(event, fields=event_fields) for field in event_fields: value = None if field == 'entity': if event.entity: value = event.entity.entity_name elif field == 'type': if event.type: value = event.type.name else: value = event_d[field] value = unicode(value).replace(os.linesep, ' ').rstrip() data_row.append(value) if event.place: # place setup place_d = full_model_to_dict(event.place) for field in place_fields: value = place_d[field] value = unicode(value).replace(os.linesep, ' ').rstrip() data_row.append(value) if event.registration_configuration: # config setup conf_d = full_model_to_dict(event.registration_configuration) for field in configuration_fields: if field == "payment_method": value = event.registration_configuration.payment_method.all() else: value = conf_d[field] value = unicode(value).replace(os.linesep, ' ').rstrip() data_row.append(value) if event.speaker_set.all(): # speaker setup for speaker in event.speaker_set.all(): speaker_d = full_model_to_dict(speaker) for field in speaker_fields: value = speaker_d[field] value = unicode(value).replace(os.linesep, ' ').rstrip() data_row.append(value) # fill out the rest of the speaker columns if event.speaker_set.all().count() < max_speakers: for i in range(0, max_speakers - event.speaker_set.all().count()): for field in speaker_fields: data_row.append('') if event.organizer_set.all(): # organizer setup for organizer in event.organizer_set.all(): organizer_d = full_model_to_dict(organizer) for field in organizer_fields: value = organizer_d[field] value = unicode(value).replace(os.linesep, ' ').rstrip() data_row.append(value) # fill out the rest of the organizer columns if event.organizer_set.all().count() < max_organizers: for i in range(0, max_organizers - event.organizer_set.all().count()): for field in organizer_fields: data_row.append('') reg_conf = event.registration_configuration if reg_conf and reg_conf.regconfpricing_set.all(): # pricing setup for pricing in reg_conf.regconfpricing_set.all(): pricing_d = full_model_to_dict(pricing) for field in pricing_fields: value = pricing_d[field] value = unicode(value).replace(os.linesep, ' ').rstrip() data_row.append(value) # fill out the rest of the pricing columns if reg_conf and reg_conf.regconfpricing_set.all().count() < max_pricings: for i in range(0, max_pricings - reg_conf.regconfpricing_set.all().count()): for field in pricing_fields: data_row.append('') data_row_list.append(data_row) fields = event_fields + ["place %s" % f for f in place_fields] fields = fields + ["config %s" % f for f in configuration_fields] for i in range(0, max_speakers): fields = fields + ["speaker %s %s" % (i, f) for f in speaker_fields] for i in range(0, max_organizers): fields = fields + ["organizer %s %s" % (i, f) for f in organizer_fields] for i in range(0, max_pricings): fields = fields + ["pricing %s %s" % (i, f) for f in pricing_fields] return render_csv(file_name, fields, data_row_list)
def report_active_members(request, template_name='reports/membership_list.html'): mems = Membership.objects.filter(expire_dt__gt=datetime.now()) # sort order of all fields for the upcoming response is_ascending_username = True is_ascending_full_name = True is_ascending_email = True is_ascending_app = True is_ascending_type = True is_ascending_subscription = True is_ascending_expiration = True is_ascending_invoice = True # get sort order sort = request.GET.get('sort', 'subscribe_dt') if sort == 'username': mems = mems.order_by('user__username') is_ascending_username = False elif sort == '-username': mems = mems.order_by('-user__username') is_ascending_username = True elif sort == 'full_name': mems = mems.order_by('user__first_name', 'user__last_name') is_ascending_full_name = False elif sort == '-full_name': mems = mems.order_by('-user__first_name', '-user__last_name') is_ascending_full_name = True elif sort == 'email': mems = mems.order_by('user__email') is_ascending_email = False elif sort == '-email': mems = mems.order_by('-user__email') is_ascending_email = True elif sort == 'app': mems = mems.order_by('ma') is_ascending_app = False elif sort == '-app': mems = mems.order_by('-ma') is_ascending_app = True elif sort == 'type': mems = mems.order_by('membership_type') is_ascending_type = False elif sort == '-type': mems = mems.order_by('-membership_type') is_ascending_type = True elif sort == 'subscription': mems = mems.order_by('subscribe_dt') is_ascending_subscription = False elif sort == '-subscription': mems = mems.order_by('-subscribe_dt') is_ascending_subscription = True elif sort == 'expiration': mems = mems.order_by('expire_dt') is_ascending_expiration = False elif sort == '-expiration': mems = mems.order_by('-expire_dt') is_ascending_expiration = True elif sort == 'invoice': # since we need to sort by a related field with the proper # conditions we'll need to bring the sorting to the python level for mem in mems: mem.valid_invoice = None if mem.get_entry(): if mem.get_entry().invoice: mem.valid_invoice = mem.get_entry().invoice.pk mems = sorted(mems, key=lambda mem: mem.valid_invoice, reverse=True) is_ascending_invoice = False elif sort == '-invoice': # since we need to sort by a related field with the proper # conditions we'll need to bring the sorting to the python level for mem in mems: mem.valid_invoice = None if mem.get_entry(): if mem.get_entry().invoice: mem.valid_invoice = mem.get_entry().invoice.pk mems = sorted(mems, key=lambda mem: mem.valid_invoice, reverse=False) is_ascending_invoice = True EventLog.objects.log() # returns csv response --------------- ouput = request.GET.get('output', '') if ouput == 'csv': table_header = [ 'username', 'full name', 'email', 'application', 'type', 'subscription', 'expiration', ] table_data = [] for mem in mems: table_data = [ mem.user.username, mem.user.get_full_name, mem.user.email, mem.ma.name, mem.membership_type.name, mem.subscribe_dt, mem.expire_dt, ] return render_csv( 'active-memberships.csv', table_header, table_data, ) # ------------------------------------ return render_to_response(template_name, { 'mems': mems, 'active': True, 'is_ascending_username': is_ascending_username, 'is_ascending_full_name': is_ascending_full_name, 'is_ascending_email': is_ascending_email, 'is_ascending_app': is_ascending_app, 'is_ascending_type': is_ascending_type, 'is_ascending_subscription': is_ascending_subscription, 'is_ascending_expiration': is_ascending_expiration, 'is_ascending_invoice': is_ascending_invoice, }, context_instance=RequestContext(request))
def run(self, **kwargs): """Create the xls file""" form_fields = [ 'title', 'slug', 'intro', 'response', 'email_text', 'subject_template', 'send_email', 'email_from', 'email_copies', 'completion_url', 'custom_payment', 'payment_methods', 'allow_anonymous_view', 'allow_user_view', 'allow_member_view', 'allow_user_edit', 'allow_member_edit', 'create_dt', 'update_dt', 'creator', 'creator_username', 'owner', 'owner_username', 'status', 'status_detail', ] field_fields = [ 'label', 'field_type', 'field_function', 'required', 'visible', 'choices', 'position', 'default', ] pricing_fields = [ 'label', 'price', ] forms = Form.objects.filter(status=True) max_fields = forms.annotate(num_fields=Count('fields')).aggregate(Max('num_fields'))['num_fields__max'] max_pricings = forms.annotate(num_pricings=Count('pricing')).aggregate(Max('num_pricings'))['num_pricings__max'] file_name = 'forms.csv' data_row_list = [] for form in forms: data_row = [] # form setup form_d = full_model_to_dict(form) for field in form_fields: if field == 'payment_methods': value = [m.human_name for m in form.payment_methods.all()] else: value = form_d[field] value = unicode(value).replace(os.linesep, ' ').rstrip() data_row.append(value) if form.fields.all(): # field setup for field in form.fields.all(): field_d = full_model_to_dict(field) for f in field_fields: value = field_d[f] value = unicode(value).replace(os.linesep, ' ').rstrip() data_row.append(value) # fill out the rest of the field columns if form.fields.all().count() < max_fields: for i in range(0, max_fields - form.fields.all().count()): for f in field_fields: data_row.append('') if form.pricing_set.all(): # field setup for pricing in form.pricing_set.all(): pricing_d = full_model_to_dict(pricing) for f in pricing_fields: value = pricing_d[f] value = unicode(value).replace(os.linesep, ' ').rstrip() data_row.append(value) # fill out the rest of the field columns if form.pricing_set.all().count() < max_pricings: for i in range(0, max_pricings - form.pricing_set.all().count()): for f in pricing_fields: data_row.append('') data_row_list.append(data_row) fields = form_fields for i in range(0, max_fields): fields = fields + ["field %s %s" % (i, f) for f in field_fields] for i in range(0, max_pricings): fields = fields + ["pricing %s %s" % (i, f) for f in pricing_fields] return render_csv(file_name, fields, data_row_list)
def run(self, model, start_dt, end_dt, file_name, **kwargs): """Create the xls file""" fields = ( 'id', 'guid', 'object_type', 'object_id', 'title', 'tender_date', 'bill_to', 'bill_to_first_name', 'bill_to_last_name', 'bill_to_company', 'bill_to_address', 'bill_to_city', 'bill_to_state', 'bill_to_zip_code', 'bill_to_country', 'bill_to_phone', 'bill_to_fax', 'bill_to_email', 'ship_to', 'ship_to_first_name', 'ship_to_last_name', 'ship_to_company', 'ship_to_address', 'ship_to_city', 'ship_to_state', 'ship_to_zip_code', 'ship_to_country', 'ship_to_phone', 'ship_to_fax', 'ship_to_email', 'ship_to_address_type', 'receipt', 'gift', 'arrival_date_time', 'greeting', 'instructions', 'po', 'terms', 'due_date', 'ship_date', 'ship_via', 'fob', 'project', 'other', 'message', 'subtotal', 'shipping', 'shipping_surcharge', 'box_and_packing', 'tax_exempt', 'tax_exemptid', 'tax_rate', 'taxable', 'tax', 'variance', 'total', 'payments_credits', 'balance', 'estimate', 'disclaimer', 'variance_notes', 'admin_notes', 'create_dt', 'update_dt', 'creator', 'creator_username', 'owner', 'owner_username', 'status_detail', 'status', ) start_dt_date = datetime.strptime(start_dt, "%Y-%m-%d") end_dt_date = datetime.strptime(end_dt, "%Y-%m-%d") items = model.objects.filter(status=True, tender_date__gte=start_dt_date, tender_date__lte=end_dt_date) data_row_list = [] for item in items: # get the available fields from the model's meta opts = item._meta d = {} for f in opts.fields + opts.many_to_many: if f.name in fields: # include specified fields only if isinstance(f, ManyToManyField): value = [ "%s" % obj for obj in f.value_from_object(item) ] if isinstance(f, ForeignKey): value = getattr(item, f.name) if isinstance(f, generic.GenericRelation): generics = f.value_from_object(item).all() value = ["%s" % obj for obj in generics] if isinstance(f, DateTimeField): if f.value_from_object(item): value = f.value_from_object(item).strftime( "%Y-%m-%d %H:%M") else: value = f.value_from_object(item) d[f.name] = value # append the accumulated values as a data row # keep in mind the ordering of the fields data_row = [] for field in fields: # clean the derived values into unicode value = unicode(d[field]).rstrip() data_row.append(value) data_row_list.append(data_row) return render_csv(file_name, fields, data_row_list)
def run(self, model, start_dt, end_dt, file_name, **kwargs): """Create the xls file""" fields = ( "id", "guid", "object_type", "object_id", "title", "tender_date", "bill_to", "bill_to_first_name", "bill_to_last_name", "bill_to_company", "bill_to_address", "bill_to_city", "bill_to_state", "bill_to_zip_code", "bill_to_country", "bill_to_phone", "bill_to_fax", "bill_to_email", "ship_to", "ship_to_first_name", "ship_to_last_name", "ship_to_company", "ship_to_address", "ship_to_city", "ship_to_state", "ship_to_zip_code", "ship_to_country", "ship_to_phone", "ship_to_fax", "ship_to_email", "ship_to_address_type", "receipt", "gift", "arrival_date_time", "greeting", "instructions", "po", "terms", "due_date", "ship_date", "ship_via", "fob", "project", "other", "message", "subtotal", "shipping", "shipping_surcharge", "box_and_packing", "tax_exempt", "tax_exemptid", "tax_rate", "taxable", "tax", "variance", "total", "payments_credits", "balance", "estimate", "disclaimer", "variance_notes", "admin_notes", "create_dt", "update_dt", "creator", "creator_username", "owner", "owner_username", "status_detail", "status", ) start_dt_date = datetime.strptime(start_dt, "%Y-%m-%d") end_dt_date = datetime.strptime(end_dt, "%Y-%m-%d") items = model.objects.filter(status=True, tender_date__gte=start_dt_date, tender_date__lte=end_dt_date) data_row_list = [] for item in items: # get the available fields from the model's meta opts = item._meta d = {} for f in opts.fields + opts.many_to_many: if f.name in fields: # include specified fields only if isinstance(f, ManyToManyField): value = ["%s" % obj for obj in f.value_from_object(item)] if isinstance(f, ForeignKey): value = getattr(item, f.name) if isinstance(f, generic.GenericRelation): generics = f.value_from_object(item).all() value = ["%s" % obj for obj in generics] if isinstance(f, DateTimeField): if f.value_from_object(item): value = f.value_from_object(item).strftime("%Y-%m-%d %H:%M") else: value = f.value_from_object(item) d[f.name] = value # append the accumulated values as a data row # keep in mind the ordering of the fields data_row = [] for field in fields: # clean the derived values into unicode value = unicode(d[field]).rstrip() data_row.append(value) data_row_list.append(data_row) return render_csv(file_name, fields, data_row_list)
def run(self, **kwargs): """Create the xls file""" event_fields = [ 'entity', 'type', 'title', 'description', 'all_day', 'start_dt', 'end_dt', 'timezone', 'private', 'password', 'on_weekend', 'external_url', 'image', 'tags', 'allow_anonymous_view', 'allow_user_view', 'allow_member_view', 'allow_anonymous_edit', 'allow_user_edit', 'allow_member_edit', 'create_dt', 'update_dt', 'creator', 'creator_username', 'owner', 'owner_username', 'status', 'status_detail', ] place_fields = [ 'name', 'description', 'address', 'city', 'state', 'zip', 'country', 'url', ] configuration_fields = [ 'payment_method', 'payment_required', 'limit', 'enabled', 'is_guest_price', 'use_custom_reg_form', 'reg_form', 'bind_reg_form_to_conf_only', ] speaker_fields = [ 'name', 'description', ] organizer_fields = [ 'name', 'description', ] pricing_fields = [ 'title', 'quantity', 'group', 'price', 'reg_form', 'start_dt', 'end_dt', 'allow_anonymous', 'allow_user', 'allow_member', 'status', ] events = Event.objects.filter(status=True) max_speakers = events.annotate( num_speakers=Count('speaker')).aggregate( Max('num_speakers'))['num_speakers__max'] max_organizers = events.annotate( num_organizers=Count('organizer')).aggregate( Max('num_organizers'))['num_organizers__max'] max_pricings = events.annotate(num_pricings=Count( 'registration_configuration__regconfpricing')).aggregate( Max('num_pricings'))['num_pricings__max'] file_name = 'events.csv' data_row_list = [] for event in events: data_row = [] # event setup event_d = full_model_to_dict(event, fields=event_fields) for field in event_fields: value = None if field == 'entity': if event.entity: value = event.entity.entity_name elif field == 'type': if event.type: value = event.type.name else: value = event_d[field] value = unicode(value).replace(os.linesep, ' ').rstrip() data_row.append(value) if event.place: # place setup place_d = full_model_to_dict(event.place) for field in place_fields: value = place_d[field] value = unicode(value).replace(os.linesep, ' ').rstrip() data_row.append(value) if event.registration_configuration: # config setup conf_d = full_model_to_dict(event.registration_configuration) for field in configuration_fields: if field == "payment_method": value = event.registration_configuration.payment_method.all( ) else: value = conf_d[field] value = unicode(value).replace(os.linesep, ' ').rstrip() data_row.append(value) if event.speaker_set.all(): # speaker setup for speaker in event.speaker_set.all(): speaker_d = full_model_to_dict(speaker) for field in speaker_fields: value = speaker_d[field] value = unicode(value).replace(os.linesep, ' ').rstrip() data_row.append(value) # fill out the rest of the speaker columns if event.speaker_set.all().count() < max_speakers: for i in range(0, max_speakers - event.speaker_set.all().count()): for field in speaker_fields: data_row.append('') if event.organizer_set.all(): # organizer setup for organizer in event.organizer_set.all(): organizer_d = full_model_to_dict(organizer) for field in organizer_fields: value = organizer_d[field] value = unicode(value).replace(os.linesep, ' ').rstrip() data_row.append(value) # fill out the rest of the organizer columns if event.organizer_set.all().count() < max_organizers: for i in range( 0, max_organizers - event.organizer_set.all().count()): for field in organizer_fields: data_row.append('') reg_conf = event.registration_configuration if reg_conf and reg_conf.regconfpricing_set.all(): # pricing setup for pricing in reg_conf.regconfpricing_set.all(): pricing_d = full_model_to_dict(pricing) for field in pricing_fields: value = pricing_d[field] value = unicode(value).replace(os.linesep, ' ').rstrip() data_row.append(value) # fill out the rest of the pricing columns if reg_conf and reg_conf.regconfpricing_set.all().count( ) < max_pricings: for i in range( 0, max_pricings - reg_conf.regconfpricing_set.all().count()): for field in pricing_fields: data_row.append('') data_row_list.append(data_row) fields = event_fields + ["place %s" % f for f in place_fields] fields = fields + ["config %s" % f for f in configuration_fields] for i in range(0, max_speakers): fields = fields + [ "speaker %s %s" % (i, f) for f in speaker_fields ] for i in range(0, max_organizers): fields = fields + [ "organizer %s %s" % (i, f) for f in organizer_fields ] for i in range(0, max_pricings): fields = fields + [ "pricing %s %s" % (i, f) for f in pricing_fields ] return render_csv(file_name, fields, data_row_list)
def run(self, **kwargs): """Create the xls file""" form_fields = [ 'title', 'slug', 'intro', 'response', 'email_text', 'subject_template', 'send_email', 'email_from', 'email_copies', 'completion_url', 'custom_payment', 'payment_methods', 'allow_anonymous_view', 'allow_user_view', 'allow_member_view', 'allow_user_edit', 'allow_member_edit', 'create_dt', 'update_dt', 'creator', 'creator_username', 'owner', 'owner_username', 'status', 'status_detail', ] field_fields = [ 'label', 'field_type', 'field_function', 'required', 'visible', 'choices', 'position', 'default', ] pricing_fields = [ 'label', 'price', ] forms = Form.objects.filter(status=True) max_fields = forms.annotate(num_fields=Count('fields')).aggregate( Max('num_fields'))['num_fields__max'] max_pricings = forms.annotate(num_pricings=Count('pricing')).aggregate( Max('num_pricings'))['num_pricings__max'] file_name = 'forms.csv' data_row_list = [] for form in forms: data_row = [] # form setup form_d = full_model_to_dict(form) for field in form_fields: if field == 'payment_methods': value = [m.human_name for m in form.payment_methods.all()] else: value = form_d[field] value = unicode(value).replace(os.linesep, ' ').rstrip() data_row.append(value) if form.fields.all(): # field setup for field in form.fields.all(): field_d = full_model_to_dict(field) for f in field_fields: value = field_d[f] value = unicode(value).replace(os.linesep, ' ').rstrip() data_row.append(value) # fill out the rest of the field columns if form.fields.all().count() < max_fields: for i in range(0, max_fields - form.fields.all().count()): for f in field_fields: data_row.append('') if form.pricing_set.all(): # field setup for pricing in form.pricing_set.all(): pricing_d = full_model_to_dict(pricing) for f in pricing_fields: value = pricing_d[f] value = unicode(value).replace(os.linesep, ' ').rstrip() data_row.append(value) # fill out the rest of the field columns if form.pricing_set.all().count() < max_pricings: for i in range(0, max_pricings - form.pricing_set.all().count()): for f in pricing_fields: data_row.append('') data_row_list.append(data_row) fields = form_fields for i in range(0, max_fields): fields = fields + ["field %s %s" % (i, f) for f in field_fields] for i in range(0, max_pricings): fields = fields + [ "pricing %s %s" % (i, f) for f in pricing_fields ] return render_csv(file_name, fields, data_row_list)
def run(self, **kwargs): """Create the xls file""" fields = [ "guid", "title", "slug", "header_image", "content", "view_contact_form", "design_notes", "syndicate", "template", "tags", "entity", "meta", "categories", "allow_anonymous_view", "allow_user_view", "allow_member_view", "allow_anonymous_edit", "allow_user_edit", "allow_member_edit", "create_dt", "update_dt", "creator", "creator_username", "owner", "owner_username", "status", "status_detail", ] file_name = "pages.csv" pages = Page.objects.active() data_row_list = [] for page in pages: # get the available fields from the model's meta opts = page._meta d = {} for f in opts.fields + opts.many_to_many: if f.name in fields: # include specified fields only if isinstance(f, ManyToManyField): value = ["%s" % obj for obj in f.value_from_object(page)] if isinstance(f, ForeignKey): value = getattr(page, f.name) if isinstance(f, generic.GenericRelation): generics = f.value_from_object(page).all() value = ["%s" % obj for obj in generics] else: value = f.value_from_object(page) d[f.name] = value # append the accumulated values as a data row # keep in mind the ordering of the fields data_row = [] for field in fields: # clean the derived values into unicode value = unicode(d[field]).rstrip() data_row.append(value) data_row_list.append(data_row) return render_csv(file_name, fields, data_row_list)
def run(self, model, start_dt, end_dt, file_name, **kwargs): """Create the xls file""" fields = ( 'id', 'guid', 'object_type', 'object_id', 'title', 'tender_date', 'bill_to', 'bill_to_first_name', 'bill_to_last_name', 'bill_to_company', 'bill_to_address', 'bill_to_city', 'bill_to_state', 'bill_to_zip_code', 'bill_to_country', 'bill_to_phone', 'bill_to_fax', 'bill_to_email', 'ship_to', 'ship_to_first_name', 'ship_to_last_name', 'ship_to_company', 'ship_to_address', 'ship_to_city', 'ship_to_state', 'ship_to_zip_code', 'ship_to_country', 'ship_to_phone', 'ship_to_fax', 'ship_to_email', 'ship_to_address_type', 'receipt', 'gift', 'arrival_date_time', 'greeting', 'instructions', 'po', 'terms', 'due_date', 'ship_date', 'ship_via', 'fob', 'project', 'other', 'message', 'subtotal', 'shipping', 'shipping_surcharge', 'box_and_packing', 'tax_exempt', 'tax_exemptid', 'tax_rate', 'taxable', 'tax', 'variance', 'discount_amount', 'total', 'payments_credits', 'balance', 'disclaimer', 'variance_notes', 'admin_notes', 'create_dt', 'update_dt', 'creator', 'creator_username', 'owner', 'owner_username', 'status_detail', 'status', ) start_dt_date = datetime.strptime(start_dt, "%Y-%m-%d") end_dt_date = datetime.strptime(end_dt, "%Y-%m-%d") items = model.objects.filter(status=True, tender_date__gte=start_dt_date, tender_date__lte=end_dt_date) data_row_list = [] for item in items: # get the available fields from the model's meta opts = item._meta d = {} for f in opts.fields + opts.many_to_many: if f.name in fields: # include specified fields only if isinstance(f, ManyToManyField): value = ["%s" % obj for obj in f.value_from_object(item)] if isinstance(f, ForeignKey): value = getattr(item, f.name) if isinstance(f, generic.GenericRelation): generics = f.value_from_object(item).all() value = ["%s" % obj for obj in generics] if isinstance(f, DateTimeField): if f.value_from_object(item): value = f.value_from_object(item).strftime("%Y-%m-%d %H:%M") else: value = f.value_from_object(item) d[f.name] = value # append the accumulated values as a data row # keep in mind the ordering of the fields data_row = [] for field in fields: # clean the derived values into unicode value = unicode(d[field]).rstrip() data_row.append(value) data_row_list.append(data_row) return render_csv(file_name, fields, data_row_list)
def run(self, **kwargs): app = kwargs.pop('app') file_name = "%s.csv" % slugify(app.name) exclude_params = ( 'horizontal-rule', 'header', ) fields = AppField.objects.filter(app=app, exportable=True).exclude(field_type__in=exclude_params).order_by('position') label_list = [field.label for field in fields] extra_field_labels = ['User Name', 'Member Number', 'Join Date', 'Renew Date', 'Expiration Date', 'Status', 'Status Detail', 'Invoice Number', 'Invoice Amount', 'Invoice Balance'] extra_field_names = ['user', 'member_number', 'join_dt', 'renew_dt', 'expire_dt', 'status', 'status_detail', 'invoice', 'invoice_total', 'invoice_balance'] label_list.extend(extra_field_labels) data_row_list = [] memberships = Membership.objects.filter(ma=app).exclude(status_detail='archive') for memb in memberships: data_row = [] field_entry_d = memb.entry_items invoice = None if memb.get_entry(): invoice = memb.get_entry().invoice for field in fields: field_name = slugify(field.label).replace('-', '_') value = '' if field.field_type in ['first-name', 'last-name', 'email', 'membership-type', 'payment-method', 'corporate_membership_id']: if field.field_type == 'first-name': value = memb.user.first_name elif field.field_type == 'last-name': value = memb.user.last_name elif field.field_type == 'email': value = memb.user.email elif field.field_type == 'membership-type': value = memb.membership_type.name elif field.field_type == 'payment-method': if memb.payment_method: value = memb.payment_method.human_name elif field.field_type == 'corporate_membership_id': value = memb.corporate_membership_id if field_name in field_entry_d: value = field_entry_d[field_name] value = value or u'' if type(value) in (bool, int, long, None): value = unicode(value) data_row.append(value) for field in extra_field_names: if field == 'user': value = memb.user.username elif field == 'join_dt': if memb.renewal: value = '' else: value = memb.subscribe_dt elif field == 'renew_dt': if memb.renewal: value = memb.subscribe_dt else: value = '' elif field == 'expire_dt': value = memb.expire_dt or 'never expire' elif field == 'invoice': if invoice: value = unicode(invoice.id) else: value = "" elif field == 'invoice_total': if invoice: value = unicode(invoice.total) else: value = "" elif field == 'invoice_balance': if invoice: value = unicode(invoice.balance) else: value = "" else: value = getattr(memb, field, '') if type(value) in (bool, int, long): value = unicode(value) data_row.append(value) data_row_list.append(data_row) EventLog.objects.log() return render_csv(file_name, label_list, data_row_list)
def run(self, **kwargs): """Create the xls file""" fields = [ 'guid', 'title', 'slug', 'header_image', 'content', 'view_contact_form', 'design_notes', 'syndicate', 'template', 'tags', 'entity', 'meta', 'categories', 'allow_anonymous_view', 'allow_user_view', 'allow_member_view', 'allow_anonymous_edit', 'allow_user_edit', 'allow_member_edit', 'create_dt', 'update_dt', 'creator', 'creator_username', 'owner', 'owner_username', 'status', 'status_detail', ] file_name = 'pages.csv' pages = Page.objects.active() data_row_list = [] for page in pages: # get the available fields from the model's meta opts = page._meta d = {} for f in opts.fields + opts.many_to_many: if f.name in fields: # include specified fields only if isinstance(f, ManyToManyField): value = [ "%s" % obj for obj in f.value_from_object(page) ] if isinstance(f, ForeignKey): value = getattr(page, f.name) if isinstance(f, generic.GenericRelation): generics = f.value_from_object(page).all() value = ["%s" % obj for obj in generics] else: value = f.value_from_object(page) d[f.name] = value # append the accumulated values as a data row # keep in mind the ordering of the fields data_row = [] for field in fields: # clean the derived values into unicode value = unicode(d[field]).rstrip() data_row.append(value) data_row_list.append(data_row) return render_csv(file_name, fields, data_row_list)
def run(self, **kwargs): """Create the xls file""" nav_fields = [ 'title', 'description', 'megamenu', 'allow_anonymous_view', 'allow_user_view', 'allow_member_view', 'allow_anonymous_edit', 'allow_user_edit', 'allow_member_edit', 'create_dt', 'update_dt', 'creator', 'creator_username', 'owner', 'owner_username', 'status', 'status_detail', ] nav_item_fields = [ 'label', 'title', 'new_window', 'css', 'ordering', 'level', 'page', 'url', ] navs = Nav.objects.filter(status=True) max_nav_items = navs.annotate(num_navitems=Count('navitem')).aggregate( Max('num_navitems'))['num_navitems__max'] file_name = 'navs.csv' data_row_list = [] for nav in navs: data_row = [] # nav setup nav_d = full_model_to_dict(nav) for field in nav_fields: value = nav_d[field] value = unicode(value).replace(os.linesep, ' ').rstrip() data_row.append(value) if nav.navitem_set.all(): # nav_item setup for nav_item in nav.navitem_set.all(): nav_item_d = full_model_to_dict(nav_item) for field in nav_item_fields: value = nav_item_d[field] value = unicode(value).replace(os.linesep, ' ').rstrip() data_row.append(value) # fill out the rest of the nav_item columns if nav.navitem_set.all().count() < max_nav_items: for i in range(0, max_nav_items - nav.navitem_set.all().count()): for field in nav_item_fields: data_row.append('') data_row_list.append(data_row) fields = nav_fields for i in range(0, max_nav_items): fields = fields + [ "nav_item %s %s" % (i, f) for f in nav_item_fields ] return render_csv(file_name, fields, data_row_list)
def membership_export(request): from django.template.defaultfilters import slugify template_name = 'memberships/export.html' form = ExportForm(request.POST or None, user=request.user) if request.method == 'POST': if form.is_valid(): # reset the password_promt session request.session['password_promt'] = False app = form.cleaned_data['app'] file_name = "%s.csv" % slugify(app.name) exclude_params = ( 'horizontal-rule', 'header', ) fields = AppField.objects.filter(app=app, exportable=True).exclude(field_type__in=exclude_params).order_by('position') label_list = [field.label for field in fields] extra_field_labels = ['User Name', 'Member Number', 'Join Date', 'Renew Date', 'Expiration Date', 'Status', 'Status Detail', 'Invoice Number', 'Invoice Amount', 'Invoice Balance'] extra_field_names = ['user', 'member_number', 'join_dt', 'renew_dt', 'expire_dt', 'status', 'status_detail', 'invoice', 'invoice_total', 'invoice_balance'] label_list.extend(extra_field_labels) data_row_list = [] memberships = Membership.objects.filter(ma=app).exclude(status_detail='archive') for memb in memberships: data_row = [] field_entry_d = memb.entry_items invoice = None if memb.get_entry(): invoice = memb.get_entry().invoice for field in fields: field_name = slugify(field.label).replace('-', '_') value = '' if field.field_type in ['first-name', 'last-name', 'email', 'membership-type', 'payment-method', 'corporate_membership_id']: if field.field_type == 'first-name': value = memb.user.first_name elif field.field_type == 'last-name': value = memb.user.last_name elif field.field_type == 'email': value = memb.user.email elif field.field_type == 'membership-type': value = memb.membership_type.name elif field.field_type == 'payment-method': if memb.payment_method: value = memb.payment_method.human_name elif field.field_type == 'corporate_membership_id': value = memb.corporate_membership_id if field_name in field_entry_d: value = field_entry_d[field_name] value = value or u'' if type(value) in (bool, int, long, None): value = unicode(value) data_row.append(value) for field in extra_field_names: if field == 'user': value = memb.user.username elif field == 'join_dt': if memb.renewal: value = '' else: value = memb.subscribe_dt elif field == 'renew_dt': if memb.renewal: value = memb.subscribe_dt else: value = '' elif field == 'expire_dt': value = memb.expire_dt or 'never expire' elif field == 'invoice': if invoice: value = unicode(invoice.id) else: value = "" elif field == 'invoice_total': if invoice: value = unicode(invoice.total) else: value = "" elif field == 'invoice_balance': if invoice: value = unicode(invoice.balance) else: value = "" else: value = getattr(memb, field, '') if type(value) in (bool, int, long): value = unicode(value) data_row.append(value) data_row_list.append(data_row) EventLog.objects.log() return render_csv(file_name, label_list, data_row_list) return render_to_response(template_name, { 'form': form }, context_instance=RequestContext(request))