Port idtracker/views.py, fixing some bugs in the proxy classes

- Legacy-Id: 3116
This commit is contained in:
Ole Laursen 2011-05-11 18:08:20 +00:00
parent 5422874e3e
commit 8764a1db11
5 changed files with 83 additions and 43 deletions

View file

@ -2,11 +2,12 @@
# Create your views here.
from django.http import HttpResponsePermanentRedirect, Http404
from django.conf import settings
from django.template import RequestContext
from django.shortcuts import get_object_or_404, render_to_response
from django.views.generic.list_detail import object_detail, object_list
from ietf.idtracker.models import InternetDraft, IDInternal, IDState, IDSubState, BallotInfo, DocumentComment
import re
import re, datetime
def state_desc(request, state, is_substate=0):
if int(state) == 100:
@ -27,15 +28,30 @@ IESG to do anything with the document.
context_instance=RequestContext(request))
def status(request):
if settings.USE_DB_REDESIGN_PROXY_CLASSES:
drafts = list(IDInternal.objects.exclude(iesg_state=None).exclude(iesg_state__in=('pub', 'dead', 'watching', 'rfcqueue')).order_by('iesg_state__order'))
drafts.sort(key=lambda d: (d.cur_state_id, d.status_date or datetime.date.min, d.b_sent_date or datetime.date.min))
# sadly we can't use the generic view because it only works with a queryset...
return render_to_response('idtracker/status_of_items.html', dict(object_list=drafts, title="IESG Status of Items"), context_instance=RequestContext(request))
queryset = IDInternal.objects.filter(primary_flag=1).exclude(cur_state__state__in=('RFC Ed Queue', 'RFC Published', 'AD is watching', 'Dead')).order_by('cur_state', 'status_date', 'ballot')
return object_list(request, template_name="idtracker/status_of_items.html", queryset=queryset, extra_context={'title': 'IESG Status of Items'})
def last_call(request):
if settings.USE_DB_REDESIGN_PROXY_CLASSES:
drafts = list(IDInternal.objects.exclude(iesg_state=None).filter(iesg_state__in=('lc', 'writeupw', 'goaheadw')).order_by('iesg_state__order'))
drafts.sort(key=lambda d: (d.cur_state_id, d.status_date or datetime.date.min, d.b_sent_date or datetime.date.min))
# sadly we can't use the generic view because it only works with a queryset...
return render_to_response('idtracker/status_of_items.html', dict(object_list=drafts, title="Documents in Last Call", lastcall=1), context_instance=RequestContext(request))
queryset = IDInternal.objects.filter(primary_flag=1).filter(cur_state__state__in=('In Last Call', 'Waiting for Writeup', 'Waiting for AD Go-Ahead')).order_by('cur_state', 'status_date', 'ballot')
return object_list(request, template_name="idtracker/status_of_items.html", queryset=queryset, extra_context={'title': 'Documents in Last Call', 'lastcall': 1})
def redirect_id(request, object_id):
'''Redirect from historical document ID to preferred filename url.'''
if settings.USE_DB_REDESIGN_PROXY_CLASSES:
raise Http404() # we don't store the numbers anymore
doc = get_object_or_404(InternetDraft, id_document_tag=object_id)
return HttpResponsePermanentRedirect("/doc/"+doc.filename+"/")
@ -46,6 +62,9 @@ def redirect_filename(request, filename):
return HttpResponsePermanentRedirect("/doc/"+filename+"/")
def redirect_ballot(request, object_id):
if settings.USE_DB_REDESIGN_PROXY_CLASSES:
raise Http404() # we don't store the numbers anymore
ballot = get_object_or_404(BallotInfo, pk=object_id)
ids = ballot.drafts.filter(primary_flag=1)
if len(ids) == 0:
@ -57,6 +76,9 @@ def redirect_ballot(request, object_id):
return HttpResponsePermanentRedirect("/doc/"+id.draft.filename+"/#ballot")
def redirect_comment(request, object_id):
if settings.USE_DB_REDESIGN_PROXY_CLASSES:
raise Http404() # we don't store the numbers anymore
comment = get_object_or_404(DocumentComment, pk=object_id)
id = comment.document
if id.rfc_flag:

