<commit_before># coding: utf-8

from __future__ import unicode_literals
import json
import logging

from django.apps import apps
from django.contrib.messages.views import SuccessMessageMixin
from django.contrib import messages
from django.contrib.contenttypes.models import ContentType
from django.http import JsonResponse
from django.shortcuts import get_object_or_404, render, redirect
from django.urls import reverse_lazy
from django.utils.safestring import mark_safe
from django.utils.translation import ugettext_lazy as _
from django.views.generic.edit import UpdateView, CreateView, DeleteView
from django.views.generic.list import ListView
from pygments import highlight
from pygments.lexers import JsonLexer
from pygments.formatters import HtmlFormatter

logger = logging.getLogger('laboite.apps')

from .models import App, Boite, Tile, TileApp, PushButton


# Boîtes

class BoiteListView(ListView):
    model = Boite

    def get_queryset(self):
        boites = Boite.objects.filter(qrcode=None)
        for boite in boites:
            boite.generate_qrcode()
            boite.save()

        return Boite.objects.filter(user=self.request.user).order_by("created_date")


def create_app_view(request, pk):
    boite = get_object_or_404(Boite, pk=pk, user=request.user)

    apps_list = []
    for model in apps.get_models():
        if issubclass(model, App):
            verbose_name =  model._meta.verbose_name.title()
            apps_list.append({'verbose_name':verbose_name[16:], 'pk':'create', 'app_label': model._meta.app_label})

    return render(request, 'boites/boite_create_app.html', {'boite': boite, 'boite_id': boite.id, 'apps': apps_list})


def tile_editor_view(request, boite_pk):
    boite = get_object_or_404(Boite, pk=boite_pk, user=request.user)

    return render(request, 'boites/tile_editor.html', {'boite': boite, 'boite_id': boite.id})


def apps_view(request, pk):
    boite = get_object_or_404(Boite, pk=pk, user=request.user)

    # update apps data
    boite.get_apps_dictionary()

    apps_list = []
    for model in apps.get_models():
        if issubclass(model, App):
            app_instances = model.objects.filter(boite=boite, enabled=True)
            if app_instances:
                for i, instance in enumerate(app_instances):
                    verbose_name =  model._meta.verbose_name.title()
                    app_label = model._meta.app_label
                    if app_instances.count() > 1:
                        verbose_name += ' ' + str(i + 1)
                    apps_list.append({'verbose_name':verbose_name[16:], 'pk':instance.pk, 'enabled':instance.enabled, 'app_label': model._meta.app_label, 'instance': instance})

    return render(request, 'boites/boite_apps.html', {'boite': boite, 'boite_id': boite.id, 'apps': apps_list})


def redirect_view(request, api_key):
    boite = get_object_or_404(Boite, api_key=api_key)
    return redirect('boites:update', pk=boite.pk)

<commit_msg>disabled app has to be displayed<commit_after># coding: utf-8

from __future__ import unicode_literals
import json
import logging

from django.apps import apps
from django.contrib.messages.views import SuccessMessageMixin
from django.contrib import messages
from django.contrib.contenttypes.models import ContentType
from django.http import JsonResponse
from django.shortcuts import get_object_or_404, render, redirect
from django.urls import reverse_lazy
from django.utils.safestring import mark_safe
from django.utils.translation import ugettext_lazy as _
from django.views.generic.edit import UpdateView, CreateView, DeleteView
from django.views.generic.list import ListView
from pygments import highlight
from pygments.lexers import JsonLexer
from pygments.formatters import HtmlFormatter

logger = logging.getLogger('laboite.apps')

from .models import App, Boite, Tile, TileApp, PushButton


# Boîtes

class BoiteListView(ListView):
    model = Boite

    def get_queryset(self):
        boites = Boite.objects.filter(qrcode=None)
        for boite in boites:
            boite.generate_qrcode()
            boite.save()

        return Boite.objects.filter(user=self.request.user).order_by("created_date")


def create_app_view(request, pk):
    boite = get_object_or_404(Boite, pk=pk, user=request.user)

    apps_list = []
    for model in apps.get_models():
        if issubclass(model, App):
            verbose_name =  model._meta.verbose_name.title()
            apps_list.append({'verbose_name':verbose_name[16:], 'pk':'create', 'app_label': model._meta.app_label})

    return render(request, 'boites/boite_create_app.html', {'boite': boite, 'boite_id': boite.id, 'apps': apps_list})


def tile_editor_view(request, boite_pk):
    boite = get_object_or_404(Boite, pk=boite_pk, user=request.user)

    return render(request, 'boites/tile_editor.html', {'boite': boite, 'boite_id': boite.id})


def apps_view(request, pk):
    boite = get_object_or_404(Boite, pk=pk, user=request.user)

    # update apps data
    boite.get_apps_dictionary()

    apps_list = []
    for model in apps.get_models():
        if issubclass(model, App):
            app_instances = model.objects.filter(boite=boite)
            if app_instances:
                for i, instance in enumerate(app_instances):
                    verbose_name =  model._meta.verbose_name.title()
                    app_label = model._meta.app_label
                    if app_instances.count() > 1:
                        verbose_name += ' ' + str(i + 1)
                    apps_list.append({'verbose_name':verbose_name[16:], 'pk':instance.pk, 'enabled':instance.enabled, 'app_label': model._meta.app_label, 'instance': instance})

    return render(request, 'boites/boite_apps.html', {'boite': boite, 'boite_id': boite.id, 'apps': apps_list})


def redirect_view(request, api_key):
    boite = get_object_or_404(Boite, api_key=api_key)
    return redirect('boites:update', pk=boite.pk)


{'fraction_non_alphanumeric': 0.10572538422563756, 'fraction_numerical': 0.007431177166019254, 'mean_word_length': 3.7262569832402233, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '569054', 'n_tokens_mistral': 1948, 'n_tokens_neox': 1848, 'n_words': 418}