Esempio n. 1
0
	def index1(self, id=None, category=None, osep='None', print_area='false'):
		if identity.current.user.basketmode:
			raise redirect(url("index2",id=id,category=category,osep=osep,print_area=print_area))
		osep = True
	
		if print_area == 'true':
			print_area = True
		else:
			print_area = False
		
		id = util.session('current_assessment', 0, id)
		category = util.session('current_category', 'Fine Motor', category)
		osep = util.session('osep', False, osep)
		child = util.session('current_child', 0)
		
		if id == 0:		# no id given
			raise redirect("/")
		
		try:
			current_assessment = Assessment.get(id)
		except SQLObjectNotFound:	# Child with given id does not exist
			raise redirect("/")

		current_child = current_assessment.child
		all_assessments = current_child.assessments
		
		sorted_assessments = Assessment.select(AND(Assessment.q.childID==current_assessment.childID,
												   Assessment.q.id!=id,
												   Assessment.q.level==current_assessment.level), orderBy='-dateEntered')
		old = list(sorted_assessments[:7])
		
		if osep:
			criteria = Criterion.selectBy(category=category, level=current_assessment.level, osep=True)
		else:
			criteria = Criterion.selectBy(category=category, level=current_assessment.level)
			
		criteria = criteria.orderBy('sort_order')
		
		crit_ids = [c.id for c in criteria]
		sums = {}
		
		for t in old:
			sum = 0;
			for s in t.scores:
				if s.criterionID in crit_ids and s.criterion.rank != "1":
					try:
						sum += int(s.value)
					except:
						pass
			sums[t.id] = sum
		sum = 0;
		for s in current_assessment.scores:
			if s.criterionID in crit_ids and s.criterion.rank != "1":
				try:
					sum += int(s.value)
				except:
					pass
		sums[current_assessment.id] = sum
		
		util.session('fill', 'missing')
		if len(old) == 0:
			temp = util.session('values', 'zeros')
			if temp == 'previous':
				cherrypy.session['values'] = 'zeros'
		else:
			util.session('values', 'previous')
		
		subtotal = Criterion.selectBy(category=category, level=current_assessment.level, prefix='Z')[0]
		_na = Criterion.selectBy(category=category, level=current_assessment.level, prefix='Y')[0]
		
		oldtotals = {}
		oldna = {}
		percents = {}
		for t in old:
			stscore = Score.selectBy(assessmentID=t.id, criterionID=subtotal.id)
			if stscore.count() > 0:
				stscore = stscore[0]
			else:
				stscore = Score(assessmentID=t.id, criterionID=subtotal.id, value="0", type='subtotal')
			oldtotals[t.id] = stscore.value
			
			nascore = Score.selectBy(assessmentID=t.id, criterionID=_na.id)
			if nascore.count() > 0:
				nascore = nascore[0]
			else:
				nascore = Score(assessmentID=t.id, criterionID=_na.id, value="0", type='na')
			oldna[t.id] = nascore.value
		
			percents[t.id] = util.percent(stscore.value, util.scorePossible(category, current_assessment.level), nascore.value)
			
		
		stscore = Score.selectBy(assessmentID=id, criterionID=subtotal.id)
		nascore = Score.selectBy(assessmentID=id, criterionID=_na.id)
		if stscore.count() > 0:
			stscore = stscore[0]
		else:
			stscore = Score(assessmentID=id, criterionID=subtotal.id, value="0", type='subtotal')
		
		if nascore.count() > 0:
			nascore = nascore[0]
		else:
			nascore = Score(assessmentID=id, criterionID=_na.id, value="0", type='na')
			
		percent = util.percent(stscore.value, util.scorePossible(category, current_assessment.level), nascore.value)
		
		return dict(child=current_child, id=id, a=current_assessment, old=old, oldtotals=oldtotals, \
					stc=subtotal, subtotal=stscore, criteria=criteria, osep=osep, sums=sums, \
					catlist=self.category_list, category=category, nextCategory=self.nextCategory, \
					print_area=print_area, getEditor=self.getEditor, pcheck=self.persistCheck, \
					shaded=util.shaded, scoreclass=util.color, scorePossible=util.scorePossible, \
					nac=_na, na=nascore, oldna=oldna, percents=percents, percent=percent)
