Changeset - 52376dff592a
[Not reviewed]
0 1 0
Christopher Neugebauer - 8 years ago 2016-12-07 06:39:13
chrisjrn@gmail.com
Adds nag mails to the UI.

Fixes #50
1 file changed with 10 insertions and 0 deletions:
0 comments (0 inline, 0 general)
registrasion/reporting/views.py
Show inline comments
...
 
@@ -546,96 +546,106 @@ def attendee_list(request):
 
            a.user.id,
 
            (profiles_by_attendee[a].attendee_name()
 
                if a in profiles_by_attendee else ""),
 
            a.user.email,
 
            a.has_registered > 0,
 
        ])
 

	
 
    # Sort by whether they've registered, then ID.
 
    data.sort(key=lambda a: (-a[3], a[0]))
 

	
 
    return AttendeeListReport("Attendees", headings, data, link_view=attendee)
 

	
 

	
 
ProfileForm = forms.model_fields_form_factory(AttendeeProfile)
 

	
 
@report_view(
 
    "Attendees By Product/Category",
 
    form_type=forms.mix_form(
 
        forms.ProductAndCategoryForm, ProfileForm, forms.GroupByForm
 
    ),
 
)
 
def attendee_data(request, form, user_id=None):
 
    ''' Lists attendees for a given product/category selection along with
 
    profile data.'''
 

	
 
    status_display = {
 
        commerce.Cart.STATUS_ACTIVE: "Unpaid",
 
        commerce.Cart.STATUS_PAID: "Paid",
 
        commerce.Cart.STATUS_RELEASED: "Refunded",
 
    }
 

	
 
    output = []
 

	
 
    by_category = form.cleaned_data["group_by"] == forms.GroupByForm.GROUP_BY_CATEGORY
 

	
 
    products = form.cleaned_data["product"]
 
    categories = form.cleaned_data["category"]
 
    fields = form.cleaned_data["fields"]
 
    name_field = AttendeeProfile.name_field()
 

	
 
    items = commerce.ProductItem.objects.filter(
 
        Q(product__in=products) | Q(product__category__in=categories),
 
    ).exclude(
 
        cart__status=commerce.Cart.STATUS_RELEASED
 
    ).select_related(
 
        "cart", "cart__user", "product", "product__category",
 
    ).order_by("cart__status")
 

	
 
    # Add invoice nag link
 
    links = []
 
    links.append((
 
        reverse(views.nag_unpaid, args=[]) + "?" + request.META["QUERY_STRING"],
 
        "Send invoice reminders",
 
    ))
 

	
 
    if items.count() > 0:
 
        output.append(Links("Actions", links))
 

	
 
    # Make sure we select all of the related fields
 
    related_fields = set(
 
        field for field in fields
 
        if isinstance(AttendeeProfile._meta.get_field(field), RelatedField)
 
    )
 

	
 
    # Get all of the relevant attendee profiles in one hit.
 
    profiles = AttendeeProfile.objects.filter(
 
        attendee__user__cart__productitem__in=items
 
    ).select_related("attendee__user").prefetch_related(*related_fields)
 
    by_user = {}
 
    for profile in profiles:
 
        by_user[profile.attendee.user] = profile
 

	
 
    cart = "attendee__user__cart"
 
    cart_status = cart + "__status"
 
    product = cart + "__productitem__product"
 
    product_name = product + "__name"
 
    category = product + "__category"
 
    category_name = category + "__name"
 

	
 
    if by_category:
 
        grouping_fields = (category, category_name)
 
        order_by = (category, )
 
        first_column = "Category"
 
        group_name = lambda i: "%s" % (i[category_name], )
 
    else:
 
        grouping_fields = (product, product_name, category_name)
 
        order_by = (category, )
 
        first_column = "Product"
 
        group_name = lambda i: "%s - %s" % (i[category_name], i[product_name])
 

	
 
    # Group the responses per-field.
 
    for field in fields:
 
        concrete_field = AttendeeProfile._meta.get_field(field)
 
        field_verbose = concrete_field.verbose_name
 

	
 
        # Render the correct values for related fields
 
        if field in related_fields:
 
            # Get all of the IDs that will appear
 
            all_ids = profiles.order_by(field).values(field)
 
            all_ids = [i[field] for i in all_ids if i[field] is not None]
 
            # Get all of the concrete objects for those IDs
 
            model = concrete_field.related_model
 
            all_objects = model.objects.filter(id__in=all_ids)
 
            all_objects_by_id = dict((i.id, i) for i in all_objects)
 

	
 
            # Define a function to render those IDs.
0 comments (0 inline, 0 general)