<commit_before>#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""Populate development database with Institution fixtures."""

import logging
import sys
import urllib

import django
from django.db import transaction
django.setup()

from website import settings
from website.app import init_app
from osf.models import Institution
from website.search.search import update_institution

logger = logging.getLogger(__name__)
logging.basicConfig(level=logging.INFO)

ENVS = ['prod', 'stage', 'stage2', 'test']
SHIBBOLETH_SP_LOGIN = '{}/Shibboleth.sso/Login?entityID={{}}'.format(settings.CAS_SERVER_URL)
SHIBBOLETH_SP_LOGOUT = '{}/Shibboleth.sso/Logout?return={{}}'.format(settings.CAS_SERVER_URL)


def encode_uri_component(val):
    return urllib.quote(val, safe='~()*!.\'')


def update_or_create(inst_data):
    inst = Institution.load(inst_data['_id'])
    if inst:
        for key, val in inst_data.iteritems():
            setattr(inst, key, val)
        inst.save()
        print('Updated {}'.format(inst.name))
        update_institution(inst)
        return inst, False
    else:
        inst = Institution(**inst_data)
        inst.save()
        print('Added new institution: {}'.format(inst._id))
        update_institution(inst)
        return inst, True


def main(env):
    INSTITUTIONS = []

    if env == 'prod':
        INSTITUTIONS = [
            {
                '_id': 'a2jlab',
                'name': 'Access to Justice Lab',
                'description': 'Based within Harvard Law School, the <a href="https://a2jlab.org/">Access to Justice Lab</a> works with court administrators, legal service providers, and other stakeholders in the U.S. legal system to design and implement randomized field experiments evaluating interventions that impact access to justice.',
                'banner_name': 'a2jlab-banner.png',
                'logo_name': 'a2jlab-shield.png',
                'login_url': None,
                'logout_url': None,
                'domains': [],
                'email_domains': ['a2jlab.org'],
                'delegation_protocol': '',
            },
            {
                '_id': 'asu',
                'name': 'Arizona State University',
                'description': '<a href="https://asu.edu">Arizona State University</a>',
                'banner_name': 'asu-banner.png',
                'logo_name': 'asu-shield.png',
                'login_url': SHIBBOLETH_SP_LOGIN.format(
                    encode_uri_component('urn:mace:incommon:asu.edu')),
                'logout_url': SHIBBOLETH_SP_LOGOUT.format(
                    encode_uri_component('https://osf.io/goodbye')),
                'domains': ['osf.asu.edu'],
                'email_domains': [],
                'delegation_protocol': 'saml-shib',
            },
            {
                '_id': 'brown',
                'name': 'Brown University',
                'description': 'A Research Project Management and Publication Tool for the Brown University Research Community in partnership with <a href="https://library.brown.edu/info/data_management">Brown University Library Research Data Management Services</a> | <a href="https://www.brown.edu/research/home">Research at Brown</a> | <a href="https://it.brown.edu/computing-policies/policy-handling-brown-restricted-information">Brown Restricted Information Handling Policy</a> | <a href="https://www.brown.edu/about/administration/provost/policies/privacy">Research Privacy Policy</a>',
                'banner_name': 'brown-banner.png',
                'logo_name': 'brown-shield.png',
                'login_url': SHIBBOLETH_SP_LOGIN.format(encode_uri_component('https://sso.brown.edu/idp/shibboleth')),
                'logout_url': SHIBBOLETH_SP_LOGOUT.format(encode_uri_component('https://osf.io/goodbye')),
                'domains': ['osf.brown.edu'],
                'email_domains': [],
                'delegation_protocol': 'saml-shib',
            },
            {
                '_id': 'bt',
                'name': '<NAME>',
                'description': 'A research data service provided by the BTNRH Research Technology Core. Please do not use this service to store or transfer personally identifiable information or personal health information. For assistance please contact <a href="mailto:<EMAIL>"><EMAIL></a>.',
                'banner_name': 'bt-banner.png',
                'logo_name': 'bt-shield.png',
                'login_url': None,
                'logout_url': None,
                'domains': ['osf.boystownhospital.org'],
                'email_domains': ['boystown.org'],
                'delegation_protocol': '',
            },
            {
                '_id': 'bu',
                'name': '<NAME>',
                'description': 'A Research Project Management Tool for BU',
                'banner_name': 'bu-banner.png',
                'logo_name': 'bu-shield.png',
                'login_url': SHIBBOLETH_SP_LOGIN.format(encode_uri_component('https://shib.bu.edu/idp/shibboleth')),
                'logout_url': SHIBBOLETH_SP_LOGOUT.format(encode_uri_component('https://osf.io/goodbye')),
                'domains': ['osf.bu.edu'],
                'email_domains': [],
                'delegation_protocol': 'saml-shib',
            },
            {
                '_id': 'busara',
                'name': 'Busara Center for Behavioral Economics',
                'description': 'The <a href="http://www.busaracenter.org/">Busara Center</a> for Behavioral Economics',
                'banner_name': 'busara-banner.png',
                'logo_name': 'busara-shield.png',
                'login_url': None,
                'logout_url': None,
                'domains': [],
                'email_domains': ['busaracenter.org'],
                'delegation_protocol': '',
            },
            {
                '_id': 'callutheran',
                'name': 'California Lutheran University',
                'description': '',
                'banner_name': 'callutheran-banner.png',
                'logo_name': 'callutheran-shield.png',
                'login_url': None,
                'logout_url': SHIBBOLETH_SP_LOGOUT.format(encode_uri_component('https://osf.io/goodbye')),
                'domains': [],
                'email_domains': [],
                'delegation_protocol': 'cas-pac4j',
            },
            {
                '_id': 'capolicylab',
                'name': 'California Policy Lab',
                'description': 'The <a href="https:www.capolicylab.org">California Policy Lab</a> pairs trusted experts from UCLA and UC Berkeley with policymakers to solve our most urgent social problems, including homelessness, poverty, crime, and education inequality.',
                'banner_name': 'capolicylab-banner.png',
                'logo_name': 'capolicylab-shield.png',
                'login_url': None,
                'logout_url': None,
                'domains': [],
                'email_domains': ['capolicylab.org'],
                'delegation_protocol': '',
            },
            {
                '_id': 'clrn',
                'name': 'Character Lab Research Network',
                'description': ' Projects listed below are run through the <a href="https://www.characterlab.org/research-network">Character Lab Research Network</a>, a consortium of trailblazing schools and elite scientists that develop and test activities designed to help students thrive. Character Lab Research Network is a proud supporter of the Student Privacy Pledge to safeguard student privacy. For more details on the Research Network privacy policy, you can refer to the <a href="https://www.characterlab.org/student-privacy">Research Network student privacy policy</a> and <a href="https://www.characterlab.org/student-privacy/faqs">FAQs</a>.',
                'banner_name': 'clrn-banner.png',
                'logo_name': 'clrn-shield.png',
                'login_url': None,
                'logout_url': None,
                'domains': [],
                'email_domains': ['characterlab.org'],
                'delegation_protocol': '',
            },
            {
                '_id': 'colorado',
                'name': 'University of Colorado Boulder',
                'description': 'This service is supported by the Center for Research Data and Digital Scholarship, which is led by <a href="https://www.rc.colorado.edu/">Research Computing</a> and the <a href="http://www.colorado.edu/libraries/">University Libraries</a>.',
                'banner_name': 'colorado-banner.png',
                'logo_name': 'colorado-shield.png',
                'login_url': SHIBBOLETH_SP_LOGIN.format(encode_uri_component('https://fedauth.colorado.edu/idp/shibboleth')),
                'logout_url': SHIBBOLETH_SP_LOGOUT.format(encode_uri_component('https://osf.io/goodbye')),
                'domains': [],
                'email_domains': [],
                'delegation_protocol': 'saml-shib',
            },
            {
                '_id': 'cos',
                'name': 'Center For Open Science',
                'description': 'COS is a non-profit technology company providing free and open services to increase inclusivity and transparency of research. Find out more at <a href="https://cos.io">cos.io</a>.',<commit_msg>Add CMU to Prod server<commit_after>#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""Populate development database with Institution fixtures."""

import logging
import sys
import urllib

import django
from django.db import transaction
django.setup()

from website import settings
from website.app import init_app
from osf.models import Institution
from website.search.search import update_institution

logger = logging.getLogger(__name__)
logging.basicConfig(level=logging.INFO)

ENVS = ['prod', 'stage', 'stage2', 'test']
SHIBBOLETH_SP_LOGIN = '{}/Shibboleth.sso/Login?entityID={{}}'.format(settings.CAS_SERVER_URL)
SHIBBOLETH_SP_LOGOUT = '{}/Shibboleth.sso/Logout?return={{}}'.format(settings.CAS_SERVER_URL)


def encode_uri_component(val):
    return urllib.quote(val, safe='~()*!.\'')


def update_or_create(inst_data):
    inst = Institution.load(inst_data['_id'])
    if inst:
        for key, val in inst_data.iteritems():
            setattr(inst, key, val)
        inst.save()
        print('Updated {}'.format(inst.name))
        update_institution(inst)
        return inst, False
    else:
        inst = Institution(**inst_data)
        inst.save()
        print('Added new institution: {}'.format(inst._id))
        update_institution(inst)
        return inst, True


def main(env):
    INSTITUTIONS = []

    if env == 'prod':
        INSTITUTIONS = [
            {
                '_id': 'a2jlab',
                'name': 'Access to Justice Lab',
                'description': 'Based within Harvard Law School, the <a href="https://a2jlab.org/">Access to Justice Lab</a> works with court administrators, legal service providers, and other stakeholders in the U.S. legal system to design and implement randomized field experiments evaluating interventions that impact access to justice.',
                'banner_name': 'a2jlab-banner.png',
                'logo_name': 'a2jlab-shield.png',
                'login_url': None,
                'logout_url': None,
                'domains': [],
                'email_domains': ['a2jlab.org'],
                'delegation_protocol': '',
            },
            {
                '_id': 'asu',
                'name': 'Arizona State University',
                'description': '<a href="https://asu.edu">Arizona State University</a>',
                'banner_name': 'asu-banner.png',
                'logo_name': 'asu-shield.png',
                'login_url': SHIBBOLETH_SP_LOGIN.format(
                    encode_uri_component('urn:mace:incommon:asu.edu')),
                'logout_url': SHIBBOLETH_SP_LOGOUT.format(
                    encode_uri_component('https://osf.io/goodbye')),
                'domains': ['osf.asu.edu'],
                'email_domains': [],
                'delegation_protocol': 'saml-shib',
            },
            {
                '_id': 'brown',
                'name': '<NAME>',
                'description': 'A Research Project Management and Publication Tool for the Brown University Research Community in partnership with <a href="https://library.brown.edu/info/data_management">Brown University Library Research Data Management Services</a> | <a href="https://www.brown.edu/research/home">Research at Brown</a> | <a href="https://it.brown.edu/computing-policies/policy-handling-brown-restricted-information">Brown Restricted Information Handling Policy</a> | <a href="https://www.brown.edu/about/administration/provost/policies/privacy">Research Privacy Policy</a>',
                'banner_name': 'brown-banner.png',
                'logo_name': 'brown-shield.png',
                'login_url': SHIBBOLETH_SP_LOGIN.format(encode_uri_component('https://sso.brown.edu/idp/shibboleth')),
                'logout_url': SHIBBOLETH_SP_LOGOUT.format(encode_uri_component('https://osf.io/goodbye')),
                'domains': ['osf.brown.edu'],
                'email_domains': [],
                'delegation_protocol': 'saml-shib',
            },
            {
                '_id': 'bt',
                'name': '<NAME>',
                'description': 'A research data service provided by the BTNRH Research Technology Core. Please do not use this service to store or transfer personally identifiable information or personal health information. For assistance please contact <a href="mailto:<EMAIL>"><EMAIL></a>.',
                'banner_name': 'bt-banner.png',
                'logo_name': 'bt-shield.png',
                'login_url': None,
                'logout_url': None,
                'domains': ['osf.boystownhospital.org'],
                'email_domains': ['boystown.org'],
                'delegation_protocol': '',
            },
            {
                '_id': 'bu',
                'name': '<NAME>',
                'description': 'A Research Project Management Tool for BU',
                'banner_name': 'bu-banner.png',
                'logo_name': 'bu-shield.png',
                'login_url': SHIBBOLETH_SP_LOGIN.format(encode_uri_component('https://shib.bu.edu/idp/shibboleth')),
                'logout_url': SHIBBOLETH_SP_LOGOUT.format(encode_uri_component('https://osf.io/goodbye')),
                'domains': ['osf.bu.edu'],
                'email_domains': [],
                'delegation_protocol': 'saml-shib',
            },
            {
                '_id': 'busara',
                'name': 'Busara Center for Behavioral Economics',
                'description': 'The <a href="http://www.busaracenter.org/">Busara Center</a> for Behavioral Economics',
                'banner_name': 'busara-banner.png',
                'logo_name': 'busara-shield.png',
                'login_url': None,
                'logout_url': None,
                'domains': [],
                'email_domains': ['busaracenter.org'],
                'delegation_protocol': '',
            },
            {
                '_id': 'callutheran',
                'name': 'California Lutheran University',
                'description': '',
                'banner_name': 'callutheran-banner.png',
                'logo_name': 'callutheran-shield.png',
                'login_url': None,
                'logout_url': SHIBBOLETH_SP_LOGOUT.format(encode_uri_component('https://osf.io/goodbye')),
                'domains': [],
                'email_domains': [],
                'delegation_protocol': 'cas-pac4j',
            },
            {
                '_id': 'capolicylab',
                'name': 'California Policy Lab',
                'description': 'The <a href="https:www.capolicylab.org">California Policy Lab</a> pairs trusted experts from UCLA and UC Berkeley with policymakers to solve our most urgent social problems, including homelessness, poverty, crime, and education inequality.',
                'banner_name': 'capolicylab-banner.png',
                'logo_name': 'capolicylab-shield.png',
                'login_url': None,
                'logout_url': None,
                'domains': [],
                'email_domains': ['capolicylab.org'],
                'delegation_protocol': '',
            },
            {
                '_id': 'clrn',
                'name': 'Character Lab Research Network',
                'description': ' Projects listed below are run through the <a href="https://www.characterlab.org/research-network">Character Lab Research Network</a>, a consortium of trailblazing schools and elite scientists that develop and test activities designed to help students thrive. Character Lab Research Network is a proud supporter of the Student Privacy Pledge to safeguard student privacy. For more details on the Research Network privacy policy, you can refer to the <a href="https://www.characterlab.org/student-privacy">Research Network student privacy policy</a> and <a href="https://www.characterlab.org/student-privacy/faqs">FAQs</a>.',
                'banner_name': 'clrn-banner.png',
                'logo_name': 'clrn-shield.png',
                'login_url': None,
                'logout_url': None,
                'domains': [],
                'email_domains': ['characterlab.org'],
                'delegation_protocol': '',
            },
            {
                '_id': 'cmu',
                'name': '<NAME>',
                'description': 'A Project Management Tool for the CMU Community: <a href="https://l'
                               'ibrary.cmu.edu/OSF">Get Help at CMU</a> | <a href="https://cos.io/o'
                               'ur-products/osf/">About OSF</a> | <a href="https://osf.io/support/"'
                               '>OSF Support</a> | <a href="https://library.cmu.edu/OSF/terms-of-us'
                               'e">Terms of Use</a>',
                'banner_name': 'cmu-banner.png',
                'logo_name': 'cmu-shield.png',
                'login_url': SHIBBOLETH_SP_LOGIN.format(encode_uri_component('https://login.cmu.edu/idp/shibboleth')),
                'logout_url': SHIBBOLETH_SP_LOGOUT.format(encode_uri_component('https://osf.io/goodbye')),
                'domains': ['osf.cmu.edu'],
                'email_domains': [],
                'delegation_protocol': 'saml-shib',
            },
            {
                '_id': 'colorado',
                'name': 'University of Colorado Boulder',
                'description': 'This service is supported by the Center for Research Data and Digital Scholarship, which is led by <a href="https://www.rc.colorado.edu/">Research Computing</a> and the <a href="http://www.colorado.edu/libraries/">University Libraries</a>.',
                'banner_name': 'colorado-banner.png',
                'logo_name': 'colorado-shield.png',
                'login_url': SHIBBOLETH_SP_LOGIN.format(encode_uri_component('https://fedauth.colorado.edu/idp/shibboleth')),
                'logout_url': SHIBBOLETH_SP_LOGOUT.format(encode_uri_component('https://osf.io/goodbye')),
                'domains': [],
                'email_domains': [],
                'delegation_protocol': 'saml-shib',
            },
            {
                '_id': 'cos',
                'name': 'Center For Open Science',
                'description': 'COS is a non-profit technology company providing free and open services to increase inclusivity and transparency of research. Find out more at <a href="https://cos.io">cos.io</a>.',
{'fraction_non_alphanumeric': 0.13437101301352386, 'fraction_numerical': 0.0008165348303138556, 'mean_word_length': 2.0913393279697114, 'pattern_counts': {'":': 0, '<': 81, '<?xml version=': 0, '>': 81, 'https://': 44, 'lorem ipsum': 0, 'www.': 18, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5607398', 'n_tokens_mistral': 5761, 'n_tokens_neox': 5393, 'n_words': 1203}