Ignore:
Timestamp:
29 Jun 2012, 10:21:03 (12 years ago)
Author:
Henrik Bettermann
Message:

Generate md5 andate_id from timestamp.

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

Legend:

Unmodified
Added
Removed
  • main/waeup.kofa/trunk/src/waeup/kofa/mandates/mandate.py

    r8846 r8847  
    2020"""
    2121import grok
     22import hashlib
    2223from datetime import datetime, timedelta
     24from time import time
    2325from grok import index
    2426from waeup.kofa.interfaces import IUserAccount
     
    3234    grok.provides(IMandate)
    3335
    34     def __init__(self, days=1):
     36    def __init__(self, days=1, category=None, mandate_id=None):
    3537        super(Mandate, self).__init__()
    3638        self.creation_date = datetime.utcnow() # offset-naive datetime
    3739        delta = timedelta(days=days)
    3840        self.expires = datetime.utcnow() + delta
    39         self.mandate_id = None
    40         self.category = None
     41        if mandate_id is None:
     42            timestamp = "%d" % int(time()*1000)
     43            mandate_id = hashlib.md5(timestamp).hexdigest()
     44        self.mandate_id = mandate_id
     45        self.category = category
    4146        self.params = {}
    4247        return
  • main/waeup.kofa/trunk/src/waeup/kofa/mandates/tests.py

    r8846 r8847  
    8585        # Add and execute a mandate with missing parameters.
    8686        mandate = Mandate()
    87         mandate.mandate_id = '12345'
    8887        mandate.category = 'student_password'
    8988        self.app['mandates'].addMandate(mandate)
     
    9291        # Add and execute an expired mandate.
    9392        mandate = Mandate(days=0)
    94         mandate.mandate_id = '12345'
    9593        mandate.category = 'student_password'
    9694        self.app['mandates'].addMandate(mandate)
     
    9997        # Ad and execute a perfect mandate
    10098        mandate = Mandate(days=0)
    101         mandate.mandate_id = '12345'
    10299        mandate.category = 'student_password'
    103100        mandate.params['student_id'] = student.student_id
     
    114111        # mandate1 is an old mandate which just expired.
    115112        mandate1 = Mandate(days=0)
    116         mandate1.mandate_id = '12345'
    117113        self.app['mandates'].addMandate(mandate1)
    118114        # mandate2 is a new mandate with default time delta.
    119         mandate2 = Mandate()
    120         mandate2.mandate_id = '23456'
     115        mandate2 = Mandate(mandate_id='23456')
    121116        self.app['mandates'].addMandate(mandate2)
    122117        self.assertEqual(len(self.app['mandates'].keys()), 2)
Note: See TracChangeset for help on using the changeset viewer.