# HG changeset patch # User Lennard de Rijk # Date 1238701228 0 # Node ID b4375ec63de582320818931e2958d2007dee040f # Parent 4df153b8424c5c321a3dbc497067bc6944896d91 Enable storing of the duplicate calculation results. Patch by: Lennard de Rijk Reviewed by: to-be-reviewed diff -r 4df153b8424c -r b4375ec63de5 app/soc/templates/soc/program/show_duplicates.html --- a/app/soc/templates/soc/program/show_duplicates.html Thu Apr 02 19:38:49 2009 +0000 +++ b/app/soc/templates/soc/program/show_duplicates.html Thu Apr 02 19:40:28 2009 +0000 @@ -55,7 +55,13 @@ - + + {% if date_of_calculation %} + Duplicates as calculated on: {{ date_of_calculation|date:"jS F Y H:i" }} + {% endif %} + + +

diff -r 4df153b8424c -r b4375ec63de5 app/soc/views/models/program.py --- a/app/soc/views/models/program.py Thu Apr 02 19:38:49 2009 +0000 +++ b/app/soc/views/models/program.py Thu Apr 02 19:40:28 2009 +0000 @@ -376,8 +376,21 @@ from django.utils import simplejson + from soc.logic.models.proposal_duplicates import logic as duplicates_logic + program_entity = program_logic.logic.getFromKeyFieldsOr404(kwargs) + if request.POST and request.POST.get('result'): + # store result in the datastore + fields = {'link_id': program_entity.link_id, + 'scope': program_entity, + 'scope_path': program_entity.key().name(), + 'json_representation' : request.POST['result'] + } + key_name = duplicates_logic.getKeyNameFromFields(fields) + duplicates_logic.updateOrCreateFromKeyName(fields, key_name) + return http.HttpResponse('Done') + context = helper.responses.getUniversalContext(request) helper.responses.useJavaScript(context, params['js_uses_all']) context['uses_duplicates'] = True @@ -396,10 +409,19 @@ 'program_key': program_entity.key().name()} json = simplejson.dumps(to_json) context['info'] = json + context['offset_length'] = 10 - # TODO(ljvderijk) cache the result of the duplicate calculation - context['duplicate_cache_content'] = simplejson.dumps({}) - context['offset_length'] = 10 + fields = {'link_id': program_entity.link_id, + 'scope': program_entity} + duplicates = duplicates_logic.getForFields(fields, unique=True) + + if duplicates: + # we have stored information + context['duplicate_cache_content'] = duplicates.json_representation + context['date_of_calculation'] = duplicates.calculated_on + else: + # no information stored + context['duplicate_cache_content'] = simplejson.dumps({}) template = 'soc/program/show_duplicates.html'