Ignore:
Timestamp:
6 Apr 2016, 07:42:09 (9 years ago)
Author:
Henrik Bettermann
Message:

Rearrange datacenter upload page. Provide modal windows to view all
processors and sources and vocabularies.

See r12932, r12933 and 12955ff

File:
1 edited

Legend:

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

    r13803 r13804  
    5555    ILocalRolesAssignable, DuplicationError, IConfigurationContainer,
    5656    IJobManager,
    57     IPasswordValidator, IContactForm, IIkobaUtils, ICSVExporter)
     57    IPasswordValidator, IContactForm, IIkobaUtils, ICSVExporter,
     58    CurrencySource)
    5859from waeup.ikoba.permissions import (
    5960    get_users_with_local_roles, get_all_roles, get_all_users,
    6061    get_users_with_role)
    61 
     62from waeup.ikoba.customers.vocabularies import GenderSource
    6263from waeup.ikoba.authentication import LocalRoleSetEvent
    6364from waeup.ikoba.utils.helpers import get_user_account, check_csv_charset
    6465from waeup.ikoba.mandates.mandate import PasswordMandate
    6566from waeup.ikoba.datacenter import DataCenterFile
     67from waeup.ikoba.customers.utils import ICustomersUtils
     68from waeup.ikoba.documents.utils import IDocumentsUtils
    6669
    6770FORBIDDEN_CHARACTERS = (160,)
     
    245248            return True
    246249    return False
     250
     251def getImporters(context):
     252    importers = getAllUtilitiesRegisteredFor(IBatchProcessor)
     253    importer_props = []
     254    for x in importers:
     255        # Skip User Processor if user isn't allowed to manage users.
     256        if x.util_name == 'userprocessor' and not checkPermission(
     257            'waeup.manageUsers', context):
     258            continue
     259        iface_fields = schema.getFields(x.iface)
     260        available_fields = []
     261        for key in iface_fields.keys():
     262            iface_fields[key] = (iface_fields[key].__class__.__name__,
     263                iface_fields[key].required)
     264        for value in x.available_fields:
     265            available_fields.append(
     266                dict(f_name=value,
     267                     f_type=iface_fields.get(value, (None, False))[0],
     268                     f_required=iface_fields.get(value, (None, False))[1]
     269                     )
     270                )
     271        available_fields = sorted(available_fields, key=lambda k: k[
     272            'f_name'])
     273        importer_props.append(
     274            dict(title=x.name, name=x.util_name, fields=available_fields))
     275    return sorted(importer_props, key=lambda k: k['title'])
    247276
    248277class LocalRoleAssignmentUtilityView(object):
     
    496525            return html
    497526
     527class SourcesOverview(grok.View):
     528    grok.context(ICompany)
     529    grok.name('sourcesoverview')
     530    grok.require('waeup.Public')
     531
     532    def _set_con_cats(self):
     533        con_cats = getUtility(IIkobaUtils).CON_CATS_DICT
     534        self.con_cats = con_cats.items()
     535        return
     536
     537    def _set_payment_categories(self):
     538        payment_categories = getUtility(IIkobaUtils).PAYMENT_CATEGORIES
     539        self.payment_categories = payment_categories.items()
     540        return
     541
     542    def _set_customer_doctypes(self):
     543        customer_doctypes = getUtility(ICustomersUtils).DOCTYPES_DICT
     544        self.customer_doctypes = customer_doctypes.items()
     545        return
     546
     547    def _set_contypes(self):
     548        contypes = getUtility(ICustomersUtils).CONTYPES_DICT
     549        self.contypes = contypes.items()
     550        return
     551
     552    def _set_doctypes(self):
     553        doctypes = getUtility(IDocumentsUtils).DOCTYPES_DICT
     554        self.doctypes = doctypes.items()
     555        return
     556
     557    def _set_customer_states(self):
     558        customer_states = getUtility(ICustomersUtils).TRANSLATED_CUSTOMER_STATES
     559        self.customer_states = customer_states.items()
     560        return
     561
     562    def _set_contract_states(self):
     563        contract_states = getUtility(ICustomersUtils).TRANSLATED_CONTRACT_STATES
     564        self.contract_states = contract_states.items()
     565        return
     566
     567    def _set_customer_document_states(self):
     568        customer_document_states = getUtility(
     569            ICustomersUtils).TRANSLATED_DOCUMENT_STATES
     570        self.customer_document_states = customer_document_states.items()
     571        return
     572
     573    def _set_document_states(self):
     574        document_states = getUtility(
     575            IDocumentsUtils).TRANSLATED_DOCUMENT_STATES
     576        self.document_states = document_states.items()
     577        return
     578
     579    def _set_currencies(self):
     580        currenciessource = CurrencySource().factory
     581        self.currencies = []
     582        for code in currenciessource.getValues():
     583            title = currenciessource.getTitle(code)
     584            self.currencies.append((code, title))
     585        return
     586
     587    def _set_sex(self):
     588        gendersource = GenderSource().factory
     589        self.sex = []
     590        for sex in gendersource.getValues():
     591            title = gendersource.getTitle(sex)
     592            self.sex.append((sex, title))
     593        return
     594
     595    def update(self):
     596        self._set_con_cats()
     597        self._set_payment_categories()
     598        self._set_customer_doctypes()
     599        self._set_contypes()
     600        self._set_doctypes()
     601        self._set_currencies()
     602        self._set_sex()
     603        self._set_customer_states()
     604        self._set_contract_states()
     605        self._set_customer_document_states()
     606        self._set_document_states()
     607
     608class SourcesOverviewPage(IkobaPage, SourcesOverview):
     609    grok.name('sources')
     610    grok.require('waeup.Public')
     611    label = _(u'Sources & Vocabularies')
     612    pnav = 0
     613
     614class ProcessorsOverview(grok.View):
     615    grok.context(ICompany)
     616    grok.name('processorsoverview')
     617    grok.require('waeup.Public')
     618
     619    def getImporters(self):
     620        return getImporters(self.context)
     621
     622class ProcessorsOverviewPage(IkobaPage, ProcessorsOverview):
     623    grok.name('processors')
     624    grok.require('waeup.Public')
     625    label = _(u'Available Processors (Importers)')
     626    pnav = 0
     627
     628class SkeletonDownloadView(UtilityView, grok.View):
     629    grok.context(ICompany)
     630    grok.name('skeleton')
     631    grok.require('waeup.Public')
     632
     633    def update(self, processorname=None):
     634        self.processorname = self.request.form['name']
     635        self.filename = ('%s_000.csv' %
     636            self.processorname.replace('processor','import'))
     637        return
     638
     639    def render(self):
     640        #ob_class = self.__implemented__.__name__.replace('waeup.kofa.','')
     641        #self.context.logger.info(
     642        #    '%s - skeleton downloaded: %s' % (ob_class, self.filename))
     643        self.response.setHeader(
     644            'Content-Type', 'text/csv; charset=UTF-8')
     645        self.response.setHeader(
     646            'Content-Disposition:', 'attachment; filename="%s' % self.filename)
     647        processor = getUtility(IBatchProcessor, name=self.processorname)
     648        csv_data = processor.get_csv_skeleton()
     649        return csv_data
     650
    498651class AdministrationPage(IkobaPage):
    499652    """ The administration overview page.
     
    9971150
    9981151    def getImporters(self):
    999         importers = getAllUtilitiesRegisteredFor(IBatchProcessor)
    1000         ikoba_utils = getUtility(IIkobaUtils)
    1001         importer_props = []
    1002         for x in importers:
    1003             if not x.util_name in ikoba_utils.BATCH_PROCESSOR_NAMES:
    1004                 continue
    1005             # Skip User Processor if user isn't allowed to manage users.
    1006             if x.util_name == 'userprocessor' and not checkPermission(
    1007                 'waeup.manageUsers', self.context):
    1008                 continue
    1009             iface_fields = schema.getFields(x.iface)
    1010             available_fields = []
    1011             for key in iface_fields.keys():
    1012                 iface_fields[key] = (iface_fields[key].__class__.__name__,
    1013                     iface_fields[key].required)
    1014             for value in x.available_fields:
    1015                 available_fields.append(
    1016                     dict(f_name=value,
    1017                          f_type=iface_fields.get(value, (None, False))[0],
    1018                          f_required=iface_fields.get(value, (None, False))[1]
    1019                          )
    1020                     )
    1021             available_fields = sorted(available_fields, key=lambda k: k['f_name'])
    1022             importer_props.append(
    1023                 dict(title=x.name, name=x.util_name, fields=available_fields))
    1024         return sorted(importer_props, key=lambda k: k['title'])
     1152        return getImporters(self.context)
    10251153
    10261154class FileDownloadView(UtilityView, grok.View):
     
    10441172        fullpath = os.path.join(self.context.storage, self.filename)
    10451173        return open(fullpath, 'rb').read()
    1046 
    1047 class SkeletonDownloadView(UtilityView, grok.View):
    1048     grok.context(IDataCenter)
    1049     grok.name('skeleton')
    1050     grok.require('waeup.manageDataCenter')
    1051 
    1052     def update(self, processorname=None):
    1053         self.processorname = self.request.form['name']
    1054         self.filename = ('%s_000.csv' %
    1055             self.processorname.replace('processor','import'))
    1056         return
    1057 
    1058     def render(self):
    1059         #ob_class = self.__implemented__.__name__.replace('waeup.ikoba.','')
    1060         #self.context.logger.info(
    1061         #    '%s - skeleton downloaded: %s' % (ob_class, self.filename))
    1062         self.response.setHeader(
    1063             'Content-Type', 'text/csv; charset=UTF-8')
    1064         self.response.setHeader(
    1065             'Content-Disposition:', 'attachment; filename="%s' % self.filename)
    1066         processor = getUtility(IBatchProcessor, name=self.processorname)
    1067         csv_data = processor.get_csv_skeleton()
    1068         return csv_data
    10691174
    10701175class DatacenterImportStep1(IkobaPage):
Note: See TracChangeset for help on using the changeset viewer.