How to use the invenio.webinterface_handler_flask_utils._ function in invenio

To help you get started, we’ve selected a few invenio examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github inveniosoftware / invenio / modules / webmessage / lib / webmessage_blueprint.py View on Github external
form = AddMsgMESSAGEForm(request.values)
    if form.validate_on_submit():
        m = MsgMESSAGE()
        form.populate_obj(m)
        m.id_user_from = uid
        m.sent_date = datetime.now()
        quotas = dbplayer.check_quota(CFG_WEBMESSAGE_MAX_NB_OF_MESSAGES - 1)
        users = filter(lambda x: quotas.has_key(x.id), m.recipients)
        #m.recipients = m.recipients.difference(users))
        for u in users:
            m.recipients.remove(u)
        if len(users) > 0:
            flash(_('Following users reached their quota %d messages: %s') % \
                  (CFG_WEBMESSAGE_MAX_NB_OF_MESSAGES, ', '.join(
                  [u.nickname for u in users]),), "error")
        flash(_('Message has %d valid recipients.') %
              (len(m.recipients),), "info")
        if len(m.recipients) == 0:
            flash(_('Message was not sent'), "info")
        else:
            if m.received_date is not None \
                and m.received_date > datetime.now():

                for um in m.sent_to_users:
                    um.status = CFG_WEBMESSAGE_STATUS_CODE['REMINDER']
            else:
                m.received_date = datetime.now()
            try:
                db.session.add(m)
                db.session.commit()
                flash(_('Message was sent'), "info")
                return redirect(url_for('.index'))
github inveniosoftware / invenio / modules / miscutil / lib / scriptutils.py View on Github external
webFile.close()
        submatch = re.compile('[0-9]+.[0-9]+.[0-9]+(\-rc[0-9])?')
        version1 = submatch.search(version)
        web_version = version1.group().split(".")

        local_version = CFG_VERSION.split(".")

        if (web_version[0] > local_version[0] or
            web_version[0] == local_version[0] and
            web_version[1] > local_version[1] or
            web_version[0] == local_version[0] and
            web_version[1] == local_version[1] and
            web_version[2] > local_version[2]):
            if flash_message:
                flash(_('A newer version of Invenio is available for '
                        'download. You may want to visit %s') %
                      ('<a href="\&quot;http://invenio-software.org/wiki'">http://invenio-software.org'
                       '/wiki/Installation/Download</a>'), 'warning')

            return False
    except Exception as e:
        print e
        if flash_message:
            flash(_('Cannot download or parse release notes from http://'
                    'invenio-software.org/repo/invenio/tree/RELEASE-NOTES'),
                  'error')
        return None
    return True
github inveniosoftware / invenio / modules / webdeposit / lib / deposition_forms / thesis_form.py View on Github external
("ger", _("German")),
                 ("dut", _("Dutch")),
                 ("ita", _("Italian")),
                 ("spa", _("Spanish")),
                 ("por", _("Portuguese")),
                 ("gre", _("Greek")),
                 ("slo", _("Slovak")),
                 ("cze", _("Czech")),
                 ("hun", _("Hungarian")),
                 ("pol", _("Polish")),
                 ("nor", _("Norwegian")),
                 ("swe", _("Swedish")),
                 ("fin", _("Finnish")),
                 ("rus", _("Russian"))]
    language = fields.LanguageField(label=_("Language"), choices=languages)
    publisher = fields.PublisherField(label=_('Thesis Publisher'))
    defence_date = fields.Date(label=_('Date of Defence'), widget=date_widget)

    funded_choices = [("yes", _("Yes")), ("no", _("No"))]
    funded = fields.SelectField(label=_("Has your thesis been funded by the CERN Doctoral Student Program?"),
                                choices=funded_choices)

    file_field = fields.FileUploadField(widget=plupload_widget)
    submit = fields.SubmitField(label=_('Submit Thesis'), widget=bootstrap_submit)

    """ Form Configuration variables """
    _title = _("Submit a Thesis")
    _drafting = True  # enable and disable drafting
github EUDAT-B2SHARE / b2share / invenio / lib / websearch_blueprint.py View on Github external
from invenio.sqlalchemyutils import db
from invenio.websearch_forms import EasySearchForm
from invenio.websearch_model import Collection, Format, Tag
from invenio.webinterface_handler_flask_utils import _, InvenioBlueprint, \
    register_template_context_processor
from invenio.webuser_flask import current_user

from invenio.bibindex_engine import get_index_id_from_index_name
from invenio.search_engine import get_creation_date, perform_request_search,\
    search_pattern, print_record, create_nearest_terms_box
from invenio.bibformat import get_output_format_content_type, print_records

blueprint = InvenioBlueprint('search', __name__, url_prefix="",
                             config='invenio.search_engine_config',
                             breadcrumbs=[],
                             menubuilder=[('main.search', _('Search'),
                                           'search.index', 1)])


def insert(name):
    def _bfe_element(bfo, **kwargs):
        # convert to utf-8 for legacy app
        kwargs = dict((k, v.encode('utf-8') if isinstance(v, unicode) else v)
                      for k, v in kwargs.iteritems())
        format_element = get_format_element(name)
        (out, dummy) = eval_format_element(format_element,
                                           bfo,
                                           kwargs)
        # returns unicode for jinja2
        return out.decode('utf-8')
    return _bfe_element
github inveniosoftware / invenio / modules / webdeposit / lib / deposition_forms / poem_form.py View on Github external
from wtforms.validators import Required
from invenio.webinterface_handler_flask_utils import _
from invenio.webdeposit_form import WebDepositForm as Form
from invenio.webdeposit_field_widgets import bootstrap_submit

# Import custom fields
from invenio.webdeposit_load_fields import fields

__all__ = ['PoemForm']


