Index: /main/waeup.kofa/branches/uli-scores-upload/src/waeup/kofa/students/viewlets.py
===================================================================
--- /main/waeup.kofa/branches/uli-scores-upload/src/waeup/kofa/students/viewlets.py	(revision 13914)
+++ /main/waeup.kofa/branches/uli-scores-upload/src/waeup/kofa/students/viewlets.py	(revision 13915)
@@ -18,14 +18,11 @@
 import grok
 from zope.component import getUtility
+from zope.i18n import translate
 from zope.interface import Interface
-from zope.i18n import translate
-from waeup.kofa.interfaces import IExtFileStore, IKofaObject
-from waeup.kofa.interfaces import MessageFactory as _
+from waeup.kofa.browser.layout import default_primary_nav_template
 from waeup.kofa.browser.viewlets import (
     PrimaryNavTab, ManageActionButton, AddActionButton)
-from waeup.kofa.browser.layout import default_primary_nav_template
-from waeup.kofa.students.workflow import (
-    ADMITTED, PAID, REQUESTED, RETURNING, CLEARED, REGISTERED,
-    VALIDATED, GRADUATED, TRANSCRIPT)
+from waeup.kofa.interfaces import MessageFactory as _
+from waeup.kofa.interfaces import IExtFileStore, IKofaObject
 from waeup.kofa.students.browser import (
     StudentsContainerPage,
@@ -42,7 +39,11 @@
     IStudentPaymentsContainer, IStudentsUtils
     )
+from waeup.kofa.students.workflow import (
+    ADMITTED, PAID, REQUESTED, RETURNING, CLEARED, REGISTERED,
+    VALIDATED, GRADUATED, TRANSCRIPT)
 from waeup.kofa.university.interfaces import ICourse
 
-grok.context(IKofaObject) # Make IKofaObject the default context
+
+grok.context(IKofaObject)  # Make IKofaObject the default context
 grok.templatedir('browser_templates')
 
@@ -50,4 +51,5 @@
 class StudentManageSidebar(grok.ViewletManager):
     grok.name('left_studentmanage')
+
 
 class StudentManageLink(grok.Viewlet):
@@ -70,10 +72,11 @@
         # Here we know that the cookie has been set
         lang = self.request.cookies.get('kofa.language')
-        text = translate(self.text, 'waeup.kofa',
-            target_language=lang)
+        text = translate(
+            self.text, 'waeup.kofa', target_language=lang)
         if not self.link:
             return ''
         return u'<li><a href="%s">%s</a></li>' % (
-                url, text)
+            url, text)
+
 
 class StudentManageApplicationLink(StudentManageLink):
@@ -87,10 +90,11 @@
         if slip:
             lang = self.request.cookies.get('kofa.language')
-            text = translate(self.text, 'waeup.kofa',
-                target_language=lang)
-            url = self.view.url(self.context.student,self.link)
+            text = translate(
+                self.text, 'waeup.kofa', target_language=lang)
+            url = self.view.url(self.context.student, self.link)
             return u'<li><a href="%s">%s</a></li>' % (
-                    url, text)
+                url, text)
         return ''
+
 
 class StudentManageBaseLink(StudentManageLink):
@@ -98,4 +102,5 @@
     link = 'index'
     text = _(u'Base Data')
+
 
 class StudentManageClearanceLink(StudentManageLink):
@@ -105,4 +110,5 @@
     text = _(u'Clearance Data')
 
+
 class StudentManagePersonalLink(StudentManageLink):
     grok.order(4)
@@ -111,8 +117,10 @@
     text = _(u'Personal Data')
 
+
 class StudentManageStudyCourseLink(StudentManageLink):
     grok.order(5)
     link = 'studycourse'
     text = _(u'Study Course')
+
 
 class StudentManagePaymentsLink(StudentManageLink):
@@ -121,4 +129,5 @@
     link = 'payments'
     text = _(u'Payments')
+
 
 class StudentManageAccommodationLink(StudentManageLink):
@@ -129,4 +138,5 @@
     text = _(u'Accommodation')
 
+
 class StudentManageHistoryLink(StudentManageLink):
     grok.order(8)
@@ -142,4 +152,5 @@
     text = _('Manage students section')
 
