<commit_before>#!/usr/bin/python
#
# Copyright (c) 2011 rPath, Inc.
#
# All rights reserved.
#

import sys
from django.db import models

from mint.django_rest.deco import D
from mint.django_rest.rbuilder import modellib
from mint.django_rest.rbuilder.users import models as usersmodels
from mint.django_rest.rbuilder.projects import models as projectsmodels
from mint.django_rest.rbuilder.rbac import models as rbacmodels
from mint.django_rest.rbuilder.querysets import errors
from mint.django_rest.rbuilder.jobs import models as jobmodels
from django.db.utils import IntegrityError
from xobj import xobj

APIReadOnly = modellib.APIReadOnly
XObjHidden = modellib.XObjHidden

OPERATOR_CHOICES = [(k, v) for k, v in modellib.filterTermMap.items()]

class Universe(modellib.XObjIdModel):
    '''Reference to the absolute all of a Given Type parent of any queryset'''
    class Meta:
        abstract = True
    _xobj = xobj.XObjMetadata(tag = "universe")
    view_name = "QuerySetUniverseResult"

class AllMembers(modellib.XObjIdModel):
    '''Query set results matched regardless of match type (below)'''
    class Meta:
        abstract = True
    _xobj = xobj.XObjMetadata(
                tag = "all_members")
    view_name = "QuerySetAllResult"

class ChosenMembers(modellib.XObjIdModel):
    '''Query set results based on resources explicitly added to the QS'''
    class Meta:
        abstract = True
    _xobj = xobj.XObjMetadata(
                tag = "chosen_members")
    view_name = "QuerySetChosenResult"

class FilteredMembers(modellib.XObjIdModel):
    '''Query set results based on given match criteria'''
    class Meta:
        abstract = True
    _xobj = xobj.XObjMetadata(
                tag = "filtered_members")
    view_name = "QuerySetFilteredResult"

class ChildMembers(modellib.XObjIdModel):
    '''Query set results that are selected because of a child query set'''
    class Meta:
        abstract = True
    _xobj = xobj.XObjMetadata(
                tag = "child_members")
    view_name = "QuerySetChildResult"

class GrantMatrix(modellib.XObjIdModel):
    '''Permissions on queryset arranged in a UI-friendly way'''
    class Meta:
        abstract = True
    _xobj = xobj.XObjMetadata(
                tag = "grant_matrix")
    view_name = "QuerySetGrantMatrix"

class FavoriteQuerySets(modellib.Collection):
    '''A list of all query sets in the rBuilder'''
    class Meta:
        abstract = True
    _xobj = xobj.XObjMetadata(
                tag = "favorite_query_sets")
    list_fields = ["query_set"]
    query_set = []
    view_name = 'FavoriteQuerySets'

class QuerySets(modellib.Collection):
    '''A list of all query sets in the rBuilder'''
    class Meta:
        abstract = True
    _xobj = xobj.XObjMetadata(
                tag = "query_sets")
    list_fields = ["query_set"]
    query_set = []

class FilterDescriptor(modellib.XObjIdModel):

    # this is a stub for serialization of a URL only, 
    # see the other FilterDescriptor in descriptors.py 

    class Meta:
        abstract = True
    _xobj = xobj.XObjMetadata(attributes = {'id':str})

    id = models.AutoField(primary_key=True)
    view_name = "QuerySetFilterDescriptor"

class CollectionId(modellib.XObjIdModel):
    class Meta:
        abstract = True
    _xobj = xobj.XObjMetadata(tag='collection')
                

