Commits

Anonymous committed e01693a

Fix _get_current_signoff (flag index changed) and add Snapshot for tests (r=pike)

  • Participants
  • Parent commits 6d1b51f

Comments (0)

Files changed (3)

signoff/models.py

 from django.db import models
 from django.forms import ModelForm, Select
 from django.contrib.auth.models import User
-
+from l10nstats.models import Run
 from life.models import Tree, Locale, Push
 
 from datetime import datetime
     def __unicode__(self):
         return '%s action for [Signoff %s] by %s [%s]' % (self.get_flag_display(), self.signoff.id, self.author, self.when)
 
+TEST_CHOICES = (
+    (0, Run),
+)
+
+class SnapshotManager(models.Manager):
+    def create(self, **kwargs):
+        if 'test' in kwargs and not isinstance(kwargs['test'], int):
+            for i in TEST_CHOICES:
+                kwargs['test']=i[0]
+                break
+        super(SnapshotManager, self).create(**kwargs)
+
+class Snapshot(models.Model):
+    signoff = models.ForeignKey(Signoff)
+    test = models.IntegerField(choices=TEST_CHOICES)
+    tid = models.IntegerField()
+    objects = SnapshotManager()
+
+    def instance(self):
+        for i in TEST_CHOICES:
+            if i[0]==self.test:
+                return i[1].objects.get(id=self.tid)
 
 STATUS_CHOICES = (
     (0, 'upcoming'),

signoff/templates/signoff/pushes.html

 #pushes tr:not(.date) td.current.accepted {
  background-color: #99ff99 !important;
 }
-#pushes tr:not(.date) td.current.accepted {
+#pushes tr:not(.date) td.current.rejected {
  background-color: #ff0000 !important;
 }
 #pushes tr:not(.date) td.current.obsoleted {
 from django.template import RequestContext
 from django.http import HttpResponseRedirect, HttpResponse
 from life.models import Locale, Push, Tree
-from signoff.models import Milestone, Signoff, AppVersion, Action, SignoffForm, ActionForm
+from signoff.models import Milestone, Signoff, Snapshot, AppVersion, Action, SignoffForm, ActionForm
 from l10nstats.models import Run
 from django import forms
 from django.conf import settings
                 form = SignoffForm(request.POST, instance=instance)
                 if form.is_valid():
                     form.save()
+                    
+                    #add a snapshot of the current test results
+                    pushobj = Push.objects.get(id=request.POST['push'])
+                    lastrun = _get_compare_locales_result(pushobj.tip, mstone.appver.tree)
+                    if lastrun:
+                        Snapshot.objects.create(signoff_id=form.instance.id, test=Run, tid=lastrun.id)
+
                     request.session['signoff_info'] = '<span style="font-style: italic">Signoff for %s %s by %s</span> added' % (mstone, locale, user.username)
                 else:
                     request.session['signoff_error'] = '<span style="font-style: italic">Signoff for %s %s by %s</span> could not be added' % (mstone, locale, user.username)
     else:
         return Push.objects.count()
 
+def _get_compare_locales_result(rev, tree):
+        try:
+            return Run.objects.filter(revisions=rev,
+                                      tree=tree).order_by('-build__id')[0]
+        except:
+            return None
+
 def _get_api_items(locale=None, mstone=None, current=None, start=0, offset=10):
     if mstone:
         forest = mstone.appver.tree.l10n
         repo_url = '%s%s/' % (forest.url, locale.code) 
-        print repo_url
         pushobjs = Push.objects.filter(changesets__repository__url=repo_url).order_by('-push_date')[start:start+offset]
     else:
         pushobjs = Push.objects.order_by('-push_date')[start:start+offset]
                     s.appversion_id=%s AND s.locale_id=%s GROUP BY a.signoff_id ORDER BY a.id DESC;", [ms.appver.id, locale.id])
     items = cursor.fetchall()
     for item in items:
-        if item[0] is not 0:
+        if item[0] is not 1:
             # if action.flag is not Accepted, skip
             continue
         return Signoff.objects.get(pk=item[1])