Ejemplo n.º 1
0
    def _on_setup_widgets(self):
        """Hook
        """
        # Application names
        w = 10
        for l in lang.langs():
            self.add_widget(widget.input.Text(
                uid='setting_app_name_' + l,
                weight=w,
                label=lang.t('settings@application_name', {'lang': lang.lang_title(l)}, l),
                default=lang.t('app_name'),
            ))
            w += 1

            self.add_widget(widget.input.Text(
                uid='setting_home_title_' + l,
                label=lang.t('settings@home_page_title', {'lang': lang.lang_title(l)}, l),
                weight=w,
            ))
            w += 1

            self.add_widget(widget.input.Text(
                uid='setting_home_description_' + l,
                label=lang.t('settings@home_page_description', {'lang': lang.lang_title(l)}, l),
                weight=w,
            ))
            w += 1

            self.add_widget(widget.input.Tokens(
                uid='setting_home_keywords_' + l,
                label=lang.t('settings@home_page_keywords', {'lang': lang.lang_title(l)}, l),
                weight=w,
            ))
            w += 1

        # Links
        self.add_widget(widget.input.StringList(
            uid='setting_links',
            weight=200,
            label=lang.t('settings@links'),
            add_btn_label=lang.t('settings@add_link'),
            rules=validation.rule.Url(),
        ))

        # It is important to call super method AFTER
        super()._on_setup_widgets()
Ejemplo n.º 2
0
    def _on_setup_widgets(self):
        """Hook
        """
        self.add_widget(_widget.select.Checkboxes(
            uid='setting_days_of_week',
            weight=10,
            label=_lang.t('content_digest@days_of_week'),
            int_keys=True,
            items=[
                (0, _lang.t('pytsite.lang@weekday_monday')),
                (1, _lang.t('pytsite.lang@weekday_tuesday')),
                (2, _lang.t('pytsite.lang@weekday_wednesday')),
                (3, _lang.t('pytsite.lang@weekday_thursday')),
                (4, _lang.t('pytsite.lang@weekday_friday')),
                (5, _lang.t('pytsite.lang@weekday_saturday')),
                (6, _lang.t('pytsite.lang@weekday_sunday')),
            ],
            default='0',
        ))

        self.add_widget(_widget.select.DateTime(
            uid='setting_day_time',
            weight=20,
            label=_lang.t('content_digest@time'),
            default='08:00',
            datepicker=False,
            h_size='col-sm-2 col-lg-1'
        ))

        self.add_widget(_widget.input.Integer(
            uid='setting_entities_number',
            weight=30,
            label=_lang.t('content_digest@entities_number'),
            min=1,
            default=10,
            h_size='col-sm-2 col-lg-1'
        ))

        self.add_widget(_content.widget.ModelCheckboxes(
            uid='setting_models',
            weight=40,
            label=_lang.t('content_digest@content_models'),
            filter=lambda entity: entity.has_field('views_count'),
        ))

        w = 50
        for lang_code in _lang.langs():
            self.add_widget(_widget.input.Text(
                uid='setting_mail_subject_{}'.format(lang_code),
                weight=w,
                label=_lang.t('content_digest@mail_subject', {'lang': _lang.lang_title(lang_code)}),
                default=_lang.t('content_digest@default_mail_subject', language=lang_code)
            ))
            w += 1

        super()._on_setup_widgets()
Ejemplo n.º 3
0
    def odm_ui_m_form_setup_widgets(self, frm: form.Form):
        """Hook
        """
        # Parent
        from ._widget import TermSelect
        frm.add_widget(
            TermSelect(
                uid='_parent',
                model=self.model,
                exclude=self if not self.is_new else None,
                exclude_descendants=True,
                label=self.t('parent'),
                append_none_item=not self.get_field('_parent').is_required,
                value=self.parent,
            ))

        # Title
        if self.has_field('title'):
            frm.add_widget(
                widget.input.Text(
                    uid='title',
                    label=lang.t('taxonomy@title'),
                    value=self.title,
                    required=self.get_field('title').is_required,
                ))

        # Alias
        if self.has_field('alias'):
            frm.add_widget(
                widget.input.Text(
                    uid='alias',
                    label=lang.t('taxonomy@alias'),
                    value=self.f_get('alias'),
                ))

        # Weight
        if self.has_field('weight'):
            frm.add_widget(
                widget.input.Integer(uid='weight',
                                     label=lang.t('taxonomy@weight'),
                                     value=self.weight,
                                     h_size='col-sm-3 col-md-2 col-lg-1'))

        # Image
        if self.has_field('image'):
            frm.add_widget(
                file_ui.widget.ImagesUpload(
                    uid='image',
                    label=lang.t('taxonomy@image'),
                    required=self.get_field('image').is_required,
                    value=self.image,
                ))

        # Language
        if self.has_field('language'):
            lng = lang.get_current() if self.is_new else self.language
            frm.add_widget(
                widget.static.Text(
                    uid='language',
                    label=lang.t('taxonomy@language'),
                    text=lang.lang_title(lng),
                    value=lng,
                    hidden=len(lang.langs()) == 1,
                ))
