mirror of
https://gitlab.ub.uni-bielefeld.de/sfb1288inf/nopaque.git
synced 2026-10-21 05:30:37 +00:00
Compare commits
81
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d023e0a8f3 | ||
|
|
ff86e35bc7 | ||
|
|
2d3e00745e | ||
|
|
cdc9a4b6e9 | ||
|
|
bf130b117d | ||
|
|
97fd9db0ae | ||
|
|
41a88fce33 | ||
|
|
56844e0898 | ||
|
|
c28d534942 | ||
|
|
80604bf8de | ||
|
|
d4cd313940 | ||
|
|
c405061574 | ||
|
|
6c1f48eb2f | ||
|
|
cda28910f5 | ||
|
|
9a805b9d14 | ||
|
|
16bf891654 | ||
|
|
cb53b27ebf | ||
|
|
6684257bc4 | ||
|
|
0d1805fb76 | ||
|
|
bb60a2ba67 | ||
|
|
328f85ba52 | ||
|
|
93344c9573 | ||
|
|
1372c86609 | ||
|
|
713a7645db | ||
|
|
0c64c07925 | ||
|
|
a6ddf4c980 | ||
|
|
cab5f7ea05 | ||
|
|
07f09cdbd9 | ||
|
|
c97b2a886e | ||
|
|
df2bffe0fd | ||
|
|
aafb3ca3ec | ||
|
|
12a3ac1d5d | ||
|
|
a2904caea2 | ||
|
|
e325552100 | ||
|
|
e269156925 | ||
|
|
9c9de242ca | ||
|
|
ec54fdc3bb | ||
|
|
2263a8d27d | ||
|
|
143cdd91f9 | ||
|
|
b5f7478e14 | ||
|
|
a95b8d979d | ||
|
|
18d5ab160e | ||
|
|
7439edacef | ||
|
|
99d7a8bdfc | ||
|
|
54c4295bf7 | ||
|
|
1e5c26b8e3 | ||
|
|
9f56647cf7 | ||
|
|
460257294d | ||
|
|
2c43333c94 | ||
|
|
fc8b11fa66 | ||
|
|
a8ab1bee71 | ||
|
|
ee7f64f5be | ||
|
|
6aacac2419 | ||
|
|
ce253f4a65 | ||
|
|
7b604ce4f2 | ||
|
|
98b20e5cab | ||
|
|
a322ffb2f1 | ||
|
|
29365984a3 | ||
|
|
bd0a9c60f8 | ||
|
|
d41ebc6efe | ||
|
|
63690222ed | ||
|
|
b4faa1c695 | ||
|
|
909b130285 | ||
|
|
c223f07289 | ||
|
|
fcb49025e9 | ||
|
|
191d7813a7 | ||
|
|
f255fef631 | ||
|
|
76171f306d | ||
|
|
5ea6d45f46 | ||
|
|
289a551122 | ||
|
|
2a28f19660 | ||
|
|
fc2ace4b9e | ||
|
|
a174bf968f | ||
|
|
551b928dca | ||
|
|
eeb5a280b3 | ||
|
|
5fc3015bf1 | ||
|
|
5f05cedf5e | ||
|
|
aabea234fe | ||
|
|
492fdc9d28 | ||
|
|
02e6c7c16c | ||
|
|
c7ca674b2f |
No files matched your search
@@ -2,8 +2,6 @@
|
|||||||
app/static/gen/
|
app/static/gen/
|
||||||
volumes/
|
volumes/
|
||||||
docker-compose.override.yml
|
docker-compose.override.yml
|
||||||
logs/
|
|
||||||
!logs/dummy
|
|
||||||
*.env
|
*.env
|
||||||
|
|
||||||
*.pjentsch-testing
|
*.pjentsch-testing
|
||||||
|
|||||||
Vendored
+19
-2
@@ -1,7 +1,24 @@
|
|||||||
{
|
{
|
||||||
"editor.rulers": [79],
|
"editor.rulers": [79],
|
||||||
"editor.tabSize": 2,
|
"editor.tabSize": 4,
|
||||||
|
"emmet.includeLanguages": {
|
||||||
|
"jinja-html": "html"
|
||||||
|
},
|
||||||
|
"files.associations": {
|
||||||
|
".flaskenv": "env",
|
||||||
|
"*.env.tpl": "env",
|
||||||
|
"*.txt.j2": "jinja"
|
||||||
|
},
|
||||||
"files.insertFinalNewline": true,
|
"files.insertFinalNewline": true,
|
||||||
"files.trimFinalNewlines": true,
|
"files.trimFinalNewlines": true,
|
||||||
"files.trimTrailingWhitespace": true
|
"files.trimTrailingWhitespace": true,
|
||||||
|
"[html]": {
|
||||||
|
"editor.tabSize": 2
|
||||||
|
},
|
||||||
|
"[javascript]": {
|
||||||
|
"editor.tabSize": 2
|
||||||
|
},
|
||||||
|
"[jinja-html]": {
|
||||||
|
"editor.tabSize": 2
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -46,7 +46,6 @@ COPY --chown=nopaque:nopaque app app
|
|||||||
COPY --chown=nopaque:nopaque migrations migrations
|
COPY --chown=nopaque:nopaque migrations migrations
|
||||||
COPY --chown=nopaque:nopaque tests tests
|
COPY --chown=nopaque:nopaque tests tests
|
||||||
COPY --chown=nopaque:nopaque boot.sh config.py wsgi.py ./
|
COPY --chown=nopaque:nopaque boot.sh config.py wsgi.py ./
|
||||||
RUN mkdir logs
|
|
||||||
|
|
||||||
|
|
||||||
EXPOSE 5000
|
EXPOSE 5000
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ username@hostname:~$ sudo mount --types cifs --options gid=${USER},password=nopa
|
|||||||
# Clone the nopaque repository
|
# Clone the nopaque repository
|
||||||
username@hostname:~$ git clone https://gitlab.ub.uni-bielefeld.de/sfb1288inf/nopaque.git
|
username@hostname:~$ git clone https://gitlab.ub.uni-bielefeld.de/sfb1288inf/nopaque.git
|
||||||
# Create data directories
|
# Create data directories
|
||||||
username@hostname:~$ mkdir data/{db,logs,mq}
|
username@hostname:~$ mkdir -p volumes/{db,mq}
|
||||||
username@hostname:~$ cp db.env.tpl db.env
|
username@hostname:~$ cp db.env.tpl db.env
|
||||||
username@hostname:~$ cp .env.tpl .env
|
username@hostname:~$ cp .env.tpl .env
|
||||||
# Fill out the variables within these files.
|
# Fill out the variables within these files.
|
||||||
|
|||||||
+84
-35
@@ -2,6 +2,8 @@ from apifairy import APIFairy
|
|||||||
from config import Config
|
from config import Config
|
||||||
from docker import DockerClient
|
from docker import DockerClient
|
||||||
from flask import Flask
|
from flask import Flask
|
||||||
|
from flask.logging import default_handler
|
||||||
|
from flask_admin import Admin
|
||||||
from flask_apscheduler import APScheduler
|
from flask_apscheduler import APScheduler
|
||||||
from flask_assets import Environment
|
from flask_assets import Environment
|
||||||
from flask_login import LoginManager
|
from flask_login import LoginManager
|
||||||
@@ -12,12 +14,17 @@ from flask_paranoid import Paranoid
|
|||||||
from flask_socketio import SocketIO
|
from flask_socketio import SocketIO
|
||||||
from flask_sqlalchemy import SQLAlchemy
|
from flask_sqlalchemy import SQLAlchemy
|
||||||
from flask_hashids import Hashids
|
from flask_hashids import Hashids
|
||||||
|
from logging import Formatter, StreamHandler
|
||||||
|
from werkzeug.middleware.proxy_fix import ProxyFix
|
||||||
|
from .extensions.nopaque_flask_admin_views import AdminIndexView, ModelView
|
||||||
|
|
||||||
|
|
||||||
|
docker_client = DockerClient.from_env()
|
||||||
|
|
||||||
|
admin = Admin()
|
||||||
apifairy = APIFairy()
|
apifairy = APIFairy()
|
||||||
assets = Environment()
|
assets = Environment()
|
||||||
db = SQLAlchemy()
|
db = SQLAlchemy()
|
||||||
docker_client = DockerClient()
|
|
||||||
hashids = Hashids()
|
hashids = Hashids()
|
||||||
login = LoginManager()
|
login = LoginManager()
|
||||||
ma = Marshmallow()
|
ma = Marshmallow()
|
||||||
@@ -28,80 +35,122 @@ scheduler = APScheduler()
|
|||||||
socketio = SocketIO()
|
socketio = SocketIO()
|
||||||
|
|
||||||
|
|
||||||
# TODO: Create export for lemmatized corpora
|
|
||||||
|
|
||||||
|
|
||||||
def create_app(config: Config = Config) -> Flask:
|
def create_app(config: Config = Config) -> Flask:
|
||||||
''' Creates an initialized Flask (WSGI Application) object. '''
|
''' Creates an initialized Flask object. '''
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
app.config.from_object(config)
|
app.config.from_object(config)
|
||||||
config.init_app(app)
|
|
||||||
|
# region Logging
|
||||||
|
log_formatter = Formatter(
|
||||||
|
fmt=app.config['NOPAQUE_LOG_FORMAT'],
|
||||||
|
datefmt=app.config['NOPAQUE_LOG_DATE_FORMAT']
|
||||||
|
)
|
||||||
|
|
||||||
|
log_handler = StreamHandler()
|
||||||
|
log_handler.setFormatter(log_formatter)
|
||||||
|
log_handler.setLevel(app.config['NOPAQUE_LOG_LEVEL'])
|
||||||
|
|
||||||
|
app.logger.setLevel('DEBUG')
|
||||||
|
app.logger.removeHandler(default_handler)
|
||||||
|
app.logger.addHandler(log_handler)
|
||||||
|
# endregion Logging
|
||||||
|
|
||||||
|
# region Middlewares
|
||||||
|
if app.config['NOPAQUE_PROXY_FIX_ENABLED']:
|
||||||
|
app.wsgi_app = ProxyFix(
|
||||||
|
app.wsgi_app,
|
||||||
|
x_for=app.config['NOPAQUE_PROXY_FIX_X_FOR'],
|
||||||
|
x_host=app.config['NOPAQUE_PROXY_FIX_X_HOST'],
|
||||||
|
x_port=app.config['NOPAQUE_PROXY_FIX_X_PORT'],
|
||||||
|
x_prefix=app.config['NOPAQUE_PROXY_FIX_X_PREFIX'],
|
||||||
|
x_proto=app.config['NOPAQUE_PROXY_FIX_X_PROTO']
|
||||||
|
)
|
||||||
|
# endregion Middlewares
|
||||||
|
|
||||||
|
# region Extensions
|
||||||
docker_client.login(
|
docker_client.login(
|
||||||
app.config['NOPAQUE_DOCKER_REGISTRY_USERNAME'],
|
app.config['NOPAQUE_DOCKER_REGISTRY_USERNAME'],
|
||||||
password=app.config['NOPAQUE_DOCKER_REGISTRY_PASSWORD'],
|
password=app.config['NOPAQUE_DOCKER_REGISTRY_PASSWORD'],
|
||||||
registry=app.config['NOPAQUE_DOCKER_REGISTRY']
|
registry=app.config['NOPAQUE_DOCKER_REGISTRY']
|
||||||
)
|
)
|
||||||
|
|
||||||
|
from .models import AnonymousUser, User
|
||||||
|
|
||||||
|
admin.init_app(app, index_view=AdminIndexView())
|
||||||
apifairy.init_app(app)
|
apifairy.init_app(app)
|
||||||
assets.init_app(app)
|
assets.init_app(app)
|
||||||
db.init_app(app)
|
db.init_app(app)
|
||||||
hashids.init_app(app)
|
hashids.init_app(app)
|
||||||
login.init_app(app)
|
login.init_app(app)
|
||||||
|
login.anonymous_user = AnonymousUser
|
||||||
|
login.login_view = 'auth.login'
|
||||||
|
login.user_loader(lambda user_id: User.query.get(int(user_id)))
|
||||||
ma.init_app(app)
|
ma.init_app(app)
|
||||||
mail.init_app(app)
|
mail.init_app(app)
|
||||||
migrate.init_app(app, db)
|
migrate.init_app(app, db)
|
||||||
paranoid.init_app(app)
|
paranoid.init_app(app)
|
||||||
scheduler.init_app(app)
|
|
||||||
socketio.init_app(app, message_queue=app.config['NOPAQUE_SOCKETIO_MESSAGE_QUEUE_URI']) # noqa
|
|
||||||
|
|
||||||
from .models import AnonymousUser, User
|
|
||||||
login.anonymous_user = AnonymousUser
|
|
||||||
login.login_view = 'auth.login'
|
|
||||||
@login.user_loader
|
|
||||||
def load_user(user_id):
|
|
||||||
return User.query.get(int(user_id))
|
|
||||||
|
|
||||||
paranoid.redirect_view = '/'
|
paranoid.redirect_view = '/'
|
||||||
|
scheduler.init_app(app)
|
||||||
|
socketio.init_app(app, message_queue=app.config['NOPAQUE_SOCKETIO_MESSAGE_QUEUE_URI'])
|
||||||
|
# endregion Extensions
|
||||||
|
|
||||||
from .models.event_listeners import register_event_listeners
|
# region Blueprints
|
||||||
register_event_listeners()
|
from .blueprints.api import bp as api_blueprint
|
||||||
|
|
||||||
from .admin import bp as admin_blueprint
|
|
||||||
app.register_blueprint(admin_blueprint, url_prefix='/admin')
|
|
||||||
|
|
||||||
from .api import bp as api_blueprint
|
|
||||||
app.register_blueprint(api_blueprint, url_prefix='/api')
|
app.register_blueprint(api_blueprint, url_prefix='/api')
|
||||||
|
|
||||||
from .auth import bp as auth_blueprint
|
from .blueprints.auth import bp as auth_blueprint
|
||||||
app.register_blueprint(auth_blueprint)
|
app.register_blueprint(auth_blueprint)
|
||||||
|
|
||||||
from .contributions import bp as contributions_blueprint
|
from .blueprints.contributions import bp as contributions_blueprint
|
||||||
app.register_blueprint(contributions_blueprint, url_prefix='/contributions')
|
app.register_blueprint(contributions_blueprint, url_prefix='/contributions')
|
||||||
|
|
||||||
from .corpora import bp as corpora_blueprint
|
from .blueprints.corpora import bp as corpora_blueprint
|
||||||
from .corpora.cqi_over_sio import CQiNamespace
|
|
||||||
app.register_blueprint(corpora_blueprint, cli_group='corpus', url_prefix='/corpora')
|
app.register_blueprint(corpora_blueprint, cli_group='corpus', url_prefix='/corpora')
|
||||||
socketio.on_namespace(CQiNamespace('/cqi_over_sio'))
|
|
||||||
|
|
||||||
from .errors import bp as errors_bp
|
from .blueprints.errors import bp as errors_bp
|
||||||
app.register_blueprint(errors_bp)
|
app.register_blueprint(errors_bp)
|
||||||
|
|
||||||
from .jobs import bp as jobs_blueprint
|
from .blueprints.jobs import bp as jobs_blueprint
|
||||||
app.register_blueprint(jobs_blueprint, url_prefix='/jobs')
|
app.register_blueprint(jobs_blueprint, url_prefix='/jobs')
|
||||||
|
|
||||||
from .main import bp as main_blueprint
|
from .blueprints.main import bp as main_blueprint
|
||||||
app.register_blueprint(main_blueprint, cli_group=None)
|
app.register_blueprint(main_blueprint, cli_group=None)
|
||||||
|
|
||||||
from .services import bp as services_blueprint
|
from .blueprints.services import bp as services_blueprint
|
||||||
app.register_blueprint(services_blueprint, url_prefix='/services')
|
app.register_blueprint(services_blueprint, url_prefix='/services')
|
||||||
|
|
||||||
from .settings import bp as settings_blueprint
|
from .blueprints.settings import bp as settings_blueprint
|
||||||
app.register_blueprint(settings_blueprint, url_prefix='/settings')
|
app.register_blueprint(settings_blueprint, url_prefix='/settings')
|
||||||
|
|
||||||
from .users import bp as users_blueprint
|
from .blueprints.users import bp as users_blueprint
|
||||||
app.register_blueprint(users_blueprint, cli_group='user', url_prefix='/users')
|
app.register_blueprint(users_blueprint, cli_group='user', url_prefix='/users')
|
||||||
|
|
||||||
from .workshops import bp as workshops_blueprint
|
from .blueprints.workshops import bp as workshops_blueprint
|
||||||
app.register_blueprint(workshops_blueprint, url_prefix='/workshops')
|
app.register_blueprint(workshops_blueprint, url_prefix='/workshops')
|
||||||
|
|
||||||
|
from .models import _models
|
||||||
|
for model in _models:
|
||||||
|
admin.add_view(ModelView(model, db.session, category='Database'))
|
||||||
|
# endregion Blueprints
|
||||||
|
|
||||||
|
# region SocketIO Namespaces
|
||||||
|
from .namespaces.cqi_over_sio import CQiOverSocketIONamespace
|
||||||
|
socketio.on_namespace(CQiOverSocketIONamespace('/cqi_over_sio'))
|
||||||
|
# endregion SocketIO Namespaces
|
||||||
|
|
||||||
|
# region Database event Listeners
|
||||||
|
from .models.event_listeners import register_event_listeners
|
||||||
|
register_event_listeners()
|
||||||
|
# endregion Database event Listeners
|
||||||
|
|
||||||
|
# region Add scheduler jobs
|
||||||
|
if app.config['NOPAQUE_IS_PRIMARY_INSTANCE']:
|
||||||
|
from .jobs import handle_corpora
|
||||||
|
scheduler.add_job('handle_corpora', handle_corpora, seconds=3, trigger='interval')
|
||||||
|
|
||||||
|
from .jobs import handle_jobs
|
||||||
|
scheduler.add_job('handle_jobs', handle_jobs, seconds=3, trigger='interval')
|
||||||
|
# endregion Add scheduler jobs
|
||||||
|
|
||||||
return app
|
return app
|
||||||
@@ -1,20 +0,0 @@
|
|||||||
from flask import Blueprint
|
|
||||||
from flask_login import login_required
|
|
||||||
from app.decorators import admin_required
|
|
||||||
|
|
||||||
|
|
||||||
bp = Blueprint('admin', __name__)
|
|
||||||
|
|
||||||
|
|
||||||
@bp.before_request
|
|
||||||
@login_required
|
|
||||||
@admin_required
|
|
||||||
def before_request():
|
|
||||||
'''
|
|
||||||
Ensures that the routes in this package can be visited only by users with
|
|
||||||
administrator privileges (login_required and admin_required).
|
|
||||||
'''
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
from . import json_routes, routes
|
|
||||||
@@ -1,49 +0,0 @@
|
|||||||
from flask_login import current_user
|
|
||||||
from flask_socketio import disconnect, Namespace
|
|
||||||
from app import db, hashids
|
|
||||||
from app.decorators import socketio_admin_required
|
|
||||||
from app.models import User
|
|
||||||
|
|
||||||
|
|
||||||
class AdminNamespace(Namespace):
|
|
||||||
def on_connect(self):
|
|
||||||
# Check if the user is authenticated and is an administrator
|
|
||||||
if not (current_user.is_authenticated and current_user.is_administrator):
|
|
||||||
disconnect()
|
|
||||||
|
|
||||||
|
|
||||||
@socketio_admin_required
|
|
||||||
def on_set_user_confirmed(self, user_hashid: str, confirmed_value: bool):
|
|
||||||
# Decode the user hashid
|
|
||||||
user_id = hashids.decode(user_hashid)
|
|
||||||
|
|
||||||
# Validate user_id
|
|
||||||
if not isinstance(user_id, int):
|
|
||||||
return {
|
|
||||||
'code': 400,
|
|
||||||
'body': 'user_id is invalid'
|
|
||||||
}
|
|
||||||
|
|
||||||
# Validate confirmed_value
|
|
||||||
if not isinstance(confirmed_value, bool):
|
|
||||||
return {
|
|
||||||
'code': 400,
|
|
||||||
'body': 'confirmed_value is invalid'
|
|
||||||
}
|
|
||||||
|
|
||||||
# Load user from database
|
|
||||||
user = User.query.get(user_id)
|
|
||||||
if user is None:
|
|
||||||
return {
|
|
||||||
'code': 404,
|
|
||||||
'body': 'User not found'
|
|
||||||
}
|
|
||||||
|
|
||||||
# Update user confirmed status
|
|
||||||
user.confirmed = confirmed_value
|
|
||||||
db.session.commit()
|
|
||||||
|
|
||||||
return {
|
|
||||||
'code': 200,
|
|
||||||
'body': f'User "{user.username}" is now {"confirmed" if confirmed_value else "unconfirmed"}'
|
|
||||||
}
|
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
from flask_wtf import FlaskForm
|
|
||||||
from wtforms import SelectField, SubmitField
|
|
||||||
from app.models import Role
|
|
||||||
|
|
||||||
|
|
||||||
class UpdateUserForm(FlaskForm):
|
|
||||||
role = SelectField('Role')
|
|
||||||
submit = SubmitField()
|
|
||||||
|
|
||||||
def __init__(self, user, *args, **kwargs):
|
|
||||||
if 'data' not in kwargs:
|
|
||||||
kwargs['data'] = {'role': user.role.hashid}
|
|
||||||
if 'prefix' not in kwargs:
|
|
||||||
kwargs['prefix'] = 'update-user-form'
|
|
||||||
super().__init__(*args, **kwargs)
|
|
||||||
self.role.choices = [(x.hashid, x.name) for x in Role.query.all()]
|
|
||||||
@@ -1,23 +0,0 @@
|
|||||||
from flask import abort, request
|
|
||||||
from app.decorators import content_negotiation
|
|
||||||
from app import db
|
|
||||||
from app.models import User
|
|
||||||
from . import bp
|
|
||||||
|
|
||||||
|
|
||||||
@bp.route('/users/<hashid:user_id>/confirmed', methods=['PUT'])
|
|
||||||
@content_negotiation(consumes='application/json', produces='application/json')
|
|
||||||
def update_user_role(user_id):
|
|
||||||
confirmed = request.json
|
|
||||||
if not isinstance(confirmed, bool):
|
|
||||||
abort(400)
|
|
||||||
user = User.query.get_or_404(user_id)
|
|
||||||
user.confirmed = confirmed
|
|
||||||
db.session.commit()
|
|
||||||
response_data = {
|
|
||||||
'message': (
|
|
||||||
f'User "{user.username}" is now '
|
|
||||||
f'{"confirmed" if confirmed else "unconfirmed"}'
|
|
||||||
)
|
|
||||||
}
|
|
||||||
return response_data, 200
|
|
||||||
@@ -1,136 +0,0 @@
|
|||||||
from flask import abort, flash, redirect, render_template, url_for
|
|
||||||
from app import db, hashids
|
|
||||||
from app.models import Avatar, Corpus, Role, User
|
|
||||||
from app.users.settings.forms import (
|
|
||||||
UpdateAvatarForm,
|
|
||||||
UpdatePasswordForm,
|
|
||||||
UpdateNotificationsForm,
|
|
||||||
UpdateAccountInformationForm,
|
|
||||||
UpdateProfileInformationForm
|
|
||||||
)
|
|
||||||
from . import bp
|
|
||||||
from .forms import UpdateUserForm
|
|
||||||
|
|
||||||
|
|
||||||
@bp.route('')
|
|
||||||
def admin():
|
|
||||||
return render_template(
|
|
||||||
'admin/admin.html.j2',
|
|
||||||
title='Administration'
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
@bp.route('/corpora')
|
|
||||||
def corpora():
|
|
||||||
corpora = Corpus.query.all()
|
|
||||||
return render_template(
|
|
||||||
'admin/corpora.html.j2',
|
|
||||||
title='Corpora',
|
|
||||||
corpora=corpora
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
@bp.route('/users')
|
|
||||||
def users():
|
|
||||||
users = User.query.all()
|
|
||||||
return render_template(
|
|
||||||
'admin/users.html.j2',
|
|
||||||
title='Users',
|
|
||||||
users=users
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
@bp.route('/users/<hashid:user_id>')
|
|
||||||
def user(user_id):
|
|
||||||
user = User.query.get_or_404(user_id)
|
|
||||||
corpora = Corpus.query.filter(Corpus.user == user).all()
|
|
||||||
return render_template(
|
|
||||||
'admin/user.html.j2',
|
|
||||||
title=user.username,
|
|
||||||
user=user,
|
|
||||||
corpora=corpora
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
@bp.route('/users/<hashid:user_id>/settings', methods=['GET', 'POST'])
|
|
||||||
def user_settings(user_id):
|
|
||||||
user = User.query.get_or_404(user_id)
|
|
||||||
update_account_information_form = UpdateAccountInformationForm(user)
|
|
||||||
update_profile_information_form = UpdateProfileInformationForm(user)
|
|
||||||
update_avatar_form = UpdateAvatarForm()
|
|
||||||
update_password_form = UpdatePasswordForm(user)
|
|
||||||
update_notifications_form = UpdateNotificationsForm(user)
|
|
||||||
update_user_form = UpdateUserForm(user)
|
|
||||||
|
|
||||||
# region handle update profile information form
|
|
||||||
if update_profile_information_form.submit.data and update_profile_information_form.validate():
|
|
||||||
user.about_me = update_profile_information_form.about_me.data
|
|
||||||
user.location = update_profile_information_form.location.data
|
|
||||||
user.organization = update_profile_information_form.organization.data
|
|
||||||
user.website = update_profile_information_form.website.data
|
|
||||||
user.full_name = update_profile_information_form.full_name.data
|
|
||||||
db.session.commit()
|
|
||||||
flash('Your changes have been saved')
|
|
||||||
return redirect(url_for('.user_settings', user_id=user.id))
|
|
||||||
# endregion handle update profile information form
|
|
||||||
|
|
||||||
# region handle update avatar form
|
|
||||||
if update_avatar_form.submit.data and update_avatar_form.validate():
|
|
||||||
try:
|
|
||||||
Avatar.create(
|
|
||||||
update_avatar_form.avatar.data,
|
|
||||||
user=user
|
|
||||||
)
|
|
||||||
except (AttributeError, OSError):
|
|
||||||
abort(500)
|
|
||||||
db.session.commit()
|
|
||||||
flash('Your changes have been saved')
|
|
||||||
return redirect(url_for('.user_settings', user_id=user.id))
|
|
||||||
# endregion handle update avatar form
|
|
||||||
|
|
||||||
# region handle update account information form
|
|
||||||
if update_account_information_form.submit.data and update_account_information_form.validate():
|
|
||||||
user.email = update_account_information_form.email.data
|
|
||||||
user.username = update_account_information_form.username.data
|
|
||||||
db.session.commit()
|
|
||||||
flash('Profile settings updated')
|
|
||||||
return redirect(url_for('.user_settings', user_id=user.id))
|
|
||||||
# endregion handle update account information form
|
|
||||||
|
|
||||||
# region handle update password form
|
|
||||||
if update_password_form.submit.data and update_password_form.validate():
|
|
||||||
user.password = update_password_form.new_password.data
|
|
||||||
db.session.commit()
|
|
||||||
flash('Your changes have been saved')
|
|
||||||
return redirect(url_for('.user_settings', user_id=user.id))
|
|
||||||
# endregion handle update password form
|
|
||||||
|
|
||||||
# region handle update notifications form
|
|
||||||
if update_notifications_form.submit.data and update_notifications_form.validate():
|
|
||||||
user.setting_job_status_mail_notification_level = \
|
|
||||||
update_notifications_form.job_status_mail_notification_level.data
|
|
||||||
db.session.commit()
|
|
||||||
flash('Your changes have been saved')
|
|
||||||
return redirect(url_for('.user_settings', user_id=user.id))
|
|
||||||
# endregion handle update notifications form
|
|
||||||
|
|
||||||
# region handle update user form
|
|
||||||
if update_user_form.submit.data and update_user_form.validate():
|
|
||||||
role_id = hashids.decode(update_user_form.role.data)
|
|
||||||
user.role = Role.query.get(role_id)
|
|
||||||
db.session.commit()
|
|
||||||
flash('Your changes have been saved')
|
|
||||||
return redirect(url_for('.user_settings', user_id=user.id))
|
|
||||||
# endregion handle update user form
|
|
||||||
|
|
||||||
return render_template(
|
|
||||||
'admin/user_settings.html.j2',
|
|
||||||
title='Settings',
|
|
||||||
update_account_information_form=update_account_information_form,
|
|
||||||
update_avatar_form=update_avatar_form,
|
|
||||||
update_notifications_form=update_notifications_form,
|
|
||||||
update_password_form=update_password_form,
|
|
||||||
update_profile_information_form=update_profile_information_form,
|
|
||||||
update_user_form=update_user_form,
|
|
||||||
user=user
|
|
||||||
)
|
|
||||||
File renamed without changes.
File renamed without changes.
File renamed without changes.
@@ -10,7 +10,7 @@ from app.models import (
|
|||||||
User,
|
User,
|
||||||
UserSettingJobStatusMailNotificationLevel
|
UserSettingJobStatusMailNotificationLevel
|
||||||
)
|
)
|
||||||
from app.services import SERVICES
|
from app.blueprints.services import SERVICES
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
File renamed without changes.
File renamed without changes.
@@ -0,0 +1,27 @@
|
|||||||
|
from flask import Blueprint, redirect, request, url_for
|
||||||
|
from flask_login import current_user
|
||||||
|
from app import db
|
||||||
|
|
||||||
|
|
||||||
|
bp = Blueprint('auth', __name__)
|
||||||
|
|
||||||
|
|
||||||
|
@bp.before_app_request
|
||||||
|
def before_request():
|
||||||
|
if not current_user.is_authenticated:
|
||||||
|
return
|
||||||
|
|
||||||
|
current_user.ping()
|
||||||
|
db.session.commit()
|
||||||
|
|
||||||
|
if (
|
||||||
|
not current_user.confirmed
|
||||||
|
and request.endpoint
|
||||||
|
and request.blueprint != 'auth'
|
||||||
|
and request.endpoint != 'static'
|
||||||
|
and request.endpoint != 'main.accept_terms_of_use'
|
||||||
|
):
|
||||||
|
return redirect(url_for('auth.unconfirmed'))
|
||||||
|
|
||||||
|
|
||||||
|
from . import routes
|
||||||
@@ -60,7 +60,11 @@ class RegistrationForm(FlaskForm):
|
|||||||
|
|
||||||
def validate_username(self, field):
|
def validate_username(self, field):
|
||||||
if User.query.filter_by(username=field.data).first():
|
if User.query.filter_by(username=field.data).first():
|
||||||
raise ValidationError('Username already in use')
|
raise ValidationError('Username already registered')
|
||||||
|
|
||||||
|
def validate_terms_of_use_accepted(self, field):
|
||||||
|
if not field.data:
|
||||||
|
raise ValidationError('Terms of Use not accepted')
|
||||||
|
|
||||||
|
|
||||||
class LoginForm(FlaskForm):
|
class LoginForm(FlaskForm):
|
||||||
@@ -12,26 +12,6 @@ from .forms import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@bp.before_app_request
|
|
||||||
def before_request():
|
|
||||||
"""
|
|
||||||
Checks if a user is unconfirmed when visiting specific sites. Redirects to
|
|
||||||
unconfirmed view if user is unconfirmed.
|
|
||||||
"""
|
|
||||||
if not current_user.is_authenticated:
|
|
||||||
return
|
|
||||||
|
|
||||||
current_user.ping()
|
|
||||||
db.session.commit()
|
|
||||||
if (not current_user.confirmed
|
|
||||||
and request.endpoint
|
|
||||||
and request.blueprint != 'auth'
|
|
||||||
and request.endpoint != 'static'):
|
|
||||||
return redirect(url_for('auth.unconfirmed'))
|
|
||||||
if not current_user.terms_of_use_accepted:
|
|
||||||
return redirect(url_for('main.terms_of_use'))
|
|
||||||
|
|
||||||
|
|
||||||
@bp.route('/register', methods=['GET', 'POST'])
|
@bp.route('/register', methods=['GET', 'POST'])
|
||||||
def register():
|
def register():
|
||||||
if current_user.is_authenticated:
|
if current_user.is_authenticated:
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
from flask import Blueprint
|
||||||
|
from flask_login import login_required
|
||||||
|
|
||||||
|
|
||||||
|
bp = Blueprint('contributions', __name__)
|
||||||
|
|
||||||
|
|
||||||
|
@bp.before_request
|
||||||
|
@login_required
|
||||||
|
def before_request():
|
||||||
|
'''
|
||||||
|
Ensures that the routes in this package can only be visited by users that
|
||||||
|
are logged in.
|
||||||
|
'''
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
from . import routes
|
||||||
|
|
||||||
|
|
||||||
|
from .spacy_nlp_pipeline_models import bp as spacy_nlp_pipeline_models_bp
|
||||||
|
bp.register_blueprint(spacy_nlp_pipeline_models_bp, url_prefix='/spacy-nlp-pipeline-models')
|
||||||
|
|
||||||
|
from .tesseract_ocr_pipeline_models import bp as tesseract_ocr_pipeline_models_bp
|
||||||
|
bp.register_blueprint(tesseract_ocr_pipeline_models_bp, url_prefix='/tesseract-ocr-pipeline-models')
|
||||||
File renamed without changes.
@@ -0,0 +1,7 @@
|
|||||||
|
from flask import render_template
|
||||||
|
from . import bp
|
||||||
|
|
||||||
|
|
||||||
|
@bp.route('')
|
||||||
|
def index():
|
||||||
|
return render_template('contributions/index.html.j2', title='Contributions')
|
||||||
+3
-3
@@ -1,8 +1,8 @@
|
|||||||
from flask import Blueprint
|
from flask import current_app, Blueprint
|
||||||
from flask_login import login_required
|
from flask_login import login_required
|
||||||
|
|
||||||
|
|
||||||
bp = Blueprint('settings', __name__)
|
bp = Blueprint('spacy_nlp_pipeline_models', __name__)
|
||||||
|
|
||||||
|
|
||||||
@bp.before_request
|
@bp.before_request
|
||||||
@@ -15,4 +15,4 @@ def before_request():
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
from . import routes
|
from . import routes, json_routes
|
||||||
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
from flask_wtf.file import FileField, FileRequired
|
from flask_wtf.file import FileField, FileRequired
|
||||||
from wtforms import StringField, ValidationError
|
from wtforms import StringField, ValidationError
|
||||||
from wtforms.validators import InputRequired, Length
|
from wtforms.validators import InputRequired, Length
|
||||||
from app.services import SERVICES
|
from app.blueprints.services import SERVICES
|
||||||
from ..forms import ContributionBaseForm, UpdateContributionBaseForm
|
from ..forms import ContributionBaseForm, UpdateContributionBaseForm
|
||||||
|
|
||||||
|
|
||||||
+5
-4
@@ -1,5 +1,5 @@
|
|||||||
from flask import abort, current_app, request
|
from flask import abort, current_app, request
|
||||||
from flask_login import current_user
|
from flask_login import current_user, login_required
|
||||||
from threading import Thread
|
from threading import Thread
|
||||||
from app import db
|
from app import db
|
||||||
from app.decorators import content_negotiation, permission_required
|
from app.decorators import content_negotiation, permission_required
|
||||||
@@ -7,7 +7,8 @@ from app.models import SpaCyNLPPipelineModel
|
|||||||
from . import bp
|
from . import bp
|
||||||
|
|
||||||
|
|
||||||
@bp.route('/spacy-nlp-pipeline-models/<hashid:spacy_nlp_pipeline_model_id>', methods=['DELETE'])
|
@bp.route('/<hashid:spacy_nlp_pipeline_model_id>', methods=['DELETE'])
|
||||||
|
@login_required
|
||||||
@content_negotiation(produces='application/json')
|
@content_negotiation(produces='application/json')
|
||||||
def delete_spacy_model(spacy_nlp_pipeline_model_id):
|
def delete_spacy_model(spacy_nlp_pipeline_model_id):
|
||||||
def _delete_spacy_model(app, spacy_nlp_pipeline_model_id):
|
def _delete_spacy_model(app, spacy_nlp_pipeline_model_id):
|
||||||
@@ -15,7 +16,7 @@ def delete_spacy_model(spacy_nlp_pipeline_model_id):
|
|||||||
snpm = SpaCyNLPPipelineModel.query.get(spacy_nlp_pipeline_model_id)
|
snpm = SpaCyNLPPipelineModel.query.get(spacy_nlp_pipeline_model_id)
|
||||||
snpm.delete()
|
snpm.delete()
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
|
||||||
snpm = SpaCyNLPPipelineModel.query.get_or_404(spacy_nlp_pipeline_model_id)
|
snpm = SpaCyNLPPipelineModel.query.get_or_404(spacy_nlp_pipeline_model_id)
|
||||||
if not (snpm.user == current_user or current_user.is_administrator):
|
if not (snpm.user == current_user or current_user.is_administrator):
|
||||||
abort(403)
|
abort(403)
|
||||||
@@ -31,7 +32,7 @@ def delete_spacy_model(spacy_nlp_pipeline_model_id):
|
|||||||
return response_data, 202
|
return response_data, 202
|
||||||
|
|
||||||
|
|
||||||
@bp.route('/spacy-nlp-pipeline-models/<hashid:spacy_nlp_pipeline_model_id>/is_public', methods=['PUT'])
|
@bp.route('/<hashid:spacy_nlp_pipeline_model_id>/is_public', methods=['PUT'])
|
||||||
@permission_required('CONTRIBUTE')
|
@permission_required('CONTRIBUTE')
|
||||||
@content_negotiation(consumes='application/json', produces='application/json')
|
@content_negotiation(consumes='application/json', produces='application/json')
|
||||||
def update_spacy_nlp_pipeline_model_is_public(spacy_nlp_pipeline_model_id):
|
def update_spacy_nlp_pipeline_model_is_public(spacy_nlp_pipeline_model_id):
|
||||||
+14
-14
@@ -1,5 +1,5 @@
|
|||||||
from flask import abort, flash, redirect, render_template, url_for
|
from flask import abort, flash, redirect, render_template, url_for
|
||||||
from flask_login import current_user
|
from flask_login import current_user, login_required
|
||||||
from app import db
|
from app import db
|
||||||
from app.models import SpaCyNLPPipelineModel
|
from app.models import SpaCyNLPPipelineModel
|
||||||
from . import bp
|
from . import bp
|
||||||
@@ -9,16 +9,15 @@ from .forms import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@bp.route('/spacy-nlp-pipeline-models')
|
@bp.route('/')
|
||||||
def spacy_nlp_pipeline_models():
|
@login_required
|
||||||
return render_template(
|
def index():
|
||||||
'contributions/spacy_nlp_pipeline_models/spacy_nlp_pipeline_models.html.j2',
|
return redirect(url_for('contributions.index', _anchor='spacy-nlp-pipeline-models'))
|
||||||
title='SpaCy NLP Pipeline Models'
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
@bp.route('/spacy-nlp-pipeline-models/create', methods=['GET', 'POST'])
|
@bp.route('/create', methods=['GET', 'POST'])
|
||||||
def create_spacy_nlp_pipeline_model():
|
@login_required
|
||||||
|
def create():
|
||||||
form = CreateSpaCyNLPPipelineModelForm()
|
form = CreateSpaCyNLPPipelineModelForm()
|
||||||
if form.is_submitted():
|
if form.is_submitted():
|
||||||
if not form.validate():
|
if not form.validate():
|
||||||
@@ -42,7 +41,7 @@ def create_spacy_nlp_pipeline_model():
|
|||||||
abort(500)
|
abort(500)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
flash(f'SpaCy NLP Pipeline model "{snpm.title}" created')
|
flash(f'SpaCy NLP Pipeline model "{snpm.title}" created')
|
||||||
return {}, 201, {'Location': url_for('.spacy_nlp_pipeline_models')}
|
return {}, 201, {'Location': url_for('.index')}
|
||||||
return render_template(
|
return render_template(
|
||||||
'contributions/spacy_nlp_pipeline_models/create.html.j2',
|
'contributions/spacy_nlp_pipeline_models/create.html.j2',
|
||||||
title='Create SpaCy NLP Pipeline Model',
|
title='Create SpaCy NLP Pipeline Model',
|
||||||
@@ -50,8 +49,9 @@ def create_spacy_nlp_pipeline_model():
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@bp.route('/spacy-nlp-pipeline-models/<hashid:spacy_nlp_pipeline_model_id>', methods=['GET', 'POST'])
|
@bp.route('/<hashid:spacy_nlp_pipeline_model_id>', methods=['GET', 'POST'])
|
||||||
def spacy_nlp_pipeline_model(spacy_nlp_pipeline_model_id):
|
@login_required
|
||||||
|
def entity(spacy_nlp_pipeline_model_id):
|
||||||
snpm = SpaCyNLPPipelineModel.query.get_or_404(spacy_nlp_pipeline_model_id)
|
snpm = SpaCyNLPPipelineModel.query.get_or_404(spacy_nlp_pipeline_model_id)
|
||||||
if not (snpm.user == current_user or current_user.is_administrator):
|
if not (snpm.user == current_user or current_user.is_administrator):
|
||||||
abort(403)
|
abort(403)
|
||||||
@@ -61,9 +61,9 @@ def spacy_nlp_pipeline_model(spacy_nlp_pipeline_model_id):
|
|||||||
if db.session.is_modified(snpm):
|
if db.session.is_modified(snpm):
|
||||||
flash(f'SpaCy NLP Pipeline model "{snpm.title}" updated')
|
flash(f'SpaCy NLP Pipeline model "{snpm.title}" updated')
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
return redirect(url_for('.spacy_nlp_pipeline_models'))
|
return redirect(url_for('.index'))
|
||||||
return render_template(
|
return render_template(
|
||||||
'contributions/spacy_nlp_pipeline_models/spacy_nlp_pipeline_model.html.j2',
|
'contributions/spacy_nlp_pipeline_models/entity.html.j2',
|
||||||
title=f'{snpm.title} {snpm.version}',
|
title=f'{snpm.title} {snpm.version}',
|
||||||
form=form,
|
form=form,
|
||||||
spacy_nlp_pipeline_model=snpm
|
spacy_nlp_pipeline_model=snpm
|
||||||
+2
-2
@@ -2,7 +2,7 @@ from flask import Blueprint
|
|||||||
from flask_login import login_required
|
from flask_login import login_required
|
||||||
|
|
||||||
|
|
||||||
bp = Blueprint('users', __name__)
|
bp = Blueprint('tesseract_ocr_pipeline_models', __name__)
|
||||||
|
|
||||||
|
|
||||||
@bp.before_request
|
@bp.before_request
|
||||||
@@ -15,4 +15,4 @@ def before_request():
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
from . import cli, events, json_routes, routes, settings
|
from . import json_routes, routes
|
||||||
+2
-2
@@ -1,6 +1,6 @@
|
|||||||
from flask_wtf.file import FileField, FileRequired
|
from flask_wtf.file import FileField, FileRequired
|
||||||
from wtforms import ValidationError
|
from wtforms import ValidationError
|
||||||
from app.services import SERVICES
|
from app.blueprints.services import SERVICES
|
||||||
from ..forms import ContributionBaseForm, UpdateContributionBaseForm
|
from ..forms import ContributionBaseForm, UpdateContributionBaseForm
|
||||||
|
|
||||||
|
|
||||||
@@ -9,7 +9,7 @@ class CreateTesseractOCRPipelineModelForm(ContributionBaseForm):
|
|||||||
'File',
|
'File',
|
||||||
validators=[FileRequired()]
|
validators=[FileRequired()]
|
||||||
)
|
)
|
||||||
|
|
||||||
def validate_tesseract_model_file(self, field):
|
def validate_tesseract_model_file(self, field):
|
||||||
if not field.data.filename.lower().endswith('.traineddata'):
|
if not field.data.filename.lower().endswith('.traineddata'):
|
||||||
raise ValidationError('traineddata files only!')
|
raise ValidationError('traineddata files only!')
|
||||||
+2
-2
@@ -7,7 +7,7 @@ from app.models import TesseractOCRPipelineModel
|
|||||||
from . import bp
|
from . import bp
|
||||||
|
|
||||||
|
|
||||||
@bp.route('/tesseract-ocr-pipeline-models/<hashid:tesseract_ocr_pipeline_model_id>', methods=['DELETE'])
|
@bp.route('/<hashid:tesseract_ocr_pipeline_model_id>', methods=['DELETE'])
|
||||||
@content_negotiation(produces='application/json')
|
@content_negotiation(produces='application/json')
|
||||||
def delete_tesseract_model(tesseract_ocr_pipeline_model_id):
|
def delete_tesseract_model(tesseract_ocr_pipeline_model_id):
|
||||||
def _delete_tesseract_ocr_pipeline_model(app, tesseract_ocr_pipeline_model_id):
|
def _delete_tesseract_ocr_pipeline_model(app, tesseract_ocr_pipeline_model_id):
|
||||||
@@ -31,7 +31,7 @@ def delete_tesseract_model(tesseract_ocr_pipeline_model_id):
|
|||||||
return response_data, 202
|
return response_data, 202
|
||||||
|
|
||||||
|
|
||||||
@bp.route('/tesseract-ocr-pipeline-models/<hashid:tesseract_ocr_pipeline_model_id>/is_public', methods=['PUT'])
|
@bp.route('/<hashid:tesseract_ocr_pipeline_model_id>/is_public', methods=['PUT'])
|
||||||
@permission_required('CONTRIBUTE')
|
@permission_required('CONTRIBUTE')
|
||||||
@content_negotiation(consumes='application/json', produces='application/json')
|
@content_negotiation(consumes='application/json', produces='application/json')
|
||||||
def update_tesseract_ocr_pipeline_model_is_public(tesseract_ocr_pipeline_model_id):
|
def update_tesseract_ocr_pipeline_model_is_public(tesseract_ocr_pipeline_model_id):
|
||||||
+10
-13
@@ -9,16 +9,13 @@ from .forms import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@bp.route('/tesseract-ocr-pipeline-models')
|
@bp.route('/')
|
||||||
def tesseract_ocr_pipeline_models():
|
def index():
|
||||||
return render_template(
|
return redirect(url_for('contributions.index', _anchor='tesseract-ocr-pipeline-models'))
|
||||||
'contributions/tesseract_ocr_pipeline_models/tesseract_ocr_pipeline_models.html.j2',
|
|
||||||
title='Tesseract OCR Pipeline Models'
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
@bp.route('/tesseract-ocr-pipeline-models/create', methods=['GET', 'POST'])
|
@bp.route('/create', methods=['GET', 'POST'])
|
||||||
def create_tesseract_ocr_pipeline_model():
|
def create():
|
||||||
form = CreateTesseractOCRPipelineModelForm()
|
form = CreateTesseractOCRPipelineModelForm()
|
||||||
if form.is_submitted():
|
if form.is_submitted():
|
||||||
if not form.validate():
|
if not form.validate():
|
||||||
@@ -41,7 +38,7 @@ def create_tesseract_ocr_pipeline_model():
|
|||||||
abort(500)
|
abort(500)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
flash(f'Tesseract OCR Pipeline model "{topm.title}" created')
|
flash(f'Tesseract OCR Pipeline model "{topm.title}" created')
|
||||||
return {}, 201, {'Location': url_for('.tesseract_ocr_pipeline_models')}
|
return {}, 201, {'Location': url_for('.index')}
|
||||||
return render_template(
|
return render_template(
|
||||||
'contributions/tesseract_ocr_pipeline_models/create.html.j2',
|
'contributions/tesseract_ocr_pipeline_models/create.html.j2',
|
||||||
title='Create Tesseract OCR Pipeline Model',
|
title='Create Tesseract OCR Pipeline Model',
|
||||||
@@ -49,8 +46,8 @@ def create_tesseract_ocr_pipeline_model():
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@bp.route('/tesseract-ocr-pipeline-models/<hashid:tesseract_ocr_pipeline_model_id>', methods=['GET', 'POST'])
|
@bp.route('/<hashid:tesseract_ocr_pipeline_model_id>', methods=['GET', 'POST'])
|
||||||
def tesseract_ocr_pipeline_model(tesseract_ocr_pipeline_model_id):
|
def entity(tesseract_ocr_pipeline_model_id):
|
||||||
topm = TesseractOCRPipelineModel.query.get_or_404(tesseract_ocr_pipeline_model_id)
|
topm = TesseractOCRPipelineModel.query.get_or_404(tesseract_ocr_pipeline_model_id)
|
||||||
if not (topm.user == current_user or current_user.is_administrator):
|
if not (topm.user == current_user or current_user.is_administrator):
|
||||||
abort(403)
|
abort(403)
|
||||||
@@ -60,9 +57,9 @@ def tesseract_ocr_pipeline_model(tesseract_ocr_pipeline_model_id):
|
|||||||
if db.session.is_modified(topm):
|
if db.session.is_modified(topm):
|
||||||
flash(f'Tesseract OCR Pipeline model "{topm.title}" updated')
|
flash(f'Tesseract OCR Pipeline model "{topm.title}" updated')
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
return redirect(url_for('.tesseract_ocr_pipeline_models'))
|
return redirect(url_for('.index'))
|
||||||
return render_template(
|
return render_template(
|
||||||
'contributions/tesseract_ocr_pipeline_models/tesseract_ocr_pipeline_model.html.j2',
|
'contributions/tesseract_ocr_pipeline_models/entity.html.j2',
|
||||||
title=f'{topm.title} {topm.version}',
|
title=f'{topm.title} {topm.version}',
|
||||||
form=form,
|
form=form,
|
||||||
tesseract_ocr_pipeline_model=topm
|
tesseract_ocr_pipeline_model=topm
|
||||||
@@ -16,4 +16,4 @@ def before_request():
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
from . import cli, files, followers, routes, json_routes
|
from . import cli, files, followers, routes
|
||||||
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
@@ -0,0 +1,299 @@
|
|||||||
|
from datetime import datetime
|
||||||
|
from flask import (
|
||||||
|
abort,
|
||||||
|
current_app,
|
||||||
|
flash,
|
||||||
|
Flask,
|
||||||
|
jsonify,
|
||||||
|
redirect,
|
||||||
|
request,
|
||||||
|
render_template,
|
||||||
|
url_for
|
||||||
|
)
|
||||||
|
from flask_login import current_user
|
||||||
|
from string import punctuation
|
||||||
|
from threading import Thread
|
||||||
|
import nltk
|
||||||
|
from app import db
|
||||||
|
from app.models import (
|
||||||
|
Corpus,
|
||||||
|
CorpusFollowerAssociation,
|
||||||
|
CorpusFollowerRole,
|
||||||
|
User
|
||||||
|
)
|
||||||
|
from . import bp
|
||||||
|
from .decorators import corpus_follower_permission_required
|
||||||
|
from .forms import CreateCorpusForm
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def _delete_corpus(app: Flask, corpus_id: int):
|
||||||
|
with app.app_context():
|
||||||
|
corpus: Corpus = Corpus.query.get(corpus_id)
|
||||||
|
corpus.delete()
|
||||||
|
db.session.commit()
|
||||||
|
|
||||||
|
|
||||||
|
def _build_corpus(app: Flask, corpus_id: int):
|
||||||
|
with app.app_context():
|
||||||
|
corpus = Corpus.query.get(corpus_id)
|
||||||
|
corpus.build()
|
||||||
|
db.session.commit()
|
||||||
|
|
||||||
|
|
||||||
|
@bp.route('')
|
||||||
|
def corpora():
|
||||||
|
return redirect(url_for('main.dashboard', _anchor='corpora'))
|
||||||
|
|
||||||
|
|
||||||
|
@bp.route('/create', methods=['GET', 'POST'])
|
||||||
|
def create_corpus():
|
||||||
|
form = CreateCorpusForm()
|
||||||
|
|
||||||
|
if form.validate_on_submit():
|
||||||
|
try:
|
||||||
|
corpus = Corpus.create(
|
||||||
|
title=form.title.data,
|
||||||
|
description=form.description.data,
|
||||||
|
user=current_user
|
||||||
|
)
|
||||||
|
except OSError:
|
||||||
|
abort(500)
|
||||||
|
db.session.commit()
|
||||||
|
|
||||||
|
flash(f'Corpus "{corpus.title}" created', 'corpus')
|
||||||
|
return redirect(corpus.url)
|
||||||
|
|
||||||
|
return render_template(
|
||||||
|
'corpora/create.html.j2',
|
||||||
|
title='Create corpus',
|
||||||
|
form=form
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@bp.route('/<hashid:corpus_id>')
|
||||||
|
def corpus(corpus_id: int):
|
||||||
|
corpus = Corpus.query.get_or_404(corpus_id)
|
||||||
|
|
||||||
|
cfa = CorpusFollowerAssociation.query.filter_by(
|
||||||
|
corpus_id=corpus_id,
|
||||||
|
follower_id=current_user.id
|
||||||
|
).first()
|
||||||
|
|
||||||
|
if cfa is None:
|
||||||
|
if corpus.user == current_user or current_user.is_administrator:
|
||||||
|
cfr = CorpusFollowerRole.query.filter_by(name='Administrator').first()
|
||||||
|
else:
|
||||||
|
cfr = CorpusFollowerRole.query.filter_by(name='Anonymous').first()
|
||||||
|
else:
|
||||||
|
cfr = cfa.role
|
||||||
|
|
||||||
|
cfrs = CorpusFollowerRole.query.all()
|
||||||
|
|
||||||
|
# TODO: Better solution for filtering admin
|
||||||
|
users = User.query.filter(
|
||||||
|
User.is_public == True,
|
||||||
|
User.id != current_user.id,
|
||||||
|
User.id != corpus.user.id,
|
||||||
|
User.role_id < 4
|
||||||
|
).all()
|
||||||
|
|
||||||
|
if (
|
||||||
|
corpus.user == current_user
|
||||||
|
or current_user.is_administrator
|
||||||
|
):
|
||||||
|
return render_template(
|
||||||
|
'corpora/corpus.html.j2',
|
||||||
|
title=corpus.title,
|
||||||
|
corpus=corpus,
|
||||||
|
cfr=cfr,
|
||||||
|
cfrs=cfrs,
|
||||||
|
users=users
|
||||||
|
)
|
||||||
|
|
||||||
|
if (
|
||||||
|
current_user.is_following_corpus(corpus)
|
||||||
|
or corpus.is_public
|
||||||
|
):
|
||||||
|
cfas = CorpusFollowerAssociation.query.filter(
|
||||||
|
Corpus.id == corpus_id,
|
||||||
|
CorpusFollowerAssociation.follower_id != corpus.user.id
|
||||||
|
).all()
|
||||||
|
return render_template(
|
||||||
|
'corpora/public_corpus.html.j2',
|
||||||
|
title=corpus.title,
|
||||||
|
corpus=corpus,
|
||||||
|
cfrs=cfrs,
|
||||||
|
cfr=cfr,
|
||||||
|
cfas=cfas,
|
||||||
|
users=users
|
||||||
|
)
|
||||||
|
|
||||||
|
abort(403)
|
||||||
|
|
||||||
|
|
||||||
|
@bp.route('/<hashid:corpus_id>', methods=['DELETE'])
|
||||||
|
def delete_corpus(corpus_id: int):
|
||||||
|
corpus = Corpus.query.get_or_404(corpus_id)
|
||||||
|
|
||||||
|
if not (
|
||||||
|
corpus.user == current_user
|
||||||
|
or current_user.is_administrator
|
||||||
|
):
|
||||||
|
abort(403)
|
||||||
|
|
||||||
|
thread = Thread(
|
||||||
|
target=_delete_corpus,
|
||||||
|
args=(current_app._get_current_object(), corpus.id)
|
||||||
|
)
|
||||||
|
thread.start()
|
||||||
|
|
||||||
|
return jsonify(f'Corpus "{corpus.title}" marked for deletion.'), 202
|
||||||
|
|
||||||
|
|
||||||
|
@bp.route('/<hashid:corpus_id>/build', methods=['POST'])
|
||||||
|
def build_corpus(corpus_id: int):
|
||||||
|
corpus = Corpus.query.get_or_404(corpus_id)
|
||||||
|
|
||||||
|
cfa = CorpusFollowerAssociation.query.filter_by(
|
||||||
|
corpus_id=corpus_id,
|
||||||
|
follower_id=current_user.id
|
||||||
|
).first()
|
||||||
|
|
||||||
|
if not (
|
||||||
|
cfa is not None and cfa.role.has_permission('MANAGE_FILES')
|
||||||
|
or corpus.user == current_user
|
||||||
|
or current_user.is_administrator
|
||||||
|
):
|
||||||
|
abort(403)
|
||||||
|
|
||||||
|
if len(corpus.files.all()) == 0:
|
||||||
|
abort(409)
|
||||||
|
|
||||||
|
thread = Thread(
|
||||||
|
target=_build_corpus,
|
||||||
|
args=(current_app._get_current_object(), corpus.id)
|
||||||
|
)
|
||||||
|
thread.start()
|
||||||
|
|
||||||
|
return jsonify(f'Corpus "{corpus.title}" marked for building.'), 202
|
||||||
|
|
||||||
|
|
||||||
|
@bp.route('/<hashid:corpus_id>/create-share-link', methods=['POST'])
|
||||||
|
def create_share_link(corpus_id: int):
|
||||||
|
data = request.json
|
||||||
|
|
||||||
|
expiration_date = data['expiration_date']
|
||||||
|
if not isinstance(expiration_date, str):
|
||||||
|
abort(400)
|
||||||
|
|
||||||
|
role_name = data['role_name']
|
||||||
|
if not isinstance(role_name, str):
|
||||||
|
abort(400)
|
||||||
|
|
||||||
|
corpus = Corpus.query.get_or_404(corpus_id)
|
||||||
|
|
||||||
|
cfa = CorpusFollowerAssociation.query.filter_by(
|
||||||
|
corpus_id=corpus_id,
|
||||||
|
follower_id=current_user.id
|
||||||
|
).first()
|
||||||
|
|
||||||
|
if not (
|
||||||
|
cfa is not None and cfa.role.has_permission('MANAGE_FOLLOWERS')
|
||||||
|
or corpus.user == current_user
|
||||||
|
or current_user.is_administrator
|
||||||
|
):
|
||||||
|
abort(403)
|
||||||
|
|
||||||
|
_expiration_date = datetime.strptime(expiration_date, '%b %d, %Y')
|
||||||
|
|
||||||
|
cfr = CorpusFollowerRole.query.filter_by(name=role_name).first()
|
||||||
|
if cfr is None:
|
||||||
|
abort(400)
|
||||||
|
|
||||||
|
token = current_user.generate_follow_corpus_token(
|
||||||
|
corpus.hashid,
|
||||||
|
role_name,
|
||||||
|
_expiration_date
|
||||||
|
)
|
||||||
|
|
||||||
|
corpus_share_link = url_for(
|
||||||
|
'corpora.follow_corpus',
|
||||||
|
corpus_id=corpus_id,
|
||||||
|
token=token,
|
||||||
|
_external=True
|
||||||
|
)
|
||||||
|
|
||||||
|
return jsonify(corpus_share_link)
|
||||||
|
|
||||||
|
|
||||||
|
@bp.route('/<hashid:corpus_id>/analysis')
|
||||||
|
@corpus_follower_permission_required('VIEW')
|
||||||
|
def analysis(corpus_id: int):
|
||||||
|
corpus = Corpus.query.get_or_404(corpus_id)
|
||||||
|
|
||||||
|
return render_template(
|
||||||
|
'corpora/analysis.html.j2',
|
||||||
|
corpus=corpus,
|
||||||
|
title=f'Analyse Corpus {corpus.title}'
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@bp.route('/<hashid:corpus_id>/analysis/stopwords')
|
||||||
|
def get_stopwords(corpus_id: int):
|
||||||
|
languages = [
|
||||||
|
'german',
|
||||||
|
'english',
|
||||||
|
'catalan',
|
||||||
|
'greek',
|
||||||
|
'spanish',
|
||||||
|
'french',
|
||||||
|
'italian',
|
||||||
|
'russian',
|
||||||
|
'chinese'
|
||||||
|
]
|
||||||
|
|
||||||
|
nltk.download('stopwords', quiet=True)
|
||||||
|
stopwords = {
|
||||||
|
language: nltk.corpus.stopwords.words(language)
|
||||||
|
for language in languages
|
||||||
|
}
|
||||||
|
stopwords['punctuation'] = list(punctuation)
|
||||||
|
stopwords['punctuation'] += ['—', '|', '–', '“', '„', '--']
|
||||||
|
stopwords['user_stopwords'] = []
|
||||||
|
|
||||||
|
return jsonify(stopwords)
|
||||||
|
|
||||||
|
|
||||||
|
@bp.route('/<hashid:corpus_id>/follow/<token>')
|
||||||
|
def follow_corpus(corpus_id: int, token: str):
|
||||||
|
corpus = Corpus.query.get_or_404(corpus_id)
|
||||||
|
|
||||||
|
if not current_user.follow_corpus_by_token(token):
|
||||||
|
abort(403)
|
||||||
|
|
||||||
|
db.session.commit()
|
||||||
|
|
||||||
|
flash(f'You are following "{corpus.title}" now', category='corpus')
|
||||||
|
return redirect(corpus.url)
|
||||||
|
|
||||||
|
|
||||||
|
@bp.route('/<hashid:corpus_id>/is-public', methods=['PUT'])
|
||||||
|
def update_is_public(corpus_id):
|
||||||
|
new_value = request.json
|
||||||
|
if not isinstance(new_value, bool):
|
||||||
|
abort(400)
|
||||||
|
|
||||||
|
corpus = Corpus.query.get_or_404(corpus_id)
|
||||||
|
|
||||||
|
if not (
|
||||||
|
corpus.user == current_user
|
||||||
|
or current_user.is_administrator
|
||||||
|
):
|
||||||
|
abort(403)
|
||||||
|
|
||||||
|
|
||||||
|
corpus.is_public = new_value
|
||||||
|
db.session.commit()
|
||||||
|
|
||||||
|
return jsonify(f'Corpus "{corpus.title}" is now {"public" if new_value else "private"}'), 200
|
||||||
File renamed without changes.
@@ -4,11 +4,17 @@ from . import bp
|
|||||||
|
|
||||||
|
|
||||||
@bp.app_errorhandler(HTTPException)
|
@bp.app_errorhandler(HTTPException)
|
||||||
def handle_http_exception(error):
|
def handle_http_exception(e: HTTPException):
|
||||||
''' Generic HTTP exception handler '''
|
''' Generic HTTP exception handler '''
|
||||||
accept_json = request.accept_mimetypes.accept_json
|
accept_json = request.accept_mimetypes.accept_json
|
||||||
accept_html = request.accept_mimetypes.accept_html
|
accept_html = request.accept_mimetypes.accept_html
|
||||||
|
|
||||||
if accept_json and not accept_html:
|
if accept_json and not accept_html:
|
||||||
response = jsonify(str(error))
|
error = {
|
||||||
return response, error.code
|
'code': e.code,
|
||||||
return render_template('errors/error.html.j2', error=error), error.code
|
'name': e.name,
|
||||||
|
'description': e.description
|
||||||
|
}
|
||||||
|
return jsonify(error), e.code
|
||||||
|
|
||||||
|
return render_template('errors/error.html.j2', error=e), e.code
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
from flask import Blueprint
|
||||||
|
|
||||||
|
|
||||||
|
bp = Blueprint('jobs', __name__)
|
||||||
|
|
||||||
|
|
||||||
|
from . import routes
|
||||||
|
|
||||||
|
from .inputs import bp as inputs_bp
|
||||||
|
bp.register_blueprint(inputs_bp, url_prefix='/<hashid:job_id>/inputs')
|
||||||
|
|
||||||
|
from .results import bp as results_bp
|
||||||
|
bp.register_blueprint(results_bp, url_prefix='/<hashid:job_id>/results')
|
||||||
@@ -1,5 +1,7 @@
|
|||||||
from flask import Blueprint
|
from flask import Blueprint
|
||||||
|
|
||||||
|
|
||||||
bp = Blueprint('auth', __name__)
|
bp = Blueprint('inputs', __name__)
|
||||||
|
|
||||||
|
|
||||||
from . import routes
|
from . import routes
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
from flask import abort, send_from_directory
|
||||||
|
from flask_login import current_user, login_required
|
||||||
|
from app.models import JobInput
|
||||||
|
from . import bp
|
||||||
|
|
||||||
|
|
||||||
|
@bp.route('/<hashid:job_input_id>/download')
|
||||||
|
@login_required
|
||||||
|
def download_job_input(job_id: int, job_input_id: int):
|
||||||
|
job_input = JobInput.query.filter_by(
|
||||||
|
job_id=job_id,
|
||||||
|
id=job_input_id
|
||||||
|
).first_or_404()
|
||||||
|
|
||||||
|
if not (
|
||||||
|
job_input.job.user == current_user
|
||||||
|
or current_user.is_administrator
|
||||||
|
):
|
||||||
|
abort(403)
|
||||||
|
|
||||||
|
return send_from_directory(
|
||||||
|
job_input.path.parent,
|
||||||
|
job_input.path.name,
|
||||||
|
as_attachment=True,
|
||||||
|
download_name=job_input.filename,
|
||||||
|
mimetype=job_input.mimetype
|
||||||
|
)
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
from flask import Blueprint
|
||||||
|
|
||||||
|
|
||||||
|
bp = Blueprint('results', __name__)
|
||||||
|
|
||||||
|
|
||||||
|
from . import routes
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
from flask import abort, send_from_directory
|
||||||
|
from flask_login import current_user, login_required
|
||||||
|
from app.models import JobResult
|
||||||
|
from . import bp
|
||||||
|
|
||||||
|
|
||||||
|
@bp.route('/<hashid:job_result_id>/download')
|
||||||
|
@login_required
|
||||||
|
def download_job_result(job_id: int, job_result_id: int):
|
||||||
|
job_result = JobResult.query.filter_by(
|
||||||
|
job_id=job_id,
|
||||||
|
id=job_result_id
|
||||||
|
).first_or_404()
|
||||||
|
|
||||||
|
if not (
|
||||||
|
job_result.job.user == current_user
|
||||||
|
or current_user.is_administrator
|
||||||
|
):
|
||||||
|
abort(403)
|
||||||
|
|
||||||
|
return send_from_directory(
|
||||||
|
job_result.path.parent,
|
||||||
|
job_result.path.name,
|
||||||
|
as_attachment=True,
|
||||||
|
download_name=job_result.filename,
|
||||||
|
mimetype=job_result.mimetype
|
||||||
|
)
|
||||||
@@ -0,0 +1,111 @@
|
|||||||
|
from flask import (
|
||||||
|
abort,
|
||||||
|
current_app,
|
||||||
|
Flask,
|
||||||
|
jsonify,
|
||||||
|
redirect,
|
||||||
|
render_template,
|
||||||
|
url_for
|
||||||
|
)
|
||||||
|
from flask_login import current_user, login_required
|
||||||
|
from threading import Thread
|
||||||
|
from app import db
|
||||||
|
from app.decorators import admin_required
|
||||||
|
from app.models import Job, JobStatus
|
||||||
|
from . import bp
|
||||||
|
|
||||||
|
|
||||||
|
@bp.route('')
|
||||||
|
@login_required
|
||||||
|
def index():
|
||||||
|
return redirect(url_for('main.dashboard', _anchor='jobs'))
|
||||||
|
|
||||||
|
|
||||||
|
@bp.route('/<hashid:job_id>')
|
||||||
|
@login_required
|
||||||
|
def job(job_id: int):
|
||||||
|
job = Job.query.get_or_404(job_id)
|
||||||
|
|
||||||
|
if not (
|
||||||
|
job.user == current_user
|
||||||
|
or current_user.is_administrator
|
||||||
|
):
|
||||||
|
abort(403)
|
||||||
|
|
||||||
|
return render_template(
|
||||||
|
'jobs/job.html.j2',
|
||||||
|
title='Job',
|
||||||
|
job=job
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def _delete_job(app: Flask, job_id: int):
|
||||||
|
with app.app_context():
|
||||||
|
job = Job.query.get(job_id)
|
||||||
|
job.delete()
|
||||||
|
db.session.commit()
|
||||||
|
|
||||||
|
|
||||||
|
@bp.route('/<hashid:job_id>', methods=['DELETE'])
|
||||||
|
@login_required
|
||||||
|
def delete_job(job_id: int):
|
||||||
|
job = Job.query.get_or_404(job_id)
|
||||||
|
|
||||||
|
if not (
|
||||||
|
job.user == current_user
|
||||||
|
or current_user.is_administrator
|
||||||
|
):
|
||||||
|
abort(403)
|
||||||
|
|
||||||
|
thread = Thread(
|
||||||
|
target=_delete_job,
|
||||||
|
args=(current_app._get_current_object(), job.id)
|
||||||
|
)
|
||||||
|
thread.start()
|
||||||
|
|
||||||
|
return jsonify(f'Job "{job.title}" marked for deletion.'), 202
|
||||||
|
|
||||||
|
|
||||||
|
@bp.route('/<hashid:job_id>/log')
|
||||||
|
@admin_required
|
||||||
|
def job_log(job_id: int):
|
||||||
|
job = Job.query.get_or_404(job_id)
|
||||||
|
|
||||||
|
if job.status not in [JobStatus.COMPLETED, JobStatus.FAILED]:
|
||||||
|
abort(409)
|
||||||
|
|
||||||
|
log_file_path = job.path / 'pipeline_data' / 'logs' / 'pyflow_log.txt'
|
||||||
|
with log_file_path.open() as log_file:
|
||||||
|
log = log_file.read()
|
||||||
|
|
||||||
|
return jsonify(log)
|
||||||
|
|
||||||
|
|
||||||
|
def _restart_job(app: Flask, job_id: int):
|
||||||
|
with app.app_context():
|
||||||
|
job = Job.query.get(job_id)
|
||||||
|
job.restart()
|
||||||
|
db.session.commit()
|
||||||
|
|
||||||
|
|
||||||
|
@bp.route('/<hashid:job_id>/restart', methods=['POST'])
|
||||||
|
@login_required
|
||||||
|
def restart_job(job_id: int):
|
||||||
|
job = Job.query.get_or_404(job_id)
|
||||||
|
|
||||||
|
if not (
|
||||||
|
job.user == current_user
|
||||||
|
or current_user.is_administrator
|
||||||
|
):
|
||||||
|
abort(403)
|
||||||
|
|
||||||
|
if job.status != JobStatus.FAILED:
|
||||||
|
abort(409)
|
||||||
|
|
||||||
|
thread = Thread(
|
||||||
|
target=_restart_job,
|
||||||
|
args=(current_app._get_current_object(), job.id)
|
||||||
|
)
|
||||||
|
thread.start()
|
||||||
|
|
||||||
|
return jsonify(f'Job "{job.title}" marked for restarting.'), 202
|
||||||
File renamed without changes.
@@ -1,7 +1,6 @@
|
|||||||
from flask import current_app
|
from flask import current_app
|
||||||
from flask_migrate import upgrade
|
from flask_migrate import upgrade
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import List
|
|
||||||
from app import db
|
from app import db
|
||||||
from app.models import (
|
from app.models import (
|
||||||
Corpus,
|
Corpus,
|
||||||
@@ -20,7 +19,7 @@ def deploy():
|
|||||||
|
|
||||||
print('Make default directories')
|
print('Make default directories')
|
||||||
base_dir = current_app.config['NOPAQUE_DATA_DIR']
|
base_dir = current_app.config['NOPAQUE_DATA_DIR']
|
||||||
default_dirs: List[Path] = [
|
default_dirs: list[Path] = [
|
||||||
base_dir / 'tmp',
|
base_dir / 'tmp',
|
||||||
base_dir / 'users'
|
base_dir / 'users'
|
||||||
]
|
]
|
||||||
@@ -45,7 +44,7 @@ def deploy():
|
|||||||
TesseractOCRPipelineModel.insert_defaults()
|
TesseractOCRPipelineModel.insert_defaults()
|
||||||
|
|
||||||
print('Stop running analysis sessions')
|
print('Stop running analysis sessions')
|
||||||
for corpus in Corpus.query.filter(Corpus.num_analysis_sessions > 0).all():
|
for corpus in Corpus.query.all():
|
||||||
corpus.num_analysis_sessions = 0
|
corpus.num_analysis_sessions = 0
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
|
||||||
@@ -1,8 +1,9 @@
|
|||||||
from flask import flash, redirect, render_template, url_for
|
from flask import abort, flash, jsonify, redirect, render_template, url_for
|
||||||
from flask_login import current_user, login_required, login_user
|
from flask_login import current_user, login_required, login_user
|
||||||
from app.auth.forms import LoginForm
|
from app.blueprints.auth.forms import LoginForm
|
||||||
from app.models import Corpus, User
|
from app.models import Corpus, User
|
||||||
from . import bp
|
from . import bp
|
||||||
|
from app import db
|
||||||
|
|
||||||
|
|
||||||
@bp.route('/', methods=['GET', 'POST'])
|
@bp.route('/', methods=['GET', 'POST'])
|
||||||
@@ -56,7 +57,7 @@ def news():
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@bp.route('/privacy_policy')
|
@bp.route('/privacy-policy')
|
||||||
def privacy_policy():
|
def privacy_policy():
|
||||||
return render_template(
|
return render_template(
|
||||||
'main/privacy_policy.html.j2',
|
'main/privacy_policy.html.j2',
|
||||||
@@ -64,24 +65,32 @@ def privacy_policy():
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@bp.route('/terms_of_use')
|
@bp.route('/terms-of-use')
|
||||||
def terms_of_use():
|
def terms_of_use():
|
||||||
return render_template(
|
return render_template(
|
||||||
'main/terms_of_use.html.j2',
|
'main/terms_of_use.html.j2',
|
||||||
title='Terms of Use'
|
title='Terms of use'
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@bp.route('/social-area')
|
@bp.route('/accept-terms-of-use', methods=['POST'])
|
||||||
@login_required
|
@login_required
|
||||||
def social_area():
|
def accept_terms_of_use():
|
||||||
print('test')
|
current_user.terms_of_use_accepted = True
|
||||||
|
db.session.commit()
|
||||||
|
|
||||||
|
return jsonify('You accepted the terms of use'), 202
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@bp.route('/social')
|
||||||
|
@login_required
|
||||||
|
def social():
|
||||||
corpora = Corpus.query.filter(Corpus.is_public == True, Corpus.user != current_user).all()
|
corpora = Corpus.query.filter(Corpus.is_public == True, Corpus.user != current_user).all()
|
||||||
print(corpora)
|
|
||||||
users = User.query.filter(User.is_public == True, User.id != current_user.id).all()
|
users = User.query.filter(User.is_public == True, User.id != current_user.id).all()
|
||||||
return render_template(
|
return render_template(
|
||||||
'main/social_area.html.j2',
|
'main/social.html.j2',
|
||||||
title='Social Area',
|
title='Social',
|
||||||
corpora=corpora,
|
corpora=corpora,
|
||||||
users=users
|
users=users
|
||||||
)
|
)
|
||||||
File renamed without changes.
@@ -61,7 +61,7 @@ class CreateTesseractOCRPipelineJobForm(CreateJobBaseForm):
|
|||||||
if field.data:
|
if field.data:
|
||||||
if not('methods' in service_info and 'binarization' in service_info['methods']):
|
if not('methods' in service_info and 'binarization' in service_info['methods']):
|
||||||
raise ValidationError('Binarization is not available')
|
raise ValidationError('Binarization is not available')
|
||||||
|
|
||||||
def validate_pdf(self, field):
|
def validate_pdf(self, field):
|
||||||
if field.data.mimetype != 'application/pdf':
|
if field.data.mimetype != 'application/pdf':
|
||||||
raise ValidationError('PDF files only!')
|
raise ValidationError('PDF files only!')
|
||||||
@@ -87,14 +87,14 @@ class CreateTesseractOCRPipelineJobForm(CreateJobBaseForm):
|
|||||||
user_models = [
|
user_models = [
|
||||||
x for x in current_user.tesseract_ocr_pipeline_models.order_by(TesseractOCRPipelineModel.title).all()
|
x for x in current_user.tesseract_ocr_pipeline_models.order_by(TesseractOCRPipelineModel.title).all()
|
||||||
]
|
]
|
||||||
models = [
|
public_models = [
|
||||||
x for x in TesseractOCRPipelineModel.query.order_by(TesseractOCRPipelineModel.title).all()
|
x for x in TesseractOCRPipelineModel.query.order_by(TesseractOCRPipelineModel.title).all()
|
||||||
if version in x.compatible_service_versions and (x.is_public == True or x.user == current_user)
|
if version in x.compatible_service_versions and x.is_public == True
|
||||||
]
|
]
|
||||||
self.model.choices = {
|
self.model.choices = {
|
||||||
'': [('', 'Choose your option')],
|
'': [('', 'Choose your option')],
|
||||||
'Your models': [(x.hashid, f'{x.title} [{x.version}]') for x in user_models] if user_models else [(0, 'Nothing here yet...')],
|
'Your models': [(x.hashid, f'{x.title} [{x.version}]') for x in user_models] if user_models else [(0, 'Nothing here yet...')],
|
||||||
'Public models': [(x.hashid, f'{x.title} [{x.version}]') for x in models]
|
'Public models': [(x.hashid, f'{x.title} [{x.version}]') for x in public_models]
|
||||||
}
|
}
|
||||||
self.model.default = ''
|
self.model.default = ''
|
||||||
self.version.choices = [(x, x) for x in service_manifest['versions']]
|
self.version.choices = [(x, x) for x in service_manifest['versions']]
|
||||||
@@ -146,7 +146,7 @@ class CreateSpacyNLPPipelineJobForm(CreateJobBaseForm):
|
|||||||
encoding_detection = BooleanField('Encoding detection', render_kw={'disabled': True})
|
encoding_detection = BooleanField('Encoding detection', render_kw={'disabled': True})
|
||||||
txt = FileField('File', validators=[FileRequired()])
|
txt = FileField('File', validators=[FileRequired()])
|
||||||
model = SelectField('Model', validators=[InputRequired()])
|
model = SelectField('Model', validators=[InputRequired()])
|
||||||
|
|
||||||
def validate_encoding_detection(self, field):
|
def validate_encoding_detection(self, field):
|
||||||
service_info = SERVICES['spacy-nlp-pipeline']['versions'][self.version.data]
|
service_info = SERVICES['spacy-nlp-pipeline']['versions'][self.version.data]
|
||||||
if field.data:
|
if field.data:
|
||||||
@@ -167,7 +167,6 @@ class CreateSpacyNLPPipelineJobForm(CreateJobBaseForm):
|
|||||||
version = kwargs.pop('version', service_manifest['latest_version'])
|
version = kwargs.pop('version', service_manifest['latest_version'])
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
service_info = service_manifest['versions'][version]
|
service_info = service_manifest['versions'][version]
|
||||||
print(service_info)
|
|
||||||
if self.encoding_detection.render_kw is None:
|
if self.encoding_detection.render_kw is None:
|
||||||
self.encoding_detection.render_kw = {}
|
self.encoding_detection.render_kw = {}
|
||||||
self.encoding_detection.render_kw['disabled'] = True
|
self.encoding_detection.render_kw['disabled'] = True
|
||||||
@@ -177,14 +176,14 @@ class CreateSpacyNLPPipelineJobForm(CreateJobBaseForm):
|
|||||||
user_models = [
|
user_models = [
|
||||||
x for x in current_user.spacy_nlp_pipeline_models.order_by(SpaCyNLPPipelineModel.title).all()
|
x for x in current_user.spacy_nlp_pipeline_models.order_by(SpaCyNLPPipelineModel.title).all()
|
||||||
]
|
]
|
||||||
models = [
|
public_models = [
|
||||||
x for x in SpaCyNLPPipelineModel.query.filter(SpaCyNLPPipelineModel.user != current_user, SpaCyNLPPipelineModel.is_public == True).order_by(SpaCyNLPPipelineModel.title).all()
|
x for x in SpaCyNLPPipelineModel.query.order_by(SpaCyNLPPipelineModel.title).all()
|
||||||
if version in x.compatible_service_versions
|
if version in x.compatible_service_versions and x.is_public == True
|
||||||
]
|
]
|
||||||
self.model.choices = {
|
self.model.choices = {
|
||||||
'': [('', 'Choose your option')],
|
'': [('', 'Choose your option')],
|
||||||
'Your models': [(x.hashid, f'{x.title} [{x.version}]') for x in user_models] if user_models else [(0, 'Nothing here yet...')],
|
'Your models': [(x.hashid, f'{x.title} [{x.version}]') for x in user_models] if user_models else [(0, 'Nothing here yet...')],
|
||||||
'Public models': [(x.hashid, f'{x.title} [{x.version}]') for x in models]
|
'Public models': [(x.hashid, f'{x.title} [{x.version}]') for x in public_models]
|
||||||
}
|
}
|
||||||
self.model.default = ''
|
self.model.default = ''
|
||||||
self.version.choices = [(x, x) for x in service_manifest['versions']]
|
self.version.choices = [(x, x) for x in service_manifest['versions']]
|
||||||
File renamed without changes.
File renamed without changes.
@@ -0,0 +1,7 @@
|
|||||||
|
from flask import Blueprint
|
||||||
|
|
||||||
|
|
||||||
|
bp = Blueprint('settings', __name__)
|
||||||
|
|
||||||
|
|
||||||
|
from . import routes
|
||||||
@@ -38,8 +38,8 @@ class UpdateAccountInformationForm(FlaskForm):
|
|||||||
]
|
]
|
||||||
)
|
)
|
||||||
submit = SubmitField()
|
submit = SubmitField()
|
||||||
|
|
||||||
def __init__(self, user, *args, **kwargs):
|
def __init__(self, user: User, *args, **kwargs):
|
||||||
if 'data' not in kwargs:
|
if 'data' not in kwargs:
|
||||||
kwargs['data'] = user.to_json_serializeable()
|
kwargs['data'] = user.to_json_serializeable()
|
||||||
if 'prefix' not in kwargs:
|
if 'prefix' not in kwargs:
|
||||||
@@ -64,7 +64,7 @@ class UpdateProfileInformationForm(FlaskForm):
|
|||||||
validators=[Length(max=128)]
|
validators=[Length(max=128)]
|
||||||
)
|
)
|
||||||
about_me = TextAreaField(
|
about_me = TextAreaField(
|
||||||
'About me',
|
'About me',
|
||||||
validators=[
|
validators=[
|
||||||
Length(max=254)
|
Length(max=254)
|
||||||
]
|
]
|
||||||
@@ -89,7 +89,7 @@ class UpdateProfileInformationForm(FlaskForm):
|
|||||||
)
|
)
|
||||||
submit = SubmitField()
|
submit = SubmitField()
|
||||||
|
|
||||||
def __init__(self, user, *args, **kwargs):
|
def __init__(self, user: User, *args, **kwargs):
|
||||||
if 'data' not in kwargs:
|
if 'data' not in kwargs:
|
||||||
kwargs['data'] = user.to_json_serializeable()
|
kwargs['data'] = user.to_json_serializeable()
|
||||||
if 'prefix' not in kwargs:
|
if 'prefix' not in kwargs:
|
||||||
@@ -130,7 +130,7 @@ class UpdatePasswordForm(FlaskForm):
|
|||||||
)
|
)
|
||||||
submit = SubmitField()
|
submit = SubmitField()
|
||||||
|
|
||||||
def __init__(self, user, *args, **kwargs):
|
def __init__(self, user: User, *args, **kwargs):
|
||||||
if 'prefix' not in kwargs:
|
if 'prefix' not in kwargs:
|
||||||
kwargs['prefix'] = 'update-password-form'
|
kwargs['prefix'] = 'update-password-form'
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
@@ -152,7 +152,7 @@ class UpdateNotificationsForm(FlaskForm):
|
|||||||
)
|
)
|
||||||
submit = SubmitField()
|
submit = SubmitField()
|
||||||
|
|
||||||
def __init__(self, user, *args, **kwargs):
|
def __init__(self, user: User, *args, **kwargs):
|
||||||
if 'data' not in kwargs:
|
if 'data' not in kwargs:
|
||||||
kwargs['data'] = user.to_json_serializeable()
|
kwargs['data'] = user.to_json_serializeable()
|
||||||
if 'prefix' not in kwargs:
|
if 'prefix' not in kwargs:
|
||||||
@@ -0,0 +1,158 @@
|
|||||||
|
from flask import (
|
||||||
|
abort,
|
||||||
|
flash,
|
||||||
|
jsonify,
|
||||||
|
redirect,
|
||||||
|
render_template,
|
||||||
|
request,
|
||||||
|
url_for
|
||||||
|
)
|
||||||
|
from flask_login import current_user, login_required
|
||||||
|
from app import db
|
||||||
|
from app.models import Avatar
|
||||||
|
from . import bp
|
||||||
|
from .forms import (
|
||||||
|
UpdateAvatarForm,
|
||||||
|
UpdatePasswordForm,
|
||||||
|
UpdateNotificationsForm,
|
||||||
|
UpdateAccountInformationForm,
|
||||||
|
UpdateProfileInformationForm
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@bp.route('', methods=['GET', 'POST'])
|
||||||
|
@login_required
|
||||||
|
def index():
|
||||||
|
update_account_information_form = UpdateAccountInformationForm(current_user)
|
||||||
|
update_profile_information_form = UpdateProfileInformationForm(current_user)
|
||||||
|
update_avatar_form = UpdateAvatarForm()
|
||||||
|
update_password_form = UpdatePasswordForm(current_user)
|
||||||
|
update_notifications_form = UpdateNotificationsForm(current_user)
|
||||||
|
|
||||||
|
# region handle update profile information form
|
||||||
|
if update_profile_information_form.submit.data and update_profile_information_form.validate():
|
||||||
|
current_user.about_me = update_profile_information_form.about_me.data
|
||||||
|
current_user.location = update_profile_information_form.location.data
|
||||||
|
current_user.organization = update_profile_information_form.organization.data
|
||||||
|
current_user.website = update_profile_information_form.website.data
|
||||||
|
current_user.full_name = update_profile_information_form.full_name.data
|
||||||
|
db.session.commit()
|
||||||
|
flash('Your changes have been saved')
|
||||||
|
return redirect(url_for('.index'))
|
||||||
|
# endregion handle update profile information form
|
||||||
|
|
||||||
|
# region handle update avatar form
|
||||||
|
if update_avatar_form.submit.data and update_avatar_form.validate():
|
||||||
|
try:
|
||||||
|
Avatar.create(
|
||||||
|
update_avatar_form.avatar.data,
|
||||||
|
user=current_user
|
||||||
|
)
|
||||||
|
except (AttributeError, OSError):
|
||||||
|
abort(500)
|
||||||
|
db.session.commit()
|
||||||
|
flash('Your changes have been saved')
|
||||||
|
return redirect(url_for('.index'))
|
||||||
|
# endregion handle update avatar form
|
||||||
|
|
||||||
|
# region handle update account information form
|
||||||
|
if update_account_information_form.submit.data and update_account_information_form.validate():
|
||||||
|
current_user.email = update_account_information_form.email.data
|
||||||
|
current_user.username = update_account_information_form.username.data
|
||||||
|
db.session.commit()
|
||||||
|
flash('Profile settings updated')
|
||||||
|
return redirect(url_for('.index'))
|
||||||
|
# endregion handle update account information form
|
||||||
|
|
||||||
|
# region handle update password form
|
||||||
|
if update_password_form.submit.data and update_password_form.validate():
|
||||||
|
current_user.password = update_password_form.new_password.data
|
||||||
|
db.session.commit()
|
||||||
|
flash('Your changes have been saved')
|
||||||
|
return redirect(url_for('.index'))
|
||||||
|
# endregion handle update password form
|
||||||
|
|
||||||
|
# region handle update notifications form
|
||||||
|
if update_notifications_form.submit.data and update_notifications_form.validate():
|
||||||
|
current_user.setting_job_status_mail_notification_level = \
|
||||||
|
update_notifications_form.job_status_mail_notification_level.data
|
||||||
|
db.session.commit()
|
||||||
|
flash('Your changes have been saved')
|
||||||
|
return redirect(url_for('.index'))
|
||||||
|
# endregion handle update notifications form
|
||||||
|
|
||||||
|
return render_template(
|
||||||
|
'settings/index.html.j2',
|
||||||
|
title='Settings',
|
||||||
|
update_account_information_form=update_account_information_form,
|
||||||
|
update_avatar_form=update_avatar_form,
|
||||||
|
update_notifications_form=update_notifications_form,
|
||||||
|
update_password_form=update_password_form,
|
||||||
|
update_profile_information_form=update_profile_information_form,
|
||||||
|
user=current_user
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@bp.route('/profile-is-public', methods=['PUT'])
|
||||||
|
@login_required
|
||||||
|
def update_profile_is_public():
|
||||||
|
new_value = request.json
|
||||||
|
|
||||||
|
if not isinstance(new_value, bool):
|
||||||
|
abort(400)
|
||||||
|
|
||||||
|
current_user.is_public = new_value
|
||||||
|
db.session.commit()
|
||||||
|
|
||||||
|
return jsonify('Your changes have been saved'), 200
|
||||||
|
|
||||||
|
|
||||||
|
@bp.route('/profile-show-email', methods=['PUT'])
|
||||||
|
@login_required
|
||||||
|
def update_profile_show_email():
|
||||||
|
new_value = request.json
|
||||||
|
|
||||||
|
if not isinstance(new_value, bool):
|
||||||
|
abort(400)
|
||||||
|
|
||||||
|
if new_value:
|
||||||
|
current_user.add_profile_privacy_setting('SHOW_EMAIL')
|
||||||
|
else:
|
||||||
|
current_user.remove_profile_privacy_setting('SHOW_EMAIL')
|
||||||
|
db.session.commit()
|
||||||
|
|
||||||
|
return jsonify('Your changes have been saved'), 200
|
||||||
|
|
||||||
|
|
||||||
|
@bp.route('/profile-show-last-seen', methods=['PUT'])
|
||||||
|
@login_required
|
||||||
|
def update_profile_show_last_seen():
|
||||||
|
new_value = request.json
|
||||||
|
|
||||||
|
if not isinstance(new_value, bool):
|
||||||
|
abort(400)
|
||||||
|
|
||||||
|
if new_value:
|
||||||
|
current_user.add_profile_privacy_setting('SHOW_LAST_SEEN')
|
||||||
|
else:
|
||||||
|
current_user.remove_profile_privacy_setting('SHOW_LAST_SEEN')
|
||||||
|
db.session.commit()
|
||||||
|
|
||||||
|
return jsonify('Your changes have been saved'), 200
|
||||||
|
|
||||||
|
|
||||||
|
@bp.route('/profile-show-member-since', methods=['PUT'])
|
||||||
|
@login_required
|
||||||
|
def update_profile_show_member_since():
|
||||||
|
new_value = request.json
|
||||||
|
|
||||||
|
if not isinstance(new_value, bool):
|
||||||
|
abort(400)
|
||||||
|
|
||||||
|
if new_value:
|
||||||
|
current_user.add_profile_privacy_setting('SHOW_MEMBER_SINCE')
|
||||||
|
else:
|
||||||
|
current_user.remove_profile_privacy_setting('SHOW_MEMBER_SINCE')
|
||||||
|
db.session.commit()
|
||||||
|
|
||||||
|
return jsonify('Your changes have been saved'), 200
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
from flask import Blueprint
|
||||||
|
|
||||||
|
|
||||||
|
bp = Blueprint('users', __name__)
|
||||||
|
|
||||||
|
|
||||||
|
from . import cli, events, routes
|
||||||
File renamed without changes.
@@ -0,0 +1,91 @@
|
|||||||
|
from flask_login import current_user
|
||||||
|
from flask_socketio import join_room, leave_room
|
||||||
|
from app import hashids, socketio
|
||||||
|
from app.decorators import socketio_login_required
|
||||||
|
from app.models import User
|
||||||
|
|
||||||
|
|
||||||
|
@socketio.on('SUBSCRIBE User')
|
||||||
|
@socketio_login_required
|
||||||
|
def subscribe(user_hashid: str) -> dict:
|
||||||
|
if not isinstance(user_hashid, str):
|
||||||
|
return {
|
||||||
|
'code': 400,
|
||||||
|
'name': 'Bad Request',
|
||||||
|
'description': 'Invalid User ID.'
|
||||||
|
}
|
||||||
|
|
||||||
|
user_id = hashids.decode(user_hashid)
|
||||||
|
|
||||||
|
if not isinstance(user_id, int):
|
||||||
|
return {
|
||||||
|
'code': 400,
|
||||||
|
'name': 'Bad Request',
|
||||||
|
'description': 'Invalid User ID.'
|
||||||
|
}
|
||||||
|
|
||||||
|
user = User.query.get(user_id)
|
||||||
|
|
||||||
|
if user is None:
|
||||||
|
return {
|
||||||
|
'code': 404,
|
||||||
|
'name': 'Not Found',
|
||||||
|
'description': 'User not found.'
|
||||||
|
}
|
||||||
|
|
||||||
|
if not (
|
||||||
|
user == current_user
|
||||||
|
or current_user.is_administrator
|
||||||
|
):
|
||||||
|
return {
|
||||||
|
'code': 403,
|
||||||
|
'name': 'Forbidden',
|
||||||
|
'description': 'Not allowed to subscribe to this user.'
|
||||||
|
}
|
||||||
|
|
||||||
|
join_room(f'/users/{user.hashid}')
|
||||||
|
|
||||||
|
return {'code': 204, 'name': 'No Content'}
|
||||||
|
|
||||||
|
|
||||||
|
@socketio.on('UNSUBSCRIBE User')
|
||||||
|
@socketio_login_required
|
||||||
|
def unsubscribe(user_hashid: str) -> dict:
|
||||||
|
if not isinstance(user_hashid, str):
|
||||||
|
return {
|
||||||
|
'code': 400,
|
||||||
|
'name': 'Bad Request',
|
||||||
|
'description': 'Invalid User ID.'
|
||||||
|
}
|
||||||
|
|
||||||
|
user_id = hashids.decode(user_hashid)
|
||||||
|
|
||||||
|
if not isinstance(user_id, int):
|
||||||
|
return {
|
||||||
|
'code': 400,
|
||||||
|
'name': 'Bad Request',
|
||||||
|
'description': 'Invalid User ID.'
|
||||||
|
}
|
||||||
|
|
||||||
|
user = User.query.get(user_id)
|
||||||
|
|
||||||
|
if user is None:
|
||||||
|
return {
|
||||||
|
'code': 404,
|
||||||
|
'name': 'Not Found',
|
||||||
|
'description': 'User not found.'
|
||||||
|
}
|
||||||
|
|
||||||
|
if not (
|
||||||
|
user == current_user
|
||||||
|
or current_user.is_administrator
|
||||||
|
):
|
||||||
|
return {
|
||||||
|
'code': 403,
|
||||||
|
'name': 'Forbidden',
|
||||||
|
'description': 'Not allowed to unsubscribe from this user.'
|
||||||
|
}
|
||||||
|
|
||||||
|
leave_room(f'/users/{user.hashid}')
|
||||||
|
|
||||||
|
return {'code': 204, 'name': 'No Content'}
|
||||||
@@ -0,0 +1,134 @@
|
|||||||
|
from flask import (
|
||||||
|
abort,
|
||||||
|
current_app,
|
||||||
|
Flask,
|
||||||
|
jsonify,
|
||||||
|
redirect,
|
||||||
|
render_template,
|
||||||
|
request,
|
||||||
|
send_from_directory,
|
||||||
|
url_for
|
||||||
|
)
|
||||||
|
from flask_login import current_user, login_required, logout_user
|
||||||
|
from threading import Thread
|
||||||
|
from app import db
|
||||||
|
from app.models import Avatar, User
|
||||||
|
from . import bp
|
||||||
|
|
||||||
|
|
||||||
|
@bp.route('')
|
||||||
|
@login_required
|
||||||
|
def index():
|
||||||
|
return redirect(url_for('main.social_area', _anchor='users'))
|
||||||
|
|
||||||
|
|
||||||
|
@bp.route('/<hashid:user_id>')
|
||||||
|
@login_required
|
||||||
|
def user(user_id: int):
|
||||||
|
user = User.query.get_or_404(user_id)
|
||||||
|
|
||||||
|
if not (
|
||||||
|
user.is_public
|
||||||
|
or user == current_user
|
||||||
|
or current_user.is_administrator
|
||||||
|
):
|
||||||
|
abort(403)
|
||||||
|
|
||||||
|
accept_json = request.accept_mimetypes.accept_json
|
||||||
|
accept_html = request.accept_mimetypes.accept_html
|
||||||
|
|
||||||
|
if accept_json and not accept_html:
|
||||||
|
return user.to_json_serializeable(
|
||||||
|
backrefs=True,
|
||||||
|
relationships=True
|
||||||
|
)
|
||||||
|
|
||||||
|
return render_template(
|
||||||
|
'users/user.html.j2',
|
||||||
|
title=user.username,
|
||||||
|
user=user
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def _delete_user(app: Flask, user_id: int):
|
||||||
|
with app.app_context():
|
||||||
|
user = User.query.get(user_id)
|
||||||
|
user.delete()
|
||||||
|
db.session.commit()
|
||||||
|
|
||||||
|
|
||||||
|
@bp.route('/<hashid:user_id>', methods=['DELETE'])
|
||||||
|
@login_required
|
||||||
|
def delete_user(user_id: int):
|
||||||
|
user = User.query.get_or_404(user_id)
|
||||||
|
|
||||||
|
if not (
|
||||||
|
user == current_user
|
||||||
|
or current_user.is_administrator
|
||||||
|
):
|
||||||
|
abort(403)
|
||||||
|
|
||||||
|
if user == current_user:
|
||||||
|
logout_user()
|
||||||
|
|
||||||
|
thread = Thread(
|
||||||
|
target=_delete_user,
|
||||||
|
args=(current_app._get_current_object(), user.id)
|
||||||
|
)
|
||||||
|
thread.start()
|
||||||
|
|
||||||
|
return jsonify(f'User "{user.username}" marked for deletion'), 202
|
||||||
|
|
||||||
|
|
||||||
|
@bp.route('/<hashid:user_id>/avatar')
|
||||||
|
@login_required
|
||||||
|
def user_avatar(user_id: int):
|
||||||
|
user = User.query.get_or_404(user_id)
|
||||||
|
|
||||||
|
if not (
|
||||||
|
user.is_public
|
||||||
|
or user == current_user
|
||||||
|
or current_user.is_administrator
|
||||||
|
):
|
||||||
|
abort(403)
|
||||||
|
|
||||||
|
if user.avatar is None:
|
||||||
|
return redirect(url_for('static', filename='images/user_avatar.png'))
|
||||||
|
|
||||||
|
return send_from_directory(
|
||||||
|
user.avatar.path.parent,
|
||||||
|
user.avatar.path.name,
|
||||||
|
as_attachment=True,
|
||||||
|
download_name=user.avatar.filename,
|
||||||
|
mimetype=user.avatar.mimetype
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def _delete_avatar(app: Flask, avatar_id: int):
|
||||||
|
with app.app_context():
|
||||||
|
avatar = Avatar.query.get(avatar_id)
|
||||||
|
avatar.delete()
|
||||||
|
db.session.commit()
|
||||||
|
|
||||||
|
|
||||||
|
@bp.route('/<hashid:user_id>/avatar', methods=['DELETE'])
|
||||||
|
@login_required
|
||||||
|
def delete_user_avatar(user_id: int):
|
||||||
|
user = User.query.get_or_404(user_id)
|
||||||
|
|
||||||
|
if user.avatar is None:
|
||||||
|
abort(409)
|
||||||
|
|
||||||
|
if not (
|
||||||
|
user == current_user
|
||||||
|
or current_user.is_administrator
|
||||||
|
):
|
||||||
|
abort(403)
|
||||||
|
|
||||||
|
thread = Thread(
|
||||||
|
target=_delete_avatar,
|
||||||
|
args=(current_app._get_current_object(), user.avatar.id)
|
||||||
|
)
|
||||||
|
thread.start()
|
||||||
|
|
||||||
|
return jsonify('Avatar marked for deletion'), 202
|
||||||
File renamed without changes.
File renamed without changes.
@@ -1,23 +0,0 @@
|
|||||||
from flask import Blueprint
|
|
||||||
from flask_login import login_required
|
|
||||||
|
|
||||||
|
|
||||||
bp = Blueprint('contributions', __name__)
|
|
||||||
|
|
||||||
|
|
||||||
@bp.before_request
|
|
||||||
@login_required
|
|
||||||
def before_request():
|
|
||||||
'''
|
|
||||||
Ensures that the routes in this package can only be visited by users that
|
|
||||||
are logged in.
|
|
||||||
'''
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
from . import (
|
|
||||||
routes,
|
|
||||||
spacy_nlp_pipeline_models,
|
|
||||||
tesseract_ocr_pipeline_models,
|
|
||||||
transkribus_htr_pipeline_models
|
|
||||||
)
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
from flask import redirect, url_for
|
|
||||||
from . import bp
|
|
||||||
|
|
||||||
|
|
||||||
@bp.route('')
|
|
||||||
def contributions():
|
|
||||||
return redirect(url_for('main.dashboard', _anchor='contributions'))
|
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
from .. import bp
|
|
||||||
from . import json_routes, routes
|
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
from .. import bp
|
|
||||||
from . import routes
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
from flask import abort
|
|
||||||
from . import bp
|
|
||||||
|
|
||||||
|
|
||||||
@bp.route('/transkribus_htr_pipeline_models')
|
|
||||||
def transkribus_htr_pipeline_models():
|
|
||||||
return abort(503)
|
|
||||||
@@ -1,7 +1,6 @@
|
|||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from flask import current_app
|
from flask import current_app
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Dict, List
|
|
||||||
import json
|
import json
|
||||||
import shutil
|
import shutil
|
||||||
from app import db
|
from app import db
|
||||||
@@ -15,7 +14,7 @@ class SandpaperConverter:
|
|||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
with self.json_db_file.open('r') as f:
|
with self.json_db_file.open('r') as f:
|
||||||
json_db: List[Dict] = json.load(f)
|
json_db: list[dict] = json.load(f)
|
||||||
|
|
||||||
for json_user in json_db:
|
for json_user in json_db:
|
||||||
if not json_user['confirmed']:
|
if not json_user['confirmed']:
|
||||||
@@ -26,7 +25,7 @@ class SandpaperConverter:
|
|||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
|
||||||
|
|
||||||
def convert_user(self, json_user: Dict, user_dir: Path):
|
def convert_user(self, json_user: dict, user_dir: Path):
|
||||||
current_app.logger.info(f'Create User {json_user["username"]}...')
|
current_app.logger.info(f'Create User {json_user["username"]}...')
|
||||||
try:
|
try:
|
||||||
user = User.create(
|
user = User.create(
|
||||||
@@ -48,7 +47,7 @@ class SandpaperConverter:
|
|||||||
current_app.logger.info('Done')
|
current_app.logger.info('Done')
|
||||||
|
|
||||||
|
|
||||||
def convert_corpus(self, json_corpus: Dict, user: User, corpus_dir: Path):
|
def convert_corpus(self, json_corpus: dict, user: User, corpus_dir: Path):
|
||||||
current_app.logger.info(f'Create Corpus {json_corpus["title"]}...')
|
current_app.logger.info(f'Create Corpus {json_corpus["title"]}...')
|
||||||
try:
|
try:
|
||||||
corpus = Corpus.create(
|
corpus = Corpus.create(
|
||||||
@@ -64,7 +63,7 @@ class SandpaperConverter:
|
|||||||
current_app.logger.info('Done')
|
current_app.logger.info('Done')
|
||||||
|
|
||||||
|
|
||||||
def convert_corpus_file(self, json_corpus_file: Dict, corpus: Corpus, corpus_dir: Path):
|
def convert_corpus_file(self, json_corpus_file: dict, corpus: Corpus, corpus_dir: Path):
|
||||||
current_app.logger.info(f'Create CorpusFile {json_corpus_file["title"]}...')
|
current_app.logger.info(f'Create CorpusFile {json_corpus_file["title"]}...')
|
||||||
corpus_file = CorpusFile(
|
corpus_file = CorpusFile(
|
||||||
corpus=corpus,
|
corpus=corpus,
|
||||||
|
|||||||
+53
-53
@@ -1,69 +1,25 @@
|
|||||||
from flask import current_app
|
from flask import current_app
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
|
||||||
def normalize_vrt_file(input_file, output_file):
|
def normalize_vrt_file(input_file: Path, output_file: Path):
|
||||||
def check_pos_attribute_order(vrt_lines):
|
|
||||||
# The following orders are possible:
|
|
||||||
# since 26.02.2019: 'word,lemma,simple_pos,pos,ner'
|
|
||||||
# since 26.03.2021: 'word,pos,lemma,simple_pos,ner'
|
|
||||||
# since 27.01.2022: 'word,pos,lemma,simple_pos'
|
|
||||||
# This Function tries to find out which order we have by looking at the
|
|
||||||
# number of attributes and the position of the simple_pos attribute
|
|
||||||
SIMPLE_POS_LABELS = [
|
|
||||||
'ADJ', 'ADP', 'ADV', 'AUX', 'CONJ',
|
|
||||||
'DET', 'INTJ', 'NOUN', 'NUM', 'PART',
|
|
||||||
'PRON', 'PROPN', 'PUNCT', 'SCONJ', 'SYM',
|
|
||||||
'VERB', 'X'
|
|
||||||
]
|
|
||||||
for line in vrt_lines:
|
|
||||||
if line.startswith('<'):
|
|
||||||
continue
|
|
||||||
pos_attrs = line.rstrip('\n').split('\t')
|
|
||||||
num_pos_attrs = len(pos_attrs)
|
|
||||||
if num_pos_attrs == 4:
|
|
||||||
if pos_attrs[3] in SIMPLE_POS_LABELS:
|
|
||||||
return ['word', 'pos', 'lemma', 'simple_pos']
|
|
||||||
continue
|
|
||||||
elif num_pos_attrs == 5:
|
|
||||||
if pos_attrs[2] in SIMPLE_POS_LABELS:
|
|
||||||
return ['word', 'lemma', 'simple_pos', 'pos', 'ner']
|
|
||||||
elif pos_attrs[3] in SIMPLE_POS_LABELS:
|
|
||||||
return ['word', 'pos', 'lemma', 'simple_pos', 'ner']
|
|
||||||
continue
|
|
||||||
return None
|
|
||||||
|
|
||||||
|
|
||||||
def check_has_ent_as_s_attr(vrt_lines):
|
|
||||||
for line in vrt_lines:
|
|
||||||
if line.startswith('<ent'):
|
|
||||||
return True
|
|
||||||
return False
|
|
||||||
|
|
||||||
|
|
||||||
def pos_attrs_to_string_1(pos_attrs):
|
|
||||||
return f'{pos_attrs[0]}\t{pos_attrs[3]}\t{pos_attrs[1]}\t{pos_attrs[2]}\n'
|
|
||||||
|
|
||||||
|
|
||||||
def pos_attrs_to_string_2(pos_attrs):
|
|
||||||
return f'{pos_attrs[0]}\t{pos_attrs[1]}\t{pos_attrs[2]}\t{pos_attrs[3]}\n'
|
|
||||||
|
|
||||||
current_app.logger.info(f'Converting {input_file}...')
|
current_app.logger.info(f'Converting {input_file}...')
|
||||||
|
|
||||||
with open(input_file) as f:
|
with input_file.open() as f:
|
||||||
input_vrt_lines = f.readlines()
|
input_vrt_lines = f.readlines()
|
||||||
|
|
||||||
pos_attr_order = check_pos_attribute_order(input_vrt_lines)
|
pos_attr_order = _check_pos_attribute_order(input_vrt_lines)
|
||||||
has_ent_as_s_attr = check_has_ent_as_s_attr(input_vrt_lines)
|
has_ent_as_s_attr = _check_has_ent_as_s_attr(input_vrt_lines)
|
||||||
|
|
||||||
current_app.logger.info(f'Detected pos_attr_order: [{",".join(pos_attr_order)}]')
|
current_app.logger.info(f'Detected pos_attr_order: [{",".join(pos_attr_order)}]')
|
||||||
current_app.logger.info(f'Detected has_ent_as_s_attr: {has_ent_as_s_attr}')
|
current_app.logger.info(f'Detected has_ent_as_s_attr: {has_ent_as_s_attr}')
|
||||||
|
|
||||||
if pos_attr_order == ['word', 'lemma', 'simple_pos', 'pos', 'ner']:
|
if pos_attr_order == ['word', 'lemma', 'simple_pos', 'pos', 'ner']:
|
||||||
pos_attrs_to_string_function = pos_attrs_to_string_1
|
pos_attrs_to_string_function = _pos_attrs_to_string_1
|
||||||
elif pos_attr_order == ['word', 'pos', 'lemma', 'simple_pos', 'ner']:
|
elif pos_attr_order == ['word', 'pos', 'lemma', 'simple_pos', 'ner']:
|
||||||
pos_attrs_to_string_function = pos_attrs_to_string_2
|
pos_attrs_to_string_function = _pos_attrs_to_string_2
|
||||||
elif pos_attr_order == ['word', 'pos', 'lemma', 'simple_pos']:
|
elif pos_attr_order == ['word', 'pos', 'lemma', 'simple_pos']:
|
||||||
pos_attrs_to_string_function = pos_attrs_to_string_2
|
pos_attrs_to_string_function = _pos_attrs_to_string_2
|
||||||
else:
|
else:
|
||||||
raise Exception('Can not handle format')
|
raise Exception('Can not handle format')
|
||||||
|
|
||||||
@@ -113,5 +69,49 @@ def normalize_vrt_file(input_file, output_file):
|
|||||||
current_ent = pos_attrs[4]
|
current_ent = pos_attrs[4]
|
||||||
output_vrt += pos_attrs_to_string_function(pos_attrs)
|
output_vrt += pos_attrs_to_string_function(pos_attrs)
|
||||||
|
|
||||||
with open(output_file, 'w') as f:
|
with output_file.open(mode='w') as f:
|
||||||
f.write(output_vrt)
|
f.write(output_vrt)
|
||||||
|
|
||||||
|
|
||||||
|
def _check_pos_attribute_order(vrt_lines: list[str]) -> list[str]:
|
||||||
|
# The following orders are possible:
|
||||||
|
# since 26.02.2019: 'word,lemma,simple_pos,pos,ner'
|
||||||
|
# since 26.03.2021: 'word,pos,lemma,simple_pos,ner'
|
||||||
|
# since 27.01.2022: 'word,pos,lemma,simple_pos'
|
||||||
|
# This Function tries to find out which order we have by looking at the
|
||||||
|
# number of attributes and the position of the simple_pos attribute
|
||||||
|
SIMPLE_POS_LABELS = [
|
||||||
|
'ADJ', 'ADP', 'ADV', 'AUX', 'CONJ', 'DET', 'INTJ', 'NOUN', 'NUM',
|
||||||
|
'PART', 'PRON', 'PROPN', 'PUNCT', 'SCONJ', 'SYM', 'VERB', 'X'
|
||||||
|
]
|
||||||
|
for line in vrt_lines:
|
||||||
|
if line.startswith('<'):
|
||||||
|
continue
|
||||||
|
pos_attrs = line.rstrip('\n').split('\t')
|
||||||
|
num_pos_attrs = len(pos_attrs)
|
||||||
|
if num_pos_attrs == 4:
|
||||||
|
if pos_attrs[3] in SIMPLE_POS_LABELS:
|
||||||
|
return ['word', 'pos', 'lemma', 'simple_pos']
|
||||||
|
continue
|
||||||
|
elif num_pos_attrs == 5:
|
||||||
|
if pos_attrs[2] in SIMPLE_POS_LABELS:
|
||||||
|
return ['word', 'lemma', 'simple_pos', 'pos', 'ner']
|
||||||
|
elif pos_attrs[3] in SIMPLE_POS_LABELS:
|
||||||
|
return ['word', 'pos', 'lemma', 'simple_pos', 'ner']
|
||||||
|
continue
|
||||||
|
# TODO: raise exception "can't determine attribute order"
|
||||||
|
|
||||||
|
|
||||||
|
def _check_has_ent_as_s_attr(vrt_lines: list[str]) -> bool:
|
||||||
|
for line in vrt_lines:
|
||||||
|
if line.startswith('<ent'):
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
def _pos_attrs_to_string_1(pos_attrs: list[str]) -> str:
|
||||||
|
return f'{pos_attrs[0]}\t{pos_attrs[3]}\t{pos_attrs[1]}\t{pos_attrs[2]}\n'
|
||||||
|
|
||||||
|
|
||||||
|
def _pos_attrs_to_string_2(pos_attrs: list[str]) -> str:
|
||||||
|
return f'{pos_attrs[0]}\t{pos_attrs[1]}\t{pos_attrs[2]}\t{pos_attrs[3]}\n'
|
||||||
@@ -1,131 +0,0 @@
|
|||||||
from cqi.models.corpora import Corpus as CQiCorpus
|
|
||||||
from cqi.models.subcorpora import Subcorpus as CQiSubcorpus
|
|
||||||
from typing import Dict, List
|
|
||||||
|
|
||||||
|
|
||||||
def lookups_by_cpos(corpus: CQiCorpus, cpos_list: List[int]) -> Dict:
|
|
||||||
lookups = {}
|
|
||||||
lookups['cpos_lookup'] = {cpos: {} for cpos in cpos_list}
|
|
||||||
for attr in corpus.positional_attributes.list():
|
|
||||||
cpos_attr_values: List[str] = attr.values_by_cpos(cpos_list)
|
|
||||||
for i, cpos in enumerate(cpos_list):
|
|
||||||
lookups['cpos_lookup'][cpos][attr.name] = cpos_attr_values[i]
|
|
||||||
for attr in corpus.structural_attributes.list():
|
|
||||||
# We only want to iterate over non subattributes, identifiable by
|
|
||||||
# attr.has_values == False
|
|
||||||
if attr.has_values:
|
|
||||||
continue
|
|
||||||
cpos_attr_ids: List[int] = attr.ids_by_cpos(cpos_list)
|
|
||||||
for i, cpos in enumerate(cpos_list):
|
|
||||||
if cpos_attr_ids[i] == -1:
|
|
||||||
continue
|
|
||||||
lookups['cpos_lookup'][cpos][attr.name] = cpos_attr_ids[i]
|
|
||||||
occured_attr_ids = [x for x in set(cpos_attr_ids) if x != -1]
|
|
||||||
if len(occured_attr_ids) == 0:
|
|
||||||
continue
|
|
||||||
subattrs = corpus.structural_attributes.list(filters={'part_of': attr})
|
|
||||||
if len(subattrs) == 0:
|
|
||||||
continue
|
|
||||||
lookup_name: str = f'{attr.name}_lookup'
|
|
||||||
lookups[lookup_name] = {}
|
|
||||||
for attr_id in occured_attr_ids:
|
|
||||||
lookups[lookup_name][attr_id] = {}
|
|
||||||
for subattr in subattrs:
|
|
||||||
subattr_name = subattr.name[(len(attr.name) + 1):] # noqa
|
|
||||||
for i, subattr_value in enumerate(subattr.values_by_ids(occured_attr_ids)): # noqa
|
|
||||||
lookups[lookup_name][occured_attr_ids[i]][subattr_name] = subattr_value # noqa
|
|
||||||
return lookups
|
|
||||||
|
|
||||||
|
|
||||||
def partial_export_subcorpus(
|
|
||||||
subcorpus: CQiSubcorpus,
|
|
||||||
match_id_list: List[int],
|
|
||||||
context: int = 25
|
|
||||||
) -> Dict:
|
|
||||||
if subcorpus.size == 0:
|
|
||||||
return {"matches": []}
|
|
||||||
match_boundaries = []
|
|
||||||
for match_id in match_id_list:
|
|
||||||
if match_id < 0 or match_id >= subcorpus.size:
|
|
||||||
continue
|
|
||||||
match_boundaries.append(
|
|
||||||
(
|
|
||||||
match_id,
|
|
||||||
subcorpus.dump(subcorpus.fields['match'], match_id, match_id)[0],
|
|
||||||
subcorpus.dump(subcorpus.fields['matchend'], match_id, match_id)[0]
|
|
||||||
)
|
|
||||||
)
|
|
||||||
cpos_set = set()
|
|
||||||
matches = []
|
|
||||||
for match_boundary in match_boundaries:
|
|
||||||
match_num, match_start, match_end = match_boundary
|
|
||||||
c = (match_start, match_end)
|
|
||||||
if match_start == 0 or context == 0:
|
|
||||||
lc = None
|
|
||||||
cpos_list_lbound = match_start
|
|
||||||
else:
|
|
||||||
lc_lbound = max(0, (match_start - context))
|
|
||||||
lc_rbound = match_start - 1
|
|
||||||
lc = (lc_lbound, lc_rbound)
|
|
||||||
cpos_list_lbound = lc_lbound
|
|
||||||
if match_end == (subcorpus.collection.corpus.size - 1) or context == 0:
|
|
||||||
rc = None
|
|
||||||
cpos_list_rbound = match_end
|
|
||||||
else:
|
|
||||||
rc_lbound = match_end + 1
|
|
||||||
rc_rbound = min(
|
|
||||||
(match_end + context),
|
|
||||||
(subcorpus.collection.corpus.size - 1)
|
|
||||||
)
|
|
||||||
rc = (rc_lbound, rc_rbound)
|
|
||||||
cpos_list_rbound = rc_rbound
|
|
||||||
match = {'num': match_num, 'lc': lc, 'c': c, 'rc': rc}
|
|
||||||
matches.append(match)
|
|
||||||
cpos_set.update(range(cpos_list_lbound, cpos_list_rbound + 1))
|
|
||||||
lookups = lookups_by_cpos(subcorpus.collection.corpus, list(cpos_set))
|
|
||||||
return {'matches': matches, **lookups}
|
|
||||||
|
|
||||||
|
|
||||||
def export_subcorpus(
|
|
||||||
subcorpus: CQiSubcorpus,
|
|
||||||
context: int = 25,
|
|
||||||
cutoff: float = float('inf'),
|
|
||||||
offset: int = 0
|
|
||||||
) -> Dict:
|
|
||||||
if subcorpus.size == 0:
|
|
||||||
return {"matches": []}
|
|
||||||
first_match = max(0, offset)
|
|
||||||
last_match = min((offset + cutoff - 1), (subcorpus.size - 1))
|
|
||||||
match_boundaries = zip(
|
|
||||||
range(first_match, last_match + 1),
|
|
||||||
subcorpus.dump(subcorpus.fields['match'], first_match, last_match),
|
|
||||||
subcorpus.dump(subcorpus.fields['matchend'], first_match, last_match)
|
|
||||||
)
|
|
||||||
cpos_set = set()
|
|
||||||
matches = []
|
|
||||||
for match_num, match_start, match_end in match_boundaries:
|
|
||||||
c = (match_start, match_end)
|
|
||||||
if match_start == 0 or context == 0:
|
|
||||||
lc = None
|
|
||||||
cpos_list_lbound = match_start
|
|
||||||
else:
|
|
||||||
lc_lbound = max(0, (match_start - context))
|
|
||||||
lc_rbound = match_start - 1
|
|
||||||
lc = (lc_lbound, lc_rbound)
|
|
||||||
cpos_list_lbound = lc_lbound
|
|
||||||
if match_end == (subcorpus.collection.corpus.size - 1) or context == 0:
|
|
||||||
rc = None
|
|
||||||
cpos_list_rbound = match_end
|
|
||||||
else:
|
|
||||||
rc_lbound = match_end + 1
|
|
||||||
rc_rbound = min(
|
|
||||||
(match_end + context),
|
|
||||||
(subcorpus.collection.corpus.size - 1)
|
|
||||||
)
|
|
||||||
rc = (rc_lbound, rc_rbound)
|
|
||||||
cpos_list_rbound = rc_rbound
|
|
||||||
match = {'num': match_num, 'lc': lc, 'c': c, 'rc': rc}
|
|
||||||
matches.append(match)
|
|
||||||
cpos_set.update(range(cpos_list_lbound, cpos_list_rbound + 1))
|
|
||||||
lookups = lookups_by_cpos(subcorpus.collection.corpus, list(cpos_set))
|
|
||||||
return {'matches': matches, **lookups}
|
|
||||||
@@ -1,45 +0,0 @@
|
|||||||
from flask_login import current_user
|
|
||||||
from flask_socketio import join_room
|
|
||||||
from app import hashids, socketio
|
|
||||||
from app.decorators import socketio_login_required
|
|
||||||
from app.models import Corpus
|
|
||||||
|
|
||||||
|
|
||||||
@socketio.on('GET /corpora/<corpus_id>')
|
|
||||||
@socketio_login_required
|
|
||||||
def get_corpus(corpus_hashid):
|
|
||||||
corpus_id = hashids.decode(corpus_hashid)
|
|
||||||
corpus = Corpus.query.get(corpus_id)
|
|
||||||
if corpus is None:
|
|
||||||
return {'options': {'status': 404, 'statusText': 'Not found'}}
|
|
||||||
if not (
|
|
||||||
corpus.is_public
|
|
||||||
or corpus.user == current_user
|
|
||||||
or current_user.is_administrator
|
|
||||||
):
|
|
||||||
return {'options': {'status': 403, 'statusText': 'Forbidden'}}
|
|
||||||
return {
|
|
||||||
'body': corpus.to_json_serializable(),
|
|
||||||
'options': {
|
|
||||||
'status': 200,
|
|
||||||
'statusText': 'OK',
|
|
||||||
'headers': {'Content-Type: application/json'}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@socketio.on('SUBSCRIBE /corpora/<corpus_id>')
|
|
||||||
@socketio_login_required
|
|
||||||
def subscribe_corpus(corpus_hashid):
|
|
||||||
corpus_id = hashids.decode(corpus_hashid)
|
|
||||||
corpus = Corpus.query.get(corpus_id)
|
|
||||||
if corpus is None:
|
|
||||||
return {'options': {'status': 404, 'statusText': 'Not found'}}
|
|
||||||
if not (
|
|
||||||
corpus.is_public
|
|
||||||
or corpus.user == current_user
|
|
||||||
or current_user.is_administrator
|
|
||||||
):
|
|
||||||
return {'options': {'status': 403, 'statusText': 'Forbidden'}}
|
|
||||||
join_room(f'/corpora/{corpus.hashid}')
|
|
||||||
return {'options': {'status': 200, 'statusText': 'OK'}}
|
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
from .. import bp
|
|
||||||
from . import json_routes, routes
|
|
||||||
@@ -1,125 +0,0 @@
|
|||||||
from datetime import datetime
|
|
||||||
from flask import abort, current_app, request, url_for
|
|
||||||
from flask_login import current_user
|
|
||||||
from threading import Thread
|
|
||||||
from app import db
|
|
||||||
from app.decorators import content_negotiation
|
|
||||||
from app.models import Corpus, CorpusFollowerRole
|
|
||||||
from . import bp
|
|
||||||
from .decorators import corpus_follower_permission_required, corpus_owner_or_admin_required
|
|
||||||
import nltk
|
|
||||||
from string import punctuation
|
|
||||||
|
|
||||||
|
|
||||||
@bp.route('/<hashid:corpus_id>', methods=['DELETE'])
|
|
||||||
@corpus_owner_or_admin_required
|
|
||||||
@content_negotiation(produces='application/json')
|
|
||||||
def delete_corpus(corpus_id):
|
|
||||||
def _delete_corpus(app, corpus_id):
|
|
||||||
with app.app_context():
|
|
||||||
corpus = Corpus.query.get(corpus_id)
|
|
||||||
corpus.delete()
|
|
||||||
db.session.commit()
|
|
||||||
|
|
||||||
corpus = Corpus.query.get_or_404(corpus_id)
|
|
||||||
thread = Thread(
|
|
||||||
target=_delete_corpus,
|
|
||||||
args=(current_app._get_current_object(), corpus.id)
|
|
||||||
)
|
|
||||||
thread.start()
|
|
||||||
response_data = {
|
|
||||||
'message': f'Corpus "{corpus.title}" marked for deletion',
|
|
||||||
'category': 'corpus'
|
|
||||||
}
|
|
||||||
return response_data, 200
|
|
||||||
|
|
||||||
|
|
||||||
@bp.route('/<hashid:corpus_id>/build', methods=['POST'])
|
|
||||||
@corpus_follower_permission_required('MANAGE_FILES')
|
|
||||||
@content_negotiation(produces='application/json')
|
|
||||||
def build_corpus(corpus_id):
|
|
||||||
def _build_corpus(app, corpus_id):
|
|
||||||
with app.app_context():
|
|
||||||
corpus = Corpus.query.get(corpus_id)
|
|
||||||
corpus.build()
|
|
||||||
db.session.commit()
|
|
||||||
|
|
||||||
corpus = Corpus.query.get_or_404(corpus_id)
|
|
||||||
if len(corpus.files.all()) == 0:
|
|
||||||
abort(409)
|
|
||||||
thread = Thread(
|
|
||||||
target=_build_corpus,
|
|
||||||
args=(current_app._get_current_object(), corpus_id)
|
|
||||||
)
|
|
||||||
thread.start()
|
|
||||||
response_data = {
|
|
||||||
'message': f'Corpus "{corpus.title}" marked for building',
|
|
||||||
'category': 'corpus'
|
|
||||||
}
|
|
||||||
return response_data, 202
|
|
||||||
|
|
||||||
@bp.route('/stopwords')
|
|
||||||
@content_negotiation(produces='application/json')
|
|
||||||
def get_stopwords():
|
|
||||||
nltk.download('stopwords', quiet=True)
|
|
||||||
languages = ["german", "english", "catalan", "greek", "spanish", "french", "italian", "russian", "chinese"]
|
|
||||||
stopwords = {}
|
|
||||||
for language in languages:
|
|
||||||
stopwords[language] = nltk.corpus.stopwords.words(language)
|
|
||||||
stopwords['punctuation'] = list(punctuation) + ['—', '|', '–', '“', '„', '--']
|
|
||||||
stopwords['user_stopwords'] = []
|
|
||||||
response_data = stopwords
|
|
||||||
return response_data, 202
|
|
||||||
|
|
||||||
@bp.route('/<hashid:corpus_id>/generate-share-link', methods=['POST'])
|
|
||||||
@corpus_follower_permission_required('MANAGE_FOLLOWERS')
|
|
||||||
@content_negotiation(consumes='application/json', produces='application/json')
|
|
||||||
def generate_corpus_share_link(corpus_id):
|
|
||||||
data = request.json
|
|
||||||
if not isinstance(data, dict):
|
|
||||||
abort(400)
|
|
||||||
expiration = data.get('expiration')
|
|
||||||
if not isinstance(expiration, str):
|
|
||||||
abort(400)
|
|
||||||
role_name = data.get('role')
|
|
||||||
if not isinstance(role_name, str):
|
|
||||||
abort(400)
|
|
||||||
expiration_date = datetime.strptime(expiration, '%b %d, %Y')
|
|
||||||
cfr = CorpusFollowerRole.query.filter_by(name=role_name).first()
|
|
||||||
if cfr is None:
|
|
||||||
abort(400)
|
|
||||||
corpus = Corpus.query.get_or_404(corpus_id)
|
|
||||||
token = current_user.generate_follow_corpus_token(corpus.hashid, role_name, expiration_date)
|
|
||||||
corpus_share_link = url_for(
|
|
||||||
'corpora.follow_corpus',
|
|
||||||
corpus_id=corpus_id,
|
|
||||||
token=token,
|
|
||||||
_external=True
|
|
||||||
)
|
|
||||||
response_data = {
|
|
||||||
'message': 'Corpus share link generated',
|
|
||||||
'category': 'corpus',
|
|
||||||
'corpusShareLink': corpus_share_link
|
|
||||||
}
|
|
||||||
return response_data, 200
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@bp.route('/<hashid:corpus_id>/is_public', methods=['PUT'])
|
|
||||||
@corpus_owner_or_admin_required
|
|
||||||
@content_negotiation(consumes='application/json', produces='application/json')
|
|
||||||
def update_corpus_is_public(corpus_id):
|
|
||||||
is_public = request.json
|
|
||||||
if not isinstance(is_public, bool):
|
|
||||||
abort(400)
|
|
||||||
corpus = Corpus.query.get_or_404(corpus_id)
|
|
||||||
corpus.is_public = is_public
|
|
||||||
db.session.commit()
|
|
||||||
response_data = {
|
|
||||||
'message': (
|
|
||||||
f'Corpus "{corpus.title}" is now'
|
|
||||||
f' {"public" if is_public else "private"}'
|
|
||||||
),
|
|
||||||
'category': 'corpus'
|
|
||||||
}
|
|
||||||
return response_data, 200
|
|
||||||
@@ -1,109 +0,0 @@
|
|||||||
from flask import abort, flash, redirect, render_template, url_for
|
|
||||||
from flask_login import current_user
|
|
||||||
from app import db
|
|
||||||
from app.models import (
|
|
||||||
Corpus,
|
|
||||||
CorpusFollowerAssociation,
|
|
||||||
CorpusFollowerRole,
|
|
||||||
User
|
|
||||||
)
|
|
||||||
from . import bp
|
|
||||||
from .decorators import corpus_follower_permission_required
|
|
||||||
from .forms import CreateCorpusForm
|
|
||||||
|
|
||||||
|
|
||||||
@bp.route('')
|
|
||||||
def corpora():
|
|
||||||
return render_template('corpora/corpora.html.j2', title='Corpora')
|
|
||||||
|
|
||||||
|
|
||||||
@bp.route('/create', methods=['GET', 'POST'])
|
|
||||||
def create_corpus():
|
|
||||||
form = CreateCorpusForm()
|
|
||||||
if form.validate_on_submit():
|
|
||||||
try:
|
|
||||||
corpus = Corpus.create(
|
|
||||||
title=form.title.data,
|
|
||||||
description=form.description.data,
|
|
||||||
user=current_user
|
|
||||||
)
|
|
||||||
except OSError:
|
|
||||||
abort(500)
|
|
||||||
db.session.commit()
|
|
||||||
flash(f'Corpus "{corpus.title}" created', 'corpus')
|
|
||||||
return redirect(corpus.url)
|
|
||||||
return render_template(
|
|
||||||
'corpora/create.html.j2',
|
|
||||||
title='Create corpus',
|
|
||||||
form=form
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
@bp.route('/<hashid:corpus_id>')
|
|
||||||
def corpus(corpus_id):
|
|
||||||
corpus = Corpus.query.get_or_404(corpus_id)
|
|
||||||
cfrs = CorpusFollowerRole.query.all()
|
|
||||||
# TODO: Better solution for filtering admin
|
|
||||||
users = User.query.filter(User.is_public == True, User.id != current_user.id, User.id != corpus.user.id, User.role_id < 4).all()
|
|
||||||
cfa = CorpusFollowerAssociation.query.filter_by(corpus_id=corpus_id, follower_id=current_user.id).first()
|
|
||||||
if cfa is None:
|
|
||||||
if corpus.user == current_user or current_user.is_administrator:
|
|
||||||
cfr = CorpusFollowerRole.query.filter_by(name='Administrator').first()
|
|
||||||
else:
|
|
||||||
cfr = CorpusFollowerRole.query.filter_by(name='Anonymous').first()
|
|
||||||
else:
|
|
||||||
cfr = cfa.role
|
|
||||||
if corpus.user == current_user or current_user.is_administrator:
|
|
||||||
return render_template(
|
|
||||||
'corpora/corpus.html.j2',
|
|
||||||
title=corpus.title,
|
|
||||||
corpus=corpus,
|
|
||||||
cfr=cfr,
|
|
||||||
cfrs=cfrs,
|
|
||||||
users=users
|
|
||||||
)
|
|
||||||
if (current_user.is_following_corpus(corpus) or corpus.is_public):
|
|
||||||
cfas = CorpusFollowerAssociation.query.filter(Corpus.id == corpus_id, CorpusFollowerAssociation.follower_id != corpus.user.id).all()
|
|
||||||
return render_template(
|
|
||||||
'corpora/public_corpus.html.j2',
|
|
||||||
title=corpus.title,
|
|
||||||
corpus=corpus,
|
|
||||||
cfrs=cfrs,
|
|
||||||
cfr=cfr,
|
|
||||||
cfas=cfas,
|
|
||||||
users=users
|
|
||||||
)
|
|
||||||
abort(403)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@bp.route('/<hashid:corpus_id>/analysis')
|
|
||||||
@corpus_follower_permission_required('VIEW')
|
|
||||||
def analysis(corpus_id):
|
|
||||||
corpus = Corpus.query.get_or_404(corpus_id)
|
|
||||||
return render_template(
|
|
||||||
'corpora/analysis.html.j2',
|
|
||||||
corpus=corpus,
|
|
||||||
title=f'Analyse Corpus {corpus.title}'
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
@bp.route('/<hashid:corpus_id>/follow/<token>')
|
|
||||||
def follow_corpus(corpus_id, token):
|
|
||||||
corpus = Corpus.query.get_or_404(corpus_id)
|
|
||||||
if current_user.follow_corpus_by_token(token):
|
|
||||||
db.session.commit()
|
|
||||||
flash(f'You are following "{corpus.title}" now', category='corpus')
|
|
||||||
return redirect(url_for('corpora.corpus', corpus_id=corpus_id))
|
|
||||||
abort(403)
|
|
||||||
|
|
||||||
|
|
||||||
@bp.route('/import', methods=['GET', 'POST'])
|
|
||||||
def import_corpus():
|
|
||||||
abort(503)
|
|
||||||
|
|
||||||
|
|
||||||
@bp.route('/<hashid:corpus_id>/export')
|
|
||||||
@corpus_follower_permission_required('VIEW')
|
|
||||||
def export_corpus(corpus_id):
|
|
||||||
abort(503)
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
from app import db
|
|
||||||
from flask import Flask
|
|
||||||
from .corpus_utils import check_corpora
|
|
||||||
from .job_utils import check_jobs
|
|
||||||
|
|
||||||
|
|
||||||
def daemon(app: Flask):
|
|
||||||
with app.app_context():
|
|
||||||
check_corpora()
|
|
||||||
check_jobs()
|
|
||||||
db.session.commit()
|
|
||||||
+5
-5
@@ -1,7 +1,7 @@
|
|||||||
from flask import abort, request
|
from flask import abort, request
|
||||||
from flask_login import current_user
|
from flask_login import current_user
|
||||||
from functools import wraps
|
from functools import wraps
|
||||||
from typing import List, Union
|
from typing import Optional
|
||||||
from werkzeug.exceptions import NotAcceptable
|
from werkzeug.exceptions import NotAcceptable
|
||||||
from app.models import Permission
|
from app.models import Permission
|
||||||
|
|
||||||
@@ -26,7 +26,7 @@ def socketio_login_required(f):
|
|||||||
def wrapper(*args, **kwargs):
|
def wrapper(*args, **kwargs):
|
||||||
if current_user.is_authenticated:
|
if current_user.is_authenticated:
|
||||||
return f(*args, **kwargs)
|
return f(*args, **kwargs)
|
||||||
return {'code': 401, 'body': 'Unauthorized'}
|
return {'status': 401, 'statusText': 'Unauthorized'}
|
||||||
return wrapper
|
return wrapper
|
||||||
|
|
||||||
|
|
||||||
@@ -35,7 +35,7 @@ def socketio_permission_required(permission):
|
|||||||
@wraps(f)
|
@wraps(f)
|
||||||
def wrapper(*args, **kwargs):
|
def wrapper(*args, **kwargs):
|
||||||
if not current_user.can(permission):
|
if not current_user.can(permission):
|
||||||
return {'code': 403, 'body': 'Forbidden'}
|
return {'status': 403, 'statusText': 'Forbidden'}
|
||||||
return f(*args, **kwargs)
|
return f(*args, **kwargs)
|
||||||
return wrapper
|
return wrapper
|
||||||
return decorator
|
return decorator
|
||||||
@@ -46,8 +46,8 @@ def socketio_admin_required(f):
|
|||||||
|
|
||||||
|
|
||||||
def content_negotiation(
|
def content_negotiation(
|
||||||
produces: Union[str, List[str], None] = None,
|
produces: Optional[str | list[str]] = None,
|
||||||
consumes: Union[str, List[str], None] = None
|
consumes: Optional[str | list[str]] = None
|
||||||
):
|
):
|
||||||
def decorator(f):
|
def decorator(f):
|
||||||
@wraps(f)
|
@wraps(f)
|
||||||
|
|||||||
+19
-12
@@ -1,25 +1,32 @@
|
|||||||
from flask import current_app, render_template
|
from flask import current_app, Flask, render_template
|
||||||
from flask_mail import Message
|
from flask_mail import Message
|
||||||
from threading import Thread
|
from threading import Thread
|
||||||
from app import mail
|
from app import mail
|
||||||
|
|
||||||
|
|
||||||
def create_message(recipient, subject, template, **kwargs):
|
def create_message(
|
||||||
subject_prefix: str = current_app.config['NOPAQUE_MAIL_SUBJECT_PREFIX']
|
recipient: str,
|
||||||
msg: Message = Message(
|
subject: str,
|
||||||
body=render_template(f'{template}.txt.j2', **kwargs),
|
template: str,
|
||||||
html=render_template(f'{template}.html.j2', **kwargs),
|
**context
|
||||||
|
) -> Message:
|
||||||
|
message = Message(
|
||||||
|
body=render_template(f'{template}.txt.j2', **context),
|
||||||
|
html=render_template(f'{template}.html.j2', **context),
|
||||||
recipients=[recipient],
|
recipients=[recipient],
|
||||||
subject=f'{subject_prefix} {subject}'
|
subject=f'[nopaque] {subject}'
|
||||||
)
|
)
|
||||||
return msg
|
return message
|
||||||
|
|
||||||
|
|
||||||
def send(msg, *args, **kwargs):
|
def send(message: Message) -> Thread:
|
||||||
def _send(app, msg):
|
def _send(app: Flask, message: Message):
|
||||||
with app.app_context():
|
with app.app_context():
|
||||||
mail.send(msg)
|
mail.send(message)
|
||||||
|
|
||||||
thread = Thread(target=_send, args=[current_app._get_current_object(), msg])
|
thread = Thread(
|
||||||
|
target=_send,
|
||||||
|
args=[current_app._get_current_object(), message]
|
||||||
|
)
|
||||||
thread.start()
|
thread.start()
|
||||||
return thread
|
return thread
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
from flask import abort
|
||||||
|
from flask_admin import (
|
||||||
|
AdminIndexView as _AdminIndexView,
|
||||||
|
expose
|
||||||
|
)
|
||||||
|
from flask_admin.contrib.sqla import ModelView as _ModelView
|
||||||
|
from flask_login import current_user
|
||||||
|
|
||||||
|
|
||||||
|
class AdminIndexView(_AdminIndexView):
|
||||||
|
@expose('/')
|
||||||
|
def index(self):
|
||||||
|
if not current_user.is_administrator:
|
||||||
|
abort(403)
|
||||||
|
return super().index()
|
||||||
|
|
||||||
|
|
||||||
|
class ModelView(_ModelView):
|
||||||
|
def is_accessible(self):
|
||||||
|
return current_user.is_administrator
|
||||||
File renamed without changes.
@@ -1,2 +0,0 @@
|
|||||||
from .types import ContainerColumn
|
|
||||||
from .types import IntEnumColumn
|
|
||||||
+2
-18
@@ -1,18 +1,2 @@
|
|||||||
from flask import Blueprint
|
from .handle_corpora import handle_corpora
|
||||||
from flask_login import login_required
|
from .handle_jobs import handle_jobs
|
||||||
|
|
||||||
|
|
||||||
bp = Blueprint('jobs', __name__)
|
|
||||||
|
|
||||||
|
|
||||||
@bp.before_request
|
|
||||||
@login_required
|
|
||||||
def before_request():
|
|
||||||
'''
|
|
||||||
Ensures that the routes in this package can only be visited by users that
|
|
||||||
are logged in.
|
|
||||||
'''
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
from . import routes, json_routes
|
|
||||||
@@ -1,138 +0,0 @@
|
|||||||
from flask import current_app
|
|
||||||
from flask_login import current_user
|
|
||||||
from flask_socketio import Namespace
|
|
||||||
from app import db, hashids, socketio
|
|
||||||
from app.extensions.flask_socketio import admin_required, login_required
|
|
||||||
from app.models import Job, JobStatus
|
|
||||||
|
|
||||||
|
|
||||||
class JobsNamespace(Namespace):
|
|
||||||
@login_required
|
|
||||||
def on_delete(self, job_hashid: str):
|
|
||||||
# Decode the job hashid
|
|
||||||
job_id = hashids.decode(job_hashid)
|
|
||||||
|
|
||||||
# Validate job_id
|
|
||||||
if not isinstance(job_id, int):
|
|
||||||
return {
|
|
||||||
'code': 400,
|
|
||||||
'body': 'job_id is invalid'
|
|
||||||
}
|
|
||||||
|
|
||||||
# Load job from database
|
|
||||||
job = Job.query.get(job_id)
|
|
||||||
if job is None:
|
|
||||||
return {
|
|
||||||
'code': 404,
|
|
||||||
'body': 'Job not found'
|
|
||||||
}
|
|
||||||
|
|
||||||
# Check if the current user is allowed to delete the job
|
|
||||||
if not (job.user == current_user or current_user.is_administrator):
|
|
||||||
return {
|
|
||||||
'code': 403,
|
|
||||||
'body': 'Forbidden'
|
|
||||||
}
|
|
||||||
|
|
||||||
# TODO: This should be a method in the Job model
|
|
||||||
def _delete_job(app, job_id):
|
|
||||||
with app.app_context():
|
|
||||||
job = Job.query.get(job_id)
|
|
||||||
job.delete()
|
|
||||||
db.session.commit()
|
|
||||||
|
|
||||||
# Delete the job in a background task
|
|
||||||
socketio.start_background_task(
|
|
||||||
target=_delete_job,
|
|
||||||
app=current_app._get_current_object(),
|
|
||||||
job_id=job_id
|
|
||||||
)
|
|
||||||
|
|
||||||
return {
|
|
||||||
'code': 202,
|
|
||||||
'body': f'Job "{job.title}" marked for deletion'
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@admin_required
|
|
||||||
def on_get_log(self, job_hashid: str):
|
|
||||||
# Decode the job hashid
|
|
||||||
job_id = hashids.decode(job_hashid)
|
|
||||||
|
|
||||||
# Validate job_id
|
|
||||||
if not isinstance(job_id, int):
|
|
||||||
return {
|
|
||||||
'code': 400,
|
|
||||||
'body': 'job_id is invalid'
|
|
||||||
}
|
|
||||||
|
|
||||||
# Load job from database
|
|
||||||
job = Job.query.get(job_id)
|
|
||||||
if job is None:
|
|
||||||
return {
|
|
||||||
'code': 404,
|
|
||||||
'body': 'Job not found'
|
|
||||||
}
|
|
||||||
|
|
||||||
# Check if the job is already processed
|
|
||||||
if job.status not in [JobStatus.COMPLETED, JobStatus.FAILED]:
|
|
||||||
return {
|
|
||||||
'code': 409,
|
|
||||||
'body': 'Job is not done processing'
|
|
||||||
}
|
|
||||||
|
|
||||||
# Read the log file
|
|
||||||
with open(job.path / 'pipeline_data' / 'logs' / 'pyflow_log.txt') as log_file:
|
|
||||||
job_log = log_file.read()
|
|
||||||
|
|
||||||
return {
|
|
||||||
'code': 200,
|
|
||||||
'body': job_log
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
|
||||||
def on_restart(self, job_hashid: str):
|
|
||||||
# Decode the job hashid
|
|
||||||
job_id = hashids.decode(job_hashid)
|
|
||||||
|
|
||||||
# Validate job_id
|
|
||||||
if not isinstance(job_id, int):
|
|
||||||
return {
|
|
||||||
'code': 400,
|
|
||||||
'body': 'job_id is invalid'
|
|
||||||
}
|
|
||||||
|
|
||||||
# Load job from database
|
|
||||||
job = Job.query.get(job_id)
|
|
||||||
if job is None:
|
|
||||||
return {
|
|
||||||
'code': 404,
|
|
||||||
'body': 'Job not found'
|
|
||||||
}
|
|
||||||
|
|
||||||
# Check if the current user is allowed to restart the job
|
|
||||||
if not (job.user == current_user or current_user.is_administrator):
|
|
||||||
return {
|
|
||||||
'code': 403,
|
|
||||||
'body': 'Forbidden'
|
|
||||||
}
|
|
||||||
|
|
||||||
# TODO: This should be a method in the Job model
|
|
||||||
def _restart_job(app, job_id):
|
|
||||||
with app.app_context():
|
|
||||||
job = Job.query.get(job_id)
|
|
||||||
job.restart()
|
|
||||||
db.session.commit()
|
|
||||||
|
|
||||||
# Restart the job in a background task
|
|
||||||
socketio.start_background_task(
|
|
||||||
target=_restart_job,
|
|
||||||
app=current_app._get_current_object(),
|
|
||||||
job_id=job_id
|
|
||||||
)
|
|
||||||
|
|
||||||
return {
|
|
||||||
'code': 202,
|
|
||||||
'body': f'Job "{job.title}" restarted'
|
|
||||||
}
|
|
||||||
@@ -1,12 +1,16 @@
|
|||||||
from app import docker_client
|
|
||||||
from app.models import Corpus, CorpusStatus
|
|
||||||
from flask import current_app
|
from flask import current_app
|
||||||
import docker
|
import docker
|
||||||
import os
|
import os
|
||||||
import shutil
|
import shutil
|
||||||
|
from app import db, docker_client, scheduler
|
||||||
|
from app.models import Corpus, CorpusStatus
|
||||||
|
|
||||||
|
|
||||||
def check_corpora():
|
def handle_corpora():
|
||||||
|
with scheduler.app.app_context():
|
||||||
|
_handle_corpora()
|
||||||
|
|
||||||
|
def _handle_corpora():
|
||||||
corpora = Corpus.query.all()
|
corpora = Corpus.query.all()
|
||||||
for corpus in [x for x in corpora if x.status == CorpusStatus.SUBMITTED]:
|
for corpus in [x for x in corpora if x.status == CorpusStatus.SUBMITTED]:
|
||||||
_create_build_corpus_service(corpus)
|
_create_build_corpus_service(corpus)
|
||||||
@@ -17,13 +21,14 @@ def check_corpora():
|
|||||||
for corpus in [x for x in corpora if x.status == CorpusStatus.RUNNING_ANALYSIS_SESSION and x.num_analysis_sessions == 0]:
|
for corpus in [x for x in corpora if x.status == CorpusStatus.RUNNING_ANALYSIS_SESSION and x.num_analysis_sessions == 0]:
|
||||||
corpus.status = CorpusStatus.CANCELING_ANALYSIS_SESSION
|
corpus.status = CorpusStatus.CANCELING_ANALYSIS_SESSION
|
||||||
for corpus in [x for x in corpora if x.status == CorpusStatus.RUNNING_ANALYSIS_SESSION]:
|
for corpus in [x for x in corpora if x.status == CorpusStatus.RUNNING_ANALYSIS_SESSION]:
|
||||||
_checkout_analysing_corpus_container(corpus)
|
_checkout_cqpserver_container(corpus)
|
||||||
for corpus in [x for x in corpora if x.status == CorpusStatus.STARTING_ANALYSIS_SESSION]:
|
for corpus in [x for x in corpora if x.status == CorpusStatus.STARTING_ANALYSIS_SESSION]:
|
||||||
_create_cqpserver_container(corpus)
|
_create_cqpserver_container(corpus)
|
||||||
for corpus in [x for x in corpora if x.status == CorpusStatus.CANCELING_ANALYSIS_SESSION]:
|
for corpus in [x for x in corpora if x.status == CorpusStatus.CANCELING_ANALYSIS_SESSION]:
|
||||||
_remove_cqpserver_container(corpus)
|
_remove_cqpserver_container(corpus)
|
||||||
|
db.session.commit()
|
||||||
|
|
||||||
def _create_build_corpus_service(corpus):
|
def _create_build_corpus_service(corpus: Corpus):
|
||||||
''' # Docker service settings # '''
|
''' # Docker service settings # '''
|
||||||
''' ## Command ## '''
|
''' ## Command ## '''
|
||||||
command = ['bash', '-c']
|
command = ['bash', '-c']
|
||||||
@@ -45,12 +50,10 @@ def _create_build_corpus_service(corpus):
|
|||||||
''' ## Constraints ## '''
|
''' ## Constraints ## '''
|
||||||
constraints = ['node.role==worker']
|
constraints = ['node.role==worker']
|
||||||
''' ## Image ## '''
|
''' ## Image ## '''
|
||||||
image = f'{current_app.config["NOPAQUE_DOCKER_IMAGE_PREFIX"]}cwb:r1879'
|
image = f'{current_app.config["NOPAQUE_DOCKER_IMAGE_PREFIX"]}cwb:r1887'
|
||||||
''' ## Labels ## '''
|
''' ## Labels ## '''
|
||||||
labels = {
|
labels = {
|
||||||
'origin': current_app.config['SERVER_NAME'],
|
'nopaque.server_name': current_app.config['SERVER_NAME']
|
||||||
'type': 'corpus.build',
|
|
||||||
'corpus_id': str(corpus.id)
|
|
||||||
}
|
}
|
||||||
''' ## Mounts ## '''
|
''' ## Mounts ## '''
|
||||||
mounts = []
|
mounts = []
|
||||||
@@ -95,7 +98,7 @@ def _create_build_corpus_service(corpus):
|
|||||||
return
|
return
|
||||||
corpus.status = CorpusStatus.QUEUED
|
corpus.status = CorpusStatus.QUEUED
|
||||||
|
|
||||||
def _checkout_build_corpus_service(corpus):
|
def _checkout_build_corpus_service(corpus: Corpus):
|
||||||
service_name = f'build-corpus_{corpus.id}'
|
service_name = f'build-corpus_{corpus.id}'
|
||||||
try:
|
try:
|
||||||
service = docker_client.services.get(service_name)
|
service = docker_client.services.get(service_name)
|
||||||
@@ -123,8 +126,7 @@ def _checkout_build_corpus_service(corpus):
|
|||||||
except docker.errors.DockerException as e:
|
except docker.errors.DockerException as e:
|
||||||
current_app.logger.error(f'Remove service "{service_name}" failed: {e}')
|
current_app.logger.error(f'Remove service "{service_name}" failed: {e}')
|
||||||
|
|
||||||
def _create_cqpserver_container(corpus):
|
def _create_cqpserver_container(corpus: Corpus):
|
||||||
''' # Docker container settings # '''
|
|
||||||
''' ## Command ## '''
|
''' ## Command ## '''
|
||||||
command = []
|
command = []
|
||||||
command.append(
|
command.append(
|
||||||
@@ -139,9 +141,9 @@ def _create_cqpserver_container(corpus):
|
|||||||
''' ## Entrypoint ## '''
|
''' ## Entrypoint ## '''
|
||||||
entrypoint = ['bash', '-c']
|
entrypoint = ['bash', '-c']
|
||||||
''' ## Image ## '''
|
''' ## Image ## '''
|
||||||
image = f'{current_app.config["NOPAQUE_DOCKER_IMAGE_PREFIX"]}cwb:r1879'
|
image = f'{current_app.config["NOPAQUE_DOCKER_IMAGE_PREFIX"]}cwb:r1887'
|
||||||
''' ## Name ## '''
|
''' ## Name ## '''
|
||||||
name = f'cqpserver_{corpus.id}'
|
name = f'nopaque-cqpserver-{corpus.id}'
|
||||||
''' ## Network ## '''
|
''' ## Network ## '''
|
||||||
network = f'{current_app.config["NOPAQUE_DOCKER_NETWORK_NAME"]}'
|
network = f'{current_app.config["NOPAQUE_DOCKER_NETWORK_NAME"]}'
|
||||||
''' ## Volumes ## '''
|
''' ## Volumes ## '''
|
||||||
@@ -198,8 +200,8 @@ def _create_cqpserver_container(corpus):
|
|||||||
return
|
return
|
||||||
corpus.status = CorpusStatus.RUNNING_ANALYSIS_SESSION
|
corpus.status = CorpusStatus.RUNNING_ANALYSIS_SESSION
|
||||||
|
|
||||||
def _checkout_analysing_corpus_container(corpus):
|
def _checkout_cqpserver_container(corpus: Corpus):
|
||||||
container_name = f'cqpserver_{corpus.id}'
|
container_name = f'nopaque-cqpserver-{corpus.id}'
|
||||||
try:
|
try:
|
||||||
docker_client.containers.get(container_name)
|
docker_client.containers.get(container_name)
|
||||||
except docker.errors.NotFound as e:
|
except docker.errors.NotFound as e:
|
||||||
@@ -209,8 +211,8 @@ def _checkout_analysing_corpus_container(corpus):
|
|||||||
except docker.errors.DockerException as e:
|
except docker.errors.DockerException as e:
|
||||||
current_app.logger.error(f'Get container "{container_name}" failed: {e}')
|
current_app.logger.error(f'Get container "{container_name}" failed: {e}')
|
||||||
|
|
||||||
def _remove_cqpserver_container(corpus):
|
def _remove_cqpserver_container(corpus: Corpus):
|
||||||
container_name = f'cqpserver_{corpus.id}'
|
container_name = f'nopaque-cqpserver-{corpus.id}'
|
||||||
try:
|
try:
|
||||||
container = docker_client.containers.get(container_name)
|
container = docker_client.containers.get(container_name)
|
||||||
except docker.errors.NotFound:
|
except docker.errors.NotFound:
|
||||||
@@ -1,11 +1,3 @@
|
|||||||
from app import db, docker_client, hashids
|
|
||||||
from app.models import (
|
|
||||||
Job,
|
|
||||||
JobResult,
|
|
||||||
JobStatus,
|
|
||||||
TesseractOCRPipelineModel,
|
|
||||||
SpaCyNLPPipelineModel
|
|
||||||
)
|
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from flask import current_app
|
from flask import current_app
|
||||||
from werkzeug.utils import secure_filename
|
from werkzeug.utils import secure_filename
|
||||||
@@ -13,9 +5,21 @@ import docker
|
|||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
import shutil
|
import shutil
|
||||||
|
from app import db, docker_client, hashids, scheduler
|
||||||
|
from app.models import (
|
||||||
|
Job,
|
||||||
|
JobResult,
|
||||||
|
JobStatus,
|
||||||
|
TesseractOCRPipelineModel,
|
||||||
|
SpaCyNLPPipelineModel
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def check_jobs():
|
def handle_jobs():
|
||||||
|
with scheduler.app.app_context():
|
||||||
|
_handle_jobs()
|
||||||
|
|
||||||
|
def _handle_jobs():
|
||||||
jobs = Job.query.all()
|
jobs = Job.query.all()
|
||||||
for job in [x for x in jobs if x.status == JobStatus.SUBMITTED]:
|
for job in [x for x in jobs if x.status == JobStatus.SUBMITTED]:
|
||||||
_create_job_service(job)
|
_create_job_service(job)
|
||||||
@@ -23,8 +27,9 @@ def check_jobs():
|
|||||||
_checkout_job_service(job)
|
_checkout_job_service(job)
|
||||||
for job in [x for x in jobs if x.status == JobStatus.CANCELING]:
|
for job in [x for x in jobs if x.status == JobStatus.CANCELING]:
|
||||||
_remove_job_service(job)
|
_remove_job_service(job)
|
||||||
|
db.session.commit()
|
||||||
|
|
||||||
def _create_job_service(job):
|
def _create_job_service(job: Job):
|
||||||
''' # Docker service settings # '''
|
''' # Docker service settings # '''
|
||||||
''' ## Service specific settings ## '''
|
''' ## Service specific settings ## '''
|
||||||
if job.service == 'file-setup-pipeline':
|
if job.service == 'file-setup-pipeline':
|
||||||
@@ -81,9 +86,7 @@ def _create_job_service(job):
|
|||||||
constraints = ['node.role==worker']
|
constraints = ['node.role==worker']
|
||||||
''' ## Labels ## '''
|
''' ## Labels ## '''
|
||||||
labels = {
|
labels = {
|
||||||
'origin': current_app.config['SERVER_NAME'],
|
'origin': current_app.config['SERVER_NAME']
|
||||||
'type': 'job',
|
|
||||||
'job_id': str(job.id)
|
|
||||||
}
|
}
|
||||||
''' ## Mounts ## '''
|
''' ## Mounts ## '''
|
||||||
mounts = []
|
mounts = []
|
||||||
@@ -164,7 +167,7 @@ def _create_job_service(job):
|
|||||||
return
|
return
|
||||||
job.status = JobStatus.QUEUED
|
job.status = JobStatus.QUEUED
|
||||||
|
|
||||||
def _checkout_job_service(job):
|
def _checkout_job_service(job: Job):
|
||||||
service_name = f'job_{job.id}'
|
service_name = f'job_{job.id}'
|
||||||
try:
|
try:
|
||||||
service = docker_client.services.get(service_name)
|
service = docker_client.services.get(service_name)
|
||||||
@@ -213,7 +216,7 @@ def _checkout_job_service(job):
|
|||||||
except docker.errors.DockerException as e:
|
except docker.errors.DockerException as e:
|
||||||
current_app.logger.error(f'Remove service "{service_name}" failed: {e}')
|
current_app.logger.error(f'Remove service "{service_name}" failed: {e}')
|
||||||
|
|
||||||
def _remove_job_service(job):
|
def _remove_job_service(job: Job):
|
||||||
service_name = f'job_{job.id}'
|
service_name = f'job_{job.id}'
|
||||||
try:
|
try:
|
||||||
service = docker_client.services.get(service_name)
|
service = docker_client.services.get(service_name)
|
||||||
@@ -1,72 +0,0 @@
|
|||||||
from flask import abort, current_app
|
|
||||||
from flask_login import current_user
|
|
||||||
from threading import Thread
|
|
||||||
from app import db
|
|
||||||
from app.decorators import admin_required, content_negotiation
|
|
||||||
from app.models import Job, JobStatus
|
|
||||||
from . import bp
|
|
||||||
|
|
||||||
|
|
||||||
@bp.route('/<hashid:job_id>', methods=['DELETE'])
|
|
||||||
@content_negotiation(produces='application/json')
|
|
||||||
def delete_job(job_id):
|
|
||||||
def _delete_job(app, job_id):
|
|
||||||
with app.app_context():
|
|
||||||
job = Job.query.get(job_id)
|
|
||||||
job.delete()
|
|
||||||
db.session.commit()
|
|
||||||
|
|
||||||
job = Job.query.get_or_404(job_id)
|
|
||||||
if not (job.user == current_user or current_user.is_administrator):
|
|
||||||
abort(403)
|
|
||||||
thread = Thread(
|
|
||||||
target=_delete_job,
|
|
||||||
args=(current_app._get_current_object(), job_id)
|
|
||||||
)
|
|
||||||
thread.start()
|
|
||||||
response_data = {
|
|
||||||
'message': f'Job "{job.title}" marked for deletion'
|
|
||||||
}
|
|
||||||
return response_data, 202
|
|
||||||
|
|
||||||
|
|
||||||
@bp.route('/<hashid:job_id>/log')
|
|
||||||
@admin_required
|
|
||||||
@content_negotiation(produces='application/json')
|
|
||||||
def job_log(job_id):
|
|
||||||
job = Job.query.get_or_404(job_id)
|
|
||||||
if job.status not in [JobStatus.COMPLETED, JobStatus.FAILED]:
|
|
||||||
response = {'errors': {'message': 'Job status is not completed or failed'}}
|
|
||||||
return response, 409
|
|
||||||
with open(job.path / 'pipeline_data' / 'logs' / 'pyflow_log.txt') as log_file:
|
|
||||||
log = log_file.read()
|
|
||||||
response_data = {
|
|
||||||
'jobLog': log
|
|
||||||
}
|
|
||||||
return response_data, 200
|
|
||||||
|
|
||||||
|
|
||||||
@bp.route('/<hashid:job_id>/restart', methods=['POST'])
|
|
||||||
@content_negotiation(produces='application/json')
|
|
||||||
def restart_job(job_id):
|
|
||||||
def _restart_job(app, job_id):
|
|
||||||
with app.app_context():
|
|
||||||
job = Job.query.get(job_id)
|
|
||||||
job.restart()
|
|
||||||
db.session.commit()
|
|
||||||
|
|
||||||
job = Job.query.get_or_404(job_id)
|
|
||||||
if not (job.user == current_user or current_user.is_administrator):
|
|
||||||
abort(403)
|
|
||||||
if job.status == JobStatus.FAILED:
|
|
||||||
response = {'errors': {'message': 'Job status is not "failed"'}}
|
|
||||||
return response, 409
|
|
||||||
thread = Thread(
|
|
||||||
target=_restart_job,
|
|
||||||
args=(current_app._get_current_object(), job_id)
|
|
||||||
)
|
|
||||||
thread.start()
|
|
||||||
response_data = {
|
|
||||||
'message': f'Job "{job.title}" marked for restarting'
|
|
||||||
}
|
|
||||||
return response_data, 202
|
|
||||||
@@ -1,56 +0,0 @@
|
|||||||
from flask import (
|
|
||||||
abort,
|
|
||||||
redirect,
|
|
||||||
render_template,
|
|
||||||
send_from_directory,
|
|
||||||
url_for
|
|
||||||
)
|
|
||||||
from flask_login import current_user
|
|
||||||
from app.models import Job, JobInput, JobResult
|
|
||||||
from . import bp
|
|
||||||
|
|
||||||
|
|
||||||
@bp.route('')
|
|
||||||
def jobs():
|
|
||||||
# return redirect(url_for('main.dashboard', _anchor='jobs'))
|
|
||||||
return render_template('jobs/jobs.html.j2', title='Jobs')
|
|
||||||
|
|
||||||
|
|
||||||
@bp.route('/<hashid:job_id>')
|
|
||||||
def job(job_id):
|
|
||||||
job = Job.query.get_or_404(job_id)
|
|
||||||
if not (job.user == current_user or current_user.is_administrator):
|
|
||||||
abort(403)
|
|
||||||
return render_template(
|
|
||||||
'jobs/job.html.j2',
|
|
||||||
title='Job',
|
|
||||||
job=job
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
@bp.route('/<hashid:job_id>/inputs/<hashid:job_input_id>/download')
|
|
||||||
def download_job_input(job_id, job_input_id):
|
|
||||||
job_input = JobInput.query.filter_by(job_id=job_id, id=job_input_id).first_or_404()
|
|
||||||
if not (job_input.job.user == current_user or current_user.is_administrator):
|
|
||||||
abort(403)
|
|
||||||
return send_from_directory(
|
|
||||||
job_input.path.parent,
|
|
||||||
job_input.path.name,
|
|
||||||
as_attachment=True,
|
|
||||||
download_name=job_input.filename,
|
|
||||||
mimetype=job_input.mimetype
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
@bp.route('/<hashid:job_id>/results/<hashid:job_result_id>/download')
|
|
||||||
def download_job_result(job_id, job_result_id):
|
|
||||||
job_result = JobResult.query.filter_by(job_id=job_id, id=job_result_id).first_or_404()
|
|
||||||
if not (job_result.job.user == current_user or current_user.is_administrator):
|
|
||||||
abort(403)
|
|
||||||
return send_from_directory(
|
|
||||||
job_result.path.parent,
|
|
||||||
job_result.path.name,
|
|
||||||
as_attachment=True,
|
|
||||||
download_name=job_result.filename,
|
|
||||||
mimetype=job_result.mimetype
|
|
||||||
)
|
|
||||||
+45
-14
@@ -1,14 +1,45 @@
|
|||||||
from .anonymous_user import *
|
from .anonymous_user import AnonymousUser
|
||||||
from .avatar import *
|
from .avatar import Avatar
|
||||||
from .corpus_file import *
|
from .corpus_file import CorpusFile
|
||||||
from .corpus_follower_association import *
|
from .corpus_follower_association import CorpusFollowerAssociation
|
||||||
from .corpus_follower_role import *
|
from .corpus_follower_role import CorpusFollowerPermission, CorpusFollowerRole
|
||||||
from .corpus import *
|
from .corpus import CorpusStatus, Corpus
|
||||||
from .job_input import *
|
from .job_input import JobInput
|
||||||
from .job_result import *
|
from .job_result import JobResult
|
||||||
from .job import *
|
from .job import JobStatus, Job
|
||||||
from .role import *
|
from .role import Permission, Role
|
||||||
from .spacy_nlp_pipeline_model import *
|
from .spacy_nlp_pipeline_model import SpaCyNLPPipelineModel
|
||||||
from .tesseract_ocr_pipeline_model import *
|
from .tesseract_ocr_pipeline_model import TesseractOCRPipelineModel
|
||||||
from .token import *
|
from .token import Token
|
||||||
from .user import *
|
from .user import (
|
||||||
|
ProfilePrivacySettings,
|
||||||
|
UserSettingJobStatusMailNotificationLevel,
|
||||||
|
User
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
_models = [
|
||||||
|
Avatar,
|
||||||
|
CorpusFile,
|
||||||
|
CorpusFollowerAssociation,
|
||||||
|
CorpusFollowerRole,
|
||||||
|
Corpus,
|
||||||
|
JobInput,
|
||||||
|
JobResult,
|
||||||
|
Job,
|
||||||
|
Role,
|
||||||
|
SpaCyNLPPipelineModel,
|
||||||
|
TesseractOCRPipelineModel,
|
||||||
|
Token,
|
||||||
|
User
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
_enums = [
|
||||||
|
CorpusFollowerPermission,
|
||||||
|
CorpusStatus,
|
||||||
|
JobStatus,
|
||||||
|
Permission,
|
||||||
|
ProfilePrivacySettings,
|
||||||
|
UserSettingJobStatusMailNotificationLevel
|
||||||
|
]
|
||||||
@@ -3,13 +3,12 @@ from enum import IntEnum
|
|||||||
from flask import current_app, url_for
|
from flask import current_app, url_for
|
||||||
from flask_hashids import HashidMixin
|
from flask_hashids import HashidMixin
|
||||||
from sqlalchemy.ext.associationproxy import association_proxy
|
from sqlalchemy.ext.associationproxy import association_proxy
|
||||||
from typing import Union
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
import shutil
|
import shutil
|
||||||
import xml.etree.ElementTree as ET
|
import xml.etree.ElementTree as ET
|
||||||
from app import db
|
from app import db
|
||||||
from app.converters.vrt import normalize_vrt_file
|
from app.converters.vrt import normalize_vrt_file
|
||||||
from app.extensions.sqlalchemy_extras import IntEnumColumn
|
from app.extensions.nopaque_sqlalchemy_type_decorators import IntEnumColumn
|
||||||
from .corpus_follower_association import CorpusFollowerAssociation
|
from .corpus_follower_association import CorpusFollowerAssociation
|
||||||
|
|
||||||
|
|
||||||
@@ -25,7 +24,7 @@ class CorpusStatus(IntEnum):
|
|||||||
CANCELING_ANALYSIS_SESSION = 9
|
CANCELING_ANALYSIS_SESSION = 9
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get(corpus_status: Union['CorpusStatus', int, str]) -> 'CorpusStatus':
|
def get(corpus_status: 'CorpusStatus | int | str') -> 'CorpusStatus':
|
||||||
if isinstance(corpus_status, CorpusStatus):
|
if isinstance(corpus_status, CorpusStatus):
|
||||||
return corpus_status
|
return corpus_status
|
||||||
if isinstance(corpus_status, int):
|
if isinstance(corpus_status, int):
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
from flask_hashids import HashidMixin
|
from flask_hashids import HashidMixin
|
||||||
from enum import IntEnum
|
from enum import IntEnum
|
||||||
from typing import Union
|
|
||||||
from app import db
|
from app import db
|
||||||
|
|
||||||
|
|
||||||
@@ -11,7 +10,7 @@ class CorpusFollowerPermission(IntEnum):
|
|||||||
MANAGE_CORPUS = 8
|
MANAGE_CORPUS = 8
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get(corpus_follower_permission: Union['CorpusFollowerPermission', int, str]) -> 'CorpusFollowerPermission':
|
def get(corpus_follower_permission: 'CorpusFollowerPermission | int | str') -> 'CorpusFollowerPermission':
|
||||||
if isinstance(corpus_follower_permission, CorpusFollowerPermission):
|
if isinstance(corpus_follower_permission, CorpusFollowerPermission):
|
||||||
return corpus_follower_permission
|
return corpus_follower_permission
|
||||||
if isinstance(corpus_follower_permission, int):
|
if isinstance(corpus_follower_permission, int):
|
||||||
@@ -38,16 +37,16 @@ class CorpusFollowerRole(HashidMixin, db.Model):
|
|||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return f'<CorpusFollowerRole {self.name}>'
|
return f'<CorpusFollowerRole {self.name}>'
|
||||||
|
|
||||||
def has_permission(self, permission: Union[CorpusFollowerPermission, int, str]):
|
def has_permission(self, permission: CorpusFollowerPermission | int | str):
|
||||||
perm = CorpusFollowerPermission.get(permission)
|
perm = CorpusFollowerPermission.get(permission)
|
||||||
return self.permissions & perm.value == perm.value
|
return self.permissions & perm.value == perm.value
|
||||||
|
|
||||||
def add_permission(self, permission: Union[CorpusFollowerPermission, int, str]):
|
def add_permission(self, permission: CorpusFollowerPermission | int | str):
|
||||||
perm = CorpusFollowerPermission.get(permission)
|
perm = CorpusFollowerPermission.get(permission)
|
||||||
if not self.has_permission(perm):
|
if not self.has_permission(perm):
|
||||||
self.permissions += perm.value
|
self.permissions += perm.value
|
||||||
|
|
||||||
def remove_permission(self, permission: Union[CorpusFollowerPermission, int, str]):
|
def remove_permission(self, permission: CorpusFollowerPermission | int | str):
|
||||||
perm = CorpusFollowerPermission.get(permission)
|
perm = CorpusFollowerPermission.get(permission)
|
||||||
if self.has_permission(perm):
|
if self.has_permission(perm):
|
||||||
self.permissions -= perm.value
|
self.permissions -= perm.value
|
||||||
|
|||||||
@@ -10,6 +10,7 @@
|
|||||||
# - '0.1.0'
|
# - '0.1.0'
|
||||||
# - '0.1.1'
|
# - '0.1.1'
|
||||||
# - '0.1.2'
|
# - '0.1.2'
|
||||||
|
# - '0.1.3b'
|
||||||
# - title: 'Amharic'
|
# - title: 'Amharic'
|
||||||
# description: ''
|
# description: ''
|
||||||
# url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/amh.traineddata'
|
# url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/amh.traineddata'
|
||||||
@@ -22,6 +23,7 @@
|
|||||||
# - '0.1.0'
|
# - '0.1.0'
|
||||||
# - '0.1.1'
|
# - '0.1.1'
|
||||||
# - '0.1.2'
|
# - '0.1.2'
|
||||||
|
# - '0.1.3b'
|
||||||
- title: 'Arabic'
|
- title: 'Arabic'
|
||||||
description: ''
|
description: ''
|
||||||
url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/ara.traineddata'
|
url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/ara.traineddata'
|
||||||
@@ -34,6 +36,7 @@
|
|||||||
- '0.1.0'
|
- '0.1.0'
|
||||||
- '0.1.1'
|
- '0.1.1'
|
||||||
- '0.1.2'
|
- '0.1.2'
|
||||||
|
- '0.1.3b'
|
||||||
# - title: 'Assamese'
|
# - title: 'Assamese'
|
||||||
# description: ''
|
# description: ''
|
||||||
# url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/asm.traineddata'
|
# url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/asm.traineddata'
|
||||||
@@ -46,6 +49,7 @@
|
|||||||
# - '0.1.0'
|
# - '0.1.0'
|
||||||
# - '0.1.1'
|
# - '0.1.1'
|
||||||
# - '0.1.2'
|
# - '0.1.2'
|
||||||
|
# - '0.1.3b'
|
||||||
# - title: 'Azerbaijani'
|
# - title: 'Azerbaijani'
|
||||||
# description: ''
|
# description: ''
|
||||||
# url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/aze.traineddata'
|
# url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/aze.traineddata'
|
||||||
@@ -58,6 +62,7 @@
|
|||||||
# - '0.1.0'
|
# - '0.1.0'
|
||||||
# - '0.1.1'
|
# - '0.1.1'
|
||||||
# - '0.1.2'
|
# - '0.1.2'
|
||||||
|
# - '0.1.3b'
|
||||||
# - title: 'Azerbaijani - Cyrillic'
|
# - title: 'Azerbaijani - Cyrillic'
|
||||||
# description: ''
|
# description: ''
|
||||||
# url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/aze_cyrl.traineddata'
|
# url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/aze_cyrl.traineddata'
|
||||||
@@ -70,6 +75,7 @@
|
|||||||
# - '0.1.0'
|
# - '0.1.0'
|
||||||
# - '0.1.1'
|
# - '0.1.1'
|
||||||
# - '0.1.2'
|
# - '0.1.2'
|
||||||
|
# - '0.1.3b'
|
||||||
# - title: 'Belarusian'
|
# - title: 'Belarusian'
|
||||||
# description: ''
|
# description: ''
|
||||||
# url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/bel.traineddata'
|
# url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/bel.traineddata'
|
||||||
@@ -82,6 +88,7 @@
|
|||||||
# - '0.1.0'
|
# - '0.1.0'
|
||||||
# - '0.1.1'
|
# - '0.1.1'
|
||||||
# - '0.1.2'
|
# - '0.1.2'
|
||||||
|
# - '0.1.3b'
|
||||||
# - title: 'Bengali'
|
# - title: 'Bengali'
|
||||||
# description: ''
|
# description: ''
|
||||||
# url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/ben.traineddata'
|
# url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/ben.traineddata'
|
||||||
@@ -94,6 +101,7 @@
|
|||||||
# - '0.1.0'
|
# - '0.1.0'
|
||||||
# - '0.1.1'
|
# - '0.1.1'
|
||||||
# - '0.1.2'
|
# - '0.1.2'
|
||||||
|
# - '0.1.3b'
|
||||||
# - title: 'Tibetan'
|
# - title: 'Tibetan'
|
||||||
# description: ''
|
# description: ''
|
||||||
# url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/bod.traineddata'
|
# url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/bod.traineddata'
|
||||||
@@ -106,6 +114,7 @@
|
|||||||
# - '0.1.0'
|
# - '0.1.0'
|
||||||
# - '0.1.1'
|
# - '0.1.1'
|
||||||
# - '0.1.2'
|
# - '0.1.2'
|
||||||
|
# - '0.1.3b'
|
||||||
# - title: 'Bosnian'
|
# - title: 'Bosnian'
|
||||||
# description: ''
|
# description: ''
|
||||||
# url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/bos.traineddata'
|
# url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/bos.traineddata'
|
||||||
@@ -118,6 +127,7 @@
|
|||||||
# - '0.1.0'
|
# - '0.1.0'
|
||||||
# - '0.1.1'
|
# - '0.1.1'
|
||||||
# - '0.1.2'
|
# - '0.1.2'
|
||||||
|
# - '0.1.3b'
|
||||||
# - title: 'Bulgarian'
|
# - title: 'Bulgarian'
|
||||||
# description: ''
|
# description: ''
|
||||||
# url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/bul.traineddata'
|
# url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/bul.traineddata'
|
||||||
@@ -130,6 +140,7 @@
|
|||||||
# - '0.1.0'
|
# - '0.1.0'
|
||||||
# - '0.1.1'
|
# - '0.1.1'
|
||||||
# - '0.1.2'
|
# - '0.1.2'
|
||||||
|
# - '0.1.3b'
|
||||||
# - title: 'Catalan; Valencian'
|
# - title: 'Catalan; Valencian'
|
||||||
# description: ''
|
# description: ''
|
||||||
# url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/cat.traineddata'
|
# url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/cat.traineddata'
|
||||||
@@ -142,6 +153,7 @@
|
|||||||
# - '0.1.0'
|
# - '0.1.0'
|
||||||
# - '0.1.1'
|
# - '0.1.1'
|
||||||
# - '0.1.2'
|
# - '0.1.2'
|
||||||
|
# - '0.1.3b'
|
||||||
# - title: 'Cebuano'
|
# - title: 'Cebuano'
|
||||||
# description: ''
|
# description: ''
|
||||||
# url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/ceb.traineddata'
|
# url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/ceb.traineddata'
|
||||||
@@ -154,6 +166,7 @@
|
|||||||
# - '0.1.0'
|
# - '0.1.0'
|
||||||
# - '0.1.1'
|
# - '0.1.1'
|
||||||
# - '0.1.2'
|
# - '0.1.2'
|
||||||
|
# - '0.1.3b'
|
||||||
# - title: 'Czech'
|
# - title: 'Czech'
|
||||||
# description: ''
|
# description: ''
|
||||||
# url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/ces.traineddata'
|
# url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/ces.traineddata'
|
||||||
@@ -166,6 +179,7 @@
|
|||||||
# - '0.1.0'
|
# - '0.1.0'
|
||||||
# - '0.1.1'
|
# - '0.1.1'
|
||||||
# - '0.1.2'
|
# - '0.1.2'
|
||||||
|
# - '0.1.3b'
|
||||||
# - title: 'Chinese - Simplified'
|
# - title: 'Chinese - Simplified'
|
||||||
# description: ''
|
# description: ''
|
||||||
# url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/chi_sim.traineddata'
|
# url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/chi_sim.traineddata'
|
||||||
@@ -178,6 +192,7 @@
|
|||||||
# - '0.1.0'
|
# - '0.1.0'
|
||||||
# - '0.1.1'
|
# - '0.1.1'
|
||||||
# - '0.1.2'
|
# - '0.1.2'
|
||||||
|
# - '0.1.3b'
|
||||||
- title: 'Chinese - Traditional'
|
- title: 'Chinese - Traditional'
|
||||||
description: ''
|
description: ''
|
||||||
url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/chi_tra.traineddata'
|
url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/chi_tra.traineddata'
|
||||||
@@ -190,6 +205,7 @@
|
|||||||
- '0.1.0'
|
- '0.1.0'
|
||||||
- '0.1.1'
|
- '0.1.1'
|
||||||
- '0.1.2'
|
- '0.1.2'
|
||||||
|
- '0.1.3b'
|
||||||
# - title: 'Cherokee'
|
# - title: 'Cherokee'
|
||||||
# description: ''
|
# description: ''
|
||||||
# url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/chr.traineddata'
|
# url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/chr.traineddata'
|
||||||
@@ -202,6 +218,7 @@
|
|||||||
# - '0.1.0'
|
# - '0.1.0'
|
||||||
# - '0.1.1'
|
# - '0.1.1'
|
||||||
# - '0.1.2'
|
# - '0.1.2'
|
||||||
|
# - '0.1.3b'
|
||||||
# - title: 'Welsh'
|
# - title: 'Welsh'
|
||||||
# description: ''
|
# description: ''
|
||||||
# url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/cym.traineddata'
|
# url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/cym.traineddata'
|
||||||
@@ -214,6 +231,7 @@
|
|||||||
# - '0.1.0'
|
# - '0.1.0'
|
||||||
# - '0.1.1'
|
# - '0.1.1'
|
||||||
# - '0.1.2'
|
# - '0.1.2'
|
||||||
|
# - '0.1.3b'
|
||||||
- title: 'Danish'
|
- title: 'Danish'
|
||||||
description: ''
|
description: ''
|
||||||
url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/dan.traineddata'
|
url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/dan.traineddata'
|
||||||
@@ -226,6 +244,7 @@
|
|||||||
- '0.1.0'
|
- '0.1.0'
|
||||||
- '0.1.1'
|
- '0.1.1'
|
||||||
- '0.1.2'
|
- '0.1.2'
|
||||||
|
- '0.1.3b'
|
||||||
- title: 'German'
|
- title: 'German'
|
||||||
description: ''
|
description: ''
|
||||||
url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/deu.traineddata'
|
url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/deu.traineddata'
|
||||||
@@ -238,6 +257,7 @@
|
|||||||
- '0.1.0'
|
- '0.1.0'
|
||||||
- '0.1.1'
|
- '0.1.1'
|
||||||
- '0.1.2'
|
- '0.1.2'
|
||||||
|
- '0.1.3b'
|
||||||
# - title: 'Dzongkha'
|
# - title: 'Dzongkha'
|
||||||
# description: ''
|
# description: ''
|
||||||
# url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/dzo.traineddata'
|
# url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/dzo.traineddata'
|
||||||
@@ -250,6 +270,7 @@
|
|||||||
# - '0.1.0'
|
# - '0.1.0'
|
||||||
# - '0.1.1'
|
# - '0.1.1'
|
||||||
# - '0.1.2'
|
# - '0.1.2'
|
||||||
|
# - '0.1.3b'
|
||||||
- title: 'Greek, Modern (1453-)'
|
- title: 'Greek, Modern (1453-)'
|
||||||
description: ''
|
description: ''
|
||||||
url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/ell.traineddata'
|
url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/ell.traineddata'
|
||||||
@@ -262,6 +283,7 @@
|
|||||||
- '0.1.0'
|
- '0.1.0'
|
||||||
- '0.1.1'
|
- '0.1.1'
|
||||||
- '0.1.2'
|
- '0.1.2'
|
||||||
|
- '0.1.3b'
|
||||||
- title: 'English'
|
- title: 'English'
|
||||||
description: ''
|
description: ''
|
||||||
url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/eng.traineddata'
|
url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/eng.traineddata'
|
||||||
@@ -274,6 +296,7 @@
|
|||||||
- '0.1.0'
|
- '0.1.0'
|
||||||
- '0.1.1'
|
- '0.1.1'
|
||||||
- '0.1.2'
|
- '0.1.2'
|
||||||
|
- '0.1.3b'
|
||||||
- title: 'English, Middle (1100-1500)'
|
- title: 'English, Middle (1100-1500)'
|
||||||
description: ''
|
description: ''
|
||||||
url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/enm.traineddata'
|
url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/enm.traineddata'
|
||||||
@@ -286,6 +309,7 @@
|
|||||||
- '0.1.0'
|
- '0.1.0'
|
||||||
- '0.1.1'
|
- '0.1.1'
|
||||||
- '0.1.2'
|
- '0.1.2'
|
||||||
|
- '0.1.3b'
|
||||||
# - title: 'Esperanto'
|
# - title: 'Esperanto'
|
||||||
# description: ''
|
# description: ''
|
||||||
# url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/epo.traineddata'
|
# url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/epo.traineddata'
|
||||||
@@ -298,6 +322,7 @@
|
|||||||
# - '0.1.0'
|
# - '0.1.0'
|
||||||
# - '0.1.1'
|
# - '0.1.1'
|
||||||
# - '0.1.2'
|
# - '0.1.2'
|
||||||
|
# - '0.1.3b'
|
||||||
# - title: 'Estonian'
|
# - title: 'Estonian'
|
||||||
# description: ''
|
# description: ''
|
||||||
# url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/est.traineddata'
|
# url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/est.traineddata'
|
||||||
@@ -310,6 +335,7 @@
|
|||||||
# - '0.1.0'
|
# - '0.1.0'
|
||||||
# - '0.1.1'
|
# - '0.1.1'
|
||||||
# - '0.1.2'
|
# - '0.1.2'
|
||||||
|
# - '0.1.3b'
|
||||||
# - title: 'Basque'
|
# - title: 'Basque'
|
||||||
# description: ''
|
# description: ''
|
||||||
# url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/eus.traineddata'
|
# url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/eus.traineddata'
|
||||||
@@ -322,6 +348,7 @@
|
|||||||
# - '0.1.0'
|
# - '0.1.0'
|
||||||
# - '0.1.1'
|
# - '0.1.1'
|
||||||
# - '0.1.2'
|
# - '0.1.2'
|
||||||
|
# - '0.1.3b'
|
||||||
# - title: 'Persian'
|
# - title: 'Persian'
|
||||||
# description: ''
|
# description: ''
|
||||||
# url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/fas.traineddata'
|
# url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/fas.traineddata'
|
||||||
@@ -334,6 +361,7 @@
|
|||||||
# - '0.1.0'
|
# - '0.1.0'
|
||||||
# - '0.1.1'
|
# - '0.1.1'
|
||||||
# - '0.1.2'
|
# - '0.1.2'
|
||||||
|
# - '0.1.3b'
|
||||||
# - title: 'Finnish'
|
# - title: 'Finnish'
|
||||||
# description: ''
|
# description: ''
|
||||||
# url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/fin.traineddata'
|
# url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/fin.traineddata'
|
||||||
@@ -346,6 +374,7 @@
|
|||||||
# - '0.1.0'
|
# - '0.1.0'
|
||||||
# - '0.1.1'
|
# - '0.1.1'
|
||||||
# - '0.1.2'
|
# - '0.1.2'
|
||||||
|
# - '0.1.3b'
|
||||||
- title: 'French'
|
- title: 'French'
|
||||||
description: ''
|
description: ''
|
||||||
url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/fra.traineddata'
|
url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/fra.traineddata'
|
||||||
@@ -358,6 +387,7 @@
|
|||||||
- '0.1.0'
|
- '0.1.0'
|
||||||
- '0.1.1'
|
- '0.1.1'
|
||||||
- '0.1.2'
|
- '0.1.2'
|
||||||
|
- '0.1.3b'
|
||||||
- title: 'German Fraktur'
|
- title: 'German Fraktur'
|
||||||
description: ''
|
description: ''
|
||||||
url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/frk.traineddata'
|
url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/frk.traineddata'
|
||||||
@@ -370,6 +400,7 @@
|
|||||||
- '0.1.0'
|
- '0.1.0'
|
||||||
- '0.1.1'
|
- '0.1.1'
|
||||||
- '0.1.2'
|
- '0.1.2'
|
||||||
|
- '0.1.3b'
|
||||||
- title: 'French, Middle (ca. 1400-1600)'
|
- title: 'French, Middle (ca. 1400-1600)'
|
||||||
description: ''
|
description: ''
|
||||||
url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/frm.traineddata'
|
url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/frm.traineddata'
|
||||||
@@ -382,6 +413,7 @@
|
|||||||
- '0.1.0'
|
- '0.1.0'
|
||||||
- '0.1.1'
|
- '0.1.1'
|
||||||
- '0.1.2'
|
- '0.1.2'
|
||||||
|
- '0.1.3b'
|
||||||
# - title: 'Irish'
|
# - title: 'Irish'
|
||||||
# description: ''
|
# description: ''
|
||||||
# url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/gle.traineddata'
|
# url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/gle.traineddata'
|
||||||
@@ -394,6 +426,7 @@
|
|||||||
# - '0.1.0'
|
# - '0.1.0'
|
||||||
# - '0.1.1'
|
# - '0.1.1'
|
||||||
# - '0.1.2'
|
# - '0.1.2'
|
||||||
|
# - '0.1.3b'
|
||||||
# - title: 'Galician'
|
# - title: 'Galician'
|
||||||
# description: ''
|
# description: ''
|
||||||
# url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/glg.traineddata'
|
# url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/glg.traineddata'
|
||||||
@@ -406,6 +439,7 @@
|
|||||||
# - '0.1.0'
|
# - '0.1.0'
|
||||||
# - '0.1.1'
|
# - '0.1.1'
|
||||||
# - '0.1.2'
|
# - '0.1.2'
|
||||||
|
# - '0.1.3b'
|
||||||
- title: 'Greek, Ancient (-1453)'
|
- title: 'Greek, Ancient (-1453)'
|
||||||
description: ''
|
description: ''
|
||||||
url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/grc.traineddata'
|
url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/grc.traineddata'
|
||||||
@@ -418,6 +452,7 @@
|
|||||||
- '0.1.0'
|
- '0.1.0'
|
||||||
- '0.1.1'
|
- '0.1.1'
|
||||||
- '0.1.2'
|
- '0.1.2'
|
||||||
|
- '0.1.3b'
|
||||||
# - title: 'Gujarati'
|
# - title: 'Gujarati'
|
||||||
# description: ''
|
# description: ''
|
||||||
# url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/guj.traineddata'
|
# url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/guj.traineddata'
|
||||||
@@ -430,6 +465,7 @@
|
|||||||
# - '0.1.0'
|
# - '0.1.0'
|
||||||
# - '0.1.1'
|
# - '0.1.1'
|
||||||
# - '0.1.2'
|
# - '0.1.2'
|
||||||
|
# - '0.1.3b'
|
||||||
# - title: 'Haitian; Haitian Creole'
|
# - title: 'Haitian; Haitian Creole'
|
||||||
# description: ''
|
# description: ''
|
||||||
# url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/hat.traineddata'
|
# url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/hat.traineddata'
|
||||||
@@ -442,6 +478,7 @@
|
|||||||
# - '0.1.0'
|
# - '0.1.0'
|
||||||
# - '0.1.1'
|
# - '0.1.1'
|
||||||
# - '0.1.2'
|
# - '0.1.2'
|
||||||
|
# - '0.1.3b'
|
||||||
# - title: 'Hebrew'
|
# - title: 'Hebrew'
|
||||||
# description: ''
|
# description: ''
|
||||||
# url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/heb.traineddata'
|
# url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/heb.traineddata'
|
||||||
@@ -454,6 +491,7 @@
|
|||||||
# - '0.1.0'
|
# - '0.1.0'
|
||||||
# - '0.1.1'
|
# - '0.1.1'
|
||||||
# - '0.1.2'
|
# - '0.1.2'
|
||||||
|
# - '0.1.3b'
|
||||||
# - title: 'Hindi'
|
# - title: 'Hindi'
|
||||||
# description: ''
|
# description: ''
|
||||||
# url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/hin.traineddata'
|
# url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/hin.traineddata'
|
||||||
@@ -466,6 +504,7 @@
|
|||||||
# - '0.1.0'
|
# - '0.1.0'
|
||||||
# - '0.1.1'
|
# - '0.1.1'
|
||||||
# - '0.1.2'
|
# - '0.1.2'
|
||||||
|
# - '0.1.3b'
|
||||||
# - title: 'Croatian'
|
# - title: 'Croatian'
|
||||||
# description: ''
|
# description: ''
|
||||||
# url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/hrv.traineddata'
|
# url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/hrv.traineddata'
|
||||||
@@ -478,6 +517,7 @@
|
|||||||
# - '0.1.0'
|
# - '0.1.0'
|
||||||
# - '0.1.1'
|
# - '0.1.1'
|
||||||
# - '0.1.2'
|
# - '0.1.2'
|
||||||
|
# - '0.1.3b'
|
||||||
# - title: 'Hungarian'
|
# - title: 'Hungarian'
|
||||||
# description: ''
|
# description: ''
|
||||||
# url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/hun.traineddata'
|
# url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/hun.traineddata'
|
||||||
@@ -490,6 +530,7 @@
|
|||||||
# - '0.1.0'
|
# - '0.1.0'
|
||||||
# - '0.1.1'
|
# - '0.1.1'
|
||||||
# - '0.1.2'
|
# - '0.1.2'
|
||||||
|
# - '0.1.3b'
|
||||||
# - title: 'Inuktitut'
|
# - title: 'Inuktitut'
|
||||||
# description: ''
|
# description: ''
|
||||||
# url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/iku.traineddata'
|
# url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/iku.traineddata'
|
||||||
@@ -502,6 +543,7 @@
|
|||||||
# - '0.1.0'
|
# - '0.1.0'
|
||||||
# - '0.1.1'
|
# - '0.1.1'
|
||||||
# - '0.1.2'
|
# - '0.1.2'
|
||||||
|
# - '0.1.3b'
|
||||||
# - title: 'Indonesian'
|
# - title: 'Indonesian'
|
||||||
# description: ''
|
# description: ''
|
||||||
# url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/ind.traineddata'
|
# url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/ind.traineddata'
|
||||||
@@ -514,6 +556,7 @@
|
|||||||
# - '0.1.0'
|
# - '0.1.0'
|
||||||
# - '0.1.1'
|
# - '0.1.1'
|
||||||
# - '0.1.2'
|
# - '0.1.2'
|
||||||
|
# - '0.1.3b'
|
||||||
# - title: 'Icelandic'
|
# - title: 'Icelandic'
|
||||||
# description: ''
|
# description: ''
|
||||||
# url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/isl.traineddata'
|
# url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/isl.traineddata'
|
||||||
@@ -526,6 +569,7 @@
|
|||||||
# - '0.1.0'
|
# - '0.1.0'
|
||||||
# - '0.1.1'
|
# - '0.1.1'
|
||||||
# - '0.1.2'
|
# - '0.1.2'
|
||||||
|
# - '0.1.3b'
|
||||||
- title: 'Italian'
|
- title: 'Italian'
|
||||||
description: ''
|
description: ''
|
||||||
url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/ita.traineddata'
|
url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/ita.traineddata'
|
||||||
@@ -538,6 +582,7 @@
|
|||||||
- '0.1.0'
|
- '0.1.0'
|
||||||
- '0.1.1'
|
- '0.1.1'
|
||||||
- '0.1.2'
|
- '0.1.2'
|
||||||
|
- '0.1.3b'
|
||||||
- title: 'Italian - Old'
|
- title: 'Italian - Old'
|
||||||
description: ''
|
description: ''
|
||||||
url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/ita_old.traineddata'
|
url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/ita_old.traineddata'
|
||||||
@@ -550,6 +595,7 @@
|
|||||||
- '0.1.0'
|
- '0.1.0'
|
||||||
- '0.1.1'
|
- '0.1.1'
|
||||||
- '0.1.2'
|
- '0.1.2'
|
||||||
|
- '0.1.3b'
|
||||||
# - title: 'Javanese'
|
# - title: 'Javanese'
|
||||||
# description: ''
|
# description: ''
|
||||||
# url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/jav.traineddata'
|
# url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/jav.traineddata'
|
||||||
@@ -562,6 +608,7 @@
|
|||||||
# - '0.1.0'
|
# - '0.1.0'
|
||||||
# - '0.1.1'
|
# - '0.1.1'
|
||||||
# - '0.1.2'
|
# - '0.1.2'
|
||||||
|
# - '0.1.3b'
|
||||||
# - title: 'Japanese'
|
# - title: 'Japanese'
|
||||||
# description: ''
|
# description: ''
|
||||||
# url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/jpn.traineddata'
|
# url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/jpn.traineddata'
|
||||||
@@ -574,6 +621,7 @@
|
|||||||
# - '0.1.0'
|
# - '0.1.0'
|
||||||
# - '0.1.1'
|
# - '0.1.1'
|
||||||
# - '0.1.2'
|
# - '0.1.2'
|
||||||
|
# - '0.1.3b'
|
||||||
# - title: 'Kannada'
|
# - title: 'Kannada'
|
||||||
# description: ''
|
# description: ''
|
||||||
# url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/kan.traineddata'
|
# url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/kan.traineddata'
|
||||||
@@ -586,6 +634,7 @@
|
|||||||
# - '0.1.0'
|
# - '0.1.0'
|
||||||
# - '0.1.1'
|
# - '0.1.1'
|
||||||
# - '0.1.2'
|
# - '0.1.2'
|
||||||
|
# - '0.1.3b'
|
||||||
# - title: 'Georgian'
|
# - title: 'Georgian'
|
||||||
# description: ''
|
# description: ''
|
||||||
# url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/kat.traineddata'
|
# url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/kat.traineddata'
|
||||||
@@ -598,6 +647,7 @@
|
|||||||
# - '0.1.0'
|
# - '0.1.0'
|
||||||
# - '0.1.1'
|
# - '0.1.1'
|
||||||
# - '0.1.2'
|
# - '0.1.2'
|
||||||
|
# - '0.1.3b'
|
||||||
# - title: 'Georgian - Old'
|
# - title: 'Georgian - Old'
|
||||||
# description: ''
|
# description: ''
|
||||||
# url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/kat_old.traineddata'
|
# url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/kat_old.traineddata'
|
||||||
@@ -610,6 +660,7 @@
|
|||||||
# - '0.1.0'
|
# - '0.1.0'
|
||||||
# - '0.1.1'
|
# - '0.1.1'
|
||||||
# - '0.1.2'
|
# - '0.1.2'
|
||||||
|
# - '0.1.3b'
|
||||||
# - title: 'Kazakh'
|
# - title: 'Kazakh'
|
||||||
# description: ''
|
# description: ''
|
||||||
# url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/kaz.traineddata'
|
# url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/kaz.traineddata'
|
||||||
@@ -622,6 +673,7 @@
|
|||||||
# - '0.1.0'
|
# - '0.1.0'
|
||||||
# - '0.1.1'
|
# - '0.1.1'
|
||||||
# - '0.1.2'
|
# - '0.1.2'
|
||||||
|
# - '0.1.3b'
|
||||||
# - title: 'Central Khmer'
|
# - title: 'Central Khmer'
|
||||||
# description: ''
|
# description: ''
|
||||||
# url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/khm.traineddata'
|
# url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/khm.traineddata'
|
||||||
@@ -634,6 +686,7 @@
|
|||||||
# - '0.1.0'
|
# - '0.1.0'
|
||||||
# - '0.1.1'
|
# - '0.1.1'
|
||||||
# - '0.1.2'
|
# - '0.1.2'
|
||||||
|
# - '0.1.3b'
|
||||||
# - title: 'Kirghiz; Kyrgyz'
|
# - title: 'Kirghiz; Kyrgyz'
|
||||||
# description: ''
|
# description: ''
|
||||||
# url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/kir.traineddata'
|
# url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/kir.traineddata'
|
||||||
@@ -646,6 +699,7 @@
|
|||||||
# - '0.1.0'
|
# - '0.1.0'
|
||||||
# - '0.1.1'
|
# - '0.1.1'
|
||||||
# - '0.1.2'
|
# - '0.1.2'
|
||||||
|
# - '0.1.3b'
|
||||||
# - title: 'Korean'
|
# - title: 'Korean'
|
||||||
# description: ''
|
# description: ''
|
||||||
# url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/kor.traineddata'
|
# url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/kor.traineddata'
|
||||||
@@ -658,6 +712,7 @@
|
|||||||
# - '0.1.0'
|
# - '0.1.0'
|
||||||
# - '0.1.1'
|
# - '0.1.1'
|
||||||
# - '0.1.2'
|
# - '0.1.2'
|
||||||
|
# - '0.1.3b'
|
||||||
# - title: 'Kurdish'
|
# - title: 'Kurdish'
|
||||||
# description: ''
|
# description: ''
|
||||||
# url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/kur.traineddata'
|
# url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/kur.traineddata'
|
||||||
@@ -670,6 +725,7 @@
|
|||||||
# - '0.1.0'
|
# - '0.1.0'
|
||||||
# - '0.1.1'
|
# - '0.1.1'
|
||||||
# - '0.1.2'
|
# - '0.1.2'
|
||||||
|
# - '0.1.3b'
|
||||||
# - title: 'Lao'
|
# - title: 'Lao'
|
||||||
# description: ''
|
# description: ''
|
||||||
# url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/lao.traineddata'
|
# url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/lao.traineddata'
|
||||||
@@ -682,6 +738,7 @@
|
|||||||
# - '0.1.0'
|
# - '0.1.0'
|
||||||
# - '0.1.1'
|
# - '0.1.1'
|
||||||
# - '0.1.2'
|
# - '0.1.2'
|
||||||
|
# - '0.1.3b'
|
||||||
# - title: 'Latin'
|
# - title: 'Latin'
|
||||||
# description: ''
|
# description: ''
|
||||||
# url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/lat.traineddata'
|
# url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/lat.traineddata'
|
||||||
@@ -694,6 +751,7 @@
|
|||||||
# - '0.1.0'
|
# - '0.1.0'
|
||||||
# - '0.1.1'
|
# - '0.1.1'
|
||||||
# - '0.1.2'
|
# - '0.1.2'
|
||||||
|
# - '0.1.3b'
|
||||||
# - title: 'Latvian'
|
# - title: 'Latvian'
|
||||||
# description: ''
|
# description: ''
|
||||||
# url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/lav.traineddata'
|
# url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/lav.traineddata'
|
||||||
@@ -706,6 +764,7 @@
|
|||||||
# - '0.1.0'
|
# - '0.1.0'
|
||||||
# - '0.1.1'
|
# - '0.1.1'
|
||||||
# - '0.1.2'
|
# - '0.1.2'
|
||||||
|
# - '0.1.3b'
|
||||||
# - title: 'Lithuanian'
|
# - title: 'Lithuanian'
|
||||||
# description: ''
|
# description: ''
|
||||||
# url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/lit.traineddata'
|
# url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/lit.traineddata'
|
||||||
@@ -718,6 +777,7 @@
|
|||||||
# - '0.1.0'
|
# - '0.1.0'
|
||||||
# - '0.1.1'
|
# - '0.1.1'
|
||||||
# - '0.1.2'
|
# - '0.1.2'
|
||||||
|
# - '0.1.3b'
|
||||||
# - title: 'Malayalam'
|
# - title: 'Malayalam'
|
||||||
# description: ''
|
# description: ''
|
||||||
# url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/mal.traineddata'
|
# url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/mal.traineddata'
|
||||||
@@ -730,6 +790,7 @@
|
|||||||
# - '0.1.0'
|
# - '0.1.0'
|
||||||
# - '0.1.1'
|
# - '0.1.1'
|
||||||
# - '0.1.2'
|
# - '0.1.2'
|
||||||
|
# - '0.1.3b'
|
||||||
# - title: 'Marathi'
|
# - title: 'Marathi'
|
||||||
# description: ''
|
# description: ''
|
||||||
# url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/mar.traineddata'
|
# url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/mar.traineddata'
|
||||||
@@ -742,6 +803,7 @@
|
|||||||
# - '0.1.0'
|
# - '0.1.0'
|
||||||
# - '0.1.1'
|
# - '0.1.1'
|
||||||
# - '0.1.2'
|
# - '0.1.2'
|
||||||
|
# - '0.1.3b'
|
||||||
# - title: 'Macedonian'
|
# - title: 'Macedonian'
|
||||||
# description: ''
|
# description: ''
|
||||||
# url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/mkd.traineddata'
|
# url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/mkd.traineddata'
|
||||||
@@ -754,6 +816,7 @@
|
|||||||
# - '0.1.0'
|
# - '0.1.0'
|
||||||
# - '0.1.1'
|
# - '0.1.1'
|
||||||
# - '0.1.2'
|
# - '0.1.2'
|
||||||
|
# - '0.1.3b'
|
||||||
# - title: 'Maltese'
|
# - title: 'Maltese'
|
||||||
# description: ''
|
# description: ''
|
||||||
# url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/mlt.traineddata'
|
# url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/mlt.traineddata'
|
||||||
@@ -766,6 +829,7 @@
|
|||||||
# - '0.1.0'
|
# - '0.1.0'
|
||||||
# - '0.1.1'
|
# - '0.1.1'
|
||||||
# - '0.1.2'
|
# - '0.1.2'
|
||||||
|
# - '0.1.3b'
|
||||||
# - title: 'Malay'
|
# - title: 'Malay'
|
||||||
# description: ''
|
# description: ''
|
||||||
# url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/msa.traineddata'
|
# url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/msa.traineddata'
|
||||||
@@ -778,6 +842,7 @@
|
|||||||
# - '0.1.0'
|
# - '0.1.0'
|
||||||
# - '0.1.1'
|
# - '0.1.1'
|
||||||
# - '0.1.2'
|
# - '0.1.2'
|
||||||
|
# - '0.1.3b'
|
||||||
# - title: 'Burmese'
|
# - title: 'Burmese'
|
||||||
# description: ''
|
# description: ''
|
||||||
# url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/mya.traineddata'
|
# url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/mya.traineddata'
|
||||||
@@ -790,6 +855,7 @@
|
|||||||
# - '0.1.0'
|
# - '0.1.0'
|
||||||
# - '0.1.1'
|
# - '0.1.1'
|
||||||
# - '0.1.2'
|
# - '0.1.2'
|
||||||
|
# - '0.1.3b'
|
||||||
# - title: 'Nepali'
|
# - title: 'Nepali'
|
||||||
# description: ''
|
# description: ''
|
||||||
# url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/nep.traineddata'
|
# url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/nep.traineddata'
|
||||||
@@ -802,6 +868,7 @@
|
|||||||
# - '0.1.0'
|
# - '0.1.0'
|
||||||
# - '0.1.1'
|
# - '0.1.1'
|
||||||
# - '0.1.2'
|
# - '0.1.2'
|
||||||
|
# - '0.1.3b'
|
||||||
# - title: 'Dutch; Flemish'
|
# - title: 'Dutch; Flemish'
|
||||||
# description: ''
|
# description: ''
|
||||||
# url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/nld.traineddata'
|
# url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/nld.traineddata'
|
||||||
@@ -814,6 +881,7 @@
|
|||||||
# - '0.1.0'
|
# - '0.1.0'
|
||||||
# - '0.1.1'
|
# - '0.1.1'
|
||||||
# - '0.1.2'
|
# - '0.1.2'
|
||||||
|
# - '0.1.3b'
|
||||||
# - title: 'Norwegian'
|
# - title: 'Norwegian'
|
||||||
# description: ''
|
# description: ''
|
||||||
# url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/nor.traineddata'
|
# url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/nor.traineddata'
|
||||||
@@ -826,6 +894,7 @@
|
|||||||
# - '0.1.0'
|
# - '0.1.0'
|
||||||
# - '0.1.1'
|
# - '0.1.1'
|
||||||
# - '0.1.2'
|
# - '0.1.2'
|
||||||
|
# - '0.1.3b'
|
||||||
# - title: 'Oriya'
|
# - title: 'Oriya'
|
||||||
# description: ''
|
# description: ''
|
||||||
# url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/ori.traineddata'
|
# url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/ori.traineddata'
|
||||||
@@ -838,6 +907,7 @@
|
|||||||
# - '0.1.0'
|
# - '0.1.0'
|
||||||
# - '0.1.1'
|
# - '0.1.1'
|
||||||
# - '0.1.2'
|
# - '0.1.2'
|
||||||
|
# - '0.1.3b'
|
||||||
# - title: 'Panjabi; Punjabi'
|
# - title: 'Panjabi; Punjabi'
|
||||||
# description: ''
|
# description: ''
|
||||||
# url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/pan.traineddata'
|
# url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/pan.traineddata'
|
||||||
@@ -850,6 +920,7 @@
|
|||||||
# - '0.1.0'
|
# - '0.1.0'
|
||||||
# - '0.1.1'
|
# - '0.1.1'
|
||||||
# - '0.1.2'
|
# - '0.1.2'
|
||||||
|
# - '0.1.3b'
|
||||||
# - title: 'Polish'
|
# - title: 'Polish'
|
||||||
# description: ''
|
# description: ''
|
||||||
# url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/pol.traineddata'
|
# url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/pol.traineddata'
|
||||||
@@ -862,6 +933,7 @@
|
|||||||
# - '0.1.0'
|
# - '0.1.0'
|
||||||
# - '0.1.1'
|
# - '0.1.1'
|
||||||
# - '0.1.2'
|
# - '0.1.2'
|
||||||
|
# - '0.1.3b'
|
||||||
- title: 'Portuguese'
|
- title: 'Portuguese'
|
||||||
description: ''
|
description: ''
|
||||||
url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/por.traineddata'
|
url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/por.traineddata'
|
||||||
@@ -874,6 +946,7 @@
|
|||||||
- '0.1.0'
|
- '0.1.0'
|
||||||
- '0.1.1'
|
- '0.1.1'
|
||||||
- '0.1.2'
|
- '0.1.2'
|
||||||
|
- '0.1.3b'
|
||||||
# - title: 'Pushto; Pashto'
|
# - title: 'Pushto; Pashto'
|
||||||
# description: ''
|
# description: ''
|
||||||
# url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/pus.traineddata'
|
# url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/pus.traineddata'
|
||||||
@@ -886,6 +959,7 @@
|
|||||||
# - '0.1.0'
|
# - '0.1.0'
|
||||||
# - '0.1.1'
|
# - '0.1.1'
|
||||||
# - '0.1.2'
|
# - '0.1.2'
|
||||||
|
# - '0.1.3b'
|
||||||
# - title: 'Romanian; Moldavian; Moldovan'
|
# - title: 'Romanian; Moldavian; Moldovan'
|
||||||
# description: ''
|
# description: ''
|
||||||
# url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/ron.traineddata'
|
# url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/ron.traineddata'
|
||||||
@@ -898,6 +972,7 @@
|
|||||||
# - '0.1.0'
|
# - '0.1.0'
|
||||||
# - '0.1.1'
|
# - '0.1.1'
|
||||||
# - '0.1.2'
|
# - '0.1.2'
|
||||||
|
# - '0.1.3b'
|
||||||
- title: 'Russian'
|
- title: 'Russian'
|
||||||
description: ''
|
description: ''
|
||||||
url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/rus.traineddata'
|
url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/rus.traineddata'
|
||||||
@@ -910,6 +985,7 @@
|
|||||||
- '0.1.0'
|
- '0.1.0'
|
||||||
- '0.1.1'
|
- '0.1.1'
|
||||||
- '0.1.2'
|
- '0.1.2'
|
||||||
|
- '0.1.3b'
|
||||||
# - title: 'Sanskrit'
|
# - title: 'Sanskrit'
|
||||||
# description: ''
|
# description: ''
|
||||||
# url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/san.traineddata'
|
# url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/san.traineddata'
|
||||||
@@ -922,6 +998,7 @@
|
|||||||
# - '0.1.0'
|
# - '0.1.0'
|
||||||
# - '0.1.1'
|
# - '0.1.1'
|
||||||
# - '0.1.2'
|
# - '0.1.2'
|
||||||
|
# - '0.1.3b'
|
||||||
# - title: 'Sinhala; Sinhalese'
|
# - title: 'Sinhala; Sinhalese'
|
||||||
# description: ''
|
# description: ''
|
||||||
# url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/sin.traineddata'
|
# url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/sin.traineddata'
|
||||||
@@ -934,6 +1011,7 @@
|
|||||||
# - '0.1.0'
|
# - '0.1.0'
|
||||||
# - '0.1.1'
|
# - '0.1.1'
|
||||||
# - '0.1.2'
|
# - '0.1.2'
|
||||||
|
# - '0.1.3b'
|
||||||
# - title: 'Slovak'
|
# - title: 'Slovak'
|
||||||
# description: ''
|
# description: ''
|
||||||
# url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/slk.traineddata'
|
# url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/slk.traineddata'
|
||||||
@@ -946,6 +1024,7 @@
|
|||||||
# - '0.1.0'
|
# - '0.1.0'
|
||||||
# - '0.1.1'
|
# - '0.1.1'
|
||||||
# - '0.1.2'
|
# - '0.1.2'
|
||||||
|
# - '0.1.3b'
|
||||||
# - title: 'Slovenian'
|
# - title: 'Slovenian'
|
||||||
# description: ''
|
# description: ''
|
||||||
# url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/slv.traineddata'
|
# url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/slv.traineddata'
|
||||||
@@ -958,6 +1037,7 @@
|
|||||||
# - '0.1.0'
|
# - '0.1.0'
|
||||||
# - '0.1.1'
|
# - '0.1.1'
|
||||||
# - '0.1.2'
|
# - '0.1.2'
|
||||||
|
# - '0.1.3b'
|
||||||
- title: 'Spanish; Castilian'
|
- title: 'Spanish; Castilian'
|
||||||
description: ''
|
description: ''
|
||||||
url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/spa.traineddata'
|
url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/spa.traineddata'
|
||||||
@@ -970,6 +1050,7 @@
|
|||||||
- '0.1.0'
|
- '0.1.0'
|
||||||
- '0.1.1'
|
- '0.1.1'
|
||||||
- '0.1.2'
|
- '0.1.2'
|
||||||
|
- '0.1.3b'
|
||||||
- title: 'Spanish; Castilian - Old'
|
- title: 'Spanish; Castilian - Old'
|
||||||
description: ''
|
description: ''
|
||||||
url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/spa_old.traineddata'
|
url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/spa_old.traineddata'
|
||||||
@@ -982,6 +1063,7 @@
|
|||||||
- '0.1.0'
|
- '0.1.0'
|
||||||
- '0.1.1'
|
- '0.1.1'
|
||||||
- '0.1.2'
|
- '0.1.2'
|
||||||
|
- '0.1.3b'
|
||||||
# - title: 'Albanian'
|
# - title: 'Albanian'
|
||||||
# description: ''
|
# description: ''
|
||||||
# url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/sqi.traineddata'
|
# url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/sqi.traineddata'
|
||||||
@@ -994,6 +1076,7 @@
|
|||||||
# - '0.1.0'
|
# - '0.1.0'
|
||||||
# - '0.1.1'
|
# - '0.1.1'
|
||||||
# - '0.1.2'
|
# - '0.1.2'
|
||||||
|
# - '0.1.3b'
|
||||||
# - title: 'Serbian'
|
# - title: 'Serbian'
|
||||||
# description: ''
|
# description: ''
|
||||||
# url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/srp.traineddata'
|
# url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/srp.traineddata'
|
||||||
@@ -1006,6 +1089,7 @@
|
|||||||
# - '0.1.0'
|
# - '0.1.0'
|
||||||
# - '0.1.1'
|
# - '0.1.1'
|
||||||
# - '0.1.2'
|
# - '0.1.2'
|
||||||
|
# - '0.1.3b'
|
||||||
# - title: 'Serbian - Latin'
|
# - title: 'Serbian - Latin'
|
||||||
# description: ''
|
# description: ''
|
||||||
# url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/srp_latn.traineddata'
|
# url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/srp_latn.traineddata'
|
||||||
@@ -1018,6 +1102,7 @@
|
|||||||
# - '0.1.0'
|
# - '0.1.0'
|
||||||
# - '0.1.1'
|
# - '0.1.1'
|
||||||
# - '0.1.2'
|
# - '0.1.2'
|
||||||
|
# - '0.1.3b'
|
||||||
# - title: 'Swahili'
|
# - title: 'Swahili'
|
||||||
# description: ''
|
# description: ''
|
||||||
# url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/swa.traineddata'
|
# url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/swa.traineddata'
|
||||||
@@ -1030,6 +1115,7 @@
|
|||||||
# - '0.1.0'
|
# - '0.1.0'
|
||||||
# - '0.1.1'
|
# - '0.1.1'
|
||||||
# - '0.1.2'
|
# - '0.1.2'
|
||||||
|
# - '0.1.3b'
|
||||||
# - title: 'Swedish'
|
# - title: 'Swedish'
|
||||||
# description: ''
|
# description: ''
|
||||||
# url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/swe.traineddata'
|
# url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/swe.traineddata'
|
||||||
@@ -1042,6 +1128,7 @@
|
|||||||
# - '0.1.0'
|
# - '0.1.0'
|
||||||
# - '0.1.1'
|
# - '0.1.1'
|
||||||
# - '0.1.2'
|
# - '0.1.2'
|
||||||
|
# - '0.1.3b'
|
||||||
# - title: 'Syriac'
|
# - title: 'Syriac'
|
||||||
# description: ''
|
# description: ''
|
||||||
# url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/syr.traineddata'
|
# url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/syr.traineddata'
|
||||||
@@ -1054,6 +1141,7 @@
|
|||||||
# - '0.1.0'
|
# - '0.1.0'
|
||||||
# - '0.1.1'
|
# - '0.1.1'
|
||||||
# - '0.1.2'
|
# - '0.1.2'
|
||||||
|
# - '0.1.3b'
|
||||||
# - title: 'Tamil'
|
# - title: 'Tamil'
|
||||||
# description: ''
|
# description: ''
|
||||||
# url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/tam.traineddata'
|
# url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/tam.traineddata'
|
||||||
@@ -1066,6 +1154,7 @@
|
|||||||
# - '0.1.0'
|
# - '0.1.0'
|
||||||
# - '0.1.1'
|
# - '0.1.1'
|
||||||
# - '0.1.2'
|
# - '0.1.2'
|
||||||
|
# - '0.1.3b'
|
||||||
# - title: 'Telugu'
|
# - title: 'Telugu'
|
||||||
# description: ''
|
# description: ''
|
||||||
# url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/tel.traineddata'
|
# url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/tel.traineddata'
|
||||||
@@ -1078,6 +1167,7 @@
|
|||||||
# - '0.1.0'
|
# - '0.1.0'
|
||||||
# - '0.1.1'
|
# - '0.1.1'
|
||||||
# - '0.1.2'
|
# - '0.1.2'
|
||||||
|
# - '0.1.3b'
|
||||||
# - title: 'Tajik'
|
# - title: 'Tajik'
|
||||||
# description: ''
|
# description: ''
|
||||||
# url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/tgk.traineddata'
|
# url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/tgk.traineddata'
|
||||||
@@ -1090,6 +1180,7 @@
|
|||||||
# - '0.1.0'
|
# - '0.1.0'
|
||||||
# - '0.1.1'
|
# - '0.1.1'
|
||||||
# - '0.1.2'
|
# - '0.1.2'
|
||||||
|
# - '0.1.3b'
|
||||||
# - title: 'Tagalog'
|
# - title: 'Tagalog'
|
||||||
# description: ''
|
# description: ''
|
||||||
# url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/tgl.traineddata'
|
# url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/tgl.traineddata'
|
||||||
@@ -1102,6 +1193,7 @@
|
|||||||
# - '0.1.0'
|
# - '0.1.0'
|
||||||
# - '0.1.1'
|
# - '0.1.1'
|
||||||
# - '0.1.2'
|
# - '0.1.2'
|
||||||
|
# - '0.1.3b'
|
||||||
# - title: 'Thai'
|
# - title: 'Thai'
|
||||||
# description: ''
|
# description: ''
|
||||||
# url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/tha.traineddata'
|
# url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/tha.traineddata'
|
||||||
@@ -1114,6 +1206,7 @@
|
|||||||
# - '0.1.0'
|
# - '0.1.0'
|
||||||
# - '0.1.1'
|
# - '0.1.1'
|
||||||
# - '0.1.2'
|
# - '0.1.2'
|
||||||
|
# - '0.1.3b'
|
||||||
# - title: 'Tigrinya'
|
# - title: 'Tigrinya'
|
||||||
# description: ''
|
# description: ''
|
||||||
# url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/tir.traineddata'
|
# url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/tir.traineddata'
|
||||||
@@ -1126,6 +1219,7 @@
|
|||||||
# - '0.1.0'
|
# - '0.1.0'
|
||||||
# - '0.1.1'
|
# - '0.1.1'
|
||||||
# - '0.1.2'
|
# - '0.1.2'
|
||||||
|
# - '0.1.3b'
|
||||||
# - title: 'Turkish'
|
# - title: 'Turkish'
|
||||||
# description: ''
|
# description: ''
|
||||||
# url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/tur.traineddata'
|
# url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/tur.traineddata'
|
||||||
@@ -1138,6 +1232,7 @@
|
|||||||
# - '0.1.0'
|
# - '0.1.0'
|
||||||
# - '0.1.1'
|
# - '0.1.1'
|
||||||
# - '0.1.2'
|
# - '0.1.2'
|
||||||
|
# - '0.1.3b'
|
||||||
# - title: 'Uighur; Uyghur'
|
# - title: 'Uighur; Uyghur'
|
||||||
# description: ''
|
# description: ''
|
||||||
# url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/uig.traineddata'
|
# url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/uig.traineddata'
|
||||||
@@ -1150,6 +1245,7 @@
|
|||||||
# - '0.1.0'
|
# - '0.1.0'
|
||||||
# - '0.1.1'
|
# - '0.1.1'
|
||||||
# - '0.1.2'
|
# - '0.1.2'
|
||||||
|
# - '0.1.3b'
|
||||||
# - title: 'Ukrainian'
|
# - title: 'Ukrainian'
|
||||||
# description: ''
|
# description: ''
|
||||||
# url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/ukr.traineddata'
|
# url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/ukr.traineddata'
|
||||||
@@ -1162,6 +1258,7 @@
|
|||||||
# - '0.1.0'
|
# - '0.1.0'
|
||||||
# - '0.1.1'
|
# - '0.1.1'
|
||||||
# - '0.1.2'
|
# - '0.1.2'
|
||||||
|
# - '0.1.3b'
|
||||||
# - title: 'Urdu'
|
# - title: 'Urdu'
|
||||||
# description: ''
|
# description: ''
|
||||||
# url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/urd.traineddata'
|
# url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/urd.traineddata'
|
||||||
@@ -1174,6 +1271,7 @@
|
|||||||
# - '0.1.0'
|
# - '0.1.0'
|
||||||
# - '0.1.1'
|
# - '0.1.1'
|
||||||
# - '0.1.2'
|
# - '0.1.2'
|
||||||
|
# - '0.1.3b'
|
||||||
# - title: 'Uzbek'
|
# - title: 'Uzbek'
|
||||||
# description: ''
|
# description: ''
|
||||||
# url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/uzb.traineddata'
|
# url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/uzb.traineddata'
|
||||||
@@ -1186,6 +1284,7 @@
|
|||||||
# - '0.1.0'
|
# - '0.1.0'
|
||||||
# - '0.1.1'
|
# - '0.1.1'
|
||||||
# - '0.1.2'
|
# - '0.1.2'
|
||||||
|
# - '0.1.3b'
|
||||||
# - title: 'Uzbek - Cyrillic'
|
# - title: 'Uzbek - Cyrillic'
|
||||||
# description: ''
|
# description: ''
|
||||||
# url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/uzb_cyrl.traineddata'
|
# url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/uzb_cyrl.traineddata'
|
||||||
@@ -1198,6 +1297,7 @@
|
|||||||
# - '0.1.0'
|
# - '0.1.0'
|
||||||
# - '0.1.1'
|
# - '0.1.1'
|
||||||
# - '0.1.2'
|
# - '0.1.2'
|
||||||
|
# - '0.1.3b'
|
||||||
# - title: 'Vietnamese'
|
# - title: 'Vietnamese'
|
||||||
# description: ''
|
# description: ''
|
||||||
# url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/vie.traineddata'
|
# url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/vie.traineddata'
|
||||||
@@ -1210,6 +1310,7 @@
|
|||||||
# - '0.1.0'
|
# - '0.1.0'
|
||||||
# - '0.1.1'
|
# - '0.1.1'
|
||||||
# - '0.1.2'
|
# - '0.1.2'
|
||||||
|
# - '0.1.3b'
|
||||||
# - title: 'Yiddish'
|
# - title: 'Yiddish'
|
||||||
# description: ''
|
# description: ''
|
||||||
# url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/yid.traineddata'
|
# url: 'https://github.com/tesseract-ocr/tessdata/raw/4.1.0/yid.traineddata'
|
||||||
@@ -1222,3 +1323,4 @@
|
|||||||
# - '0.1.0'
|
# - '0.1.0'
|
||||||
# - '0.1.1'
|
# - '0.1.1'
|
||||||
# - '0.1.2'
|
# - '0.1.2'
|
||||||
|
# - '0.1.3b'
|
||||||
+2
-3
@@ -3,11 +3,10 @@ from enum import IntEnum
|
|||||||
from flask import current_app, url_for
|
from flask import current_app, url_for
|
||||||
from flask_hashids import HashidMixin
|
from flask_hashids import HashidMixin
|
||||||
from time import sleep
|
from time import sleep
|
||||||
from typing import Union
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
import shutil
|
import shutil
|
||||||
from app import db
|
from app import db
|
||||||
from app.extensions.sqlalchemy_extras import ContainerColumn, IntEnumColumn
|
from app.extensions.nopaque_sqlalchemy_type_decorators import ContainerColumn, IntEnumColumn
|
||||||
|
|
||||||
|
|
||||||
class JobStatus(IntEnum):
|
class JobStatus(IntEnum):
|
||||||
@@ -21,7 +20,7 @@ class JobStatus(IntEnum):
|
|||||||
FAILED = 8
|
FAILED = 8
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get(job_status: Union['JobStatus', int, str]) -> 'JobStatus':
|
def get(job_status: 'JobStatus | int | str') -> 'JobStatus':
|
||||||
if isinstance(job_status, JobStatus):
|
if isinstance(job_status, JobStatus):
|
||||||
return job_status
|
return job_status
|
||||||
if isinstance(job_status, int):
|
if isinstance(job_status, int):
|
||||||
|
|||||||
@@ -20,14 +20,6 @@ class JobInput(FileMixin, HashidMixin, db.Model):
|
|||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return f'<JobInput {self.filename}>'
|
return f'<JobInput {self.filename}>'
|
||||||
|
|
||||||
@property
|
|
||||||
def content_url(self):
|
|
||||||
return url_for(
|
|
||||||
'jobs.download_job_input',
|
|
||||||
job_id=self.job.id,
|
|
||||||
job_input_id=self.id
|
|
||||||
)
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def jsonpatch_path(self):
|
def jsonpatch_path(self):
|
||||||
return f'{self.job.jsonpatch_path}/inputs/{self.hashid}'
|
return f'{self.job.jsonpatch_path}/inputs/{self.hashid}'
|
||||||
@@ -40,7 +32,7 @@ class JobInput(FileMixin, HashidMixin, db.Model):
|
|||||||
def url(self):
|
def url(self):
|
||||||
return url_for(
|
return url_for(
|
||||||
'jobs.job',
|
'jobs.job',
|
||||||
job_id=self.job_id,
|
job_input_id=self.id,
|
||||||
_anchor=f'job-{self.job.hashid}-input-{self.hashid}'
|
_anchor=f'job-{self.job.hashid}-input-{self.hashid}'
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -22,14 +22,6 @@ class JobResult(FileMixin, HashidMixin, db.Model):
|
|||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return f'<JobResult {self.filename}>'
|
return f'<JobResult {self.filename}>'
|
||||||
|
|
||||||
@property
|
|
||||||
def download_url(self):
|
|
||||||
return url_for(
|
|
||||||
'jobs.download_job_result',
|
|
||||||
job_id=self.job_id,
|
|
||||||
job_result_id=self.id
|
|
||||||
)
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def jsonpatch_path(self):
|
def jsonpatch_path(self):
|
||||||
return f'{self.job.jsonpatch_path}/results/{self.hashid}'
|
return f'{self.job.jsonpatch_path}/results/{self.hashid}'
|
||||||
@@ -41,8 +33,8 @@ class JobResult(FileMixin, HashidMixin, db.Model):
|
|||||||
@property
|
@property
|
||||||
def url(self):
|
def url(self):
|
||||||
return url_for(
|
return url_for(
|
||||||
'jobs.job',
|
'job_results.job_result',
|
||||||
job_id=self.job_id,
|
job_result_id=self.id,
|
||||||
_anchor=f'job-{self.job.hashid}-result-{self.hashid}'
|
_anchor=f'job-{self.job.hashid}-result-{self.hashid}'
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
+6
-7
@@ -1,6 +1,5 @@
|
|||||||
from enum import IntEnum
|
from enum import IntEnum
|
||||||
from flask_hashids import HashidMixin
|
from flask_hashids import HashidMixin
|
||||||
from typing import Union
|
|
||||||
from app import db
|
from app import db
|
||||||
|
|
||||||
|
|
||||||
@@ -14,7 +13,7 @@ class Permission(IntEnum):
|
|||||||
USE_API = 4
|
USE_API = 4
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get(permission: Union['Permission', int, str]) -> 'Permission':
|
def get(permission: 'Permission | int | str') -> 'Permission':
|
||||||
if isinstance(permission, Permission):
|
if isinstance(permission, Permission):
|
||||||
return permission
|
return permission
|
||||||
if isinstance(permission, int):
|
if isinstance(permission, int):
|
||||||
@@ -38,16 +37,16 @@ class Role(HashidMixin, db.Model):
|
|||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return f'<Role {self.name}>'
|
return f'<Role {self.name}>'
|
||||||
|
|
||||||
def has_permission(self, permission: Union[Permission, int, str]):
|
def has_permission(self, permission: Permission | int | str):
|
||||||
p = Permission.get(permission)
|
p = Permission.get(permission)
|
||||||
return self.permissions & p.value == p.value
|
return self.permissions & p.value == p.value
|
||||||
|
|
||||||
def add_permission(self, permission: Union[Permission, int, str]):
|
def add_permission(self, permission: Permission | int | str):
|
||||||
p = Permission.get(permission)
|
p = Permission.get(permission)
|
||||||
if not self.has_permission(p):
|
if not self.has_permission(p):
|
||||||
self.permissions += p.value
|
self.permissions += p.value
|
||||||
|
|
||||||
def remove_permission(self, permission: Union[Permission, int, str]):
|
def remove_permission(self, permission: Permission | int | str):
|
||||||
p = Permission.get(permission)
|
p = Permission.get(permission)
|
||||||
if self.has_permission(p):
|
if self.has_permission(p):
|
||||||
self.permissions -= p.value
|
self.permissions -= p.value
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ from pathlib import Path
|
|||||||
import requests
|
import requests
|
||||||
import yaml
|
import yaml
|
||||||
from app import db
|
from app import db
|
||||||
from app.extensions.sqlalchemy_extras import ContainerColumn
|
from app.extensions.nopaque_sqlalchemy_type_decorators import ContainerColumn
|
||||||
from .file_mixin import FileMixin
|
from .file_mixin import FileMixin
|
||||||
from .user import User
|
from .user import User
|
||||||
|
|
||||||
@@ -41,7 +41,7 @@ class SpaCyNLPPipelineModel(FileMixin, HashidMixin, db.Model):
|
|||||||
@property
|
@property
|
||||||
def url(self):
|
def url(self):
|
||||||
return url_for(
|
return url_for(
|
||||||
'contributions.spacy_nlp_pipeline_model',
|
'contributions.spacy_nlp_pipeline_models.entity',
|
||||||
spacy_nlp_pipeline_model_id=self.id
|
spacy_nlp_pipeline_model_id=self.id
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -104,7 +104,7 @@ class SpaCyNLPPipelineModel(FileMixin, HashidMixin, db.Model):
|
|||||||
f.write(chunk)
|
f.write(chunk)
|
||||||
pbar.close()
|
pbar.close()
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
|
||||||
def delete(self):
|
def delete(self):
|
||||||
try:
|
try:
|
||||||
self.path.unlink(missing_ok=True)
|
self.path.unlink(missing_ok=True)
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ from pathlib import Path
|
|||||||
import requests
|
import requests
|
||||||
import yaml
|
import yaml
|
||||||
from app import db
|
from app import db
|
||||||
from app.extensions.sqlalchemy_extras import ContainerColumn
|
from app.extensions.nopaque_sqlalchemy_type_decorators import ContainerColumn
|
||||||
from .file_mixin import FileMixin
|
from .file_mixin import FileMixin
|
||||||
from .user import User
|
from .user import User
|
||||||
|
|
||||||
@@ -40,7 +40,7 @@ class TesseractOCRPipelineModel(FileMixin, HashidMixin, db.Model):
|
|||||||
@property
|
@property
|
||||||
def url(self):
|
def url(self):
|
||||||
return url_for(
|
return url_for(
|
||||||
'contributions.tesseract_ocr_pipeline_model',
|
'contributions.tesseract_ocr_pipeline_models.entity',
|
||||||
tesseract_ocr_pipeline_model_id=self.id
|
tesseract_ocr_pipeline_model_id=self.id
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
+5
-6
@@ -5,14 +5,13 @@ from flask_hashids import HashidMixin
|
|||||||
from flask_login import UserMixin
|
from flask_login import UserMixin
|
||||||
from sqlalchemy.ext.associationproxy import association_proxy
|
from sqlalchemy.ext.associationproxy import association_proxy
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Union
|
|
||||||
from werkzeug.security import generate_password_hash, check_password_hash
|
from werkzeug.security import generate_password_hash, check_password_hash
|
||||||
import jwt
|
import jwt
|
||||||
import re
|
import re
|
||||||
import secrets
|
import secrets
|
||||||
import shutil
|
import shutil
|
||||||
from app import db, hashids
|
from app import db, hashids
|
||||||
from app.extensions.sqlalchemy_extras import IntEnumColumn
|
from app.extensions.nopaque_sqlalchemy_type_decorators import IntEnumColumn
|
||||||
from .corpus import Corpus
|
from .corpus import Corpus
|
||||||
from .corpus_follower_association import CorpusFollowerAssociation
|
from .corpus_follower_association import CorpusFollowerAssociation
|
||||||
from .corpus_follower_role import CorpusFollowerRole
|
from .corpus_follower_role import CorpusFollowerRole
|
||||||
@@ -26,7 +25,7 @@ class ProfilePrivacySettings(IntEnum):
|
|||||||
SHOW_MEMBER_SINCE = 4
|
SHOW_MEMBER_SINCE = 4
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get(profile_privacy_setting: Union['ProfilePrivacySettings', int, str]) -> 'ProfilePrivacySettings':
|
def get(profile_privacy_setting: 'ProfilePrivacySettings | int | str') -> 'ProfilePrivacySettings':
|
||||||
if isinstance(profile_privacy_setting, ProfilePrivacySettings):
|
if isinstance(profile_privacy_setting, ProfilePrivacySettings):
|
||||||
return profile_privacy_setting
|
return profile_privacy_setting
|
||||||
if isinstance(profile_privacy_setting, int):
|
if isinstance(profile_privacy_setting, int):
|
||||||
@@ -315,7 +314,7 @@ class User(HashidMixin, UserMixin, db.Model):
|
|||||||
def has_profile_privacy_setting(self, setting):
|
def has_profile_privacy_setting(self, setting):
|
||||||
s = ProfilePrivacySettings.get(setting)
|
s = ProfilePrivacySettings.get(setting)
|
||||||
return self.profile_privacy_settings & s.value == s.value
|
return self.profile_privacy_settings & s.value == s.value
|
||||||
|
|
||||||
def add_profile_privacy_setting(self, setting):
|
def add_profile_privacy_setting(self, setting):
|
||||||
s = ProfilePrivacySettings.get(setting)
|
s = ProfilePrivacySettings.get(setting)
|
||||||
if not self.has_profile_privacy_setting(s):
|
if not self.has_profile_privacy_setting(s):
|
||||||
@@ -350,7 +349,7 @@ class User(HashidMixin, UserMixin, db.Model):
|
|||||||
|
|
||||||
def is_following_corpus(self, corpus):
|
def is_following_corpus(self, corpus):
|
||||||
return corpus in self.followed_corpora
|
return corpus in self.followed_corpora
|
||||||
|
|
||||||
def generate_follow_corpus_token(self, corpus_hashid, role_name, expiration=7):
|
def generate_follow_corpus_token(self, corpus_hashid, role_name, expiration=7):
|
||||||
now = datetime.utcnow()
|
now = datetime.utcnow()
|
||||||
payload = {
|
payload = {
|
||||||
@@ -366,7 +365,7 @@ class User(HashidMixin, UserMixin, db.Model):
|
|||||||
current_app.config['SECRET_KEY'],
|
current_app.config['SECRET_KEY'],
|
||||||
algorithm='HS256'
|
algorithm='HS256'
|
||||||
)
|
)
|
||||||
|
|
||||||
def follow_corpus_by_token(self, token):
|
def follow_corpus_by_token(self, token):
|
||||||
try:
|
try:
|
||||||
payload = jwt.decode(
|
payload = jwt.decode(
|
||||||
|
|||||||
Loaded 100 of 207 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user