Esempio n. 1
0
File: rule.py Progetto: Hualin/prams
	def on_reivew_subject(self):
		# give history
		# delete previous pending job
		# give next pending job
		if not self.checked:
			raise('invalid calling order, update() should be called after check()!')
		from prams import db
		import model
		pObj = model.PendingJob.query.filter_by(subject_id = self.cur_subject_id, stage = self.cur_stage_name).first()
		db.session.delete(pObj)
		db.session.commit()

		from rule import FormStructure
		fm = FormStructure()
		sObj = model.Subject.query.filter_by(subject_id = self.cur_subject_id).first()
		newSection = model.History(g.user.user_id, g.user.occupation, 'reviewed', self.cur_subject_id, self.cur_status)
		next = self.rule_list[self.rule_key][1]
		sObj.status = next
		a, b = fm.get_responsibility(next).split(' ')
		paObj = model.PendingJob(g.user.user_id, a, self.cur_subject_id, next)
		pbObj = model.PendingJob(g.user.user_id, b, self.cur_subject_id, next)
		db.session.add(newSection)
		db.session.add(paObj)
		db.session.add(pbObj)
		db.session.add(sObj)
		db.session.commit()
Esempio n. 2
0
File: rule.py Progetto: Hualin/prams
	def on_seal(self):
		# give history
		# delete previous pending job
		# give next pending job
		if not self.checked:
			raise('invalid calling order, update() should be called after check()!')
		from prams import db
		import model
		pObj = model.PendingJob.query.filter_by(subject_id = self.cur_subject_id, stage = self.cur_stage_name, to_user_occupation = g.user.occupation).first()
		db.session.delete(pObj)
		db.session.commit()

		from rule import FormStructure
		fm = FormStructure()
		sealers = set(fm.get_responsibility(self.cur_status).split(' '))
		sealers.remove(g.user.occupation)

		newSection = model.History(g.user.user_id, g.user.occupation, 'sealed', self.cur_subject_id, self.cur_status)

		apObj = model.PendingJob.query.filter_by(subject_id = self.cur_subject_id, stage = self.cur_stage_name, to_user_occupation = sealers.pop()).first()
		if apObj == None:
			next = self.rule_list[self.rule_key][1]
			sObj = model.Subject.query.filter_by(subject_id = self.cur_subject_id).first()
			db.session.add(sObj)
			sObj.status = next
		db.session.add(newSection)
		db.session.commit()
Esempio n. 3
0
def view_subject(subject_id):
	if not g.user:
		abort(401)
	# basic information
	subject_info = {}
	subject_info['subject_id'] = subject_id
	from model import f1b1, Subject
	qObj = f1b1.query.filter_by(subject_id = subject_id).first()
	sObj = Subject.query.filter_by(subject_id = subject_id).first()
	subject_info['department'] = qObj.field01
	subject_info['title'] = qObj.field02
	subject_info['holder'] = qObj.field03
	subject_info['new'] = qObj.field04
	subject_info['subject_status'] = sObj.status

	extra_action = None
	done_before = False
	from rule import StateMachine
	sm = StateMachine(subject_id)
	if sObj.status in ('wait_to_allocate', 'wait_to_review', 'final_review'):
		extra_action = sObj.status
		from model import PendingJob
		done_before = (PendingJob.query.filter_by(subject_id = subject_id, stage = extra_action, to_user_occupation = g.user.occupation).first() == None)
	# form A table
	# order by: section, block responisbility action, status
	from rule import FormStructure
	import model
	fm = FormStructure()
	tb_fA = []
	for block_name in fm.get_blocks('Form A'):
		bClass = getattr(model, block_name)
		tb_fA.append([
			(block_name == sObj.status), # activated
			fm.get_sectionName(block_name), # section name
			block_name, # block name
			fm.get_responsibility(block_name), # responsibility
			sm.get_view_OR_edit(block_name, g.user.occupation), # action
			bClass.query.filter_by(subject_id = subject_id).first().status # block status
			])

	# form B table
	tb_fB = []
	# form C table
	tb_fC = []
	return render_template('subject.html', 
		subject_info = subject_info, 
		table_formA = tb_fA, 
		table_formB = tb_fB,
		table_formC = tb_fC,
		extra_action = extra_action,
		sm = sm,
		done_before = done_before
		)
Esempio n. 4
0
File: rule.py Progetto: Hualin/prams
	def on_submit_block(self):
		if not self.checked:
			raise('invalid calling order, update() should be called after check()!')
		# chage block status
		# give history
		# move to next stage
		# give pending
		from prams import db
		import model
		#delete: filter=select id and stage to choice the subject 
		pObj = model.PendingJob.query.filter_by(subject_id = self.cur_subject_id, stage = self.cur_stage_name).first()
		db.session.delete(pObj)
		db.session.commit()

		sObj = model.Subject.query.filter_by(subject_id = self.cur_subject_id).first()
		newSection = model.History(g.user.user_id, g.user.occupation, 'submited', self.cur_subject_id, self.cur_status)
		bClass = getattr(model, self.cur_stage_name)#getattr = get class by class name
		qObj = bClass.query.filter_by(subject_id = self.cur_subject_id).first()
		qObj.status = 2 # 2 means the block has been submitted and can not be changed anymore
		next = self.rule_list[self.rule_key][1]
		fm = FormStructure()
		if self.rule_key[0] != 'f1b5' and self.rule_key[0] != 'f1b6':
			sObj.status = next
		elif self.rule_key[0] == 'f1b5' or self.rule_key[0] == 'f1b6':
			# its really tricky here
			# here get the field01 key which are approved, decline or referr. the next key means go to next stage from the field01. fiedle01 has the stage from approved or decline/...
			nextKey = qObj.field01
			sObj.status = next[nextKey]
		else:
			raise("internal error")
		pObj = model.PendingJob(g.user.user_id, fm.get_responsibility(sObj.status), self.cur_subject_id, sObj.status)
		db.session.add(pObj)
		db.session.add(newSection)
		db.session.add(sObj)
		db.session.add(qObj)
		db.session.commit()