<s> import datetime <EOL> from django . contrib . admin . sites import AdminSite <EOL> from django . db . models import Q <EOL> from django . contrib import messages <EOL> from django . shortcuts import render <EOL> from hado . models import * <EOL> from hado . forms import PaymentFormAdmin , PaymentFormAdminFormset <EOL> class HackdoAdmin ( AdminSite ) : <EOL> def index ( self , request ) : <EOL> '''<STR_LIT>''' <EOL> members = { } <EOL> users = User . objects . select_related ( '<STR_LIT>' ) <EOL> members [ '<STR_LIT>' ] = len ( users ) <EOL> members [ '<STR_LIT>' ] = Contract . objects . filter ( ctype__desc = '<STR_LIT>' , <EOL> status = '<STR_LIT>' ) . count ( ) <EOL> members [ '<STR_LIT>' ] = Contract . objects . filter ( ctype__desc = '<STR_LIT>' , <EOL> status = '<STR_LIT>' ) . count ( ) <EOL> income = { } <EOL> this_month = datetime . date . today ( ) . month <EOL> payments_this_month = Payment . objects . filter ( <EOL> date_paid__month = this_month ) <EOL> ctypes = ContractType . objects . all ( ) <EOL> for c in ctypes : <EOL> income [ c . desc ] = payments_this_month . filter ( contract__ctype__desc = c . desc ) . aggregate ( Sum ( '<STR_LIT>' ) ) [ '<STR_LIT>' ] or <NUM_LIT:0.0> <EOL> income [ '<STR_LIT>' ] = { } <EOL> income [ '<STR_LIT>' ] [ '<STR_LIT>' ] = Contract . objects . filter ( Q ( status = '<STR_LIT>' ) | Q ( status = '<STR_LIT>' ) ) . aggregate ( Sum ( '<STR_LIT>' ) ) [ '<STR_LIT>' ] or <NUM_LIT:0.0> <EOL> income [ '<STR_LIT>' ] [ '<STR_LIT>' ] = payments_this_month . aggregate ( Sum ( '<STR_LIT>' ) ) [ '<STR_LIT>' ] or <NUM_LIT:0.0> <EOL> income [ '<STR_LIT>' ] [ '<STR_LIT>' ] = income [ '<STR_LIT>' ] [ '<STR_LIT>' ] - income [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> if request . method == '<STR_LIT:POST>' : <EOL> pformset = PaymentFormAdminFormset ( <EOL> request . POST , queryset = Payment . objects . filter ( verified = False ) ) <EOL> if pformset . is_valid ( ) : <EOL> pformset . save ( ) <EOL> messages . success ( request , "<STR_LIT>" ) <EOL> else : <EOL> print pformset . errors <EOL> pformset = PaymentFormAdminFormset ( <EOL> queryset = Payment . objects . filter ( verified = False ) ) <EOL> return render ( request , '<STR_LIT>' , <EOL> { '<STR_LIT>' : members , '<STR_LIT>' : income , '<STR_LIT>' : pformset } ) <EOL> def lapsed_contracts ( self , request ) : <EOL> '''<STR_LIT>''' <EOL> pass </s>
