# Path: narwhal/plugins/user/ban/models.py
# class Ban(Model):
#     user     = ForeignKey(User, verbose_name=_('User'))
#     start    = DateTimeField(_('Start'), auto_now=True, auto_now_add=True)
#     end      = DateTimeField(_('End'), null=True, blank=True)
#     reason   = TextField(_('Reason'))


from datetime import datetime
from django.http import HttpResponseForbidden
from django.core.urlresolvers import reverse
from django.contrib.auth.models import User
from .models import Ban
from django.template.loader import get_template
from django.template.context import RequestContext
from django.contrib.auth import logout

## needs work




class BanMiddleware:
    
    def process_view(self, request):
        ban = Ban.objects.filter(user=request.user, start__lte=datetime.now(), end__gte=datetime.now())
        if ban:
            logout(request)

# Path: narwhal/plugins/user/ban/models.py
# class Ban(Model):
#     user     = ForeignKey(User, verbose_name=_('User'))
#     start    = DateTimeField(_('Start'), auto_now=True, auto_now_add=True)
#     end      = DateTimeField(_('End'), null=True, blank=True)
#     reason   = TextField(_('Reason'))


# Path: narwhal/plugins/user/ban/middleware.py
from datetime import datetime
from django.http import HttpResponseForbidden
from django.core.urlresolvers import reverse
from django.contrib.auth.models import User
from .models import Ban
from django.template.loader import get_template
from django.template.context import RequestContext
from django.contrib.auth import logout


## needs work




class BanMiddleware:
    
    def process_view(self, request):
        ban = Ban.objects.filter(user=request.user, start__lte=datetime.now(), end__gte=datetime.now())
        if ban:
            logout(request)

            return HttpResponseForbidden( get_template('user/ban.html').render( RequestContext(request, {'ban':ban} )) )