<commit_before>from tastypie.authorization import Authorization
from tastypie.resources import ModelResource, fields, ALL_WITH_RELATIONS
from oms_pds.authentication import OAuth2Authentication
from oms_pds.authorization import PDSAuthorization
#from oms_pds.trust.models import SharingLevel, Role, Purpose
from oms_pds import settings
import datetime
import json, ast

from tastypie import fields
from tastypie.authorization import Authorization
from tastypie.validation import Validation
from oms_pds.tastypie_mongodb.resources import MongoDBResource, Document
from oms_pds.pds.models import AuditEntry, Profile, SharingLevel, Role, Purpose, Scope
from django.db import models

import pdb

class FunfResource(MongoDBResource):

    id = fields.CharField(attribute="_id")
    key = fields.CharField(attribute="key", null=True, help_text='The funf probe name.')
    time = fields.DateTimeField(attribute="time", null=True, help_text='A human readable datetime.  The time represents when funf collected the data.')
    value = fields.CharField(attribute="value", null=True, help_text='A json blob of funf data.')

    class Meta:
        authentication = OAuth2Authentication("funf_write")
        authorization = PDSAuthorization(scope = "funf_write", audit_enabled = True)
        resource_name = "funf"
        list_allowed_methods = ["delete", "get", "post"]
#        authorization = Authorization()
        object_class = Document
        collection = "funf" # collection name

class FunfConfigResource(MongoDBResource):

    id = fields.CharField(attribute="_id")
    key = fields.CharField(attribute="key", null=True)

    class Meta:
        resource_name = "funfconfig"
        list_allowed_methods = ["delete", "get", "post"]
        authorization = Authorization()
        object_class = Document
        collection = "funfconfig" # collection name

class AnswerResource(MongoDBResource):
    id = fields.CharField(attribute="_id", help_text='A guid identifier for an answer entry.')
    key = fields.CharField(attribute="key", help_text='A unique string to identify each answer.', null=False, unique=True)
#    data = fields.ToManyField('oms_pds.pds.api.resources.SocialHealthResource', 'socialhealth_set', related_name='realityanalysis')
    value = fields.DictField(attribute="data", help_text='A json blob of answer data.', null=True, )

    class Meta:<commit_msg>Added filtering on key(probe) to funf resource<commit_after>from tastypie.authorization import Authorization
from tastypie.resources import ModelResource, fields, ALL_WITH_RELATIONS
from oms_pds.authentication import OAuth2Authentication
from oms_pds.authorization import PDSAuthorization
#from oms_pds.trust.models import SharingLevel, Role, Purpose
from oms_pds import settings
import datetime
import json, ast

from tastypie import fields
from tastypie.authorization import Authorization
from tastypie.validation import Validation
from oms_pds.tastypie_mongodb.resources import MongoDBResource, Document
from oms_pds.pds.models import AuditEntry, Profile, SharingLevel, Role, Purpose, Scope
from django.db import models

import pdb

class FunfResource(MongoDBResource):

    id = fields.CharField(attribute="_id")
    key = fields.CharField(attribute="key", null=True, help_text='The funf probe name.')
    time = fields.DateTimeField(attribute="time", null=True, help_text='A human readable datetime.  The time represents when funf collected the data.')
    value = fields.CharField(attribute="value", null=True, help_text='A json blob of funf data.')

    class Meta:
        authentication = OAuth2Authentication("funf_write")
        authorization = PDSAuthorization(scope = "funf_write", audit_enabled = True)
        resource_name = "funf"
        list_allowed_methods = ["delete", "get", "post"]
#        authorization = Authorization()
        object_class = Document
        collection = "funf" # collection name
#        filtering = { "key" : ["exact"]}    
   
    def obj_get_list(self, request=None, **kwargs):
        """
        Maps mongodb documents to Document class.
        """
#	pdb.set_trace()
        if (request and "key" in request.GET):
            return map(Document, self.get_collection(request).find({ "key": request.GET["key"]}))
        return map(Document, self.get_collection(request).find())

class FunfConfigResource(MongoDBResource):

    id = fields.CharField(attribute="_id")
    key = fields.CharField(attribute="key", null=True)

    class Meta:
        resource_name = "funfconfig"
        list_allowed_methods = ["delete", "get", "post"]
        authorization = Authorization()
        object_class = Document
        collection = "funfconfig" # collection name

class AnswerResource(MongoDBResource):
    id = fields.CharField(attribute="_id", help_text='A guid identifier for an answer entry.')
    key = fields.CharField(attribute="key", help_text='A unique string to identify each answer.', null=False, unique=True)
#    data = fields.ToManyField('oms_pds.pds.api.resources.SocialHealthResource', 'socialhealth_set', related_name='realityanalysis')
    value = fields.DictField(attribute="data", help_text='A json blob of answer data.', null=True, )

    class Meta:
{'fraction_non_alphanumeric': 0.0993453985367732, 'fraction_numerical': 0.0007701193685021178, 'mean_word_length': 4.616216216216216, 'pattern_counts': {'":': 1, '<': 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': '7204442', 'n_tokens_mistral': 1483, 'n_tokens_neox': 1461, 'n_words': 399}