コード例 #1
0
ファイル: env_term.py プロジェクト: graphy21/ezmicrobiome
def env_term_create(request):
	if request.method == 'POST':
		user = request.user
		env_term = request.POST.get('newEnvTerm')
		env_tax = request.POST.get('fullName')
		env_tax = '{}{}'.format(env_tax, env_term)
		env_tag_list = env_tax.replace(';', '|') if env_tax[-1] != ';' else\
				env_tax[:-1].replace(';','|')
		description = ''

		# check env term duplication
		if EnvTerm.objects.filter(env_term=env_term):
			return HttpResponseBadRequest("New Env Term is duplicated.") 
		# add new env term
		new_env_term = EnvTerm(env_term=env_term, env_tax=env_tax,
				env_tag_list=env_tag_list, description=description)
		new_env_term.save()
		# inherit parent node qualifiers
		if len(env_tax.split(';')) > 1:
			parent_name = env_tax.split(';')[-2]
			parent_env_term = EnvTerm.objects.get(env_term=parent_name)
			qualifiers = Qualifier.objects.filter(env_term=parent_env_term)
			for qualifier in qualifiers:
				new_qualifier = Qualifier(qualifier = qualifier.qualifier, 
						env_term = new_env_term, 
						data_type = qualifier.data_type,
						data_value = qualifier.data_value, 
						definition = qualifier.definition, 
						example = qualifier.example)
				new_qualifier.save()
		# add log
		log_record = EnvTermLog(target=new_env_term, editor=user,
				action='CR', log='Env Term created.')
		log_record.save()
		return HttpResponse('good')
コード例 #2
0
ファイル: env_term.py プロジェクト: graphy21/ezmicrobiome
	def form_valid(self, form):
		user = self.request.user
		env_term = form.cleaned_data['new_env_term']
		env_tax = form.cleaned_data['parent_node']
		env_tax = '{}{}'.format(env_tax, env_term)
		env_tag_list = env_tax.replace(';', '|') if env_tax[-1] != ';' else\
				env_tax[:-1].replace(';','|')
		description = ''
		new_env_term = EnvTerm(env_term=env_term, env_tax=env_tax,
				env_tag_list=env_tag_list, description=description)
		new_env_term.save()
		log_record = self.log_model(target=new_env_term, editor=user,
				action='CR', log=self.log_msg)
		log_record.save()
		return super(EnvTermCreate, self).form_valid(form)