View file

@ -13,6 +13,7 @@ class InternetDraft(Document):
status=lambda v: ("state", { 1: 'active', 2: 'expired', 3: 'rfc', 4: 'auth-rm', 5: 'repl', 6: 'ietf-rm'}[v]),
job_owner="ad",
rfc_number=lambda v: ("docalias__name", "rfc%s" % v),
cur_state="iesg_state__order",
))
DAYS_TO_EXPIRE=185
@ -324,7 +325,7 @@ class InternetDraft(Document):
#cur_state = models.ForeignKey(IDState, db_column='cur_state', related_name='docs')
@property
def cur_state(self):
return IDState().from_old_object(self.iesg_state)
return IDState().from_object(self.iesg_state) if self.iesg_state else None
@property
def cur_state_id(self):
@ -334,7 +335,7 @@ class InternetDraft(Document):
@property
def prev_state(self):
ds = self.dochistory_set.exclude(iesg_state=self.iesg_state).order_by('-time')[:1]
return IDState().from_old_object(ds[0].iesg_state) if ds else None
return IDState().from_object(ds[0].iesg_state) if ds else None
#assigned_to = models.CharField(blank=True, max_length=25) # unused
@ -360,11 +361,17 @@ class InternetDraft(Document):
#area_acronym = models.ForeignKey(Area)
@property
def area_acronym(self):
if self.group:
return self.group.parent
from group.proxy import Area
g = super(self.__class__, self).group # be careful with group which is proxied
if g and g.type_id != "individ":
return Area().from_object(g.parent)
elif self.ad:
# return area for AD
return ad.role_set.get(type="ad", group__state="active").group
try:
area = Group.objects.get(role__name="ad", role__email=self.ad, state="active")
return Area().from_object(area)
except Group.DoesNotExist:
return None
else:
return None
@ -372,7 +379,7 @@ class InternetDraft(Document):
@property
def cur_sub_state(self):
s = self.tags.filter(slug__in=['extpty', 'need-rev', 'ad-f-up', 'point'])
return IDSubState().from_old_object(s[0]) if s else None
return IDSubState().from_object(s[0]) if s else None
@property
def cur_sub_state_id(self):
s = self.cur_sub_state
@ -383,7 +390,7 @@ class InternetDraft(Document):
def prev_sub_state(self):
ds = self.dochistory_set.all().order_by('-time')[:1]
substates = ds[0].tags.filter(slug__in=['extpty', 'need-rev', 'ad-f-up', 'point']) if ds else None
return IDSubState().from_old_object(substates[0]) if substates else None
return IDSubState().from_object(substates[0]) if substates else None
@property
def prev_sub_state_id(self):
s = self.prev_sub_state
@ -546,7 +553,7 @@ class InternetDraft(Document):
res = []
def add(ad, pos):
from person.proxy import IESGLogin as IESGLoginProxy
res.append(dict(ad=IESGLoginProxy(ad), pos=Position().from_old_object(pos) if pos else None))
res.append(dict(ad=IESGLoginProxy(ad), pos=Position().from_object(pos) if pos else None))
found = set()
for pos in BallotPositionEvent.objects.filter(doc=self, type="changed_ballot_position", ad__in=active_ads).select_related('ad').order_by("-time", "-id"):
@ -755,7 +762,7 @@ class DocumentComment(Event):
class Position(BallotPositionEvent):
def from_old_object(self, base):
def from_object(self, base):
for f in base._meta.fields:
if not f.name in ('discuss',): # don't overwrite properties
setattr(self, f.name, getattr(base, f.name))
@ -816,7 +823,9 @@ class IDState(IesgDocStateName):
DEAD = 99
DO_NOT_PUBLISH_STATES = (33, 34)
def from_old_object(self, base):
objects = TranslatingManager(dict(pk="order"))
def from_object(self, base):
for f in base._meta.fields:
setattr(self, f.name, getattr(base, f.name))
return self
@ -859,14 +868,17 @@ class IDState(IesgDocStateName):
proxy = True
class IDSubStateManager(models.Manager):
class IDSubStateManager(TranslatingManager):
def __init__(self, *args):
super(IDSubStateManager, self).__init__(*args)
def all(self):
return self.filter(slug__in=['extpty', 'need-rev', 'ad-f-up', 'point'])
class IDSubState(DocInfoTagName):
objects = IDSubStateManager()
objects = IDSubStateManager(dict(pk="order"))
def from_old_object(self, base):
def from_object(self, base):
for f in base._meta.fields:
setattr(self, f.name, getattr(base, f.name))
return self

