Revision 8f50f91c invitations/invitations.py

b/invitations/invitations.py
85 85
    if errors:
86 86
        data = render_to_string('invitations.html',
87 87
                                {'invitations': invitations_for_user(request),
88
                                    'errors': errors, 'ajax': request.is_ajax()},
88
                                    'errors': errors,
89
                                    'ajax': request.is_ajax(),
90
                                    'invitations_left': get_invitations_left(request.user)
91
                                },
89 92
                                context_instance=RequestContext(request))
90 93
        response =  HttpResponse(data)
91 94
        _logger.warn("Error adding invitation %s -> %s: %s"%(request.user.uniq,
......
130 133

  
131 134
    if request.method == 'GET':
132 135
        data = render_to_string('invitations.html',
133
                {'invitations': invitations_for_user(request), 'ajax': request.is_ajax()},
136
                {'invitations': invitations_for_user(request),
137
                    'ajax': request.is_ajax(),
138
                    'invitations_left': get_invitations_left(request.user)
139
                },
134 140
                                context_instance=RequestContext(request))
135 141
        return  HttpResponse(data)
136 142
    elif request.method == 'POST':
......
303 309
    invitation.accepted = True
304 310
    invitation.save()
305 311

  
312

  
313
def get_invitations_left(user):
314
    """
315
    Get user invitations left
316
    """
317
    num_inv = Invitations.objects.filter(source = user).count()
318
    return user.max_invitations - num_inv
319

  
306 320
class InvitationException(Exception):
307 321
    messages = []
308 322

  

Also available in: Unified diff