Ignore:
Timestamp:
21 Nov 2014, 08:07:15 (10 years ago)
Author:
Henrik Bettermann
Message:

Add more browser components for document editing. Editing is allowed only under certain conditions.

  • work in progress -
Location:
main/waeup.ikoba/trunk/src/waeup/ikoba
Files:
1 added
9 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.ikoba/trunk/src/waeup/ikoba/customers/browser.py

    r12016 r12018  
    4343from waeup.ikoba.browser.interfaces import ICaptchaManager
    4444from waeup.ikoba.mandates.mandate import PasswordMandate
     45from waeup.ikoba.documents.workflow import VERIFIED, REJECTED, OUTDATED
    4546from waeup.ikoba.utils.helpers import get_current_principal, to_timezone, now
    4647from waeup.ikoba.customers.interfaces import (
     
    577578
    578579    def update(self):
    579         PWCHANGE_STATES = getUtility(ICustomersUtils).PWCHANGE_STATES
    580         if self.context.customer.state not in PWCHANGE_STATES:
     580        CUSTMANAGE_STATES = getUtility(ICustomersUtils).CUSTMANAGE_STATES
     581        if self.context.customer.state not in CUSTMANAGE_STATES:
    581582            emit_lock_message(self)
    582583            return
     
    756757    pnav = 4
    757758
     759    #@property
     760    #def label(self):
     761    #    return _('${a}: Document ${b}', mapping = {
     762    #        'a':self.context.customer.display_fullname,
     763    #        'b':self.context.document_id})
     764
    758765    @property
    759766    def label(self):
    760         return _('${a}: Document ${b}', mapping = {
    761             'a':self.context.customer.display_fullname,
    762             'b':self.context.document_id})
    763         return self.context.document_id
     767        return _('${a}', mapping = {'a':self.context.title})
    764768
    765769
     
    770774    grok.name('manage')
    771775    grok.require('waeup.manageCustomer')
     776    grok.template('documenteditpage')
    772777    form_fields = grok.AutoFields(ICustomerDocument)
    773778    pnav = 4
    774779
     780    #@property
     781    #def label(self):
     782    #    return _('${a}: Document ${b}', mapping = {
     783    #        'a':self.context.customer.display_fullname,
     784    #        'b':self.context.document_id})
     785
    775786    @property
    776787    def label(self):
    777         return _('${a}: Document ${b}', mapping = {
    778             'a':self.context.customer.display_fullname,
    779             'b':self.context.document_id})
    780         return self.context.document_id
     788        return _('${a}', mapping = {'a':self.context.title})
    781789
    782790    @action(_('Save'), style='primary')
     
    784792        msave(self, **data)
    785793        return
     794
     795class DocumentEditFormPage(DocumentManageFormPage):
     796    """ Page to edit a document
     797    """
     798    grok.context(ICustomerDocument)
     799    grok.name('edit')
     800    grok.require('waeup.handleCustomer')
     801    form_fields = grok.AutoFields(ICustomerDocument)
     802    pnav = 4
     803
     804    def update(self):
     805        if not self.context.is_editable:
     806            emit_lock_message(self)
     807            return
     808        return super(DocumentEditFormPage, self).update()
  • main/waeup.ikoba/trunk/src/waeup/ikoba/customers/documents.py

    r12015 r12018  
    2020"""
    2121import grok
     22from zope.component import queryUtility, getUtility
    2223from zope.component.interfaces import IFactory
    2324from zope.interface import implementedBy
    2425from waeup.ikoba.interfaces import MessageFactory as _
    2526from waeup.ikoba.customers.interfaces import (
    26     ICustomerDocumentsContainer, ICustomerNavigation, ICustomerDocument)
     27    ICustomerDocumentsContainer, ICustomerNavigation, ICustomerDocument,
     28    ICustomersUtils)
    2729from waeup.ikoba.documents import DocumentsContainer, Document
     30from waeup.ikoba.documents.interfaces import IDocumentsUtils
    2831from waeup.ikoba.utils.helpers import attrs_to_fields
    2932
     
    6770        return self.__parent__.__parent__.writeLogMessage(view, message)
    6871
     72    @property
     73    def is_editable(self):
     74        try:
     75            # Customer must be approved
     76            cond1 = self.customer.state in getUtility(
     77                ICustomersUtils).DOCMANAGE_STATES
     78            # Document must be in state created
     79            cond2 = self.state in getUtility(
     80                IDocumentsUtils).DOCMANAGE_STATES
     81            if not (cond1 and cond2):
     82                return False
     83        except AttributeError:
     84            pass
     85        return True
     86
    6987CustomerDocument = attrs_to_fields(CustomerDocument)
    7088
  • main/waeup.ikoba/trunk/src/waeup/ikoba/customers/export.py

    r12007 r12018  
    145145    fields = tuple(
    146146        sorted(iface_names(
    147             ICustomerDocument, exclude_attribs=False))) + (
     147            ICustomerDocument,
     148            exclude_attribs=False,
     149            omit=['is_editable']))) + (
    148150            'customer_id',)
    149151
  • main/waeup.ikoba/trunk/src/waeup/ikoba/customers/interfaces.py

    r11997 r12018  
    1 ## $Id: interfaces.py 11589 2014-04-22 07:13:16Z henrik $
     1## $Id$
    22##
    33## Copyright (C) 2014 Uli Fouquet & Henrik Bettermann
     
    241241    """
    242242
     243    is_editable = Attribute('Document editable by customer')
  • main/waeup.ikoba/trunk/src/waeup/ikoba/customers/tests/test_browser.py

    r12016 r12018  
    107107        # Set password
    108108        IUserAccount(
    109             self.app['customers'][self.customer_id]).setPassword('spwd')
     109            self.app['customers'][self.customer_id]).setPassword('cpwd')
    110110
    111111        self.login_path = 'http://localhost/app/login'
     
    484484        self.browser.open(self.login_path)
    485485        self.browser.getControl(name="form.login").value = self.customer_id
    486         self.browser.getControl(name="form.password").value = 'spwd'
     486        self.browser.getControl(name="form.password").value = 'cpwd'
    487487        self.browser.getControl("Login").click()
    488488        self.assertMatches(
     
    511511        self.browser.open(self.login_path)
    512512        self.browser.getControl(name="form.login").value = self.customer_id
    513         self.browser.getControl(name="form.password").value = 'spwd'
     513        self.browser.getControl(name="form.password").value = 'cpwd'
    514514        self.browser.getControl("Login").click()
    515515        self.assertEqual(self.browser.url, self.customer_path)
     
    554554        self.browser.open(self.login_path)
    555555        self.browser.getControl(name="form.login").value = self.customer_id
    556         self.browser.getControl(name="form.password").value = 'spwd'
     556        self.browser.getControl(name="form.password").value = 'cpwd'
    557557        self.browser.getControl("Login").click()
    558558        self.assertMatches(
     
    575575        self.browser.open(self.login_path)
    576576        self.browser.getControl(name="form.login").value = self.customer_id
    577         self.browser.getControl(name="form.password").value = 'spwd'
     577        self.browser.getControl(name="form.password").value = 'cpwd'
    578578        self.browser.getControl("Login").click()
    579579        self.assertEqual(self.browser.url, self.customer_path)
     
    594594        self.browser.open(self.login_path)
    595595        self.browser.getControl(name="form.login").value = self.customer_id
    596         self.browser.getControl(name="form.password").value = 'spwd'
     596        self.browser.getControl(name="form.password").value = 'cpwd'
    597597        self.browser.getControl("Login").click()
    598598        self.assertTrue(
     
    600600        # We set the password again
    601601        IUserAccount(
    602             self.app['customers'][self.customer_id]).setPassword('spwd')
     602            self.app['customers'][self.customer_id]).setPassword('cpwd')
    603603        # Customers can't login if their account is suspended/deactivated
    604604        self.customer.suspended = True
    605605        self.browser.open(self.login_path)
    606606        self.browser.getControl(name="form.login").value = self.customer_id
    607         self.browser.getControl(name="form.password").value = 'spwd'
     607        self.browser.getControl(name="form.password").value = 'cpwd'
    608608        self.browser.getControl("Login").click()
    609609        self.assertMatches(
     
    613613        self.customer.suspended_comment = u'Aetsch baetsch!'
    614614        self.browser.getControl(name="form.login").value = self.customer_id
    615         self.browser.getControl(name="form.password").value = 'spwd'
     615        self.browser.getControl(name="form.password").value = 'cpwd'
    616616        self.browser.getControl("Login").click()
    617617        self.assertMatches(
     
    622622        # is not expired
    623623        self.app['customers'][self.customer_id].setTempPassword(
    624             'anybody', 'temp_spwd')
    625         self.browser.open(self.login_path)
    626         self.browser.getControl(name="form.login").value = self.customer_id
    627         self.browser.getControl(name="form.password").value = 'spwd'
     624            'anybody', 'temp_cpwd')
     625        self.browser.open(self.login_path)
     626        self.browser.getControl(name="form.login").value = self.customer_id
     627        self.browser.getControl(name="form.password").value = 'cpwd'
    628628        self.browser.getControl("Login").click()
    629629        self.assertMatches(
     
    633633        self.browser.open(self.login_path)
    634634        self.browser.getControl(name="form.login").value = self.customer_id
    635         self.browser.getControl(name="form.password").value = 'temp_spwd'
     635        self.browser.getControl(name="form.password").value = 'temp_cpwd'
    636636        self.browser.getControl("Login").click()
    637637        self.assertMatches(
     
    652652        self.browser.open(self.login_path)
    653653        self.browser.getControl(name="form.login").value = self.customer_id
    654         self.browser.getControl(name="form.password").value = 'spwd'
     654        self.browser.getControl(name="form.password").value = 'cpwd'
    655655        self.browser.getControl("Login").click()
    656656        self.assertMatches(
     
    825825            '- K1000000 - removed: %s'
    826826            % document.document_id in logcontent)
     827
     828    def test_edit_document(self):
     829        # Customers can manage documents under certain conditions
     830        self.browser.open(self.login_path)
     831        self.browser.getControl(name="form.login").value = self.customer_id
     832        self.browser.getControl(name="form.password").value = 'cpwd'
     833        self.browser.getControl("Login").click()
     834        self.assertMatches(
     835            '...You logged in...', self.browser.contents)
     836        self.browser.getLink("Documents").click()
     837        self.browser.getLink("Add document").click()
     838        self.browser.getControl(name="doctype").value = ['generic']
     839        self.browser.getControl("Create document").click()
     840        self.assertTrue('Generic Document created.' in self.browser.contents)
     841        document = self.customer['documents']['d102']
     842
     843        # Document can be edited ...
     844        self.browser.getLink("d102").click()
     845
     846
     847        self.browser.open(self.documents_path + '/d102/edit')
     848        #self.browser.getLink("Edit").click()
     849        self.assertTrue('The requested form is locked' in self.browser.contents)
     850
     851
     852
     853
     854
     855
     856
     857        self.browser.getControl(name="form.title").value = 'My second doc'
     858        self.browser.getControl("Save").click()
     859        self.assertTrue('Form has been saved.' in self.browser.contents)
     860        self.browser.getLink("View").click()
     861        self.assertEqual(self.browser.url, self.documents_path + '/d102/index')
  • main/waeup.ikoba/trunk/src/waeup/ikoba/customers/utils.py

    r11997 r12018  
    1 ## $Id: utils.py 11875 2014-10-24 12:47:13Z henrik $
     1## $Id$
    22##
    33## Copyright (C) 2014 Uli Fouquet & Henrik Bettermann
     
    1919"""
    2020import grok
    21 from waeup.ikoba.interfaces import STARTED
     21from waeup.ikoba.interfaces import STARTED, APPROVED
    2222from waeup.ikoba.customers.interfaces import ICustomersUtils
    2323
     
    3838    CUSTOMER_ID_PREFIX = u'K'
    3939
    40     PWCHANGE_STATES = (STARTED,)
     40    CUSTMANAGE_STATES = (STARTED,)
     41
     42    DOCMANAGE_STATES = (APPROVED,)
  • main/waeup.ikoba/trunk/src/waeup/ikoba/customers/viewlets.py

    r12016 r12018  
    307307    target = 'manage'
    308308
     309
     310class DocumentEditActionButton(ManageActionButton):
     311    grok.order(1)
     312    grok.context(ICustomerDocument)
     313    grok.view(DocumentDisplayFormPage)
     314    grok.require('waeup.handleCustomer')
     315    text = _('Edit')
     316    target = 'edit'
     317
     318    @property
     319    def target_url(self):
     320        if not self.context.is_editable:
     321            return ''
     322        return self.view.url(self.view.context, self.target)
     323
     324
    309325class DocumentViewActionButton(ManageActionButton):
    310326    grok.order(1)
    311327    grok.context(ICustomerDocument)
    312328    grok.view(DocumentManageFormPage)
    313     grok.require('waeup.manageCustomer')
     329    grok.require('waeup.handleCustomer')
    314330    text = _('View')
    315331    target = 'index'
  • main/waeup.ikoba/trunk/src/waeup/ikoba/documents/interfaces.py

    r12017 r12018  
    1616## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
    1717##
    18 from zope.interface import Attribute
     18from zope.interface import Attribute, Interface
    1919from zope import schema
    2020from waeup.ikoba.interfaces import (
     
    5252        )
    5353
     54class IDocumentsUtils(Interface):
     55    """A collection of methods which are subject to customization.
    5456
     57    """
     58
  • main/waeup.ikoba/trunk/src/waeup/ikoba/documents/utils.py

    r12005 r12018  
    1919"""
    2020import grok
     21from waeup.ikoba.documents.workflow import CREATED
     22from waeup.ikoba.documents.interfaces import IDocumentsUtils
    2123
    2224
     
    2426    new_id = grok.getSite().unique_document_id
    2527    return new_id
     28
     29
     30class DocumentssUtils(grok.GlobalUtility):
     31    """A collection of methods subject to customization.
     32    """
     33    grok.implements(IDocumentsUtils)
     34
     35    DOCMANAGE_STATES = (CREATED,)
Note: See TracChangeset for help on using the changeset viewer.