View file

@ -7,9 +7,10 @@ class Acronym(Group):
INDIVIDUAL_SUBMITTER = LazyIndividualSubmitter()
def __init__(self, base):
def from_object(self, base):
for f in base._meta.fields:
setattr(self, f.name, getattr(base, f.name))
return self
#acronym_id = models.AutoField(primary_key=True)
@property
@ -32,11 +33,16 @@ class Acronym(Group):
proxy = True
class Area(Group):
def from_object(self, base):
for f in base._meta.fields:
setattr(self, f.name, getattr(base, f.name))
return self
ACTIVE=1
#area_acronym = models.OneToOneField(Acronym, primary_key=True)
@property
def area_acronym(self):
return Acronym(self)
return Acronym().from_object(self)
#start_date = models.DateField(auto_now_add=True)
#concluded_date = models.DateField(null=True, blank=True)
@ -63,7 +69,7 @@ class IETFWG(Group):
#group_acronym = models.OneToOneField(Acronym, primary_key=True, editable=False)
@property
def group_acronym(self):
return Acronym(self)
return Acronym().from_object(self)
#group_type = models.ForeignKey(WGType)
#proposed_date = models.DateField(null=True, blank=True)

View file

@ -755,7 +755,7 @@ if document_name_to_import:
#all_drafts = all_drafts.none()
for index, o in enumerate(all_drafts.iterator()):
print "importing", o.id_document_tag, o.filename, index
print "importing", o.id_document_tag, o.filename, index, "ballot %s" % o.idinternal.ballot_id if o.idinternal and o.idinternal.ballot_id else ""
try:
d = Document.objects.get(name=o.filename)

View file

