コード例 #1
0
ファイル: report.py プロジェクト: gogogo/gogogo-hk
def submit(request,kind,id):
	"""
	Submit a new report
	"""
	
	kind = "gogogo_" + kind
	if not kind in _supported_model:
		raise Http404
	model = _supported_model[kind]
	
	object = getCachedObjectOr404(model,key_name = id)
	
	report = Report(reference = object)
	message = ""
	
	if request.method == 'POST':
		form = ReportForm(request.POST,instance=report)
		if form.is_valid():
			form.cleaned_data['reference'] = object
			form.save()
			return HttpResponseRedirect(object.get_absolute_url())
		else:
			form.reference = object
	else:
		form = ReportForm(instance=report)
	
	return render_to_response( 
		request,
		'gogogo/db/report/form.html',
		{ "form" : form , 
		"message" : message
		   })		
コード例 #2
0
ファイル: widgets.py プロジェクト: gogogo/gogogo-hk
	def render(self, name, value, attrs=None):
		
		input = super(ReferenceLinkWidget, self).render(name, value, attrs)	
		
		ret = ""
		if value is not None:
			object = getCachedObjectOr404(key = value)
			ret = mark_safe(input + "<a href='%s'>%s</a>" % (object.get_absolute_url() , unicode(object) ))
		
		return ret
コード例 #3
0
ファイル: widgets.py プロジェクト: gogogo/gogogo-hk
    def clean(self, value):
        final_value = None
        if self.required and not value:
            raise forms.ValidationError(_(u'This field is required.'))
        elif not self.required and not value:
            return None
                        
        if isinstance(value,basestring):
            id = id_or_name(value)
            final_value = db.Key.from_path(self.___model_class.kind(),id)

        try:
            object = getCachedObjectOr404(self.___model_class,key = final_value)
        except Http404:
            raise forms.ValidationError(_(u'This record not found.'))            
        
        return final_value
コード例 #4
0
ファイル: widgets.py プロジェクト: gogogo/gogogo-hk
 def render(self, name, value, attrs=None):
     
     object = None
     try:
         if value != None:
             object = getCachedObjectOr404(self.___model_class,key = value)
     except Http404:
         pass
     
     if isinstance(value,db.Key):
         value = value.id_or_name()
     
     input = super(SimpleReferenceWidget, self).render(name, value, attrs)	
     ret = input
     if object:
         ret = mark_safe(input + " <a href='%s'>%s</a>" % (object.get_absolute_url() , unicode(object) ))
     
     return ret