- Timestamp:
- 22 Nov 2014, 10:14:38 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.ikoba/trunk/src/waeup/ikoba/customers/customer.py
r12032 r12035 20 20 """ 21 21 import os 22 import re23 22 import shutil 24 23 import grok … … 42 41 ICustomer, ICustomerNavigation, ICSVCustomerExporter, 43 42 ICustomersUtils) 44 from waeup.ikoba.customers.utils import generate_customer_id 43 from waeup.ikoba.customers.utils import generate_customer_id, path_from_custid 45 44 from waeup.ikoba.customers.documents import CustomerDocumentsContainer 46 45 from waeup.ikoba.utils.helpers import attrs_to_fields, now, copy_filesystem_tree 47 48 RE_CUSTID_NON_NUM = re.compile('[^\d]+')49 50 46 51 47 class Customer(grok.Container): … … 188 184 return 189 185 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 customer197 should be stored. This is a relative path, relative to any general198 customers folder with 5 zero-padded digits (except when customer_id199 is overlong).200 201 We normally map 1,000 different customer ids into one single202 path. For instance ``K1000000`` will give ``01000/K1000000``,203 ``K1234567`` will give ``0123/K1234567`` and ``K12345678`` will204 result in ``1234/K12345678``.205 206 For lower numbers < 10**6 we return the same path for up to 10,000207 customer_ids. So for instance ``KM123456`` will result in208 ``00120/KM123456`` (there will be no path starting with209 ``00123``).210 211 Works also with overlong number: here the leading zeros will be212 missing but ``K123456789`` will give reliably213 ``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 digits219 num = num / 10000 * 10220 else:221 # store max. of 1000 custs per folder222 num = num / 1000223 # format folder name to have 5 zero-padded digits224 folder_name = u'%05d' % num225 folder_name = os.path.join(folder_name, customer_id)226 return folder_name227 228 229 186 def move_customer_files(customer, del_dir): 230 187 """Move files belonging to `customer` to `del_dir`. … … 340 297 `context` is an :class:`Customer` instance. 341 298 342 The :class:`Customer ImageNameChooser` can build/check file ids for299 The :class:`CustomerFileNameChooser` can build/check file ids for 343 300 :class:`Customer` objects suitable for use with 344 301 :class:`ExtFileStore` instances. The delivered file_id contains … … 380 337 ``'__file-customer__customers/A/A123456/nice_image_A123456.jpeg'`` 381 338 382 meaning that the nice image of this applicantwould be339 meaning that the nice image of this customer would be 383 340 stored in the site-wide file storage in path: 384 341
Note: See TracChangeset for help on using the changeset viewer.