예제 #1
0
    def _process_POST(self):
        name = request.form.get('contact_name', settings.get('contact_name'))
        email = request.form.get('contact_email',
                                 settings.get('contact_email'))
        enabled = request.form.get('joined', False)
        uuid = settings.get('uuid')
        try:
            if not enabled:
                unregister_instance()
            elif enabled and uuid:
                sync_instance(name, email)
            elif enabled and not uuid:
                register_instance(name, email)
        except HTTPError as err:
            flash(
                _("Operation failed, the community hub returned: {err.message}"
                  ).format(err=err), 'error')
        except Timeout:
            flash(_("The operation timed-out. Please try again in a while."),
                  'error')
        except RequestException as err:
            flash(
                _("Unexpected exception while contacting the Community Hub: {err.message}"
                  ).format(err=err))

        return redirect(url_for('.index'))
예제 #2
0
파일: admins.py 프로젝트: florv/indico
 def getVars(self):
     wvars = wcomponents.WTemplated.getVars(self)
     minfo = info.HelperMaKaCInfo.getMaKaCInfoInstance()
     wvars['title'] = minfo.getTitle()
     wvars['organisation'] = minfo.getOrganisation()
     wvars['supportEmail'] = Config.getInstance().getSupportEmail()
     wvars['publicSupportEmail'] = Config.getInstance().getPublicSupportEmail()
     wvars['noReplyEmail'] = Config.getInstance().getNoReplyEmail()
     wvars['lang'] = minfo.getLang()
     wvars['address'] = ''
     if minfo.getCity() != '':
         wvars['address'] = minfo.getCity()
     if minfo.getCountry() != '':
         if wvars['address'] != '':
             wvars['address'] = '{0} ({1})'.format(wvars['address'], minfo.getCountry())
         else:
             wvars['address'] = minfo.getCountry()
     wvars['timezone'] = Config.getInstance().getDefaultTimezone()
     wvars['systemIconAdmins'] = Config.getInstance().getSystemIconURL('admin')
     iconDisabled = str(Config.getInstance().getSystemIconURL('disabledSection'))
     iconEnabled = str(Config.getInstance().getSystemIconURL('enabledSection'))
     url = urlHandlers.UHAdminSwitchNewsActive.getURL()
     icon = iconEnabled if minfo.isNewsActive() else iconDisabled
     wvars['features'] = i18nformat('<a href="{}"><img src="{}" border="0"'
                                    'style="float:left; padding-right: 5px">_("News Pages")</a>').format(url, icon)
     wvars['administrators'] = fossilize(sorted([u.as_avatar for u in User.find(is_admin=True, is_deleted=False)],
                                                key=methodcaller('getStraightFullName')))
     wvars['tracker_url'] = urljoin(Config.getInstance().getTrackerURL(),
                                    'api/instance/{}'.format(cephalopod_settings.get('uuid')))
     wvars['cephalopod_data'] = {'enabled': cephalopod_settings.get('joined'),
                                 'contact': cephalopod_settings.get('contact_name'),
                                 'email': cephalopod_settings.get('contact_email'),
                                 'url': Config.getInstance().getBaseURL(),
                                 'organisation': minfo.getOrganisation()}
     return wvars