Ejemplo n.º 4
0
    def odm_ui_m_form_setup_widgets(self, frm: _form.Form):
        """Setup of a modification form.
        """
        if frm.current_step == 1:
            frm.add_widget(_widget.select.Checkbox(
                weight=10,
                uid='enabled',
                label=self.t('enabled'),
                value=self.enabled,
            ))

            frm.add_widget(_file_ui.widget.ImagesUpload(
                weight=20,
                uid='logo',
                label=self.t('logo'),
                value=self.logo,
                max_files=1,
                show_numbers=False,
                dnd=False,
            ))

            frm.add_widget(_widget.input.Text(
                weight=30,
                uid='description',
                label=self.t('description'),
                value=self.description,
            ))

            frm.add_widget(_content.widget.ModelSelect(
                weight=40,
                uid='content_model',
                label=self.t('content_model'),
                value=self.content_model,
                h_size='col-sm-4',
                required=True,
            ))

            frm.add_widget(_section.widget.SectionSelect(
                weight=50,
                uid='content_section',
                label=self.t('content_section'),
                value=self.content_section,
                h_size='col-sm-4',
                required=True,
            ))

            frm.add_widget(_content.widget.StatusSelect(
                weight=60,
                uid='content_status',
                label=self.t('content_status'),
                value=self.content_status,
                h_size='col-sm-4',
                required=True,
            ))

            frm.add_widget(_auth_ui.widget.UserSelect(
                weight=70,
                uid='content_author',
                label=self.t('content_author'),
                value=self.content_author if not self.is_new else _auth.get_current_user(),
                h_size='col-sm-4',
                required=True,
            ))

            frm.add_widget(_content_import_widget.DriverSelect(
                weight=80,
                uid='driver',
                label=self.t('driver'),
                value=self.driver,
                h_size='col-sm-4',
                required=True,
            ))

            frm.add_widget(_widget.input.Tokens(
                weight=90,
                uid='add_tags',
                label=self.t('additional_tags'),
                value=self.add_tags,
            ))

            frm.add_widget(_widget.select.DateTime(
                weight=100,
                uid='paused_till',
                label=self.t('paused_till'),
                value=self.paused_till,
                h_size='col-sm-5 col-md-4 col-lg-3',
                hidden=self.is_new,
            ))

            frm.add_widget(_widget.input.Integer(
                weight=110,
                uid='errors',
                label=self.t('errors'),
                value=self.errors,
                h_size='col-sm-1',
                hidden=self.is_new or not self.errors,
            ))

            frm.add_widget(_widget.static.Text(
                weight=120,
                uid='content_language',
                label=self.t('content_language'),
                value=self.content_language,
                text=_lang.lang_title(self.content_language),
                h_size='col-sm-4',
                required=True,
            ))

        if frm.current_step == 2:
            driver = _api.get_driver(_router.request().inp.get('driver'))
            settings_widget = driver.get_settings_widget(self.driver_opts)
            frm.add_widget(settings_widget)
