~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/app/browser/lazrjs.py

  • Committer: Launchpad Patch Queue Manager
  • Date: 2011-08-03 11:23:34 UTC
  • mfrom: (13457.6.16 upgrade-stderr)
  • Revision ID: launchpad@pqm.canonical.com-20110803112334-acnupsa7jmzmdeet
[r=stevenk][bug=819751] Fix the implementation of several methods in
 LoggingUIFactory.

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
    'vocabulary_to_choice_edit_items',
17
17
    ]
18
18
 
19
 
from lazr.enum import IEnumeratedType
20
 
from lazr.restful.declarations import LAZR_WEBSERVICE_EXPORTED
21
 
from lazr.restful.utils import (
22
 
    get_current_browser_request,
23
 
    safe_hasattr,
24
 
    )
25
19
import simplejson
 
20
 
26
21
from zope.app.pagetemplate.viewpagetemplatefile import ViewPageTemplateFile
27
22
from zope.component import getUtility
 
23
from zope.security.checker import canAccess, canWrite
28
24
from zope.schema.interfaces import (
29
25
    ICollection,
30
26
    IVocabulary,
31
27
    )
32
28
from zope.schema.vocabulary import getVocabularyRegistry
33
 
from zope.security.checker import (
34
 
    canAccess,
35
 
    canWrite,
36
 
    )
37
 
 
 
29
 
 
30
from lazr.enum import IEnumeratedType
 
31
from lazr.restful.declarations import LAZR_WEBSERVICE_EXPORTED
 
32
from canonical.lazr.utils import get_current_browser_request
 
33
from canonical.lazr.utils import safe_hasattr
 
34
 
 
35
from canonical.launchpad.webapp.interfaces import ILaunchBag
 
36
from canonical.launchpad.webapp.publisher import canonical_url
 
37
from canonical.launchpad.webapp.vocabulary import IHugeVocabulary
38
38
from lp.app.browser.stringformatter import FormattersAPI
39
39
from lp.app.browser.vocabulary import get_person_picker_entry_metadata
40
40
from lp.services.propertycache import cachedproperty
41
 
from lp.services.webapp.interfaces import ILaunchBag
42
 
from lp.services.webapp.publisher import canonical_url
43
 
from lp.services.webapp.vocabulary import IHugeVocabulary
44
41
 
45
42
 
46
43
class WidgetBase:
245
242
                 content_box_id=None, header='Select an item',
246
243
                 step_title='Search',
247
244
                 null_display_value='None',
248
 
                 edit_view="+edit", edit_url=None, edit_title='',
249
 
                 help_link=None):
 
245
                 edit_view="+edit", edit_url=None, edit_title=''):
250
246
        """Create a widget wrapper.
251
247
 
252
248
        :param context: The object that is being edited.
271
267
        self.header = header
272
268
        self.step_title = step_title
273
269
        self.null_display_value = null_display_value
274
 
        self.help_link = help_link
275
270
 
276
271
        # JSON encoded attributes.
277
272
        self.json_content_box_id = simplejson.dumps(self.content_box_id)
311
306
            selected_value=self.selected_value,
312
307
            selected_value_metadata=self.selected_value_metadata,
313
308
            null_display_value=self.null_display_value,
314
 
            show_search_box=self.show_search_box,
315
 
            vocabulary_filters=self.vocabulary_filters)
 
309
            show_search_box=self.show_search_box)
316
310
 
317
311
    @property
318
312
    def json_config(self):
324
318
        return registry.get(
325
319
            IVocabulary, self.exported_field.vocabularyName)
326
320
 
327
 
    @cachedproperty
328
 
    def vocabulary_filters(self):
329
 
        # Only IHugeVocabulary's have filters.
330
 
        if not IHugeVocabulary.providedBy(self.vocabulary):
331
 
            return []
332
 
        supported_filters = self.vocabulary.supportedFilters()
333
 
        # If we have no filters or just the ALL filter, then no filtering
334
 
        # support is required.
335
 
        filters = []
336
 
        if (len(supported_filters) == 0 or
337
 
           (len(supported_filters) == 1
338
 
            and supported_filters[0].name == 'ALL')):
339
 
            return filters
340
 
        for filter in supported_filters:
341
 
            filters.append({
342
 
                'name': filter.name,
343
 
                'title': filter.title,
344
 
                'description': filter.description,
345
 
                })
346
 
        return filters
347
 
 
348
321
    @property
349
322
    def show_search_box(self):
350
323
        return IHugeVocabulary.providedBy(self.vocabulary)
357
330
                 remove_person_text='Remove person',
358
331
                 remove_team_text='Remove team',
359
332
                 null_display_value='None',
360
 
                 edit_view="+edit", edit_url=None, edit_title='',
361
 
                 help_link=None):
 
333
                 edit_view="+edit", edit_url=None, edit_title=''):
362
334
        """Create a widget wrapper.
363
335
 
364
336
        :param context: The object that is being edited.
378
350
        :param edit_url: The URL to use for editing when the user isn't logged
379
351
            in and when JS is off.  Defaults to the edit_view on the context.
380
352
        :param edit_title: Used to set the title attribute of the anchor.
381
 
        :param help_link: Used to set a link for help for the widget.
382
 
        :param target_context: The target the person is being set for.
383
353
        """
384
354
        super(InlinePersonEditPickerWidget, self).__init__(
385
355
            context, exported_field, default_html, content_box_id, header,
386
356
            step_title, null_display_value,
387
 
            edit_view, edit_url, edit_title, help_link)
 
357
            edit_view, edit_url, edit_title)
388
358
 
389
359
        self.assign_me_text = assign_me_text
390
360
        self.remove_person_text = remove_person_text