Beispiel #1
0
 def update_config(self, config_):
     toolkit.add_template_directory(config_, 'templates')
     toolkit.add_public_directory(config_, 'public')
     toolkit.add_resource('styles/css', 'gobar_css')
     toolkit.add_resource('js', 'gobar_js')
     toolkit.add_resource('recline', 'gobar_data_preview')
     gobar_helpers.get_theme_config()
def new_user_content(admin_user, new_user):
    if new_user.fullname and len(new_user.fullname) > 0:
        username = new_user.fullname
    else:
        username = new_user.name
    if admin_user.fullname and len(admin_user.fullname) > 0:
        admin_username = admin_user.fullname
    else:
        admin_username = admin_user.name
    login_username = new_user.name
    reset_link = ckan_mailer.get_reset_link(new_user)
    site_title = gobar_helpers.get_theme_config('title.site-title',
                                                'Portal Andino')
    plain_body = new_user_plain_body.format(admin_username=admin_username,
                                            username=username,
                                            reset_link=reset_link,
                                            site_title=site_title,
                                            login_username=login_username)
    html_body = new_user_html_body.format(admin_username=admin_username,
                                          username=username,
                                          reset_link=reset_link,
                                          site_title=site_title,
                                          login_username=login_username)
    subject = new_user_subject.format(admin_username=admin_username)
    return subject, plain_body, html_body
Beispiel #3
0
def reset_mail_content(user):
    if user.fullname:
        username = user.fullname
    else:
        username = user.name
    reset_link = ckan_mailer.get_reset_link(user)
    site_title = gobar_helpers.get_theme_config('title.site-title', 'Portal Andino')
    plain_body = reset_password_plain_body.format(username=username, reset_link=reset_link, site_title=site_title)
    html_body = reset_password_html_body.format(username=username, reset_link=reset_link, site_title=site_title)
    subject = reset_password_subject.format(site_title=site_title)
    return subject, plain_body, html_body
    def view_about_section(self, title):
        sections = gobar_helpers.get_theme_config('about.sections', [])

        for section in sections:
            if section['title'] == title:
                # la variable `section` contiene la sección buscada
                break
        else:
            base.abort(404, u'Sección no encontrada')

        return base.render('section_view.html',
                           extra_vars={'section': section})
Beispiel #5
0
def assemble_email(msg_plain_body, msg_html_body, msg_subject, recipient_name, recipient_email):
    text_msg = MIMEText(msg_plain_body, 'plain', 'UTF-8')
    html_msg = MIMEText(msg_html_body, 'html', 'UTF-8')
    msg = MIMEMultipart('alternative')
    msg.attach(text_msg)
    msg.attach(html_msg)
    msg['Subject'] = Header(msg_subject.encode('utf-8'), 'utf-8')
    site_title = gobar_helpers.get_theme_config('title.site-title', 'Portal Andino')
    msg['From'] = "%s <%s>" % (site_title, andino_address)
    recipient = u"%s <%s>" % (recipient_name, recipient_email)
    msg['To'] = Header(recipient, 'utf-8')
    msg['Date'] = Utils.formatdate(time())
    msg['X-Mailer'] = "CKAN %s" % ckan.__version__
    return msg
Beispiel #6
0
def send_test_mail(admin_user):
    current_time = datetime.now().strftime("%H:%M:%S")
    plain_body = html_body = u'Ésta es una prueba de envío de mail. Hora de envío: {}.'.format(current_time)
    subject = \
        u'Prueba de envío de mail - {}'.format(gobar_helpers.get_theme_config('title.site-title', 'Portal Andino'))
    msg = assemble_email(plain_body, html_body, subject, admin_user.display_name, admin_user.email)
    try:
        return_value = send_mail(msg, admin_user.email)
    except Exception as e:
        return_value = {'error': e.message}

    if gobar_helpers.search_for_value_in_config_file('smtp.server') == 'postfix':
        sleep(5)  # Le damos tiempo a postfix para loguear
        return_value['log'] = get_postfix_log()
        issue = search_for_last_postfix_log_issue(return_value['log'], admin_user.email)
        if issue:
            return_value['error'] = \
                '{0}{1}'.format('{} | '.format(return_value.get('error')) if return_value.get('error') else '', issue)
    return return_value
