Beispiel #1
0
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

import logging

from flask_script import Command

from udata.commands import manager
from udata.tasks import celery

log = logging.getLogger(__name__)


class Worker(Command):
    '''Run a celery worker'''
    def run(self, *args, **kwargs):
        celery.start()


manager.add_command('worker', Worker())
Beispiel #2
0
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

import logging

from flask.ext.script import Command

from udata.commands import manager
from udata.search import es, adapter_catalog

log = logging.getLogger(__name__)


class Reindex(Command):
    '''Reindex all models'''

    def run(self):
        print('Deleting index {0}'.format(es.index_name))
        if es.indices.exists(es.index_name):
            es.indices.delete(index=es.index_name)
        es.initialize()
        for model, adapter in adapter_catalog.items():
            print 'Reindexing {0} objects'.format(model.__name__)
            for obj in model.objects:
                es.index(index=es.index_name, doc_type=adapter.doc_type(), id=obj.id, body=adapter.serialize(obj))
        es.indices.refresh(index=es.index_name)


manager.add_command('reindex', Reindex())
Beispiel #3
0
            'email': prompt('Email'),
            'password': prompt_pass('Password'),
            'password_confirm': prompt_pass('Confirm Password'),
        }
        form = RegisterForm(MultiDict(data), csrf_enabled=False)
        if form.validate():
            data['password'] = encrypt_password(data['password'])
            user = datastore.create_user(**data)
            print '\nUser created successfully'
            print 'User(id=%s email=%s)' % (user.id, user.email)
            return
        print '\nError creating user:'******'\n'.join(errors)


class DeleteUserCommand(Command):
    '''Delete an existing user'''
    def run(self):
        email = prompt('Email')
        user = User.objects(email=email).first()
        if not user:
            print 'Invalid user'
            return
        user.delete()
        print 'User deleted successfully'


manager.add_command('create_user', CreateUserCommand())
manager.add_command('delete_user', DeleteUserCommand())
Beispiel #4
0
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

import logging

from flask.ext.script import Command

from udata.commands import manager
from udata.tasks import celery

log = logging.getLogger(__name__)


class Worker(Command):
    '''Run a celery worker'''
    def run(self, *args, **kwargs):
        celery.start()


manager.add_command('worker', Worker())