<commit_before>from django.contrib.contenttypes.models import ContentType
from django.shortcuts import render

from django.conf import settings
from django.db.models.fields import related
from django.template.loader import get_template
from django.template import Context

import json

graph_settings = getattr(settings, 'GRAPH_MODELS', {})
apps = graph_settings.get('apps',[])

def plate(request):

    models = ContentType.objects.filter(app_label__in=apps)
    nodes = []
    edges = []
    for model in models:
        model.doc  = model.model_class().__doc__
        _id = "%s__%s"%(model.app_label,model.model)
        label = "%s"%(model.model)
        fields = [f for f in model.model_class()._meta.fields if not str(f.name).endswith('_ptr')]
        many = [f for f in model.model_class()._meta.many_to_many]
        if graph_settings.get('show_fields',True):
            label += "\n%s\n"%("-"*len(model.model))
            label += "\n".join([str(f.name) for f in fields])
        edge_color = {'inherit':'from'}

        for f in fields:
            f.ftype = str(f.__class__).split('.')[-1][:-2]
            if type(f) == related.ForeignKey:
                _to = tuple(str(f.related_field).lower().split('.')[0:2])
                if _to[0] != model.app_label:
                    edge_color = {'inherit':'both'}
                edges.append(
                    {
                        'from':_id,
                        'to':"%s__%s"%_to,
                        'color':edge_color,
                        'arrows':{'to':{'scaleFactor':0.75}}
                    }
                )
        for f in many:
            #print dir(f)
            m = f.rel.to._meta
            #if m.app_label != model.app_label:
            edge_color = {'color':'gray'}<commit_msg>added potential to exclude model<commit_after>from django.contrib.contenttypes.models import ContentType
from django.shortcuts import render

from django.conf import settings
from django.db.models.fields import related
from django.template.loader import get_template
from django.template import Context

import json

graph_settings = getattr(settings, 'SPAGHETTI_SAUCE', {})
apps = graph_settings.get('apps',[])

def plate(request):
    excludes = ['%s__%s'%(app,model) for app,models in graph_settings.get('exclude',{}).items() for model in models ]
    models = ContentType.objects.filter(app_label__in=apps)
    nodes = []
    edges = []
    for model in models:
        model.doc  = model.model_class().__doc__
        _id = "%s__%s"%(model.app_label,model.model)
        if _id in excludes:
            continue
        label = "%s"%(model.model)
        fields = [f for f in model.model_class()._meta.fields if not str(f.name).endswith('_ptr')]
        many = [f for f in model.model_class()._meta.many_to_many]
        if graph_settings.get('show_fields',True):
            label += "\n%s\n"%("-"*len(model.model))
            label += "\n".join([str(f.name) for f in fields])
        edge_color = {'inherit':'from'}

        for f in fields:
            f.ftype = str(f.__class__).split('.')[-1][:-2]
            if type(f) == related.ForeignKey:
                _to = tuple(str(f.related_field).lower().split('.')[0:2])
                if _to[0] != model.app_label:
                    edge_color = {'inherit':'both'}
                edges.append(
                    {
                        'from':_id,
                        'to':"%s__%s"%_to,
                        'color':edge_color,
                        'arrows':{'to':{'scaleFactor':0.75}}
                    }
                )
        for f in many:
            #print dir(f)
            m = f.rel.to._meta
            #if m.app_label != model.app_label:
            edge_color = {'color':'gray'}
{'fraction_non_alphanumeric': 0.14323748668796593, 'fraction_numerical': 0.004259850905218318, 'mean_word_length': 2.012830793905373, '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': '1042130', 'n_tokens_mistral': 1154, 'n_tokens_neox': 1120, 'n_words': 234}