コード例 #1
0
ファイル: views.py プロジェクト: bluearth/harmony
def save_draft(request,nota_id):
	
	nota_index = nota_id
	l_subject = request.POST['subjectTxt']
	l_serial = request.POST['serialNoTxt']
	l_content = request.POST['contentTxa']
	l_recipients = request.POST['recipientList']
	l_ccrecipients = request.POST['ccRecipientList']	
	l_nota_date = datetime.datetime.now()
	
	if nota_index == None :					# If nota_id not in GET
		nota_index = request.POST['notaId']	# fetch nota id from POST instead
	
	if nota_index <> None and nota_index.strip() <> '':
		nota = NotaDinas.objects.get( id = nota_index )
		draft = Draft.objects.get(nota__id__exact = nota.id)
	else : 					
		nota = NotaDinas()
		draft = Draft() 

	nota.subject = l_subject
	nota.serialno = l_serial
	nota.content = l_content 
	nota.author = request.user
	nota.create_date = l_nota_date
	nota.recipients = l_recipients
	nota.ccrecipients = l_ccrecipients			
	nota.save()
					
	draft.nota = nota
	draft.last_edit = l_nota_date	
	draft.save()	
	
	msg = [
		ValidationMsg(elemId='',desc='Draft tersimpan.'),
	]	
	
	return render_to_response('index.html',
		{
			'settings_app_name': settings.APP_NAME,
			'user' : request.user,
			'action_result_msgs' : msg,
		})
コード例 #2
0
ファイル: views.py プロジェクト: bluearth/harmony
def disposisi_nota(request):
	msg = []
	nota_index = None # replace with url pass GET vars
	
	l_subject = request.POST['subjectTxt']
	l_serial = request.POST['serialNoTxt']
	l_content = request.POST['contentTxa']
	l_recipients = request.POST['recipientList']
	l_ccrecipients = request.POST['ccRecipientList']	
	l_nota_date = datetime.datetime.now()
	
	if nota_index == None :					# If nota_id not in GET
		nota_index = request.POST['notaId']	# fetch nota id from POST instead
		print 'Got id from POST'
	
	## Create or update nota
	if nota_index <> None and nota_index.strip() <> '': 	# Update
		nota = NotaDinas.objects.get( id = nota_index )
		draft = Draft.objects.get(nota__id__exact = nota.id)
		print 'Updating nota ' + str(nota.id)
	else : 		# Create
		nota = NotaDinas()
		draft = Draft() 
		print 'Saving new nota'
		
	nota.subject = l_subject
	nota.serialno = l_serial
	nota.content = l_content 
	nota.author = request.user
	nota.create_date = l_nota_date
	nota.recipients = l_recipients
	nota.ccrecipients = l_ccrecipients
	nota.save()
					
	draft.nota = nota
	draft.last_edit = l_nota_date	
	draft.save()			
	####

	# Start disposisi
	dispatch_date = datetime.datetime.now()
	try:
		for recuser in split_recipients(l_recipients):
			dispo = Disposisi()
			dispo.nota = nota
			dispo.initiator = request.user.first_name + ' ' + request.user.last_name
			dispo.recipient = recuser
			dispo.dispatch_date = dispatch_date
			dispo.forwarded_from = None
			dispo.save()
	
		for ccrecuser in split_recipients(l_ccrecipients):
			dispo = Disposisi()
			dispo.nota = nota
			dispo.initiator = request.user.first_name + ' ' + request.user.last_name
			dispo.recipient = ccrecuser
			dispo.dispatch_date = dispatch_date
			dispo.forwarded_from = None			
			dispo.save()
			
	except ObjectDoesNotExist:
		msg.append( ValidationMsg(elemId='',desc='User tidak terdaftar.') )
		return render_to_response('index.html',
			{
				'settings_app_name': settings.APP_NAME,
				'user' : request.user,
				'action_result_msgs' : msg,
			})
		
	# Remove draft if exists
	drafts = Draft.objects.filter(nota__id__exact = nota.id)
	for draft in drafts:
		draft.delete()

	msg.append(	ValidationMsg(elemId='',desc='Nota terkirim.') )	
	
	return render_to_response('index.html',
		{
			'settings_app_name': settings.APP_NAME,
			'user' : request.user,
			'action_result_msgs' : msg,
		})