Exemplo n.º 1
0
 def update(self):
     need(IRegisterPage)
     captcha = getMultiAdapter((self.context, self.request), name='captcha')
     self._process(captcha)
     self.url = absoluteURL(self.context, self.request)
     self.captcha_img = captcha.image_tag()
     self.captcha_audio_url = captcha.audio_url()
Exemplo n.º 2
0
    def __call__(self):
        need(IFormResources)
        # Request now provide local by default
        assert hasattr(self.request, 'locale')
        convert_request_form_to_unicode(self.request.form)

        return super(ZopeForm, self).__call__()
Exemplo n.º 3
0
 def GET(self):
     root = self.context.get_root()
     self.version = root.get_silva_software_version()
     need(IAboutResources)
     data = {"content": {"ifaces": ["text-overlay"], "html": self.template.render(self)}}
     ResourcesProvider(self, self.request)(self, data)
     return self.json_response(data)
Exemplo n.º 4
0
    def update(self):
        need(ICalendarResources)
        self.now = datetime.now(self.context.get_timezone())
        self.selected_month = self.get_int_param('month', self.now.month)
        self.selected_year = self.get_int_param('year', self.now.year)
        try:
            self.selected_day = datetime(
                self.selected_year,
                self.selected_month,
                self.get_selected_day(self.now),
                tzinfo=self.context.get_timezone())
        except ValueError:
            self.selected_day = self.now
            self.selected_year = self.now.year
            self.selected_month = self.now.month

        self.start = datetimeutils.start_of_month(self.selected_day)
        self.end = datetimeutils.end_of_month(self.selected_day)

        self._day_events = self._selected_day_events()
        self.calendar = self.build_calendar(
            self.selected_day.date(), self.start, self.end, self.now.date())

        if self.should_display_prev_link():
            self.calendar.prev_link = \
                '<a class="prevmonth caljump" href="%s">&lt;</a>' % \
                    self.prev_month_url()
        if self.should_display_next_link():
            self.calendar.next_link = \
                '<a class="nextmonth caljump" href="%s">&gt;</a>' % \
                    self.next_month_url()
Exemplo n.º 5
0
 def update(self):
     super(CustomPathWidget, self).update()
     need(ICustomPathResources)
     int_id = getUtility(IIntIds).register(self.form.context)
     self._htmlAttributes['data-lookup-url'] = self.lookup_url
     self._htmlAttributes['data-target-id'] = str(int_id)
     self._htmlAttributes['size'] = '24'
     self._htmlAttributes['placeholder'] = _(u'Shortcut...')
Exemplo n.º 6
0
 def update(self):
     need(ICalendarResources)
     timezone = self.context.get_timezone()
     now = datetime.now()
     self.year = int(self.request.get('year', now.year))
     self.start = datetime(self.year, 1, 1, tzinfo=timezone)
     self.end = datetimeutils.end_of_year(self.start)
     self.calendar = self.build_calendar(
         self.start.date(), self.start, self.end, now.date())
 def update(self):
     self.actives = []
     self.changes = []
     if self.include_changes:
         need(IGraphResources)
         self.changes = self.context.get_changes_since(self.days)
         self.values = json.dumps([len(a) for a in self.changes])
     if self.include_actives:
         self.actives = self.context.get_most_active()
 def update(self):
     self.actives = []
     self.changes = []
     if self.include_changes:
         need(IGraphResources)
         self.changes  = self.context.get_changes_since(self.days)
         self.values = json.dumps([len(a) for a in self.changes])
     if self.include_actives:
         self.actives = self.context.get_most_active()
Exemplo n.º 9
0
 def __call__(self, edition=False):
     __info__ = 'Rendering design: %s' % self.__template_path__
     self.update()
     namespace = {}
     namespace.update(self.default_namespace())
     namespace.update(self.namespace())
     if edition:
         need(IEditionResources)
         self.edition = True
     return self.template(**namespace)
