refactored close_open_ballots, creating a way to close one abllot at a time. rewrote the clear ballot code to close each open ballot and open a new one

- Legacy-Id: 4885
This commit is contained in:
Robert Sparks 2012-09-27 21:41:11 +00:00
parent 27186d111e
commit b3bdbc9506
2 changed files with 16 additions and 15 deletions

View file

@ -74,20 +74,23 @@ def needed_ballot_positions(doc, active_positions):
return " ".join(answer)
def create_ballot_if_not_open(doc, by, ballot_type_slug):
if not doc.ballot_open(ballot_type_slug):
def create_ballot_if_not_open(doc, by, ballot_slug):
if not doc.ballot_open(ballot_slug):
e = BallotDocEvent(type="created_ballot", by=by, doc=doc)
e.ballot_type = BallotType.objects.get(doc_type=doc.type, slug=ballot_type_slug)
e.ballot_type = BallotType.objects.get(doc_type=doc.type, slug=ballot_slug)
e.desc = u'Created "%s" ballot' % e.ballot_type.name
e.save()
def close_ballot(doc, by, ballot_slug):
if doc.ballot_open(ballot_slug):
e = BallotDocEvent(type="closed_ballot", doc=doc, by=by)
e.ballot_type = BallotType.objects.get(doc_type=doc.type,slug=ballot_slug)
e.desc = 'Closed "%s" ballot' % e.ballot_type.name
e.save()
def close_open_ballots(doc, by):
for t in BallotType.objects.filter(doc_type=doc.type_id):
if doc.ballot_open(t.slug):
e = BallotDocEvent(type="closed_ballot", doc=doc, by=by)
e.ballot_type = t
e.desc = 'Closed "%s" ballot' % t.name
e.save()
close_ballot(doc, by, t.slug )
def augment_with_start_time(docs):
"""Add a started_time attribute to each document with the time of

View file

@ -385,15 +385,13 @@ if settings.USE_DB_REDESIGN_PROXY_CLASSES:
@group_required('Secretariat')
def clear_ballot(request, name):
"""Clear all positions and discusses. This is actually accomplished by creating a new
started_iesg_process DocEvent."""
"""Clear all positions and discusses on every open ballot for a document."""
doc = get_object_or_404(Document, name=name)
if request.method == 'POST':
DocEvent.objects.create(type='started_iesg_process',
doc=doc,
by=request.user.get_profile(),
desc='cleared_ballot')
by = request.user.get_profile()
for t in BallotType.objects.filter(doc_type=doc.type_id):
close_ballot(doc, by, t.slug)
create_ballot_if_not_open(doc, by, t.slug)
return HttpResponseRedirect(urlreverse("doc_view", kwargs=dict(name=doc.name)))
return render_to_response('idrfc/clear_ballot.html',