<commit_before>#!/usr/bin/env python
# -*- coding: utf-8 -*-

from flask import render_template, url_for, redirect, request, session, flash, Blueprint
from models import User, Collection
from helpers import user_required
from database import db
import json

bp = Blueprint('collection', __name__, url_prefix='/collection/')


@bp.route('')
@user_required
def mine():
    """ Affiche la collection de l’utilisateur connecté """

    username = session["username"]
    collections = Collection.query.filter_by(login_user=session["username"]).all()

    return render_template("collection/index.html", **locals())


@bp.route('update', methods=["POST"])
@user_required
def update():
    """ Met à jour la collection de l’utilisateur connecté """

    text = request.form["json"]
    data = json.loads(text)
    for id, modifs in data.items():
        modification = {}
        for modif in modifs:
            modification[modif["type"]] = modif["value"]

        if modification["possede"] == 1:
            modification["souhaite"] = 0

        collec = Collection().query.get(id)
        collec.possede = modification["possede"]
        collec.souhaite = modification["souhaite"]
        collec.ngoods = modification["ngoods"]

    db.session.commit()

    return redirect(url_for("echange.compute"))<commit_msg>adapted collection module to new models<commit_after>#!/usr/bin/env python
# -*- coding: utf-8 -*-

from flask import render_template, url_for, redirect, request, session, flash, Blueprint
from models import User, Collection
from helpers import user_required
from database import db
import json

bp = Blueprint('collection', __name__, url_prefix='/collection/')


@bp.route('')
@user_required
def mine():
    """ Affiche la collection de l’utilisateur connecté """

    collections = User.query.get(session["username"]).collections

    return render_template("collection/index.html", **locals())


@bp.route('update', methods=["POST"])
@user_required
def update():
    """ Met à jour la collection de l’utilisateur connecté """

    text = request.form["json"]
    data = json.loads(text)
    for id, modifs in data.items():
        if modifs["wishesit"] == 1:
            modifs["hasit"] = 0

        if modifs["hasit"] == 1:
            modifs["wishesit"] = 0

        collec = Collection.query.get(id)
        collec.has_it = modifs["hasit"]
        collec.wishes_it = modifs["wishesit"]
        collec.value = modifs["value"]

        db.session.commit()

    return redirect(url_for("exchange.compute"))
{'fraction_non_alphanumeric': 0.1400238000793336, 'fraction_numerical': 0.0031733439111463705, 'mean_word_length': 3.636029411764706, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1318707', 'n_tokens_mistral': 767, 'n_tokens_neox': 753, 'n_words': 190}