Exemplo n.º 10
0
 def update(self):
     need(ILoginPage)
     self.url = absoluteURL(self.context, self.request)
     if self.action is None:
         raise BadRequest()
     # Due how PAS monkey patch Zope, we need to do this by hand here.
     headers = queryMultiAdapter(
         (self.request, self),
         IHTTPResponseHeaders)
     if headers is not None:
         headers()
Exemplo n.º 11
0
    def update(self):
        super(ReferenceWidgetInput, self).update()
        need(IReferenceUIResources)

        resolver = ReferenceInfoResolver(
            self.request, self.form.context, self,
            multiple=False,
            message=self.referenceLabel)
        resolver.update(
            interface=self.component.schemaName,
            show_index=self.component.showIndex)
        resolver.add(value_id=self.inputValue())
Exemplo n.º 12
0
 def update(self):
     need(ITabResources)
     self.tabs = []
     for content in self.content:
         version = content.get_viewable()
         details = queryMultiAdapter(
             (version, self.request), IDocumentDetails)
         if details is None:
             continue
         self.tabs.append(
             {'identifier': uuid.uuid1(),
              'title': details.get_title(),
              'content':details.get_text()
              })
Exemplo n.º 13
0
    def update(self):
        need(IPhotoGalleryResources)
        self.photos = []
        self.intro = self.context.get_default()
        get_metadata = getUtility(IMetadataService).getMetadataValue

        def get_info(image):
            return {
                'title': image.get_title_or_id(),
                'url': image.url(),
                'thumbnail': image.url(thumbnail=True),
                'description': get_metadata(image, 'silva-extra', 'content_description')}

        self.photos = map(get_info, self.context.objectValues('Silva Image'))
Exemplo n.º 14
0
 def update(self):
     need(ITabResources)
     self.tabs = []
     for content in self.content:
         version = content.get_viewable()
         details = queryMultiAdapter((version, self.request),
                                     IDocumentDetails)
         if details is None:
             continue
         self.tabs.append({
             'identifier': uuid.uuid1(),
             'title': details.get_title(),
             'content': details.get_text()
         })
Exemplo n.º 15
0
 def update(self):
     need(ISlideshowResources)
     self.contents = []
     for content in self.container.get_ordered_publishables(IMediaContent):
         version = content.get_viewable()
         if version is None:
             continue
         info = {"title": version.get_title(), "text": version.get_text().strip(), "image": None}
         asset = version.get_asset()
         if IImage.providedBy(asset):
             dimensions = asset.get_dimensions()
             info.update(
                 {"image": asset.url(request=self.request), "width": dimensions.width, "height": dimensions.height}
             )
         self.contents.append(info)
Exemplo n.º 16
0
    def content(self):
        assert isinstance(self.__parent__, CompareVersionScreen)
        assert self.__parent__.version1 is not None
        assert self.__parent__.version2 is not None

        version1_view = getMultiAdapter(
            (self.context, self.request), name='content.html')
        version1_view.content = self.__parent__.version1
        version1_html = version1_view()

        version2_view = getMultiAdapter(
            (self.context, self.request), name='content.html')
        version2_view.content = self.__parent__.version2
        version2_html = version2_view()

        need(ICompareResources)
        return lxml.html.diff.htmldiff(version2_html, version1_html)
Exemplo n.º 17
0
    def update(self):
        need(self.resources)
        self.results = []
        self.result_widgets = []
        self.message = u''
        self.batch = u''
        # Search for results
        if 'search_submit' in self.request.form:
            try:
                results = self.context.searchResults(self.request)
            except ValueError as error:
                self.message = error[0]
            else:
                # Filter results on View permission
                # XXX This could be done more in a more lazy fashion
                verify = getSecurityManager().checkPermission
                self.results = batch(filter(
                    lambda b: verify('View', b.getObject()), results),
                                     count=20,
                                     request=self.request)

                if self.results:
                    for field in self.context.getPublicResultFields():
                        widget = getMultiAdapter(
                            (field, self.context, self.request), IResultView)
                        widget.update(self)
                        self.result_widgets.append(widget)

                    self.batch = component.getMultiAdapter(
                        (self.context, self.results, self.request),
                        IBatching)()
                else:
                    self.message = _(u'No items matched your search.')

        # Search Widgets
        self.widgets = []
        for field in self.context.getPublicSearchFields():
            widget = getMultiAdapter((field, self.context, self.request),
                                     ICriterionView)
            self.widgets.append(widget)