Ejemplo n.º 5
0
    def odm_ui_m_form_setup_widgets(self, frm: form.Form):
        """Hook
        """
        from . import widget as _content_widget

        # Title
        if self.has_field('title'):
            f = self.get_field('title')  # type: odm.field.String
            frm.add_widget(widget.input.Text(
                uid='title',
                label=self.t('title'),
                required=f.is_required,
                min_length=f.min_length,
                max_length=f.max_length,
                value=self.title,
            ))

        # Description
        if self.has_field('description'):
            f = self.get_field('description')  # type: odm.field.String
            frm.add_widget(widget.input.Text(
                uid='description',
                label=self.t('description'),
                required=self.get_field('description').is_required,
                min_length=f.min_length,
                max_length=f.max_length,
                value=self.description,
            ))

        # Images
        if self.has_field('images'):
            frm.add_widget(file_ui.widget.ImagesUpload(
                uid='images',
                label=self.t('images'),
                value=self.f_get('images'),
                max_file_size=reg.get('content.max_image_size', 5),
                max_files=reg.get('content.max_images', 200),
            ))
            if self.get_field('images').is_required:
                frm.add_rule('images', validation.rule.NonEmpty())

        # Video links
        if self.has_field('video_links'):
            frm.add_widget(widget.input.StringList(
                uid='video_links',
                label=self.t('video'),
                add_btn_label=self.t('add_link'),
                value=self.video_links,
            ))
            frm.add_rule('video_links', validation.rule.VideoHostingUrl())

        # Body
        if self.has_field('body'):
            frm.add_widget(ckeditor.widget.CKEditor(
                uid='body',
                label=self.t('body'),
                value=self.f_get('body', process_tags=False),
            ))
            if self.get_field('body').is_required:
                frm.add_rule('body', validation.rule.NonEmpty())

        # Tags
        if self.has_field('tags'):
            frm.add_widget(taxonomy.widget.TokensInput(
                uid='tags',
                weight=250,
                model='tag',
                label=self.t('tags'),
                value=self.tags,
                required=self.get_field('tags').is_required,
            ))

        # External links
        if self.has_field('ext_links'):
            frm.add_widget(widget.input.StringList(
                uid='ext_links',
                weight=550,
                label=self.t('external_links'),
                add_btn_label=self.t('add_link'),
                value=self.ext_links,
                required=self.get_field('ext_links').is_required,
            ))
            frm.add_rule('ext_links', validation.rule.Url())

        # Status
        if self.has_field('status'):
            frm.add_widget(_content_widget.StatusSelect(
                uid='status',
                entity=self,
            ))

        # Publish time
        if self.has_field('publish_time') and self.odm_auth_check_entity_permissions(CONTENT_PERM_SET_PUBLISH_TIME):
            frm.add_widget(widget.select.DateTime(
                uid='publish_time',
                label=self.t('publish_time'),
                value=self.publish_time,
                h_size='col-xs-12 col-12 col-sm-4 col-md-3',
                required=self.get_field('publish_time'),
            ))

        # Language
        lng = lang.get_current() if self.is_new else self.language
        frm.add_widget(widget.static.Text(
            uid='language',
            label=self.t('language'),
            text=lang.lang_title(lng),
            value=lng,
            hidden=False if len(lang.langs()) > 1 else True,
        ))

        # Localizations
        if self.has_field('localization_' + lng) and \
                self.odm_auth_check_entity_permissions(CONTENT_PERM_SET_LOCALIZATION):
            for i, l in enumerate(lang.langs(False)):
                frm.add_widget(_content_widget.EntitySelect(
                    uid='localization_' + l,
                    label=self.t('localization', {'lang': lang.lang_title(l)}),
                    model=self.model,
                    ajax_url_query={'language': l},
                    value=self.f_get('localization_' + l)
                ))

        # Author
        if self.has_field('author') and auth.get_current_user().is_admin:
            frm.add_widget(auth_ui.widget.UserSelect(
                uid='author',
                label=self.t('author'),
                value=auth.get_current_user() if self.is_new else self.author,
                h_size='col-xs-12 col-12 col-sm-4',
                required=True,
            ))
Ejemplo n.º 6
0
def _generate_sitemap():
    """Generate content sitemap
    """
    global _sitemap_generation_works

    if _sitemap_generation_works:
        raise RuntimeError('Sitemap generation is still in progress')

    _sitemap_generation_works = True
    logger.info('Sitemap generation start.')

    output_dir = path.join(reg.get('paths.static'), 'sitemap')
    if path.exists(output_dir):
        rmtree(output_dir)
    makedirs(output_dir, 0o755, True)

    sitemap_index = sitemap.Index()
    links_per_file = 50000
    loop_count = 1
    loop_links = 1
    sm = sitemap.Sitemap()
    sm.add_url(router.base_url(), datetime.now(), 'always', 1)
    for lng in lang.langs():
        for model in reg.get('content.sitemap_models', ()):
            logger.info(
                "Sitemap generation started for model '{}', language '{}'".
                format(model, lang.lang_title(lng)))

            for entity in _api.find(model,
                                    language=lng):  # type: ContentWithURL
                sm.add_url(entity.url, entity.publish_time)
                loop_links += 1

                # Flush sitemap
                if loop_links >= links_per_file:
                    loop_count += 1
                    loop_links = 0
                    sitemap_path = sm.write(
                        path.join(output_dir, 'data-%02d.xml' % loop_count),
                        True)
                    logger.info(
                        "'{}' successfully written with {} links".format(
                            sitemap_path, loop_links))
                    sitemap_index.add_url(
                        router.url('/sitemap/{}'.format(
                            path.basename(sitemap_path))))
                    del sm
                    sm = sitemap.Sitemap()

    # If non-flushed sitemap exist
    if len(sm):
        sitemap_path = sm.write(
            path.join(output_dir, 'data-%02d.xml' % loop_count), True)
        logger.info("'{}' successfully written with {} links.".format(
            sitemap_path, loop_links))
        sitemap_index.add_url(
            router.url('/sitemap/{}'.format(path.basename(sitemap_path))))

    if len(sitemap_index):
        sitemap_index_path = sitemap_index.write(
            path.join(output_dir, 'index.xml'))
        logger.info("'{}' successfully written.".format(sitemap_index_path))

    logger.info('Sitemap generation stop.')
    _sitemap_generation_works = False