예제 #3
0
 def getVars(self):
     wvars = wcomponents.WTemplated.getVars(self)
     minfo = info.HelperMaKaCInfo.getMaKaCInfoInstance()
     wvars['title'] = minfo.getTitle()
     wvars['organisation'] = minfo.getOrganisation()
     wvars['supportEmail'] = Config.getInstance().getSupportEmail()
     wvars['publicSupportEmail'] = Config.getInstance().getPublicSupportEmail()
     wvars['noReplyEmail'] = Config.getInstance().getNoReplyEmail()
     wvars['lang'] = Config.getInstance().getDefaultLocale()
     wvars['address'] = ''
     if minfo.getCity() != '':
         wvars['address'] = minfo.getCity()
     if minfo.getCountry() != '':
         if wvars['address'] != '':
             wvars['address'] = '{0} ({1})'.format(wvars['address'], minfo.getCountry())
         else:
             wvars['address'] = minfo.getCountry()
     wvars['timezone'] = Config.getInstance().getDefaultTimezone()
     wvars['systemIconAdmins'] = Config.getInstance().getSystemIconURL('admin')
     wvars['administrators'] = fossilize(sorted([u.as_avatar for u in User.find(is_admin=True, is_deleted=False)],
                                                key=methodcaller('getStraightFullName')))
     wvars['tracker_url'] = urljoin(Config.getInstance().getTrackerURL(),
                                    'api/instance/{}'.format(cephalopod_settings.get('uuid')))
     wvars['cephalopod_data'] = {'enabled': cephalopod_settings.get('joined'),
                                 'contact': cephalopod_settings.get('contact_name'),
                                 'email': cephalopod_settings.get('contact_email'),
                                 'url': Config.getInstance().getBaseURL(),
                                 'organisation': minfo.getOrganisation()}
     return wvars
예제 #4
0
파일: util.py 프로젝트: wtakase/indico
def sync_instance(contact, email):
    contact = contact or settings.get('contact_name')
    email = email or settings.get('contact_email')
    # registration needed if the instance does not have a uuid
    if not settings.get('uuid'):
        logger.warn(
            'unable to synchronise: missing uuid, registering the server instead'
        )
        register_instance(contact, email)
        return

    organisation = HelperMaKaCInfo.getMaKaCInfoInstance().getOrganisation()
    payload = {
        'enabled': True,
        'url': Config.getInstance().getBaseURL(),
        'contact': contact,
        'email': email,
        'organisation': organisation
    }
    url = urljoin(_url, settings.get('uuid'))
    response = requests.patch(url,
                              data=dumps(payload),
                              headers=_headers,
                              timeout=TIMEOUT)
    try:
        response.raise_for_status()
    except HTTPError as err:
        if err.response.status_code == 404:
            logger.warn(
                'unable to synchronise: the server was not registered, registering the server now'
            )
            register_instance(contact, email)
        else:
            logger.error(
                'failed to synchronise the server with the community hub, got: %s',
                err.message)
            raise
    except Timeout:
        logger.error(
            'failed to synchronise: timeout while contacting the community hub'
        )
        raise
    except RequestException as err:
        logger.error(
            'unexpected exception while synchronizing the server with the Community Hub: %s',
            err.message)
        raise
    else:
        settings.set_multi({
            'joined': True,
            'contact_name': payload['contact'],
            'contact_email': payload['email']
        })
        logger.info(
            'successfully synchronized the server with the community hub')
예제 #5
0
파일: admins.py 프로젝트: belokop/indico
 def getVars(self):
     wvars = wcomponents.WTemplated.getVars(self)
     minfo = info.HelperMaKaCInfo.getMaKaCInfoInstance()
     wvars['title'] = minfo.getTitle()
     wvars['organisation'] = minfo.getOrganisation()
     wvars['supportEmail'] = Config.getInstance().getSupportEmail()
     wvars['publicSupportEmail'] = Config.getInstance(
     ).getPublicSupportEmail()
     wvars['noReplyEmail'] = Config.getInstance().getNoReplyEmail()
     wvars['lang'] = minfo.getLang()
     wvars['address'] = ''
     if minfo.getCity() != '':
         wvars['address'] = minfo.getCity()
     if minfo.getCountry() != '':
         if wvars['address'] != '':
             wvars['address'] = '{0} ({1})'.format(wvars['address'],
                                                   minfo.getCountry())
         else:
             wvars['address'] = minfo.getCountry()
     wvars['timezone'] = Config.getInstance().getDefaultTimezone()
     wvars['systemIconAdmins'] = Config.getInstance().getSystemIconURL(
         'admin')
     iconDisabled = str(
         Config.getInstance().getSystemIconURL('disabledSection'))
     iconEnabled = str(
         Config.getInstance().getSystemIconURL('enabledSection'))
     url = urlHandlers.UHAdminSwitchNewsActive.getURL()
     icon = iconEnabled if minfo.isNewsActive() else iconDisabled
     wvars['features'] = i18nformat(
         '<a href="{}"><img src="{}" border="0"'
         'style="float:left; padding-right: 5px">_("News Pages")</a>'
     ).format(url, icon)
     wvars['administrators'] = fossilize(
         sorted([
             u.as_avatar for u in User.find(is_admin=True, is_deleted=False)
         ],
                key=methodcaller('getStraightFullName')))
     wvars['tracker_url'] = urljoin(
         Config.getInstance().getTrackerURL(),
         'api/instance/{}'.format(cephalopod_settings.get('uuid')))
     wvars['cephalopod_data'] = {
         'enabled': cephalopod_settings.get('joined'),
         'contact': cephalopod_settings.get('contact_name'),
         'email': cephalopod_settings.get('contact_email'),
         'url': Config.getInstance().getBaseURL(),
         'organisation': minfo.getOrganisation()
     }
     return wvars