Exemplo n.º 18
0
    def update(self):
        need(self.resources)
        self.results = []
        self.result_widgets = []
        self.message = u''
        self.batch = u''
        # Search for results
        if 'search_submit' in self.request.form:
            try:
                results = self.context.searchResults(self.request)
            except ValueError as error:
                self.message = error[0]
            else:
                # Filter results on View permission
                # XXX This could be done more in a more lazy fashion
                verify = getSecurityManager().checkPermission
                self.results = batch(
                    filter(lambda b: verify('View', b.getObject()), results),
                    count=20,
                    request=self.request)

                if self.results:
                    for field in self.context.getPublicResultFields():
                        widget = getMultiAdapter(
                            (field, self.context, self.request), IResultView)
                        widget.update(self)
                        self.result_widgets.append(widget)

                    self.batch = component.getMultiAdapter(
                        (self.context, self.results, self.request), IBatching)()
                else:
                    self.message = _(u'No items matched your search.')

        # Search Widgets
        self.widgets = []
        for field in self.context.getPublicSearchFields():
            widget = getMultiAdapter((
                    field, self.context, self.request), ICriterionView)
            self.widgets.append(widget)
Exemplo n.º 19
0
 def update(self):
     need(IMultiPickupFieldResources)
     super(MultiPickupFieldWidget, self).update()
Exemplo n.º 20
0
 def update(self, install=False, refresh=False, locations=[]):
     super(ManageInstallCodeSources, self).update(install=install,
                                                  refresh=refresh,
                                                  locations=locations)
     need(jquery)
Exemplo n.º 21
0
 def update(self):
     need(IForumResources)
     self.emoticons_directory = self.static['emoticons']()
Exemplo n.º 22
0
 def update(self):
     need(IDateTimeResources)
     super(DateTimeFieldWidget, self).update()
Exemplo n.º 23
0
    def update(self, answer=None):
        need(IPollQuestionResources)
        # This code is too complicated and would need
        # simplification. This is all the logic that was in the
        # template before.
        now = datetime.now()
        locale_opts = {'size': 'full',
                       'locale': get_locale_info(self.request),
                       'display_time': False}
        self.question = self.content.get_question()
        self.has_voted = self.content.has_voted(self.request)
        self.show_results_not_ready = False

        if self.is_preview:
            # Preview: show poll and results
            self.show_poll_not_ready = False
            self.show_poll = True
            self.show_results = True
            self.show_outdated = False
        else:
            # Public view: show corresponding section depending of the
            # current time
            start_date = self.content.question_start_datetime()
            end_date = self.content.question_end_datetime()
            self.show_poll_not_ready = start_date is not None and start_date > now
            if self.show_poll_not_ready:
                self.poll_start_date = get_formatted_date(
                    start_date, **locale_opts)
            self.show_poll = (
                (start_date is not None and start_date < now) and
                (end_date is None or end_date > now))
            start_date = self.content.result_start_datetime()
            end_date = self.content.result_end_datetime()
            self.show_outdated = end_date is not None and end_date < now
            self.show_results = (
                (start_date is not None and start_date < now) and
                (end_date is None or end_date > now))

        if self.show_poll:
            # We want to show the poll.
            if self.has_voted:
                # The user already voted, don't show the poll, even if
                # the dates are ok.
                self.show_poll = False
            else:
                if answer is not None:
                    # User just voted, register the code, and don't
                    # show the poll.
                    answer = unicode(answer, 'utf-8')
                    self.content.vote(self.request, answer)
                    self.has_voted = True
                    self.show_poll = False
                else:
                    # The user didn't vote yet. Really show poll.
                    self.answers = []
                    for index, answer in enumerate(self.content.get_answers()):
                        self.answers.append({'title': answer,
                                             'id': 'answer-%02d' % index})

        if self.show_results:
            all_votes = self.content.get_votes()
            self.total_votes = sum(all_votes)
            self.results = []
            for answer, votes in zip(self.content.get_answers(), all_votes):
                percentage = 0
                if self.total_votes:
                    percentage = round((votes * 100.0)/ self.total_votes)
                self.results.append({'answer': answer,
                                     'votes': votes,
                                     'percentage': percentage})
        elif self.has_voted:
            # The user voted, but cannot see the results yet. Tell him
            # when he will be able to see them.

            # The result start and end date and the last fetch into
            # start_date, and end_date. Preview code doesn't fetch
            # them, but in preview the results are always shown.
            self.show_results_not_ready = True
            self.show_results_start_date = get_formatted_date(
                start_date, **locale_opts)
            self.show_results_end_date = None
            if end_date is not None:
                self.show_results_end_date = get_formatted_date(
                    end_date, **locale_opts)