class QuerySet(modellib.XObjIdModel):
    '''An individual queryset, ex: "All Systems"'''

    objects = modellib.SaveableManyToManyManager()
    _xobj = xobj.XObjMetadata(
                tag = "query_set")
    _xobj_explicit_accessors = set([])
    _m2m_safe_to_create = [ 'filter_entries' ]
    summary_view = [ 'name', 'description' ]

    query_set_id = D(models.AutoField(primary_key=True),
        "The database id for the query set")
    name = D(models.TextField(unique=True),
        "Query set name, must be unique", short="Queryset name")
    description = D(models.TextField(null=True),
        "Query set description, is null by default", short="Queryset description")
    created_date = D(modellib.DateTimeUtcField(auto_now_add=True),
        "Date the query set was created")
    modified_date = D(modellib.DateTimeUtcField(auto_now_add=True),
        "Date the query set was modified")
    tagged_date = D(modellib.DateTimeUtcField(auto_now_add=False),
        "Date the query set was last tagged")
    children = D(models.ManyToManyField("self", symmetrical=False),
        "Query sets that are children of this query set")
    filter_entries = D(models.ManyToManyField("FilterEntry"),
        "Defined filter entries for this query set")
    resource_type = D(models.TextField(),
        "Name of the resource this query set operates on")
    presentation_type = D(models.TextField(),
        "A classification for client to use when displaying the objects.  For example, stages can be on projects, branches, platforms, etc.")
    can_modify = D(models.BooleanField(default=True),
        "Whether this query set can be deleted through the API.  Boolean, defaults to False")
    # TODO: make this an href field and not inline
    config_environments = D(models.ManyToManyField("ConfigEnvironment", through='QuerySetConfigEnvironment', 
        symmetrical=False, related_name='querysets'), "Query sets that are children of this query set")

    actions = D(modellib.SyntheticField(jobmodels.Actions), 'Available actions on this query set')
    # public querysets are querysets like "All Systems" and do not require rbac ReadSet permissions
    # to be visible, but will be empty unless ReadMember(ship) is conveyed on some of their contents.
    is_public = APIReadOnly(models.BooleanField(default=False))<commit_msg>Fixed some nullable fields that were not marked so in the django models (RCE-1879)<commit_after>#!/usr/bin/python
#
# Copyright (c) 2011 rPath, Inc.
#
# All rights reserved.
#

import sys
from django.db import models

from mint.django_rest.deco import D
from mint.django_rest.rbuilder import modellib
from mint.django_rest.rbuilder.users import models as usersmodels
from mint.django_rest.rbuilder.projects import models as projectsmodels
from mint.django_rest.rbuilder.rbac import models as rbacmodels
from mint.django_rest.rbuilder.querysets import errors
from mint.django_rest.rbuilder.jobs import models as jobmodels
from django.db.utils import IntegrityError
from xobj import xobj

APIReadOnly = modellib.APIReadOnly
XObjHidden = modellib.XObjHidden

OPERATOR_CHOICES = [(k, v) for k, v in modellib.filterTermMap.items()]

class Universe(modellib.XObjIdModel):
    '''Reference to the absolute all of a Given Type parent of any queryset'''
    class Meta:
        abstract = True
    _xobj = xobj.XObjMetadata(tag = "universe")
    view_name = "QuerySetUniverseResult"

class AllMembers(modellib.XObjIdModel):
    '''Query set results matched regardless of match type (below)'''
    class Meta:
        abstract = True
    _xobj = xobj.XObjMetadata(
                tag = "all_members")
    view_name = "QuerySetAllResult"

class ChosenMembers(modellib.XObjIdModel):
    '''Query set results based on resources explicitly added to the QS'''
    class Meta:
        abstract = True
    _xobj = xobj.XObjMetadata(
                tag = "chosen_members")
    view_name = "QuerySetChosenResult"

class FilteredMembers(modellib.XObjIdModel):
    '''Query set results based on given match criteria'''
    class Meta:
        abstract = True
    _xobj = xobj.XObjMetadata(
                tag = "filtered_members")
    view_name = "QuerySetFilteredResult"

class ChildMembers(modellib.XObjIdModel):
    '''Query set results that are selected because of a child query set'''
    class Meta:
        abstract = True
    _xobj = xobj.XObjMetadata(
                tag = "child_members")
    view_name = "QuerySetChildResult"