예제 #6
0
파일: util.py 프로젝트: wtakase/indico
def unregister_instance():
    payload = {'enabled': False}
    url = urljoin(_url, settings.get('uuid'))
    response = requests.patch(url,
                              data=dumps(payload),
                              headers=_headers,
                              timeout=TIMEOUT)
    try:
        response.raise_for_status()
    except HTTPError as err:
        if err.response.status_code != 404:
            logger.error(
                'failed to unregister the server to the community hub, got: %s',
                err.message)
            raise
    except Timeout:
        logger.error(
            'failed to unregister: timeout while contacting the community hub')
        raise
    except RequestException as err:
        logger.error(
            'unexpected exception while unregistering the server with the Community Hub: %s',
            err.message)
        raise
    settings.set('joined', False)
    logger.info('successfully unregistered the server from the community hub')
예제 #7
0
    def _process(self):
        if not settings.get('joined'):
            flash(_("Synchronization is not possible if you don't join the community first."),
                  'error')
        else:
            contact_name = settings.get('contact_name')
            contact_email = settings.get('contact_email')
            try:
                sync_instance(contact_name, contact_email)
            except HTTPError as err:
                flash(_("Synchronization failed, the community hub returned: {err.message}").format(err=err),
                      'error')
            except Timeout:
                flash(_("Synchronization timed-out. Please try again in a while."), 'error')
            except RequestException as err:
                flash(_("Unexpected exception while contacting the Community Hub: {err.message}").format(err=err))

            return redirect(url_for('.index'))
예제 #8
0
    def _process_GET(self):
        defaults = FormDefaults(**settings.get_all())
        form = CephalopodForm(request.form, obj=defaults)

        affiliation = HelperMaKaCInfo.getMaKaCInfoInstance().getOrganisation()
        enabled = settings.get('joined')
        config = Config.getInstance()
        instance_url = config.getBaseURL()
        language = config.getDefaultLocale()
        tracker_url = urljoin(config.getTrackerURL(), 'api/instance/{}'.format(settings.get('uuid')))
        return WPCephalopod.render_template('cephalopod.html',
                                            affiliation=affiliation,
                                            enabled=enabled,
                                            form=form,
                                            indico_version=MaKaC.__version__,
                                            instance_url=instance_url,
                                            language=language,
                                            python_version=python_version(),
                                            tracker_url=tracker_url)
예제 #9
0
    def _process_GET(self):
        defaults = FormDefaults(**settings.get_all())
        form = CephalopodForm(request.form, obj=defaults)

        affiliation = HelperMaKaCInfo.getMaKaCInfoInstance().getOrganisation()
        enabled = settings.get('joined')
        instance_url = Config.getInstance().getBaseURL()
        language = HelperMaKaCInfo.getMaKaCInfoInstance().getLang()
        tracker_url = urljoin(Config.getInstance().getTrackerURL(),
                              'api/instance/{}'.format(settings.get('uuid')))
        return WPCephalopod.render_template('cephalopod.html',
                                            affiliation=affiliation,
                                            enabled=enabled,
                                            form=form,
                                            indico_version=MaKaC.__version__,
                                            instance_url=instance_url,
                                            language=language,
                                            python_version=python_version(),
                                            tracker_url=tracker_url)