Beispiel #7
0
    def wrap_json_catalog(dataset_dict, json_export_map):
        andino_platform = True
        import ckanext.gobar_theme.helpers as gobar_helpers
        try:
            site_title = gobar_helpers.get_theme_config("title.site-title", "")
            mbox = gobar_helpers.get_theme_config("social.mail", "")
            site_description = gobar_helpers.get_theme_config(
                "title.site-description", "")
        except AttributeError:
            # Esto significa que no estoy corriendo dentro de Andino.
            andino_platform = False
            site_title = ""
            mbox = ""
            site_description = ""
        superThemeTaxonomy = "http://datos.gob.ar/superThemeTaxonomy.json"
        import ckan.logic as logic
        from ckan.common import c
        import ckan.model as model
        context = {
            'model': model,
            'session': model.Session,
            'user': c.user or c.author
        }
        data_dict_page_results = {
            'all_fields': True,
            'type': 'group',
            'limit': None,
            'offset': 0,
        }
        my_themes = []
        from os import path, environ
        from ConfigParser import ConfigParser
        ckan_owner = ''
        if 'CKAN_CONFIG' in environ:
            if path.exists(environ['CKAN_CONFIG']):
                tmp_ckan_config = ConfigParser()
                tmp_ckan_config.read(environ['CKAN_CONFIG'])
                try:
                    ckan_owner = tmp_ckan_config.get('app:main', 'ckan.owner')
                except Exception:
                    pass
                try:
                    tmp_mbox = tmp_ckan_config.get('app:main',
                                                   'ckan.owner.email')
                    if len(tmp_mbox) > 0:
                        mbox = tmp_mbox
                except Exception:
                    pass
                if not andino_platform:
                    try:
                        site_title = tmp_ckan_config.get(
                            'app:main', 'ckan.site.title')
                    except Exception:
                        site_title = "No definido en \"config.ini\""
                    try:
                        site_description = tmp_ckan_config.get(
                            'app:main', 'ckan.site.description')
                    except Exception:
                        site_description = "No definido en \"config.ini\""

        for theme in logic.get_action('group_list')(context,
                                                    data_dict_page_results):
            my_themes.append({
                'id': theme['name'],
                'description': theme['description'],
                'label': theme['display_name']
            })
        catalog_headers = [("title", site_title),
                           ("description", site_description),
                           ("superThemeTaxonomy", superThemeTaxonomy),
                           ("publisher", {
                               "name": ckan_owner,
                               "mbox": mbox
                           }), ("themeTaxonomy", my_themes)]
        # catalog_headers = [(x, y) for x, y in json_export_map.get('catalog_headers').iteritems()]
        catalog = OrderedDict(catalog_headers + [('dataset', dataset_dict)])
        return catalog