class GrantMatrix(modellib.XObjIdModel):
    '''Permissions on queryset arranged in a UI-friendly way'''
    class Meta:
        abstract = True
    _xobj = xobj.XObjMetadata(
                tag = "grant_matrix")
    view_name = "QuerySetGrantMatrix"

class FavoriteQuerySets(modellib.Collection):
    '''A list of all query sets in the rBuilder'''
    class Meta:
        abstract = True
    _xobj = xobj.XObjMetadata(
                tag = "favorite_query_sets")
    list_fields = ["query_set"]
    query_set = []
    view_name = 'FavoriteQuerySets'

class QuerySets(modellib.Collection):
    '''A list of all query sets in the rBuilder'''
    class Meta:
        abstract = True
    _xobj = xobj.XObjMetadata(
                tag = "query_sets")
    list_fields = ["query_set"]
    query_set = []

class FilterDescriptor(modellib.XObjIdModel):

    # this is a stub for serialization of a URL only, 
    # see the other FilterDescriptor in descriptors.py 

    class Meta:
        abstract = True
    _xobj = xobj.XObjMetadata(attributes = {'id':str})

    id = models.AutoField(primary_key=True)
    view_name = "QuerySetFilterDescriptor"

class CollectionId(modellib.XObjIdModel):
    class Meta:
        abstract = True
    _xobj = xobj.XObjMetadata(tag='collection')
                

class QuerySet(modellib.XObjIdModel):
    '''An individual queryset, ex: "All Systems"'''

    objects = modellib.SaveableManyToManyManager()
    _xobj = xobj.XObjMetadata(
                tag = "query_set")
    _xobj_explicit_accessors = set([])
    _m2m_safe_to_create = [ 'filter_entries' ]
    summary_view = [ 'name', 'description' ]

    query_set_id = D(models.AutoField(primary_key=True),
        "The database id for the query set")
    name = D(models.TextField(unique=True),
        "Query set name, must be unique", short="Queryset name")
    description = D(models.TextField(null=True),
        "Query set description, is null by default", short="Queryset description")
    created_date = D(modellib.DateTimeUtcField(auto_now_add=True),
        "Date the query set was created")
    modified_date = D(modellib.DateTimeUtcField(auto_now_add=True),
        "Date the query set was modified")
    tagged_date = D(modellib.DateTimeUtcField(auto_now_add=False, null=True),
        "Date the query set was last tagged")
    children = D(models.ManyToManyField("self", symmetrical=False),
        "Query sets that are children of this query set")
    filter_entries = D(models.ManyToManyField("FilterEntry"),
        "Defined filter entries for this query set")
    resource_type = D(models.TextField(),
        "Name of the resource this query set operates on")
    presentation_type = D(models.TextField(null=True),
        "A classification for client to use when displaying the objects.  For example, stages can be on projects, branches, platforms, etc.")
    can_modify = D(models.BooleanField(default=True),
        "Whether this query set can be deleted through the API.  Boolean, defaults to False")
    # TODO: make this an href field and not inline
    config_environments = D(models.ManyToManyField("ConfigEnvironment", through='QuerySetConfigEnvironment', 
        symmetrical=False, related_name='querysets'), "Query sets that are children of this query set")

    actions = D(modellib.SyntheticField(jobmodels.Actions), 'Available actions on this query set')
    # public querysets are querysets like "All Systems" and do not require rbac ReadSet permissions
    # to be visible, but will be empty unless ReadMember(ship) is conveyed on some of their contents.
    is_public = APIReadOnly(models.BooleanField(default=False))
{'fraction_non_alphanumeric': 0.08961232169423296, 'fraction_numerical': 0.0012251684606633412, 'mean_word_length': 3.499212598425197, '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': '124794', 'n_tokens_mistral': 3371, 'n_tokens_neox': 3323, 'n_words': 1003}