def _new_activity_report( request, challenge, reports, top_reporters ): # first get list of existing reporters for dropdown form = ActivityReportForm( request.POST ) if( form.is_valid() ): name = form.cleaned_data['reporter_new_name'] or form.cleaned_data['reporter_existing_name'] query = Reporter.all() query.filter('name =', name ) results = query.fetch(1) if( len( results ) ): reporter = results[0] else: reporter = Reporter( name = name ) reporter.put( ) report = Report( reporter = reporter, challenge = challenge, reported_date = _makeDate( form.cleaned_data['reported_date'] ), flights_up = form.cleaned_data['flights_up'], flights_down = form.cleaned_data['flights_down'] ) report.put() return HttpResponseRedirect(reverse('challenge.views.show_challenge', kwargs={'id':str(challenge.key().id() ) }) ) else: return object_list(request, reports, paginate_by=15, extra_context=locals(), template_name='challenge/activity_report.html' )
def list_reports( request, challenge_id, reporter_id ): challenge = Challenge.get_by_id( int(challenge_id ) ) reporter = Reporter.get_by_id( int(reporter_id) ) reports = challenge.report_set.filter( 'reporter = ', reporter ).order("-reported_date" ) return object_list( request, reports, paginate_by=10, extra_context=locals() )
def spark_line( request, challenge_id, reporter_id ): challenge = Challenge.get_by_id( int( challenge_id ) ) reporter = Reporter.get_by_id( int( reporter_id ) ) return HttpResponseRedirect(reporter.spark_line_url( challenge ) )
def __init__(self, *args, **kwargs): super(ActivityReportForm, self).__init__(*args, **kwargs) self.fields['reporter_existing_name'].choices = [ ('', "--------" ) ] + [ ( reporter.name, reporter.name ) for reporter in Reporter.all() ]