Changeset - fd7fff7879b3
[Not reviewed]
0 2 0
Christopher Neugebauer - 7 years ago 2017-01-07 23:44:19
chrisjrn@gmail.com
Allows contexts to directly supply a user (so we can access registration data when e-mailing people.)
2 files changed with 27 insertions and 8 deletions:
0 comments (0 inline, 0 general)
registrasion/templatetags/registrasion_tags.py
Show inline comments
...
 
@@ -11,2 +11,11 @@ register = template.Library()
 

	
 
def user_for_context(context):
 
    ''' Returns either context.user or context.request.user if the former is
 
    not defined. '''
 
    try:
 
        return context["user"]
 
    except KeyError:
 
        return context.request.user
 

	
 

	
 
@register.assignment_tag(takes_context=True)
...
 
@@ -20,3 +29,3 @@ def available_categories(context):
 
    '''
 
    return CategoryController.available_categories(context.request.user)
 
    return CategoryController.available_categories(user_for_context(context))
 

	
...
 
@@ -26,3 +35,3 @@ def missing_categories(context):
 
    ''' Adds the categories that the user does not currently have. '''
 
    user = context.request.user
 
    user = user_for_context(context)
 
    categories_available = set(CategoryController.available_categories(user))
...
 
@@ -49,3 +58,3 @@ def available_credit(context):
 
    notes = commerce.CreditNote.unclaimed().filter(
 
        invoice__user=context.request.user,
 
        invoice__user=user_for_context(context),
 
    )
...
 
@@ -61,3 +70,3 @@ def invoices(context):
 
        [models.commerce.Invoice, ...]: All of the current user's invoices. '''
 
    return commerce.Invoice.objects.filter(user=context.request.user)
 
    return commerce.Invoice.objects.filter(user=user_for_context(context))
 

	
...
 
@@ -66,4 +75,9 @@ def invoices(context):
 
def items_pending(context):
 
    ''' Gets all of the items that the user from this context has reserved.'''
 
    return ItemController(context.request.user).items_pending()
 
    ''' Gets all of the items that the user from this context has reserved.
 

	
 
    The user will be either `context.user`, and `context.request.user` if
 
    the former is not defined.
 
    '''
 

	
 
    return ItemController(user_for_context(context)).items_pending()
 

	
...
 
@@ -72,5 +86,9 @@ def items_pending(context):
 
def items_purchased(context, category=None):
 
    ''' Returns the items purchased for this user. '''
 
    ''' Returns the items purchased for this user.
 

	
 
    The user will be either `context.user`, and `context.request.user` if
 
    the former is not defined.
 
    '''
 

	
 
    return ItemController(context.request.user).items_purchased(
 
    return ItemController(user_for_context(context)).items_purchased(
 
        category=category
registrasion/views.py
Show inline comments
...
 
@@ -953,2 +953,3 @@ def invoice_mailout(request):
 
                    "invoice" : invoice,
 
                    "user" : invoice.user,
 
                })
0 comments (0 inline, 0 general)