@ -40,100 +40,100 @@ class TranslatingQuerySet(QuerySet):
# overridden methods
def _clone(self, *args, **kwargs):
c = super(self.__class__, self)._clone(*args, **kwargs)
c = super(TranslatingQuerySet, self)._clone(*args, **kwargs)
c.translated_attrs = self.translated_attrs
return c
def dates(self, *args, **kwargs):
kwargs = self.translated_kwargs(kwargs)
return super(self.__class__, self).dates(*args, **kwargs)
return super(TranslatingQuerySet, self).dates(*args, **kwargs)
def distinct(self, *args, **kwargs):
kwargs = self.translated_kwargs(kwargs)
return super(self.__class__, self).distinct(*args, **kwargs)
return super(TranslatingQuerySet, self).distinct(*args, **kwargs)
def extra(self, *args, **kwargs):
kwargs = self.translated_kwargs(kwargs)
return super(self.__class__, self).extra(*args, **kwargs)
return super(TranslatingQuerySet, self).extra(*args, **kwargs)
def get(self, *args, **kwargs):
kwargs = self.translated_kwargs(kwargs)
return super(self.__class__, self).get(*args, **kwargs)
return super(TranslatingQuerySet, self).get(*args, **kwargs)
def get_or_create(self, **kwargs):
kwargs = self.translated_kwargs(kwargs)
return super(self.__class__, self).get_or_create(**kwargs)
return super(TranslatingQuerySet, self).get_or_create(**kwargs)
def create(self, **kwargs):
kwargs = self.translated_kwargs(kwargs)
return super(self.__class__, self).create(**kwargs)
return super(TranslatingQuerySet, self).create(**kwargs)
def filter(self, *args, **kwargs):
kwargs = self.translated_kwargs(kwargs)
return super(self.__class__, self).filter(*args, **kwargs)
return super(TranslatingQuerySet, self).filter(*args, **kwargs)
def aggregate(self, *args, **kwargs):
kwargs = self.translated_kwargs(kwargs)
return super(self.__class__, self).aggregate(*args, **kwargs)
return super(TranslatingQuerySet, self).aggregate(*args, **kwargs)
def annotate(self, *args, **kwargs):
kwargs = self.translated_kwargs(kwargs)
return super(self.__class__, self).annotate(*args, **kwargs)
return super(TranslatingQuerySet, self).annotate(*args, **kwargs)
def complex_filter(self, *args, **kwargs):
kwargs = self.translated_kwargs(kwargs)
return super(self.__class__, self).complex_filter(*args, **kwargs)
return super(TranslatingQuerySet, self).complex_filter(*args, **kwargs)
def exclude(self, *args, **kwargs):
kwargs = self.translated_kwargs(kwargs)
return super(self.__class__, self).exclude(*args, **kwargs)
return super(TranslatingQuerySet, self).exclude(*args, **kwargs)
def in_bulk(self, *args, **kwargs):
kwargs = self.translated_kwargs(kwargs)
return super(self.__class__, self).in_bulk(*args, **kwargs)
return super(TranslatingQuerySet, self).in_bulk(*args, **kwargs)
def iterator(self, *args, **kwargs):
kwargs = self.translated_kwargs(kwargs)
return super(self.__class__, self).iterator(*args, **kwargs)
return super(TranslatingQuerySet, self).iterator(*args, **kwargs)
def latest(self, *args, **kwargs):
kwargs = self.translated_kwargs(kwargs)
return super(self.__class__, self).latest(*args, **kwargs)
return super(TranslatingQuerySet, self).latest(*args, **kwargs)
def order_by(self, *args, **kwargs):
args = self.translated_args(args)
kwargs = self.translated_kwargs(kwargs)
return super(self.__class__, self).order_by(*args, **kwargs)
return super(TranslatingQuerySet, self).order_by(*args, **kwargs)
def select_related(self, *args, **kwargs):
kwargs = self.translated_kwargs(kwargs)
return super(self.__class__, self).select_related(*args, **kwargs)
return super(TranslatingQuerySet, self).select_related(*args, **kwargs)
def values(self, *args, **kwargs):
args = self.translated_args(args)
kwargs = self.translated_kwargs(kwargs)
return super(self.__class__, self).values(*args, **kwargs)
return super(TranslatingQuerySet, self).values(*args, **kwargs)
def values_list(self, *args, **kwargs):
args = self.translated_args(args)
kwargs = self.translated_kwargs(kwargs)
return super(self.__class__, self).values_list(*args, **kwargs)
return super(TranslatingQuerySet, self).values_list(*args, **kwargs)
def update(self, *args, **kwargs):
kwargs = self.translated_kwargs(kwargs)
return super(self.__class__, self).update(*args, **kwargs)
return super(TranslatingQuerySet, self).update(*args, **kwargs)
def reverse(self, *args, **kwargs):
kwargs = self.translated_kwargs(kwargs)
return super(self.__class__, self).reverse(*args, **kwargs)
return super(TranslatingQuerySet, self).reverse(*args, **kwargs)
def defer(self, *args, **kwargs):
kwargs = self.translated_kwargs(kwargs)
return super(self.__class__, self).defer(*args, **kwargs)
return super(TranslatingQuerySet, self).defer(*args, **kwargs)
def only(self, *args, **kwargs):
kwargs = self.translated_kwargs(kwargs)
return super(self.__class__, self).only(*args, **kwargs)
return super(TranslatingQuerySet, self).only(*args, **kwargs)
def _insert(self, values, **kwargs):
kwargs = self.translated_kwargs(kwargs)
@ -141,7 +141,7 @@ class TranslatingQuerySet(QuerySet):
def _update(self, values, **kwargs):
kwargs = self.translated_kwargs(kwargs)
return super(self.__class__, self)._update(values, **kwargs)
return super(TranslatingQuerySet, self)._update(values, **kwargs)
class TranslatingManager(Manager):
"""Translates keyword arguments for the ORM, for use in proxy
@ -151,7 +151,7 @@ class TranslatingManager(Manager):
with the right-hand side to transform it."""
def __init__(self, trans):
super(self.__class__, self).__init__()
super(TranslatingManager, self).__init__()
self.translated_attrs = trans
def get_query_set(self):