Changeset 13201


Ignore:
Timestamp:
16 Aug 2015, 05:06:02 (9 years ago)
Author:
Henrik Bettermann
Message:

Remove duplicate code.

Location:
main/waeup.kofa/trunk/src/waeup/kofa
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.kofa/trunk/src/waeup/kofa/browser/pages.py

    r13199 r13201  
    260260            return True
    261261    return False
     262
     263def exports_not_allowed(view):
     264    """Return flash message if exports are not allowed.
     265    """
     266    utils = queryUtility(IKofaUtils)
     267    if utils.export_disabled_message():
     268        view.entries = doll_up(view, user=None)
     269        return utils.export_disabled_message()
     270    if not utils.expensive_actions_allowed():
     271        view.entries = doll_up(view, user=None)
     272        return _("Currently, exporters cannot be started due to high "
     273                 "system load. Please try again later.")
     274    if running_jobs(view):
     275        view.entries = doll_up(view, user=None)
     276        return _("Sorry, another export job is running. "
     277                 "Please try again later.")
     278    return
    262279
    263280def getImporters(context):
     
    17551772            return
    17561773        if CREATE:
    1757             utils = queryUtility(IKofaUtils)
    1758             if utils.export_disabled_message():
    1759                 self.flash(utils.export_disabled_message(), type='danger')
    1760                 self.entries = doll_up(self, user=None)
    1761                 return
    1762             if not utils.expensive_actions_allowed():
    1763                 self.flash(_(
    1764                     "Currently, exporters cannot be started due to high "
    1765                     "system load. Please try again later."), type='danger')
    1766                 self.entries = doll_up(self, user=None)
    1767                 return
    1768             if running_jobs(self):
    1769                 self.flash(_(
    1770                     "Sorry, another export job is running. "
    1771                     "Please try again later."), type='danger')
    1772                 self.entries = doll_up(self, user=None)
    1773                 return
     1774            ena = exports_not_allowed(self)
     1775            if ena:
     1776                self.flash(ena, type='danger')
     1777                return
    17741778            job_id = self.context.start_export_job(
    17751779                exporter, self.request.principal.id)
  • main/waeup.kofa/trunk/src/waeup/kofa/students/browser.py

    r13200 r13201  
    3939from waeup.kofa.browser.breadcrumbs import Breadcrumb
    4040from waeup.kofa.browser.pages import (
    41     ContactAdminFormPage, ExportCSVView, doll_up, running_jobs)
     41    ContactAdminFormPage, ExportCSVView, doll_up, exports_not_allowed)
    4242from waeup.kofa.browser.interfaces import ICaptchaManager
    4343from waeup.kofa.hostels.hostel import NOT_OCCUPIED
     
    32363236        if START is None:
    32373237            return
    3238         utils = queryUtility(IKofaUtils)
    3239         if utils.export_disabled_message():
    3240             self.flash(utils.export_disabled_message(), type='danger')
    3241             self.entries = doll_up(self, user=None)
    3242             return
    3243         if not utils.expensive_actions_allowed():
    3244             self.flash(_(
    3245                 "Currently, exporters cannot be started due to high "
    3246                 "system load. Please try again later."), type='danger')
    3247             return
    3248         if running_jobs(self):
    3249             self.flash(_(
    3250                 "Sorry, another export job is running. "
    3251                 "Please try again later."), type='danger')
    3252             self.entries = doll_up(self, user=None)
     3238        ena = exports_not_allowed(self)
     3239        if ena:
     3240            self.flash(ena, type='danger')
    32533241            return
    32543242        if payments_start or payments_end:
     
    33463334        if START is None:
    33473335            return
    3348         utils = queryUtility(IKofaUtils)
    3349         if utils.export_disabled_message():
    3350             self.flash(utils.export_disabled_message(), type='danger')
    3351             self.entries = doll_up(self, user=None)
    3352             return
    3353         if not utils.expensive_actions_allowed():
    3354             self.flash(_(
    3355                 "Currently, exporters cannot be started due to high "
    3356                 "system load. Please try again later."), type='danger')
    3357             return
    3358         if running_jobs(self):
    3359             self.flash(_(
    3360                 "Sorry, another export job is running. "
    3361                 "Please try again later."), type='danger')
    3362             self.entries = doll_up(self, user=None)
     3336        ena = exports_not_allowed(self)
     3337        if ena:
     3338            self.flash(ena, type='danger')
    33633339            return
    33643340        try:
     
    34423418        if START is None:
    34433419            return
    3444         utils = queryUtility(IKofaUtils)
    3445         if utils.export_disabled_message():
    3446             self.flash(utils.export_disabled_message(), type='danger')
    3447             self.entries = doll_up(self, user=None)
    3448             return
    3449         if not utils.expensive_actions_allowed():
    3450             self.flash(_(
    3451                 "Currently, exporters cannot be started due to high "
    3452                 "system load. Please try again later."), type='danger')
    3453             return
    3454         if running_jobs(self):
    3455             self.flash(_(
    3456                 "Sorry, another export job is running. "
    3457                 "Please try again later."), type='danger')
    3458             self.entries = doll_up(self, user=None)
     3420        ena = exports_not_allowed(self)
     3421        if ena:
     3422            self.flash(ena, type='danger')
    34593423            return
    34603424        if session == 'all':
Note: See TracChangeset for help on using the changeset viewer.