+
 class StudentsContainerAddActionButton(AddActionButton):
     grok.order(1)
@@ -149,4 +160,5 @@
     text = _('Add student')
     target = 'addstudent'
+
 
 class ContactActionButton(ManageActionButton):
@@ -159,4 +171,5 @@
     target = 'contactstudent'
 
+
 class StudentBaseManageActionButton(ManageActionButton):
     grok.order(1)
@@ -166,4 +179,5 @@
     text = _('Manage')
     target = 'manage_base'
+
 
 class StudentTrigTransActionButton(ManageActionButton):
@@ -176,4 +190,5 @@
     target = 'trigtrans'
 
+
 class StudentLoginAsActionButton(ManageActionButton):
     grok.order(3)
@@ -185,4 +200,5 @@
     target = 'loginasstep1'
 
+
 class AdmissionSlipActionButton(ManageActionButton):
     grok.order(4)
@@ -194,4 +210,5 @@
     target = 'admission_slip.pdf'
 
+
 class StudentTransferButton(ManageActionButton):
     grok.order(6)
@@ -203,4 +220,5 @@
     icon = 'actionicon_redo.png'
 
+
 class StudentDeactivateActionButton(ManageActionButton):
     grok.order(7)
@@ -223,4 +241,5 @@
             "'A history message will be added. Are you sure?'")
 
+
 class StudentActivateActionButton(ManageActionButton):
     grok.order(7)
@@ -243,4 +262,5 @@
             "'A history message will be added. Are you sure?'")
 
+
 class StudentClearanceManageActionButton(ManageActionButton):
     grok.order(1)
@@ -250,4 +270,5 @@
     text = _('Manage')
     target = 'manage_clearance'
+
 
 class StudentClearActionButton(ManageActionButton):
@@ -262,5 +283,6 @@
     @property
     def target_url(self):
-        cdm = getUtility(IStudentsUtils).clearance_disabled_message(self.context)
+        cdm = getUtility(
+            IStudentsUtils).clearance_disabled_message(self.context)
         if cdm:
             return ''
@@ -268,4 +290,5 @@
             return ''
         return self.view.url(self.view.context, self.target)
+
 
 class StudentRejectClearanceActionButton(ManageActionButton):
@@ -280,5 +303,6 @@
     @property
     def target_url(self):
-        cdm = getUtility(IStudentsUtils).clearance_disabled_message(self.context)
+        cdm = getUtility(
+            IStudentsUtils).clearance_disabled_message(self.context)
         if cdm:
             return ''
@@ -286,4 +310,5 @@
             return ''
         return self.view.url(self.view.context, self.target)
+
 
 class ClearanceSlipActionButton(ManageActionButton):
@@ -296,4 +321,5 @@
     target = 'clearance_slip.pdf'
 
+
 class ClearanceViewActionButton(ManageActionButton):
     grok.order(1)
@@ -305,4 +331,5 @@
     target = 'view_clearance'
 
+
 class PersonalViewActionButton(ManageActionButton):
     grok.order(1)
@@ -314,4 +341,5 @@
     target = 'view_personal'
 
+
 class StudentPersonalManageActionButton(ManageActionButton):
     grok.order(1)
@@ -322,4 +350,5 @@
     target = 'manage_personal'
 
+
 class StudentPersonalEditActionButton(ManageActionButton):
     grok.order(2)
@@ -329,4 +358,5 @@
     text = _('Edit')
     target = 'edit_personal'
+
 
 class StudyCourseManageActionButton(ManageActionButton):
@@ -343,4 +373,5 @@
             return self.view.url(self.view.context, self.target)
         return False
+
 
 class StudyCourseTranscriptActionButton(ManageActionButton):
@@ -359,4 +390,5 @@
         return False
 
+
 class TranscriptSlipActionButton(ManageActionButton):
     grok.order(1)
@@ -374,4 +406,5 @@
         return False
 
+
 class RevertTransferActionButton(ManageActionButton):
     grok.order(1)
@@ -389,4 +422,5 @@
         return False
 
+
 class StudyLevelManageActionButton(ManageActionButton):
     grok.order(1)
@@ -403,4 +437,5 @@
             return ''
         return self.view.url(self.view.context, self.target)