Exemplo n.º 24
0
 def update(self):
     need(IJSCalendarResources)
 def update(self, install=False, refresh=False, locations=[]):
     super(ManageInstallCodeSources, self).update(
         install=install, refresh=refresh, locations=locations)
     need(jquery)
 def update(self):
     need(IGraphResources)
     self.changes = self.context.get_changes_since(self.days)
     self.values = json.dumps([len(a) for a in self.changes])
Exemplo n.º 27
0
 def update(self):
     need(IUploadResources)
     super(FileWidgetInput, self).update()
Exemplo n.º 28
0
 def update(self):
     need(ITreeResources)
     super(TreeWidgetInput, self).update()
Exemplo n.º 29
0
    def update(self):
        # Redirect to the root of the SMI if we are not already
        site = IVirtualSite(self.request)
        settings = getUtility(IUIService)
        if settings.smi_access_root:
            top_level = site.get_silva_root()
        else:
            top_level = site.get_root()

        # We lookup for the highest container where we have access
        root = self.context.get_container()
        while root != top_level:
            parent = root.get_real_container()
            if (parent is None or
                    not checkPermission('silva.ReadSilvaContent', parent)):
                # We don't have access at that level
                break
            root = parent

        root_content_url = getMultiAdapter((root, self.request), IContentURL)
        root_url = root_content_url.url()
        if root != self.context:
            # Relative path of the content from the root.
            content_url = getMultiAdapter(
                (self.context, self.request), IContentURL)
            root_path = root_content_url.url(relative=True).split('/')
            content_path = content_url.url(relative=True).split('/')
            path = '/'.join(relative_path(root_path, content_path))

            raise Redirect('/'.join((root_url, 'edit')) + '#!' + path)

        # Set the proper SMI skin
        set_smi_skin(self.context, self.request)

        # Load the extensions
        for load_entry in iter_entry_points('silva.ui.resources'):
            resource = load_entry.load()
            need(resource)

        # Customization from service
        if settings.logo is not None:
            settings_content_url = getMultiAdapter(
                (settings, self.request), IContentURL)
            self.logo_url = '/'.join((settings_content_url.url(), 'logo'))
        else:
            self.logo_url = self.static['img']['silva.png']()
        self.background = '#7996ac'
        self.name = settings.name
        self.listing_preview = settings.folder_icon_preview
        self.maintenance_message = settings.maintenance_message
        self.test_mode = settings.test_mode
        self.preview_resolutions = []
        self.notifications_life = settings.notifications_life
        if settings.preview_use_resolutions:
            self.preview_resolutions = list(settings.preview_resolutions)
        if settings.background:
            self.background = settings.background

        # Prepare values for template
        languages = IUserPreferredLanguages(
            self.request).getPreferredLanguages()

        self.language = languages[0] if languages else 'en'
        self.root_url = root_url
        self.can_manage = getSecurityManager().checkPermission(
            'View Management Screens', self.context)
 def update(self):
     need(IGraphResources)
     self.changes  = self.context.get_changes_since(self.days)
     self.values = json.dumps([len(a) for a in self.changes])
