Ignore:
Timestamp:
29 Jun 2012, 14:40:37 (12 years ago)
Author:
Henrik Bettermann
Message:

Some changes according to Uli's suggestions.

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

Legend:

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

    r8846 r8849  
    3434
    3535class IMandate(IKofaObject):
    36     """A base representation of mandates.
     36    """A representation of all mandates.
    3737
    3838    """
     
    4040    expires = Attribute('Expiration Datetime')
    4141    params = Attribute('Dictionary with mandate parameters')
    42     category = Attribute('Mandate Category')
     42
     43    def execute():
     44        """Method which is performed by the mandate.
     45        """
  • main/waeup.kofa/trunk/src/waeup/kofa/mandates/mandate.py

    r8848 r8849  
    2121import grok
    2222import hashlib
     23import os
    2324from datetime import datetime, timedelta
    24 from time import time
    2525from grok import index
    2626from waeup.kofa.interfaces import IUserAccount
     
    2828from waeup.kofa.mandates.interfaces import IMandate
    2929
    30 class Mandate(grok.Container):
    31     """This is a mandate which can set a student password.
     30class Mandate(grok.Model):
     31    """This is a mandate.
    3232    """
    3333    grok.implements(IMandate)
    3434    grok.provides(IMandate)
     35    grok.baseclass()
    3536
    36     def __init__(self, days=1, category=None, mandate_id=None):
     37    def __init__(self, days=1, mandate_id=None):
    3738        super(Mandate, self).__init__()
    3839        self.creation_date = datetime.utcnow() # offset-naive datetime
     
    4041        self.expires = datetime.utcnow() + delta
    4142        if mandate_id is None:
    42             timestamp = "%d" % int(time()*1000)
    43             mandate_id = hashlib.md5(timestamp).hexdigest()
     43            mandate_id = os.urandom(20)
     44            mandate_id = hashlib.md5(mandate_id).hexdigest()
    4445        self.mandate_id = mandate_id
    45         self.category = category
    4646        self.params = {}
    4747        return
     48
     49    def execute(self):
     50        return _('Nothing to do.')
     51
     52class StudentPasswordMandate(Mandate):
     53    """This is a mandate which can set a student password.
     54    """
    4855
    4956    def _setStudentPassword(self):
     
    6067        if self.expires < datetime.utcnow():
    6168            msg = _('Mandate expired.')
    62         elif self.category == 'student_password':
    63             if self._setStudentPassword():
    64                 msg = _('Password has been successfully set.')
     69        if self._setStudentPassword():
     70            msg = _('Password has been successfully set.')
    6571        del self.__parent__[self.mandate_id]
    6672        return msg
  • main/waeup.kofa/trunk/src/waeup/kofa/mandates/tests.py

    r8848 r8849  
    3131    IMandatesContainer, IMandate)
    3232from waeup.kofa.mandates.container import MandatesContainer
    33 from waeup.kofa.mandates.mandate import Mandate
     33from waeup.kofa.mandates.mandate import StudentPasswordMandate
    3434from waeup.kofa.testing import (FunctionalLayer, FunctionalTestCase)
    3535
     
    5050        self.assertTrue(
    5151            verifyClass(
    52                 IMandate, Mandate)
     52                IMandate, StudentPasswordMandate)
    5353            )
    5454        self.assertTrue(
    5555            verifyObject(
    56                 IMandate, Mandate())
     56                IMandate, StudentPasswordMandate())
    5757            )
    5858        return
     
    8888        self.app['students'].addStudent(student)
    8989        # Add and execute a mandate with missing parameters.
    90         mandate = Mandate()
     90        mandate = StudentPasswordMandate()
    9191        mandate.category = 'student_password'
    9292        self.app['mandates'].addMandate(mandate)
     
    9494        self.assertEqual(msg, u'Wrong mandate parameters.')
    9595        # Add and execute an expired mandate.
    96         mandate = Mandate(days=0)
     96        mandate = StudentPasswordMandate(days=0)
    9797        mandate.category = 'student_password'
    9898        self.app['mandates'].addMandate(mandate)
     
    100100        self.assertEqual(msg, u'Mandate expired.')
    101101        # Add and execute a perfect mandate
    102         mandate = Mandate()
     102        mandate = StudentPasswordMandate()
    103103        mandate.category = 'student_password'
    104104        mandate.params['student_id'] = student.student_id
     
    114114    def test_remove_expired(self):
    115115        # mandate1 is an old mandate which just expired.
    116         mandate1 = Mandate(days=0)
     116        mandate1 = StudentPasswordMandate(days=0)
    117117        self.app['mandates'].addMandate(mandate1)
    118118        # mandate2 is a new mandate with default time delta.
    119         mandate2 = Mandate(mandate_id='23456')
     119        mandate2 = StudentPasswordMandate(mandate_id='23456')
    120120        self.app['mandates'].addMandate(mandate2)
    121121        self.assertEqual(len(self.app['mandates'].keys()), 2)
     
    128128        student = createObject('waeup.Student')
    129129        self.app['students'].addStudent(student)
    130         mandate = Mandate()
     130        mandate = StudentPasswordMandate()
    131131        mandate.category = 'student_password'
    132132        mandate.params['student_id'] = student.student_id
Note: See TracChangeset for help on using the changeset viewer.