예제 #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