+
 
 class StudentValidateCoursesActionButton(ManageActionButton):
@@ -415,10 +450,12 @@
     @property
     def target_url(self):
-        is_current = self.context.__parent__.is_current
-        if self.context.student.state != REGISTERED or \
-            str(self.context.__parent__.current_level) != self.context.__name__ or\
-            not is_current:
-            return ''
-        return self.view.url(self.view.context, self.target)
+        if not self.context.__parent__.is_current:
+            return ''
+        if self.context.student.state != REGISTERED:
+            return ''
+        if str(self.context.__parent__.current_level) != self.context.__name__:
+            return ''
+        return self.view.url(self.view.context, self.target)
+
 
 class StudentRejectCoursesActionButton(ManageActionButton):
@@ -433,10 +470,12 @@
     @property
     def target_url(self):
-        is_current = self.context.__parent__.is_current
-        if self.context.student.state not in (VALIDATED, REGISTERED) or \
-            str(self.context.__parent__.current_level) != self.context.__name__ or\
-            not is_current:
-            return ''
-        return self.view.url(self.view.context, self.target)
+        if not self.context.__parent__.is_current:
+            return ''
+        if self.context.student.state not in (VALIDATED, REGISTERED):
+            return ''
+        if str(self.context.__parent__.current_level) != self.context.__name__:
+            return ''
+        return self.view.url(self.view.context, self.target)
+
 
 class StudentUnregisterCoursesActionButton(ManageActionButton):
@@ -451,10 +490,12 @@
     @property
     def target_url(self):
-        is_current = self.context.__parent__.is_current
-        if self.context.student.state != REGISTERED or \
-            str(self.context.__parent__.current_level) != self.context.__name__ or\
-            not is_current:
-            return ''
-        return self.view.url(self.view.context, self.target)
+        if not self.context.__parent__.is_current:
+            return ''
+        if self.context.student.state != REGISTERED:
+            return ''
+        if str(self.context.__parent__.current_level) != self.context.__name__:
+            return ''
+        return self.view.url(self.view.context, self.target)
+
 
 class CourseRegistrationSlipActionButton(ManageActionButton):
@@ -474,4 +515,5 @@
         return self.view.url(self.view.context, self.target)
 
+
 class CourseTicketManageActionButton(ManageActionButton):
     grok.order(1)
@@ -482,14 +524,7 @@
     target = 'manage'
 
-#class OnlinePaymentManageActionButton(ManageActionButton):
-#    grok.order(1)
-#    grok.context(IStudentPaymentsContainer)
-#    grok.view(PaymentsDisplayFormPage)
-#    grok.require('waeup.manageStudent')
-#    text = 'Manage payments'
-#    target = 'manage'
 
 class PaymentReceiptActionButton(ManageActionButton):
-    grok.order(9) # This button should always be the last one.
+    grok.order(9)  # This button should always be the last one.
     grok.context(IStudentOnlinePayment)
     grok.view(OnlinePaymentDisplayFormPage)
@@ -504,4 +539,5 @@
         #    return ''
         return self.view.url(self.view.context, self.target)
+
 
 class ApprovePaymentActionButton(ManageActionButton):
@@ -520,4 +556,5 @@
         return self.view.url(self.view.context, self.target)
 
+
 class BedTicketSlipActionButton(ManageActionButton):
     grok.order(1)
@@ -529,4 +566,5 @@
     target = 'bed_allocation_slip.pdf'
 
+
 class RelocateStudentActionButton(ManageActionButton):
     grok.order(2)
@@ -538,4 +576,5 @@
     target = 'relocate'
 
+
 class StudentBaseActionButton(ManageActionButton):
     grok.order(1)
@@ -545,4 +584,5 @@
     text = _('Edit')
     target = 'edit_base'
+
 
 class StudentPasswordActionButton(ManageActionButton):
@@ -555,4 +595,5 @@
     target = 'change_password'
 
+
 class StudentPassportActionButton(ManageActionButton):
     grok.order(3)
@@ -566,8 +607,10 @@
     @property
     def target_url(self):
