<commit_before># Copyright 2017 the Isard-vdi project authors:
#      <NAME>
#      <NAME>
# License: AGPLv3

#!flask/bin/python
# coding=utf-8
import json

from flask import render_template, Response, request, redirect, url_for, flash
from flask_login import login_required, login_user, logout_user, current_user

from webapp import app
from ...lib import admin_api

app.adminapi = admin_api.isardAdmin()

from ...lib.isardUpdates import Updates
u=Updates()

from .decorators import isAdmin

@app.route('/admin/updates', methods=['GET'])
@login_required
@isAdmin
def admin_updates():
    registered=u.is_registered()
    if not registered:
        flash("Unable to contact updates website.","error")
    return render_template('admin/pages/updates.html', title="Updates", nav="Updates", registered=registered)

@app.route('/admin/updates_register', methods=['POST'])
@login_required
@isAdmin
def admin_updates_register():
    if request.method == 'POST':
        try:
            if not u.is_registered():
                u.register()
        except Exception as e:
            log.error('Error registering client: '+str(e))
            #~ return False
    return redirect(url_for('admin_updates'))
            
@app.route('/admin/updates/<kind>', methods=['GET'])
@login_required
@isAdmin
def admin_updates_json(kind):
    return json.dumps(u.getNewKind(kind,current_user.id))

@app.route('/admin/updates/<action>/<kind>', methods=['POST'])
@app.route('/admin/updates/<action>/<kind>/<id>', methods=['POST'])
@login_required
@isAdmin
def admin_updates_actions(action,kind,id=False):
    if request.method == 'POST':
        if action == 'download':
            if id is not False:
                # Only one id
                d=u.getNewKindId(kind,current_user.id,id)
                missing_resources=u.get_missing_resources(d,current_user.id)
                for k,v in missing_resources.items():
                    for resource in v:
                        app.adminapi.insert_or_update_table_dict(k,v)
                if d is not False:
                    if kind == 'domains':
                        d=u.formatDomains([d],current_user)[0]
                    elif kind == 'media':<commit_msg>Resources fix<commit_after># Copyright 2017 the Isard-vdi project authors:
#      <NAME>
#      <NAME>
# License: AGPLv3

#!flask/bin/python
# coding=utf-8
import json

from flask import render_template, Response, request, redirect, url_for, flash
from flask_login import login_required, login_user, logout_user, current_user

from webapp import app
from ...lib import admin_api

app.adminapi = admin_api.isardAdmin()

from ...lib.isardUpdates import Updates
u=Updates()

from .decorators import isAdmin

@app.route('/admin/updates', methods=['GET'])
@login_required
@isAdmin
def admin_updates():
    registered=u.is_registered()
    if not registered:
        flash("Unable to contact updates website.","error")
    return render_template('admin/pages/updates.html', title="Updates", nav="Updates", registered=registered)

@app.route('/admin/updates_register', methods=['POST'])
@login_required
@isAdmin
def admin_updates_register():
    if request.method == 'POST':
        try:
            if not u.is_registered():
                u.register()
        except Exception as e:
            log.error('Error registering client: '+str(e))
            #~ return False
    return redirect(url_for('admin_updates'))
            
@app.route('/admin/updates/<kind>', methods=['GET'])
@login_required
@isAdmin
def admin_updates_json(kind):
    return json.dumps(u.getNewKind(kind,current_user.id))

@app.route('/admin/updates/<action>/<kind>', methods=['POST'])
@app.route('/admin/updates/<action>/<kind>/<id>', methods=['POST'])
@login_required
@isAdmin
def admin_updates_actions(action,kind,id=False):
    if request.method == 'POST':
        if action == 'download':
            if id is not False:
                # Only one id
                d=u.getNewKindId(kind,current_user.id,id)
                if kind == 'domains':
                    missing_resources=u.get_missing_resources(d,current_user.id)
                    for k,v in missing_resources.items():
                        for resource in v:
                            app.adminapi.insert_or_update_table_dict(k,v)
                if d is not False:
                    if kind == 'domains':
                        d=u.formatDomains([d],current_user)[0]
                    elif kind == 'media':
{'fraction_non_alphanumeric': 0.12796952039444195, 'fraction_numerical': 0.0031376064545047063, 'mean_word_length': 2.85405872193437, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '910630', 'n_tokens_mistral': 1370, 'n_tokens_neox': 1326, 'n_words': 301}