Esempio n. 2
0
	def index2(self, id=None, category=None, osep='None', print_area='false'):
		if not identity.current.user.basketmode:
			raise redirect(url("index1",id=id,category=category,osep=osep,print_area=print_area))
		
		osep = True

		if print_area == 'true':
			print_area = True
		else:
			print_area = False

		id = util.session('current_assessment', 0, id)
		child = util.session('current_child', 0)

		if id == 0:		# no id given
			raise redirect("/")

		try:
			current_assessment = Assessment.get(id)
		except SQLObjectNotFound:	# Child with given id does not exist
			raise redirect("/")

		current_child = current_assessment.child
		all_assessments = current_child.assessments
		sorted_assessments = Assessment.select(AND(Assessment.q.childID==current_assessment.childID,
												   Assessment.q.id!=id,
												   Assessment.q.level==current_assessment.level), orderBy='-dateEntered')
		old = list(sorted_assessments[:7])


		categories = self.category_list
		data = {}

		for c in categories:
			cdata = {}
			
			subtotal = Criterion.selectBy(category=c, level=current_assessment.level, prefix='Z')[0]
			_na = Criterion.selectBy(category=c, level=current_assessment.level, prefix='Y')[0]

			cdata['subtotal'] = subtotal
			cdata['na'] = _na

			oldtotals = {}
			oldna = {}
			percents = {}
			for t in old:
				stscore = Score.selectBy(assessmentID=t.id, criterionID=subtotal.id)
				if stscore.count() > 0:
					stscore = stscore[0]
				else:
					stscore = Score(assessmentID=t.id, criterionID=subtotal.id, value="0", type='subtotal')
				oldtotals[t.id] = stscore.value

				nascore = Score.selectBy(assessmentID=t.id, criterionID=_na.id)
				if nascore.count() > 0:
					nascore = nascore[0]
				else:
					nascore = Score(assessmentID=t.id, criterionID=_na.id, value="0", type='na')
				oldna[t.id] = nascore.value

				percents[t.id] = util.percent(stscore.value, util.scorePossible(c, current_assessment.level), nascore.value)
			
			cdata['oldtotals'] = oldtotals
			cdata['oldna'] = oldna
			cdata['percents'] = percents

			stscore = Score.selectBy(assessmentID=id, criterionID=subtotal.id)
			nascore = Score.selectBy(assessmentID=id, criterionID=_na.id)
			if stscore.count() > 0:
				stscore = stscore[0]
			else:
				stscore = Score(assessmentID=id, criterionID=subtotal.id, value="0", type='subtotal')

			if nascore.count() > 0:
				nascore = nascore[0]
			else:
				nascore = Score(assessmentID=id, criterionID=_na.id, value="0", type='na')

			percent = util.percent(stscore.value, util.scorePossible(c, current_assessment.level), nascore.value)
			
			cdata['stscore'] = stscore
			cdata['nascore'] = nascore
			cdata['percent'] = percent
			
			data[c] = cdata
			
		baskets = []
		for i in [1,2,3]:
			
			bdata = {}
			
			prefix = "B" + str(i)
			b = Criterion.selectBy(level=current_assessment.level, prefix=prefix)[0]
			
			oldb = {}
			for t in old:
				bscore = Score.selectBy(assessmentID=t.id, criterionID=b.id)
				if bscore.count() > 0:
					bscore = bscore[0]
				else:
					bscore = Score(assessmentID=t.id, criterionID=b.id, value="0", type='basket')
				oldb[t.id] = bscore
			bdata['old'] = oldb
			
			bscore = Score.selectBy(assessmentID=id, criterionID=b.id)
			if bscore.count() > 0:
				bscore = bscore[0]
			else:
				bscore = Score(assessmentID=id, criterionID=b.id, value="0", type='basket')
			bdata['val'] = bscore
			baskets.append(bdata)

		return dict(child=current_child, id=id, a=current_assessment, old=old, categories=categories, \
					print_area=print_area, getEditor=self.getEditor, pcheck=self.persistCheck, \
					shaded=util.shaded, scoreclass=util.color, scorePossible=util.scorePossible, \
					data=data, baskets=baskets)