예제 #1
0
def setup_app(command, conf, vars):
    """Place any commands to setup georegistry here"""
    # If we are not in a testing environment,
    if not pylons.test.pylonsapp:
        load_environment(conf.global_conf, conf.local_conf)
    # Create the tables if they don't already exist
    Base.metadata.create_all(bind=Session.bind)
    # If we are not in a testing environment and users do not exist,
    if not pylons.test.pylonsapp and not Session.query(model.Person).all():
        # Show feedback
        print 'Please create an administrator account.'
        # Prepare
        passwordDefault = store.makeRandomString(parameter.PASSWORD_LENGTH_AVERAGE)
        # Create
        person = model.Person(raw_input('Username (administrator): ') or 'administrator', model.hashString(getpass.getpass('Password (%s): ' % passwordDefault) or passwordDefault), raw_input('Nickname (Administrator): ') or u'Administrator', raw_input('Email ([email protected]): ') or '*****@*****.**')
        person.is_super = True
        Session.add(person)
        Session.commit()
예제 #2
0
def getTags(string, addMissing=False):
    'Return corresponding tags'
    # Load tagTexts and discard empty lines
    tagTexts = filter(lambda x: x, (x.strip() for x in string.splitlines()))
    if not tagTexts:
        raise GeoRegistryError('Must specify at least one tag in tags')
    # Check whether tagTexts are too long
    longTagTexts = filter(lambda x: len(x) > parameter.TAG_LENGTH_MAXIMUM, tagTexts)
    if longTagTexts:
        raise GeoRegistryError('Cannot add the following tags because they are too long:\n%s' % '\n'.join(longTagTexts))
    # Check whether tags exist
    missingTagTexts = list(set(tagTexts).difference(tag.text for tag in Session.query(Tag).filter(Tag.text.in_(tagTexts))))
    if missingTagTexts:
        # If we are not supposed to add missing tags,
        if not addMissing:
            raise GeoRegistryError('Cannot match the following tags: %s' % missingTagTexts)
        # Add tags that don't exist
        Session.execute(tags_table.insert(), [{
            'text': x,
        } for x in missingTagTexts])
        # Commit
        Session.commit()
    # Return
    return Session.query(Tag).filter(Tag.text.in_(tagTexts)).all()