-        PORTRAIT_CHANGE_STATES = getUtility(IStudentsUtils).PORTRAIT_CHANGE_STATES
+        PORTRAIT_CHANGE_STATES = getUtility(
+            IStudentsUtils).PORTRAIT_CHANGE_STATES
         if self.context.state not in PORTRAIT_CHANGE_STATES:
             return ''
         return self.view.url(self.view.context, self.target)
+
 
 class StudentClearanceStartActionButton(ManageActionButton):
@@ -586,4 +629,5 @@
         return self.view.url(self.view.context, self.target)
 
+
 class StudentClearanceEditActionButton(ManageActionButton):
     grok.order(1)
@@ -599,4 +643,5 @@
             return ''
         return self.view.url(self.view.context, self.target)
+
 
 class StartSessionActionButton(ManageActionButton):
@@ -614,4 +659,5 @@
             return self.view.url(self.view.context, self.target)
         return False
+
 
 class AddStudyLevelActionButton(AddActionButton):
@@ -633,4 +679,5 @@
             return ''
         return self.view.url(self.view.context, self.target)
+
 
 class StudyLevelEditActionButton(ManageActionButton):
@@ -652,4 +699,5 @@
         return ''
 
+
 class AddPaymentActionButton(AddActionButton):
     grok.order(1)
@@ -659,4 +707,5 @@
     text = _('Add current session payment ticket')
     target = 'addop'
+
 
 class AddPreviousPaymentActionButton(AddActionButton):
@@ -676,4 +725,5 @@
         return self.view.url(self.view.context, self.target)
 
+
 class AddBalancePaymentActionButton(AddActionButton):
     grok.order(3)
@@ -691,4 +741,5 @@
         return self.view.url(self.view.context, self.target)
 
+
 class RequestTranscriptActionButton(ManageActionButton):
     grok.order(8)
@@ -705,4 +756,5 @@
             return ''
         return self.view.url(self.view.context, self.target)
+
 
 class ProcessTranscriptRequestActionButton(ManageActionButton):
@@ -721,8 +773,8 @@
         return self.view.url(self.view.context, self.target)
 
+
 class StudentsTab(PrimaryNavTab):
     """Students tab in primary navigation.
     """
-
     grok.context(IKofaObject)
     grok.order(4)
@@ -737,8 +789,10 @@
         return self.view.application_url('students')
 
+
 class PrimaryStudentNavManager(grok.ViewletManager):
     """Viewlet manager for the primary navigation tab.
     """
     grok.name('primary_nav_student')
+
 
 class PrimaryStudentNavTab(grok.Viewlet):
@@ -764,4 +818,5 @@
             return 'active'
         return ''
+
 
 class MyStudentDataTab(PrimaryStudentNavTab):
@@ -790,18 +845,20 @@
         targets = []
         if app_slip:
-            targets = [{'url':student_url + '/application_slip',
-                        'title':_('Application Slip')},]
+            targets = [{'url': student_url + '/application_slip',
+                        'title': _('Application Slip')}, ]
         targets += [
-            {'url':student_url, 'title':'Base Data'},
-            {'url':student_url + '/view_clearance',
-             'title':_('Clearance Data')},
-            {'url':student_url + '/view_personal', 'title':_('Personal Data')},
-            {'url':student_url + '/studycourse', 'title':_('Study Course')},
-            {'url':student_url + '/payments', 'title':_('Payments')},
-            {'url':student_url + '/accommodation',
-             'title':_('Accommodation Data')},
-            {'url':student_url + '/history', 'title':_('History')},
+            {'url': student_url, 'title': 'Base Data'},
+            {'url': student_url + '/view_clearance',
+             'title': _('Clearance Data')},
+            {'url': student_url + '/view_personal',
+             'title': _('Personal Data')},
+            {'url': student_url + '/studycourse', 'title': _('Study Course')},
+            {'url': student_url + '/payments', 'title': _('Payments')},
+            {'url': student_url + '/accommodation',
+             'title': _('Accommodation Data')},
+            {'url': student_url + '/history', 'title': _('History')},
             ]
         return targets
+
 
 class DownloadCSVFileActionButton(ManageActionButton):
@@ -817,4 +874,5 @@
     grok.order(1)
 
+
 class DownloadTicketOverviewActionButton(ManageActionButton):
     """ 'Download ticket overview' button for courses.