Exemplo n.º 31
0
 def update(self):
     super(CropImageInputWidget, self).update()
     need(ICropResources)
     self.url = self.form.url(self.form.context) + '?hires'
 def includeResources(self):
     need(IPhotoGalleryResources)
     return u''
Exemplo n.º 33
0
 def update(self):
     need(IComboBoxResources)
     super(ComboBoxFieldWidget, self).update()
Exemplo n.º 34
0
 def update(self):
     super(ReferenceMultipleWidgetInput, self).update()
     need(IReferenceUIResources)
Exemplo n.º 35
0
 def update(self):
     need(IRecurrenceResources)
     super(RecurrenceWidgetInput, self).update()
Exemplo n.º 36
0
 def render(self):
     need(IFullLayer)
     return u'<html><head></head><body>Hello</body></html>'
Exemplo n.º 37
0
    def update(self, answer=None):
        need(IPollQuestionResources)
        # This code is too complicated and would need
        # simplification. This is all the logic that was in the
        # template before.
        now = datetime.now()
        locale_opts = {
            'size': 'full',
            'locale': get_locale_info(self.request),
            'display_time': False
        }
        self.question = self.content.get_question()
        self.has_voted = self.content.has_voted(self.request)
        self.show_results_not_ready = False

        if self.is_preview:
            # Preview: show poll and results
            self.show_poll_not_ready = False
            self.show_poll = True
            self.show_results = True
            self.show_outdated = False
        else:
            # Public view: show corresponding section depending of the
            # current time
            start_date = self.content.question_start_datetime()
            end_date = self.content.question_end_datetime()
            self.show_poll_not_ready = start_date is not None and start_date > now
            if self.show_poll_not_ready:
                self.poll_start_date = get_formatted_date(
                    start_date, **locale_opts)
            self.show_poll = ((start_date is not None and start_date < now)
                              and (end_date is None or end_date > now))
            start_date = self.content.result_start_datetime()
            end_date = self.content.result_end_datetime()
            self.show_outdated = end_date is not None and end_date < now
            self.show_results = ((start_date is not None and start_date < now)
                                 and (end_date is None or end_date > now))

        if self.show_poll:
            # We want to show the poll.
            if self.has_voted:
                # The user already voted, don't show the poll, even if
                # the dates are ok.
                self.show_poll = False
            else:
                if answer is not None:
                    # User just voted, register the code, and don't
                    # show the poll.
                    answer = str(answer, 'utf-8')
                    self.content.vote(self.request, answer)
                    self.has_voted = True
                    self.show_poll = False
                else:
                    # The user didn't vote yet. Really show poll.
                    self.answers = []
                    for index, answer in enumerate(self.content.get_answers()):
                        self.answers.append({
                            'title': answer,
                            'id': 'answer-%02d' % index
                        })

        if self.show_results:
            all_votes = self.content.get_votes()
            self.total_votes = sum(all_votes)
            self.results = []
            for answer, votes in zip(self.content.get_answers(), all_votes):
                percentage = 0
                if self.total_votes:
                    percentage = round((votes * 100.0) / self.total_votes)
                self.results.append({
                    'answer': answer,
                    'votes': votes,
                    'percentage': percentage
                })
        elif self.has_voted:
            # The user voted, but cannot see the results yet. Tell him
            # when he will be able to see them.

            # The result start and end date and the last fetch into
            # start_date, and end_date. Preview code doesn't fetch
            # them, but in preview the results are always shown.
            self.show_results_not_ready = True
            self.show_results_start_date = get_formatted_date(
                start_date, **locale_opts)
            self.show_results_end_date = None
            if end_date is not None:
                self.show_results_end_date = get_formatted_date(
                    end_date, **locale_opts)