Ignore:
Timestamp:
22 Nov 2014, 10:14:38 (10 years ago)
Author:
Henrik Bettermann
Message:

Add document file viewlets. Tests will follow.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.ikoba/trunk/src/waeup/ikoba/customers/customer.py

    r12032 r12035  
    2020"""
    2121import os
    22 import re
    2322import shutil
    2423import grok
     
    4241    ICustomer, ICustomerNavigation, ICSVCustomerExporter,
    4342    ICustomersUtils)
    44 from waeup.ikoba.customers.utils import generate_customer_id
     43from waeup.ikoba.customers.utils import generate_customer_id, path_from_custid
    4544from waeup.ikoba.customers.documents import CustomerDocumentsContainer
    4645from waeup.ikoba.utils.helpers import attrs_to_fields, now, copy_filesystem_tree
    47 
    48 RE_CUSTID_NON_NUM = re.compile('[^\d]+')
    49 
    5046
    5147class Customer(grok.Container):
     
    188184    return
    189185
    190 
    191 def path_from_custid(customer_id):
    192     """Convert a customer_id into a predictable relative folder path.
    193 
    194     Used for storing files.
    195 
    196     Returns the name of folder in which files for a particular customer
    197     should be stored. This is a relative path, relative to any general
    198     customers folder with 5 zero-padded digits (except when customer_id
    199     is overlong).
    200 
    201     We normally map 1,000 different customer ids into one single
    202     path. For instance ``K1000000`` will give ``01000/K1000000``,
    203     ``K1234567`` will give ``0123/K1234567`` and ``K12345678`` will
    204     result in ``1234/K12345678``.
    205 
    206     For lower numbers < 10**6 we return the same path for up to 10,000
    207     customer_ids. So for instance ``KM123456`` will result in
    208     ``00120/KM123456`` (there will be no path starting with
    209     ``00123``).
    210 
    211     Works also with overlong number: here the leading zeros will be
    212     missing but ``K123456789`` will give reliably
    213     ``12345/K123456789`` as expected.
    214     """
    215     # remove all non numeric characters and turn this into an int.
    216     num = int(RE_CUSTID_NON_NUM.sub('', customer_id))
    217     if num < 10**6:
    218         # store max. of 10000 custs per folder and correct num for 5 digits
    219         num = num / 10000 * 10
    220     else:
    221         # store max. of 1000 custs per folder
    222         num = num / 1000
    223     # format folder name to have 5 zero-padded digits
    224     folder_name = u'%05d' % num
    225     folder_name = os.path.join(folder_name, customer_id)
    226     return folder_name
    227 
    228 
    229186def move_customer_files(customer, del_dir):
    230187    """Move files belonging to `customer` to `del_dir`.
     
    340297    `context` is an :class:`Customer` instance.
    341298
    342     The :class:`CustomerImageNameChooser` can build/check file ids for
     299    The :class:`CustomerFileNameChooser` can build/check file ids for
    343300    :class:`Customer` objects suitable for use with
    344301    :class:`ExtFileStore` instances. The delivered file_id contains
     
    380337          ``'__file-customer__customers/A/A123456/nice_image_A123456.jpeg'``
    381338
    382         meaning that the nice image of this applicant would be
     339        meaning that the nice image of this customer would be
    383340        stored in the site-wide file storage in path:
    384341
Note: See TracChangeset for help on using the changeset viewer.