class PoemForm(Form):

    title = fields.TitleField(label=_('Poem Title'), validators=[Required()])
    author = fields.AuthorField(label=_('Author'), validators=[Required()])
    languages = [("en", _("English")),
                ("fre", _("French")),
                ("ger", _("German")),
                ("dut", _("Dutch")),
                ("ita", _("Italian")),
                ("spa", _("Spanish")),
                ("por", _("Portuguese")),
                ("gre", _("Greek")),
                ("slo", _("Slovak")),
                ("cze", _("Czech")),
                ("hun", _("Hungarian")),
                ("pol", _("Polish")),
                ("nor", _("Norwegian")),
                ("swe", _("Swedish")),
                ("fin", _("Finnish")),
                ("rus", _("Russian"))]
github inveniosoftware / invenio / modules / websession / lib / webaccount_blueprint.py View on Github external
form.password.data.encode('utf8'),
                                    form.nickname.data.encode('utf8'),
                                    ln=g.ln)
        if ruid == 0:
            title = _("Account created")
            messages.append(_("Your account has been successfully created."))
            state = "success"
            if CFG_ACCESS_CONTROL_NOTIFY_USER_ABOUT_NEW_ACCOUNT == 1:
                messages.append(_("In order to confirm its validity, an email message containing an account activation key has been sent to the given email address."))
                messages.append(_("Please follow instructions presented there in order to complete the account registration process."))
            if CFG_ACCESS_CONTROL_LEVEL_ACCOUNTS >= 1:
                messages.append(_("A second email will be sent when the account has been activated and can be used."))
            elif CFG_ACCESS_CONTROL_NOTIFY_USER_ABOUT_NEW_ACCOUNT != 1:
                user = User.query.filter(User.email == form.email.data.lower()).one()
                login_user(user.get_id())
                messages.append(_("You can now access your account."))
        else:
            title = _("Registration failure")
            state = "danger"
            if ruid == 5:
                messages.append(_("Users cannot register themselves, only admin can register them."))
            elif ruid == 6 or ruid == 1:
                # Note, code 1 is used both for invalid email, and email sending
                # problems, however the email address is validated by the form,
                # so we only have to report a problem sending the email here
                messages.append(_("The site is having troubles in sending you an email for confirming your email address."))
                messages.append(_("The error has been logged and will be taken in consideration as soon as possible."))
            else:
                # Errors [-2, (1), 2, 3, 4] taken care of by form validation
                messages.append(_("Internal error %s") % ruid)
    elif request.method == 'POST':
        title = _("Registration failure")
github inveniosoftware / invenio / modules / websession / lib / webaccount_forms.py View on Github external
def validate_current_password(self, field):
        if len(field.data) == 0:
            raise validators.ValidationError(
                _("Please enter your current password"))

        from invenio.webaccount_blueprint import update_login
        if update_login(current_user['nickname'], field.data) is None:
            raise validators.ValidationError(
                _("The current password you entered does\
                  not match with our records."))
github inveniosoftware / invenio / modules / websession / lib / webaccount_forms.py View on Github external
class RegisterForm(Form):
    """
    User registration form
    """
    email = TextField(
        _("Email address"),
        validators=[Required(message=_("Email not provided"))],
        description=_("Example") + ": john.doe@example.com")
    nickname = TextField(
        _("Nickname"),
        validators=[Required(message=_("Nickname not provided"))],
        description=_("Example") + ": johnd")
    password = PasswordField(
        _("Password"),
        description=_("The password phrase may contain punctuation, spaces, etc."))
    password2 = PasswordField(_("Confirm password"),)
    referer = HiddenField()
    action = HiddenField(default='login')
    submit = SubmitField(_("Register"))

    def validate_nickname(self, field):
        if nickname_valid_p(field.data) != 1:
            raise validators.ValidationError(
                _("Desired nickname %s is invalid.") % field.data
            )

        # is nickname already taken?
        try:
            User.query.filter(User.nickname == field.data).one()
            raise validators.ValidationError(
                _("Desired nickname %s already exists in the database.") % field.data
github EUDAT-B2SHARE / b2share / invenio / lib / webaccount_forms.py View on Github external
def validate_nickname(self, field):
        if nickname_valid_p(field.data) != 1:
            raise validators.ValidationError(
                _("Desired user name %s is invalid.") % field.data
            )

        # is nickname already taken?
        try:
            User.query.filter(User.nickname == field.data).one()
            raise validators.ValidationError(
                _("Desired user name %s already exists in the database.") % field.data
            )
        except SQLAlchemyError:
            pass
github inveniosoftware / invenio / modules / webdeposit / lib / deposition_forms / thesis_form.py View on Github external
("por", _("Portuguese")),
                 ("gre", _("Greek")),
                 ("slo", _("Slovak")),
                 ("cze", _("Czech")),
                 ("hun", _("Hungarian")),
                 ("pol", _("Polish")),
                 ("nor", _("Norwegian")),
                 ("swe", _("Swedish")),
                 ("fin", _("Finnish")),
                 ("rus", _("Russian"))]
    language = fields.LanguageField(label=_("Language"), choices=languages)
    publisher = fields.PublisherField(label=_('Thesis Publisher'))
    defence_date = fields.Date(label=_('Date of Defence'), widget=date_widget)

    funded_choices = [("yes", _("Yes")), ("no", _("No"))]
    funded = fields.SelectField(label=_("Has your thesis been funded by the CERN Doctoral Student Program?"),
                                choices=funded_choices)

    file_field = fields.FileUploadField(widget=plupload_widget)
    submit = fields.SubmitField(label=_('Submit Thesis'), widget=bootstrap_submit)

    """ Form Configuration variables """
    _title = _("Submit a Thesis")
    _drafting = True  # enable and disable drafting