Conjunto de mudanças 6537 no repositório publico


Ignorar:
Timestamp:
21/06/2012 00:46:52 (9 anos atrás)
Autor:
mazza
Mensagem:

refatoracao: classe BoxAware? e constante NUMBER_OF_PRE_CREATED_BOXES criadas

Localização:
PortalInterlegis/produtos/il.portalinterlegis/trunk/src/il/portalinterlegis
Arquivos:
2 editados

Legenda:

Não Modificado
Adicionado
Removido
  • PortalInterlegis/produtos/il.portalinterlegis/trunk/src/il/portalinterlegis/browser/boxes/manager.py

    r6536 r6537  
    2929
    3030
    31 class BaseBox(object):
     31class BoxAware(object):
     32
     33    ALL_BOXES_KEY = 'il.portalinterlegis.boxes'
     34
     35    def get_box_data(self, context, key):
     36        annotations = IAnnotations(context)
     37        boxes = get_or_create_from_dict(annotations, self.ALL_BOXES_KEY)
     38        return get_or_create_from_dict(boxes, key)
     39
     40    def erase_box_data(self, context, key):
     41        annotations = IAnnotations(context)
     42        boxes = annotations.get(self.ALL_BOXES_KEY, None)
     43        if boxes and key in boxes:
     44            del boxes[key]
     45
     46
     47class BaseBox(BoxAware):
    3248    """Base abstract class for editable boxes.
    3349    """
     50
    3451
    3552    def __init__(self, permission=ModifyPortalContent):
     
    4764    @property
    4865    def id(self):
     66        "id of the box. Used in the template."
    4967        raise NotImplementedError
    5068
     
    5876
    5977class Box(BaseBox):
    60 
    61     ALL_BOXES_KEY = 'il.portalinterlegis.boxes'
    6278
    6379    def __init__(self, schema, number, permission=ModifyPortalContent, form_label=None):
     
    7692
    7793    def get_data_from(self, context):
    78         annotations = IAnnotations(context)
    79         boxes = get_or_create_persistent_dict(annotations, self.ALL_BOXES_KEY)
    80         return get_or_create_persistent_dict(boxes, self.id)
     94        return self.get_box_data(context, self.id)
     95
     96    def erase_data_from(self, context):
     97        self.erase_box_data(context, self.id)
    8198
    8299    @property
     
    88105    edit_href = form_name  # To be overridden independently
    89106
     107def get_or_create_from_dict(dictionary, key, type_to_create=PersistentDict):
     108    value = dictionary.get(key, None)
     109    if not value:
     110        dictionary[key] = value = type_to_create()
     111    return value
    90112
    91113def build_box_form(box):
     
    124146
    125147def build_many_box_forms(schema, max_number):
    126     for number in range(1, max_number + 1):
     148    for number in range(max_number):
    127149        build_box_form(Box(schema, number))
    128150
     
    177199
    178200# initialize all the box managers
     201NUMBER_OF_PRE_CREATED_BOXES = 10
    179202for s in box_schemas():
    180     build_many_box_forms(s, 10)
     203    build_many_box_forms(s, NUMBER_OF_PRE_CREATED_BOXES)
  • PortalInterlegis/produtos/il.portalinterlegis/trunk/src/il/portalinterlegis/tests/testintegration.py

    r6535 r6537  
    77from fixtures import IL_PORTALINTERLEGIS_INTEGRATION_TESTING
    88from il.portalinterlegis.browser.boxes.interfaces import ISimpleBox
    9 from il.portalinterlegis.browser.boxes.manager import Box, build_box_form
     9from il.portalinterlegis.browser.boxes.manager import \
     10     Box, build_box_form, NUMBER_OF_PRE_CREATED_BOXES
    1011from il.portalinterlegis.browser.interfaces import \
    1112     IComunidadeLegislativa, IInformacao, ICapacitacao, ITecnologia, IComunicacao
     
    9394                         box_2.get_data_from(context))
    9495
    95     def test_box_forms_numbers_begin_from_1_not_zero(self):
     96    def test_box_forms_are_limited(self):
     97        browser = self.layer.manager_browser()
     98        # These are ok. No exception raised
     99        browser.open(self.url(Box(ISimpleBox, 0).form_name))
     100        browser.open(self.url(Box(ISimpleBox,
     101                                  NUMBER_OF_PRE_CREATED_BOXES - 1).form_name))
    96102        with self.assertRaises(NotFound):
    97             browser = self.layer.manager_browser()
    98             browser.open(self.url(Box(ISimpleBox, 0).form_name))
    99 
    100     def test_box_forms_are_limited(self):
    101         with self.assertRaises(NotFound):
    102             browser = self.layer.manager_browser()
    103             browser.open(self.url(Box(ISimpleBox, 1000000).form_name))
     103            # This doesn't exist
     104            browser.open(self.url(Box(ISimpleBox,
     105                                      NUMBER_OF_PRE_CREATED_BOXES).form_name))
    104106
    105107    def test_box_form_cannot_be_created_after_initialization(self):
Note: Veja TracChangeset para ajuda no uso do visualizador de conjunto de mudanças.
 

The contents and data of this website are published under license:
Creative Commons 4.0 Brasil - Atribuir Fonte - Compartilhar Igual.