Enable storing of the duplicate calculation results.
Patch by: Lennard de Rijk
Reviewed by: to-be-reviewed
--- 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 @@
</script>
<input type="button" id="id_button_duplicate_slots" onclick="javascript:duplicateSlots.showDuplicatesInit();" class="button" />
<span class="progressBar" style="display:none;" id="duplicates_progress_bar"></span>
-<span id="description_progressbar"></span><span id="description_done"></span>
+<span id="description_progressbar">
+ {% if date_of_calculation %}
+ Duplicates as calculated on: {{ date_of_calculation|date:"jS F Y H:i" }}
+ {% endif %}
+</span>
+
+<span id="description_done"></span>
<br /><br />
<div id="div_duplicate_slots"></div>
--- 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'