<commit_before># -*- coding: utf-8 -*-
import datetime

from django.contrib.admin.sites import AdminSite
from django.db.models import Q
from django.contrib import messages

from hado.models import *
from hado.forms import PaymentFormAdmin, PaymentFormAdminFormset

from utils import render

# Subclassing a custom admin to provide a custom interface
class HackdoAdmin(AdminSite):

	def index(self, request):
		'''This view forms the admin dashboard for HackDo'''
		
		# Members stats
		members = {}
		users = User.objects.select_related('contracts')
		members['total'] = len(users)

		members['active'] = Contract.objects.filter(ctype__desc='Membership', status='ACT').count()
		members['lapsed'] = Contract.objects.filter(ctype__desc='Membership', status='LAP').count()

		# Income stats
		income = {}
		this_month = datetime.date.today().month
		payments_this_month = Payment.objects.filter(date_paid__month=this_month)
		# Get ContracTypes
		ctypes = ContractType.objects.all()		
		for c in ctypes:
			income[c.desc] = payments_this_month.filter(contract__ctype__desc=c.desc).aggregate(Sum('amount'))['amount__sum'] or 0.0
		
		
		# Supposed income this month
		income['summary'] = {}
		income['summary']['supposed'] = Contract.objects.filter(Q(status='ACT') | Q(status='LAP')).aggregate(Sum('tier__fee'))['tier__fee__sum'] or 0.0
		income['summary']['actual'] = payments_this_month.aggregate(Sum('amount'))['amount__sum'] or 0.0
		income['summary']['shortfall'] = income['summary']['supposed'] - income['summary']['actual']
		
		
		# Incoming Payments pending verification
		pformset = PaymentFormAdminFormset(queryset=Payment.objects.filter(verified=False))
		
		return render(request, 'admin/index.html', {'members':members, 'income':income, 'pformset':pformset})



	def lapsed_contracts(self, request):
		'''Shows details about lapsed contracts'''
		pass
		
	
	<commit_msg>Making sure that Payment verification does, in fact, work<commit_after># -*- coding: utf-8 -*-
import datetime

from django.contrib.admin.sites import AdminSite
from django.db.models import Q
from django.contrib import messages

from hado.models import *
from hado.forms import PaymentFormAdmin, PaymentFormAdminFormset

from utils import render

# Subclassing a custom admin to provide a custom interface
class HackdoAdmin(AdminSite):

	def index(self, request):
		'''This view forms the admin dashboard for HackDo'''
		
		# Members stats
		members = {}
		users = User.objects.select_related('contracts')
		members['total'] = len(users)

		members['active'] = Contract.objects.filter(ctype__desc='Membership', status='ACT').count()
		members['lapsed'] = Contract.objects.filter(ctype__desc='Membership', status='LAP').count()

		# Income stats
		income = {}
		this_month = datetime.date.today().month
		payments_this_month = Payment.objects.filter(date_paid__month=this_month)
		# Get ContracTypes
		ctypes = ContractType.objects.all()		
		for c in ctypes:
			income[c.desc] = payments_this_month.filter(contract__ctype__desc=c.desc).aggregate(Sum('amount'))['amount__sum'] or 0.0
		
		
		# Supposed income this month
		income['summary'] = {}
		income['summary']['supposed'] = Contract.objects.filter(Q(status='ACT') | Q(status='LAP')).aggregate(Sum('tier__fee'))['tier__fee__sum'] or 0.0
		income['summary']['actual'] = payments_this_month.aggregate(Sum('amount'))['amount__sum'] or 0.0
		income['summary']['shortfall'] = income['summary']['supposed'] - income['summary']['actual']
		
		
		# Incoming Payments pending verification
		if request.method == 'POST':
			pformset = PaymentFormAdminFormset(request.POST, queryset=Payment.objects.filter(verified=False))
	
			if pformset.is_valid():
				pformset.save()
				
				# On success, add a note
				messages.success(request, "Payments verified")
			else:
				print pformset.errors

		# Create a new formset anyway	
		pformset = PaymentFormAdminFormset(queryset=Payment.objects.filter(verified=False))
		
		return render(request, 'admin/index.html', {'members':members, 'income':income, 'pformset':pformset})



	def lapsed_contracts(self, request):
		'''Shows details about lapsed contracts'''
		pass
		
	
	
{'fraction_non_alphanumeric': 0.13837237382274814, 'fraction_numerical': 0.0033808258874667954, 'mean_word_length': 5.372307692307692, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '611855', 'n_tokens_mistral': 1409, 'n_tokens_neox': 1228, 'n_words': 275}