Changeset 7186 for main


Ignore:
Timestamp:
24 Nov 2011, 11:31:04 (13 years ago)
Author:
Henrik Bettermann
Message:

Rename functions according to the WAeUP style guide:

functions and methods with property decorator with underscore

methods with CamelCase

Location:
main/waeup.sirp/trunk/src/waeup/sirp
Files:
11 edited

Legend:

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

    r7184 r7186  
    3737    ISessionConfiguration, ISessionConfigurationAdd, academic_sessions_vocab,
    3838    IPasswordValidator)
    39 from waeup.sirp.permissions import get_users_with_local_roles, getAllRoles
     39from waeup.sirp.permissions import get_users_with_local_roles, get_all_roles
    4040from waeup.sirp.university.catalog import search
    4141from waeup.sirp.university.vocabularies import course_levels
     
    266266        site_url = self.url(grok.getSite())
    267267        for local_role in local_roles.keys():
    268             role_title = dict(getAllRoles())[local_role].title
     268            role_title = dict(get_all_roles())[local_role].title
    269269            objects_string = ''
    270270            for object in local_roles[local_role]:
     
    279279        site_roles_string = ''
    280280        for site_role in site_roles:
    281             role_title = dict(getAllRoles())[site_role].title
     281            role_title = dict(get_all_roles())[site_role].title
    282282            site_roles_string += '%s <br />' % role_title
    283283        return site_roles_string
     
    385385        local_roles_userfriendly = {}
    386386        for local_role in local_roles:
    387             role_title = dict(getAllRoles())[local_role].title
     387            role_title = dict(get_all_roles())[local_role].title
    388388            local_roles_userfriendly[role_title] = local_roles[local_role]
    389389        return local_roles_userfriendly
     
    394394        site_roles_userfriendly = []
    395395        for site_role in site_roles:
    396             role_title = dict(getAllRoles())[site_role].title
     396            role_title = dict(get_all_roles())[site_role].title
    397397            site_roles_userfriendly.append(role_title)
    398398        return site_roles_userfriendly
  • main/waeup.sirp/trunk/src/waeup/sirp/datacenter.py

    r7137 r7186  
    1212from waeup.sirp.interfaces import (IDataCenter, IDataCenterFile,
    1313                                   IDataCenterStorageMovedEvent)
    14 from waeup.sirp.utils.helpers import copyFileSystemTree
     14from waeup.sirp.utils.helpers import copy_filesystem_tree
    1515from waeup.sirp.utils.logger import Logger
    1616
     
    8080        if move is True:
    8181
    82             not_copied = copyFileSystemTree(self.storage, path,
     82            not_copied = copy_filesystem_tree(self.storage, path,
    8383                                            overwrite=overwrite)
    8484        self.storage = path
  • main/waeup.sirp/trunk/src/waeup/sirp/interfaces.py

    r7178 r7186  
    8181    def getValues(self):
    8282        # late import: in interfaces we should not import local modules
    83         from waeup.sirp.permissions import getWAeUPRoleNames
    84         return getWAeUPRoleNames()
     83        from waeup.sirp.permissions import get_waeup_role_names
     84        return get_waeup_role_names()
    8585
    8686    def getTitle(self, value):
    8787        # late import: in interfaces we should not import local modules
    88         from waeup.sirp.permissions import getAllRoles
    89         roles = dict(getAllRoles())
     88        from waeup.sirp.permissions import get_all_roles
     89        roles = dict(get_all_roles())
    9090        if value in roles.keys():
    9191            title = roles[value].title
  • main/waeup.sirp/trunk/src/waeup/sirp/permissions.py

    r7185 r7186  
    9797                     'waeup.viewHostels', 'waeup.manageHostels')
    9898
    99 def getAllRoles():
     99def get_all_roles():
    100100    """Return a list of tuples ``<ROLE-NAME>, <ROLE>``.
    101101    """
    102102    return getUtilitiesFor(IRole)
    103103
    104 def getWAeUPRoles(also_local=False):
     104def get_waeup_roles(also_local=False):
    105105    """Get all WAeUP roles.
    106106
     
    114114    Returns a generator of the found roles.
    115115    """
    116     for name, item in getAllRoles():
     116    for name, item in get_all_roles():
    117117        if not name.startswith('waeup.'):
    118118            # Ignore non-WAeUP roles...
     
    123123        yield item
    124124
    125 def getWAeUPRoleNames():
     125def get_waeup_role_names():
    126126    """Get the ids of all WAeUP roles.
    127127
    128     See :func:`getWAeUPRoles` for what a 'WAeUPRole' is.
     128    See :func:`get_waeup_roles` for what a 'WAeUPRole' is.
    129129
    130130    This function returns a sorted list of WAeUP role names.
    131131    """
    132     return sorted([x.id for x in getWAeUPRoles()])
     132    return sorted([x.id for x in get_waeup_roles()])
    133133
    134134class LocalRolesAssignable(grok.Adapter):
     
    160160        self.context = context
    161161        role_ids = getattr(context, 'local_roles', self._roles)
    162         self._roles = [(name, role) for name, role in getAllRoles()
     162        self._roles = [(name, role) for name, role in get_all_roles()
    163163                       if name in role_ids]
    164164        return
     
    191191        user = grok.getSite()['users'].get(user_name,None)
    192192        user_title = getattr(user, 'description', user_name)
    193         local_role_title = dict(getAllRoles())[local_role].title
     193        local_role_title = dict(get_all_roles())[local_role].title
    194194        yield dict(user_name = user_name,
    195195                   user_title = user_title,
  • main/waeup.sirp/trunk/src/waeup/sirp/permissions.txt

    r7185 r7186  
    1313roles.
    1414
    15 :func:`getAllRoles`
    16 -------------------
     15:func:`get_all_roles`
     16---------------------
    1717
    1818Gives us all roles defined in a WAeUP SIRP portal. We get tuples of
     
    2424with the ZCA (a string) and ``<ROLE>`` is the real role object.
    2525
    26     >>> from waeup.sirp.permissions import getAllRoles
    27     >>> getAllRoles()
     26    >>> from waeup.sirp.permissions import get_all_roles
     27    >>> get_all_roles()
    2828    <generator object...at 0x...>
    2929
    30     >>> sorted(list(getAllRoles()))
     30    >>> sorted(list(get_all_roles()))
    3131    [(u'waeup.ACManager', <waeup.sirp.permissions.ACManager object at 0x...]
    3232
    33 :func:`getWAeUPRoles`
    34 ---------------------
     33:func:`get_waeup_roles`
     34-----------------------
    3535
    3636Gives us all roles, except the WAeUP specific roles. We can get a list
    3737with or without local roles:
    3838
    39     >>> from waeup.sirp.permissions import getWAeUPRoles
    40     >>> len(list(getWAeUPRoles()))
     39    >>> from waeup.sirp.permissions import get_waeup_roles
     40    >>> len(list(get_waeup_roles()))
    4141    10
    4242
    43     >>> len(list(getWAeUPRoles(also_local=True)))
     43    >>> len(list(get_waeup_roles(also_local=True)))
    4444    16
    4545
    4646
    47 :func:`getRoleNames`
    48 --------------------
     47:func:`get_waeup_role_names`
     48----------------------------
    4949
    5050We can get all role names defined in a WAeUP portal (except 'local'
    5151roles that are meant not to be assigned globally):
    5252
    53     >>> from waeup.sirp.permissions import getWAeUPRoleNames
    54     >>> list(getWAeUPRoleNames())
     53    >>> from waeup.sirp.permissions import get_waeup_role_names
     54    >>> list(get_waeup_role_names())
    5555    [u'waeup.ACManager', u'waeup.AcademicsOfficer',
    5656     u'waeup.AccommodationOfficer', u'waeup.Applicant',
  • main/waeup.sirp/trunk/src/waeup/sirp/students/browser.py

    r7184 r7186  
    737737            self.request)
    738738        students_utils = getUtility(IStudentsUtils)
    739         return students_utils.render_pdf(
     739        return students_utils.renderPDF(
    740740            self,'Course Registration', 'course_registration.pdf',
    741741            self.context.getStudent, studentview)
     
    10221022                return
    10231023        students_utils = getUtility(IStudentsUtils)
    1024         pay_details  = students_utils.get_payment_details(
     1024        pay_details  = students_utils.getPaymentDetails(
    10251025            p_category,student)
    10261026        if pay_details['error']:
     
    11771177            self.request)
    11781178        students_utils = getUtility(IStudentsUtils)
    1179         return students_utils.render_pdf(self,'Payment', 'payment_receipt.pdf',
     1179        return students_utils.renderPDF(self,'Payment', 'payment_receipt.pdf',
    11801180            self.context.getStudent, studentview)
    11811181
     
    12891289        student = self.context.getStudent()
    12901290        students_utils = getUtility(IStudentsUtils)
    1291         acc_details  = students_utils.get_accommodation_details(student)
     1291        acc_details  = students_utils.getAccommodationDetails(student)
    12921292        if not student.state in acc_details['allowed_states']:
    12931293            self.flash("You are in the wrong registration state.")
     
    13271327            if available_beds:
    13281328                students_utils = getUtility(IStudentsUtils)
    1329                 bed = students_utils.select_bed(available_beds)
     1329                bed = students_utils.selectBed(available_beds)
    13301330                bed.bookBed(student.student_id)
    13311331            else:
     
    14091409            self.request)
    14101410        students_utils = getUtility(IStudentsUtils)
    1411         return students_utils.render_pdf(
     1411        return students_utils.renderPDF(
    14121412            self,'Bed Allocation', 'bed_allocation.pdf',
    14131413            self.context.getStudent, studentview)
     
    14341434        student = self.context.getStudent()
    14351435        students_utils = getUtility(IStudentsUtils)
    1436         acc_details  = students_utils.get_accommodation_details(student)
     1436        acc_details  = students_utils.getAccommodationDetails(student)
    14371437        if self.context.bed != None and \
    14381438              'reserved' in self.context.bed.bed_type:
     
    14621462            if available_beds:
    14631463                students_utils = getUtility(IStudentsUtils)
    1464                 new_bed = students_utils.select_bed(available_beds)
     1464                new_bed = students_utils.selectBed(available_beds)
    14651465                new_bed.bookBed(student.student_id)
    14661466            else:
     
    17191719
    17201720    @grok.action('Save and request clearance')
    1721     def requestclearance(self, **data):
     1721    def requestClearance(self, **data):
    17221722        self.applyData(self.context, **data)
    17231723        self.context._p_changed = True
     
    19641964
    19651965    @grok.action('Register course list')
    1966     def register_courses(self, **data):
     1966    def RegisterCourses(self, **data):
    19671967        state = IWorkflowState(self.context.getStudent()).getState()
    19681968        IWorkflowInfo(self.context.getStudent()).fireTransition('register_courses')
  • main/waeup.sirp/trunk/src/waeup/sirp/students/interfaces.py

    r7150 r7186  
    3030
    3131    """
    32     def get_payment_details(category, student):
     32    def getPaymentDetails(category, student):
    3333        """Get the payment dates of a student for the payment category
    3434        specified.
     
    3636        """
    3737
    38     def get_accommodation_details(student):
     38    def getAccommodation_details(student):
    3939        """Determine the accommodation dates of a student.
    4040
    4141        """
    4242
    43     def select_bed(available_beds):
     43    def selectBed(available_beds):
    4444        """Select a bed from a list of available beds.
    4545
     
    4848        """
    4949
    50     def render_pdf(view, subject='', filename='slip.pdf',):
     50    def renderPDF(view, subject='', filename='slip.pdf',):
    5151        """Render pdf slips for various pages.
    5252
  • main/waeup.sirp/trunk/src/waeup/sirp/students/utils.py

    r7150 r7186  
    3535    return
    3636
    37 def setUpWidgets(view, ignore_request=False):
     37def set_up_widgets(view, ignore_request=False):
    3838    view.adapters = {}
    3939    view.widgets = setUpEditWidgets(
     
    4444
    4545def render_student_data(student, studentview):
    46     setUpWidgets(studentview, ignore_request=True)
     46    set_up_widgets(studentview, ignore_request=True)
    4747    data = []
    4848    style = getSampleStyleSheet()
     
    6363    grok.implements(IStudentsUtils)
    6464
    65     def get_payment_details(self,category, student):
     65    def getPaymentDetails(self,category, student):
    6666        d = {}
    6767        d['p_item'] = u''
     
    8585            d['amount'] = academic_session.clearance_fee
    8686        elif category == 'bed_allocation':
    87             d['p_item'] = self.get_accommodation_details(student)['bt']
     87            d['p_item'] = self.getAccommodationDetails(student)['bt']
    8888            d['amount'] = academic_session.booking_fee
    8989        return d
    9090
    91     def get_accommodation_details(self, student):
     91    def getAccommodationDetails(self, student):
    9292        d = {}
    9393        d['error'] = u''
     
    117117    # In the standard configuration we select the first bed found,
    118118    # but can also randomize the selection if we like.
    119     def select_bed(self, available_beds):
     119    def selectBed(self, available_beds):
    120120        return available_beds[0]
    121121
    122     def render_pdf(self, view, subject='', filename='slip.pdf',
     122    def renderPDF(self, view, subject='', filename='slip.pdf',
    123123        student=None, studentview=None):
    124124        # (0,0),(-1,-1) = whole table
     
    153153            story.append(studenttable)
    154154        story.append(Spacer(1, 18))
    155         setUpWidgets(view)
     155        set_up_widgets(view)
    156156        data = []
    157157        for widget in view.widgets:
  • main/waeup.sirp/trunk/src/waeup/sirp/utils/helpers.py

    r7175 r7186  
    1919BUFSIZE = 8 * 1024
    2020
    21 def removeFileOrDirectory(filepath):
     21def remove_file_or_directory(filepath):
    2222    """Remove a file or directory.
    2323
     
    3535    return
    3636
    37 def copyFileSystemTree(src, dst, overwrite=False, del_old=False):
     37def copy_filesystem_tree(src, dst, overwrite=False, del_old=False):
    3838    """Copy contents of directory src to directory dst.
    3939
     
    6868        if os.path.exists(itemdst):
    6969            if overwrite is True:
    70                 removeFileOrDirectory(itemdst)
     70                remove_file_or_directory(itemdst)
    7171            else:
    7272                not_copied.append(item)
     
    7878            shutil.copy2(itemsrc, itemdst)
    7979        if del_old:
    80             removeFileOrDirectory(itemsrc)
     80            remove_file_or_directory(itemsrc)
    8181    return not_copied
    8282
    8383
    84 def getInnerHTMLPart(html_code):
     84def get_inner_HTML_part(html_code):
    8585    """Return the 'inner' part of a complete HTML snippet.
    8686
     
    9595
    9696       >>> doc = '<html><form>My Form</form>Outside the form</html>'
    97        >>> getInnerHTMLPart(doc)
     97       >>> get_inner_HTML_part(doc)
    9898       '<form>My Form</form>'
    9999
     
    101101
    102102       >>> doc = '<html><body>My Body</body>Trailing Trash</html>'
    103        >>> getInnerHTMLPart(doc)
     103       >>> get_inner_HTML_part(doc)
    104104       'My Body'
    105105
     
    107107
    108108       >>> doc = '<html>without body nor form</html>'
    109        >>> getInnerHTMLPart(doc)
     109       >>> get_inner_HTML_part(doc)
    110110       '<html>without body nor form</html>'
    111111
     
    309309    if warning_msgs == '':
    310310        warning_msgs = None
    311     result = getInnerHTMLPart(fulldoc).strip()
     311    result = get_inner_HTML_part(fulldoc).strip()
    312312    if not isinstance(result, unicode):
    313313        result = result.decode('utf-8')
  • main/waeup.sirp/trunk/src/waeup/sirp/utils/helpers.txt

    r5140 r7186  
    88.. :doctest:
    99
    10 :func:`removeFileOrDirectory`
    11 =============================
    12 
    13 .. function:: removeFileOrDirectory(path)
     10:func:`remove_file_or_directory`
     11================================
     12
     13.. function:: remove_file_or_directory(path)
    1414
    1515   Removes a file or directory given by a path. We can remove files:
    1616
    1717     >>> import os
    18      >>> from waeup.sirp.utils.helpers import removeFileOrDirectory
     18     >>> from waeup.sirp.utils.helpers import remove_file_or_directory
    1919     >>> open('blah', 'wb').write('nonsense')
    2020     >>> 'blah' in os.listdir('.')
    2121     True
    2222
    23      >>> removeFileOrDirectory('blah')
     23     >>> remove_file_or_directory('blah')
    2424     >>> 'blah' in os.listdir('.')
    2525     False
     
    3131     True
    3232
    33      >>> removeFileOrDirectory('blah')
     33     >>> remove_file_or_directory('blah')
    3434     >>> 'blah' in os.listdir('.')
    3535     False
    3636
    3737
    38 :func:`copyFileSystemTree`
    39 ==========================
    40 
    41 .. function:: copyFileSystemTree(src_path, dst_path[, overwrite=False[, del_old=False]])
     38:func:`copy_filesystem_tree`
     39============================
     40
     41.. function:: ccopy_filesystem_tree(src_path, dst_path[, overwrite=False[, del_old=False]])
    4242
    4343   Copies the contents of an (existing) directory to another
     
    6767     >>> open(os.path.join('src', 'blah'), 'wb').write('nonsense')
    6868
    69      >>> from waeup.sirp.utils.helpers import copyFileSystemTree
    70      >>> result = copyFileSystemTree('src', 'dst')
     69     >>> from waeup.sirp.utils.helpers import copy_filesystem_tree
     70     >>> result = copy_filesystem_tree('src', 'dst')
    7171
    7272   As a result we get a list of non-copied files:
     
    8383
    8484     >>> open(os.path.join('src', '.blah'), 'wb').write('nonsense')
    85      >>> result = copyFileSystemTree('src', 'dst')
     85     >>> result = copy_filesystem_tree('src', 'dst')
    8686     >>> '.blah' in os.listdir('dst')
    8787     False
     
    100100
    101101    >>> open(os.path.join('src', 'blah'), 'wb').write('newnonsense')
    102     >>> result = copyFileSystemTree('src', 'dst')
     102    >>> result = copy_filesystem_tree('src', 'dst')
    103103    >>> open(os.path.join('dst', 'blah'), 'rb').read()
    104104    'nonsense'
     
    113113overwritten:
    114114
    115     >>> result = copyFileSystemTree('src', 'dst', overwrite=True)
     115    >>> result = copy_filesystem_tree('src', 'dst', overwrite=True)
    116116    >>> open(os.path.join('dst', 'blah'), 'rb').read()
    117117    'newnonsense'
     
    129129    ...   'dst', 'mydir', 'blah'), 'wb').write('dstblah')
    130130
    131     >>> result = copyFileSystemTree('src', 'dst', overwrite=True)
     131    >>> result = copy_filesystem_tree('src', 'dst', overwrite=True)
    132132    >>> open(os.path.join('dst', 'mydir', 'blah'), 'rb').read()
    133133    'srcblah'
     
    140140removed from the src dir. Default is `False`.
    141141
    142     >>> result = copyFileSystemTree('src', 'dst', overwrite=True,
     142    >>> result = copy_filesystem_tree('src', 'dst', overwrite=True,
    143143    ...                                           del_old=True)
    144144    >>> os.listdir('src')
     
    151151Clean up:
    152152
    153     >>> removeFileOrDirectory('src')
    154     >>> removeFileOrDirectory('dst')
    155 
    156 
    157 :func:`getInnerHTMLPart()`
    158 ==========================
    159 
    160 .. function:: getInnerHTMLPart(html_code)
     153    >>> remove_file_or_directory('src')
     154    >>> remove_file_or_directory('dst')
     155
     156
     157:func:`get_inner_HTML_part()`
     158=============================
     159
     160.. function:: get_inner_HTML_part(html_code)
    161161
    162162   Get the 'inner' part out of a piece of HTML code.
     
    172172   returned with all preceeding/following stuff stripped:
    173173
    174      >>> from waeup.sirp.utils.helpers import getInnerHTMLPart
    175      >>> print getInnerHTMLPart("""<html>
     174     >>> from waeup.sirp.utils.helpers import get_inner_HTML_part
     175     >>> print get_inner_HTML_part("""<html>
    176176     ... <head>
    177177     ... </head>
     
    198198   If there is no ``<form>`` part, try to find any ``<body>`` part:
    199199
    200      >>> print getInnerHTMLPart("""<html>
     200     >>> print get_inner_HTML_part("""<html>
    201201     ... <head>
    202202     ... </head>
     
    213213   If there is also no ``<body>`` tag, we return the input as-is:
    214214
    215      >>> print getInnerHTMLPart("""<div>
     215     >>> print get_inner_HTML_part("""<div>
    216216     ...  <div>Some content</div>
    217217     ... </div>
  • main/waeup.sirp/trunk/src/waeup/sirp/utils/tests/test_helpers.py

    r7137 r7186  
    5454
    5555    def test_handle_not_existing_path(self):
    56         result = helpers.removeFileOrDirectory(self.non_file)
     56        result = helpers.remove_file_or_directory(self.non_file)
    5757        self.assertTrue(result is None)
    5858        return
    5959
    6060    def test_handle_dir(self):
    61         helpers.removeFileOrDirectory(self.dirpath)
     61        helpers.remove_file_or_directory(self.dirpath)
    6262        self.assertFalse(
    6363            os.path.exists(self.dirpath)
     
    6666
    6767    def test_handle_file(self):
    68         helpers.removeFileOrDirectory(self.filepath)
     68        helpers.remove_file_or_directory(self.filepath)
    6969        self.assertFalse(
    7070            os.path.exists(self.filepath)
     
    7373
    7474class CopyFileSystemTreeTestCase(unittest.TestCase):
    75     # Test edge cases of copyFileSystemTree().
     75    # Test edge cases of copy_filesystem_tree().
    7676    #
    7777    # This is a typical case of tests not written as doctest as it is
     
    9494
    9595    def test_source_and_dst_existing(self):
    96         helpers.copyFileSystemTree(self.existing_src, self.existing_dst)
     96        helpers.copy_filesystem_tree(self.existing_src, self.existing_dst)
    9797        self.assertTrue(
    9898            os.path.exists(
     
    105105        self.assertRaises(
    106106            ValueError,
    107             helpers.copyFileSystemTree,
     107            helpers.copy_filesystem_tree,
    108108            self.not_existing_dir,
    109109            self.existing_dst
     
    114114        self.assertRaises(
    115115            ValueError,
    116             helpers.copyFileSystemTree,
     116            helpers.copy_filesystem_tree,
    117117            self.existing_src,
    118118            self.not_existing_dir
     
    123123        self.assertRaises(
    124124            ValueError,
    125             helpers.copyFileSystemTree,
     125            helpers.copy_filesystem_tree,
    126126            self.filepath,
    127127            self.existing_dst
     
    132132        self.assertRaises(
    133133            ValueError,
    134             helpers.copyFileSystemTree,
     134            helpers.copy_filesystem_tree,
    135135            self.existing_src,
    136136            self.filepath
Note: See TracChangeset for help on using the changeset viewer.