Refactor slightly to make views_doc.py independent of other idrfc code

- Legacy-Id: 5294
This commit is contained in:
Ole Laursen 2013-01-18 10:32:05 +00:00
parent 3e8de2a43f
commit 1a3aa3b443
5 changed files with 19 additions and 29 deletions

View file

@ -220,10 +220,16 @@ def add_state_change_event(doc, by, prev_state, new_state, timestamp=None):
e.save()
return e
def prettify_std_name(n):
if re.match(r"(rfc|bcp|fyi|std)[0-9]{4}", n):
return n[:3].upper() + " " + n[3:]
else:
return n
def nice_consensus(consensus):
mapping = {
None: "Unknown",
True: "Yes",
False: "No"
}
return mapping[consensus]

View file

@ -177,19 +177,3 @@ def update_telechatREDESIGN(request, doc, by, new_telechat_date, new_returning_i
if settings.USE_DB_REDESIGN_PROXY_CLASSES:
update_telechat = update_telechatREDESIGN
def can_edit_intended_std_level(user, doc):
return user.is_authenticated() and (
has_role(user, ["Secretariat", "Area Director"]) or is_authorized_in_doc_stream(user, doc))
def can_edit_consensus(user, doc):
return user.is_authenticated() and (
has_role(user, ["Secretariat", "Area Director"]) or is_authorized_in_doc_stream(user, doc))
def nice_consensus(consensus):
mapping = {
None: "Unknown",
True: "Yes",
False: "No"
}
return mapping[consensus]

View file

@ -43,7 +43,6 @@ from django.middleware.gzip import GZipMiddleware
from django.core.urlresolvers import reverse as urlreverse, NoReverseMatch
from django.conf import settings
from ietf.idrfc.utils import *
from ietf.doc.models import *
from ietf.doc.utils import *
from ietf.utils.history import find_history_active_at
@ -140,10 +139,11 @@ def document_main(request, name, rev=None):
can_edit = has_role(request.user, ("Area Director", "Secretariat"))
stream_slugs = StreamName.objects.values_list("slug", flat=True)
can_change_stream = bool(can_edit or (request.user.is_authenticated() and
Role.objects.filter(name__in=("chair", "auth"),
group__acronym__in=stream_slugs,
person__user=request.user)))
can_change_stream = bool(can_edit or (
request.user.is_authenticated() and
Role.objects.filter(name__in=("chair", "auth"),
group__acronym__in=stream_slugs,
person__user=request.user)))
can_edit_iana_state = has_role(request.user, ("Secretariat", "IANA"))
rfc_number = name[3:] if name.startswith("") else None
@ -313,8 +313,6 @@ def document_main(request, name, rev=None):
can_change_stream=can_change_stream,
can_edit_stream_info=can_edit_stream_info,
can_edit_shepherd_writeup=can_edit_shepherd_writeup,
can_edit_intended_std_level=can_edit_intended_std_level(request.user, doc),
can_edit_consensus=can_edit_consensus(request.user, doc),
can_edit_iana_state=can_edit_iana_state,
rfc_number=rfc_number,
@ -644,7 +642,7 @@ def get_ballot(name):
from ietf.doc.models import DocAlias
alias = get_object_or_404(DocAlias, name=name)
d = alias.document
from ietf.idtracker.models import InternetDraft
from ietf.idtracker.models import InternetDraft, BallotInfo
from ietf.idrfc.idrfc_wrapper import BallotWrapper, IdWrapper, RfcWrapper
id = None
bw = None

View file

@ -271,7 +271,8 @@ def change_intention(request, name):
if doc.type_id != 'draft':
raise Http404
if not can_edit_intended_std_level(request.user, doc):
if not (has_role(request.user, ("Secretariat", "Area Director"))
or is_authorized_in_doc_stream(request.user, doc)):
return HttpResponseForbidden("You do not have the necessary permissions to view this page")
login = request.user.get_profile()
@ -902,7 +903,8 @@ def edit_consensus(request, name):
doc = get_object_or_404(Document, type="draft", name=name)
if not can_edit_consensus(request.user, doc):
if not (has_role(request.user, ("Secretariat", "Area Director"))
or is_authorized_in_doc_stream(request.user, doc)):
return HttpResponseForbidden("You do not have the necessary permissions to view this page")
e = doc.latest_event(ConsensusDocEvent, type="changed_consensus")

View file

@ -62,7 +62,7 @@
<tr>
<td>Intended RFC status:</td>
<td>
<a {% if can_edit %}class="editlink" href="{% url doc_change_intended_status name=doc.name %}"{% endif %}>
<a {% if can_edit or can_edit_stream_info %}class="editlink" href="{% url doc_change_intended_status name=doc.name %}"{% endif %}>
{{ doc.intended_std_level|default:"Unknown" }}</a>
</td>
</tr>
@ -110,7 +110,7 @@
<tr>
<td>Consensus:</td>
<td>
<a title="Whether the document is the result of a community consensus process as defined in RFC 5741" {% if can_edit_consensus %}class="editlink" href="{% url doc_edit_consensus name=doc.name %}"{% endif %}>
<a title="Whether the document is the result of a community consensus process as defined in RFC 5741" {% if can_edit or can_edit_stream_info %}class="editlink" href="{% url doc_edit_consensus name=doc.name %}"{% endif %}>
{{ consensus }}
</a>
</td>