예제 #10
0
    def _process_POST(self):
        name = request.form.get('contact_name', settings.get('contact_name'))
        email = request.form.get('contact_email', settings.get('contact_email'))
        enabled = request.form.get('joined', False)
        uuid = settings.get('uuid')
        try:
            if not enabled:
                unregister_instance()
            elif enabled and uuid:
                sync_instance(name, email)
            elif enabled and not uuid:
                register_instance(name, email)
        except HTTPError as err:
            flash(_("Operation failed, the community hub returned: {err.message}").format(err=err), 'error')
        except Timeout:
            flash(_("The operation timed-out. Please try again in a while."), 'error')
        except RequestException as err:
            flash(_("Unexpected exception while contacting the Community Hub: {err.message}").format(err=err))

        return redirect(url_for('.index'))
예제 #11
0
def sync_instance(contact, email):
    contact = contact or settings.get('contact_name')
    email = email or settings.get('contact_email')
    # registration needed if the instance does not have a uuid
    if not settings.get('uuid'):
        logger.warn('unable to synchronise: missing uuid, registering the server instead')
        register_instance(contact, email)
        return

    organisation = HelperMaKaCInfo.getMaKaCInfoInstance().getOrganisation()
    payload = {'enabled': True,
               'url': Config.getInstance().getBaseURL(),
               'contact': contact,
               'email': email,
               'organisation': organisation}
    url = urljoin(_url, settings.get('uuid'))
    response = requests.patch(url, data=dumps(payload), headers=_headers, timeout=TIMEOUT)
    try:
        response.raise_for_status()
    except HTTPError as err:
        if err.response.status_code == 404:
            logger.warn('unable to synchronise: the server was not registered, registering the server now')
            register_instance(contact, email)
        else:
            logger.error('failed to synchronise the server with the community hub, got: {err.message}'.format(err=err))
            raise
    except Timeout:
        logger.error('failed to synchronise: timeout while contacting the community hub')
        raise
    except RequestException as err:
        logger.error('unexpected exception while synchronizing the server with the Community Hub: {err.message}'
                     .format(err=err))
        raise
    else:
        settings.set_multi({
            'joined': True,
            'contact_name': payload['contact'],
            'contact_email': payload['email']})
        logger.info('successfully synchronized the server with the community hub')
예제 #12
0
    def _process(self):
        if not settings.get('joined'):
            flash(
                _("Synchronization is not possible if you don't join the community first."
                  ), 'error')
        else:
            contact_name = settings.get('contact_name')
            contact_email = settings.get('contact_email')
            try:
                sync_instance(contact_name, contact_email)
            except HTTPError as err:
                flash(
                    _("Synchronization failed, the community hub returned: {err.message}"
                      ).format(err=err), 'error')
            except Timeout:
                flash(
                    _("Synchronization timed-out. Please try again in a while."
                      ), 'error')
            except RequestException as err:
                flash(
                    _("Unexpected exception while contacting the Community Hub: {err.message}"
                      ).format(err=err))

            return redirect(url_for('.index'))
예제 #13
0
파일: util.py 프로젝트: OmeGak/indico
def unregister_instance():
    payload = {'enabled': False}
    url = urljoin(_url, settings.get('uuid'))
    response = requests.patch(url, data=dumps(payload), headers=_headers, timeout=TIMEOUT)
    try:
        response.raise_for_status()
    except HTTPError as err:
        if err.response.status_code != 404:
            logger.error('failed to unregister the server to the community hub, got: %s', err.message)
            raise
    except Timeout:
        logger.error('failed to unregister: timeout while contacting the community hub')
        raise
    except RequestException as err:
        logger.error('unexpected exception while unregistering the server with the Community Hub: %s', err.message)
        raise
    settings.set('joined', False)
    logger.info('successfully unregistered the server from the community hub')