Beispiel #8
0
def get_catalog_data():
    datajson = {}
    publisher = {}
    set_nonempty_value(publisher, 'mbox',
                       gobar_helpers.get_theme_config("social.mail", ""))
    set_nonempty_value(
        publisher, 'name',
        gobar_helpers.get_theme_config("title.site-organization", ""))
    spatial = []
    spatial_config_fields = ['country', 'province', 'districts']
    for spatial_config_field in spatial_config_fields:
        spatial_config_field_value = gobar_helpers.get_theme_config(
            "portal-metadata.%s" % spatial_config_field, "")
        if spatial_config_field_value and spatial_config_field_value != "None":
            spatial.extend(spatial_config_field_value.split(','))
    data_dict_page_results = {
        'all_fields': True,
        'type': 'group',
        'limit': None,
        'offset': 0,
    }
    groups = []
    for theme in logic.get_action('group_list')({}, data_dict_page_results):
        theme_attributes = {}
        theme_name = theme['name']
        if theme_name:
            theme_attributes['id'] = theme_name
        theme_description = theme['display_name']
        if theme_description:
            theme_attributes['description'] = theme_description
        theme_label = theme['display_name']
        if theme_label:
            theme_attributes['label'] = theme['display_name']
        if theme_attributes:
            groups.append(theme_attributes)

    set_nonempty_value(datajson, 'version', ANDINO_METADATA_VERSION)
    set_nonempty_value(datajson, 'superThemeTaxonomy', SUPERTHEME_TAXONOMY_URL)
    set_nonempty_value(
        datajson, 'identifier',
        gobar_helpers.get_theme_config("portal-metadata.id", ""))
    set_nonempty_value(datajson, 'title',
                       gobar_helpers.get_theme_config("title.site-title", ""))
    set_nonempty_value(
        datajson, 'description',
        gobar_helpers.get_theme_config("title.site-description", ""))
    set_nonempty_value(datajson, 'publisher', publisher)
    set_nonempty_value(
        datajson, 'issued',
        gobar_helpers.date_format_to_iso(
            gobar_helpers.get_theme_config("portal-metadata.launch_date", "")))
    set_nonempty_value(
        datajson, 'modified',
        gobar_helpers.date_format_to_iso(
            gobar_helpers.get_theme_config("portal-metadata.last_updated",
                                           "")))
    set_nonempty_value(
        datajson, 'language',
        gobar_helpers.get_theme_config("portal-metadata.languages", ""))
    set_nonempty_value(
        datajson, 'license',
        gobar_helpers.get_theme_config("portal-metadata.license",
                                       u"CC-BY-4.0"))
    set_nonempty_value(
        datajson, 'homepage',
        gobar_helpers.get_theme_config('portal-metadata.homepage'))
    set_nonempty_value(
        datajson, 'rights',
        gobar_helpers.get_theme_config("portal-metadata.licence_conditions",
                                       ""))
    set_nonempty_value(datajson, 'spatial', spatial)
    set_nonempty_value(datajson, 'themeTaxonomy', groups)
    return datajson
    def wrap_json_catalog(dataset_dict, json_export_map):
        andino_platform = True
        import ckanext.gobar_theme.helpers as gobar_helpers
        from plugin import DataJsonPlugin
        version = DataJsonPlugin.METADATA_VERSION
        try:
            identifier = gobar_helpers.get_theme_config(
                "portal-metadata.id", "")
            issued = gobar_helpers.get_theme_config(
                "portal-metadata.launch_date", "")
            if issued:
                issued = moment.date(issued, "%d/%m/%Y").isoformat()
            last_updated = gobar_helpers.get_theme_config(
                "portal-metadata.last_updated", "")
            languages = gobar_helpers.get_theme_config(
                "portal-metadata.languages", "")
            license = gobar_helpers.get_theme_config("portal-metadata.license",
                                                     "")
            homepage = gobar_helpers.get_theme_config(
                "portal-metadata.homepage", "")
            licence_conditions = gobar_helpers.get_theme_config(
                "portal-metadata.licence_conditions", "")

            spatial = []
            spatial_config_fields = ['country', 'province', 'districts']
            for spatial_config_field in spatial_config_fields:
                spatial_config_field_value = gobar_helpers.get_theme_config(
                    "portal-metadata.%s" % spatial_config_field, "")
                if spatial_config_field_value:
                    spatial.extend(spatial_config_field_value.split(','))

            site_title = gobar_helpers.get_theme_config("title.site-title", "")
            mbox = gobar_helpers.get_theme_config("social.mail", "")
            ckan_owner = ''
            try:
                ckan_owner = gobar_helpers.get_theme_config(
                    "title.site-organization", "")
            except Exception:
                log.debug(
                    u"No se pudo obtener la configuración de 'title.site-organization'"
                )
            site_description = gobar_helpers.get_theme_config(
                "title.site-description", "")
        except AttributeError:
            # Esto significa que no estoy corriendo dentro de Andino, o sea, en datos.gob.ar
            # FIXME: AttributeError por no tener el get_theme_config? datos.gob.ar debería tener este método.
            # O al menos detectar mejor si estamos o no en andino
            andino_platform = False
            site_title = "Datos Argentina"
            mbox = "*****@*****.**"
            site_description = "Catálogo de datos abiertos de la Administración Pública Nacional de Argentina."
            identifier = "datosgobar"
            ckan_owner = "Ministerio de Modernización"
            issued = "2016-03-08"
            last_updated = "2018-02-20"
            languages = ["SPA"]
            license = "Open Database License (ODbL) v1.0"
            homepage = "http://www.datos.gob.ar"
            licence_conditions = ""
            spatial = ["ARG"]
        superThemeTaxonomy = "http://datos.gob.ar/superThemeTaxonomy.json"
        import ckan.logic as logic
        from ckan.common import c
        import ckan.model as model
        context = {
            'model': model,
            'session': model.Session,
            'user': c.user or c.author
        }
        data_dict_page_results = {
            'all_fields': True,
            'type': 'group',
            'limit': None,
            'offset': 0,
        }
        my_themes = []
        from os import path, environ
        from ConfigParser import ConfigParser
        if 'CKAN_CONFIG' in environ:
            if path.exists(environ['CKAN_CONFIG']):
                tmp_ckan_config = ConfigParser()
                tmp_ckan_config.read(environ['CKAN_CONFIG'])
                try:
                    if len(tmp_ckan_config.get('app:main', 'ckan.owner')) > 0:
                        ckan_owner = tmp_ckan_config.get(
                            'app:main', 'ckan.owner')
                except Exception:
                    pass
                try:
                    tmp_mbox = tmp_ckan_config.get('app:main',
                                                   'ckan.owner.email')
                    if len(tmp_mbox) > 0:
                        mbox = tmp_mbox
                except Exception:
                    pass
                if not andino_platform:
                    try:
                        site_title = tmp_ckan_config.get(
                            'app:main', 'ckan.site.title') or site_title
                    except Exception:
                        site_title = "No definido en \"config.ini\""
                    try:
                        site_description = tmp_ckan_config.get(
                            'app:main',
                            'ckan.site.description') or site_description
                    except Exception:
                        site_description = "No definido en \"config.ini\""

        for theme in logic.get_action('group_list')(context,
                                                    data_dict_page_results):
            my_themes.append({
                'id': theme['name'],
                'description': theme['description'],
                'label': theme['display_name']
            })
        catalog_headers = [
            ("version", version),
            ("identifier", identifier),
            ("title", site_title),
            ("description", site_description),
            ("superThemeTaxonomy", superThemeTaxonomy),
            ("publisher", {
                "name": ckan_owner,
                "mbox": mbox
            }),
            ("issued", issued),
            ("modified", last_updated),
            ("language", languages),
            ("license", license),
            ("homepage", homepage),
            ("rights", licence_conditions),
            ("spatial", spatial),
            ("themeTaxonomy", my_themes),
        ]
        # catalog_headers = [(x, y) for x, y in json_export_map.get('catalog_headers').iteritems()]
        catalog = OrderedDict(catalog_headers + [('dataset', dataset_dict)])
        return catalog