<commit_before>#!/usr/bin/python
##
## Copyright 2009 <NAME> & <NAME>
##
## Licensed under the Apache License, Version 2.0 (the "License"); you
## may not use this file except in compliance with the License. You
## may obtain a copy of the License at
##
## http://www.apache.org/licenses/LICENSE-2.0
##
## Unless required by applicable law or agreed to in writing, software
## distributed under the License is distributed on an "AS IS" BASIS,
## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
## implied. See the License for the specific language governing
## permissions and limitations under the License.
##

from django.core.urlresolvers import reverse
from django.http import Http404, HttpResponse, HttpResponsePermanentRedirect
from django.shortcuts import render_to_response, get_object_or_404

from django.db.models import Q

import pymine.api.views as api
from pymine.api.models import Tag, Item, Relation, Comment, Vurl

from minekey import MineKey

##################################################################
##################################################################
##################################################################

def demofeed(request, *args, **kwargs):

    # get RELATION

    r = Relation.objects.get(id=1)

    # select (PUBLIC|SHARED) items marked FOR:RELATION

    qs1 = r.items_explicitly_for.filter(Q(status='P') | Q(status='S'))

    # select PUBLIC items where ITEM.TAG_CLOUD intersects RELATION.INTERESTS

    qs2 = Item.objects.none()

    # tbd

    # add the two above, together

    qs = qs1 | qs2

    # if RELATION.REQUIRES, reject items where ITEM.TAG_CLOUD fails to intersect it

    # tbd

    # reject items where ITEM.TAG_CLOUD intersects RELATION.EXCLUDES

    # tbd

    # reject items marked not:relation

    # tbd

    # distinct

    qs = qs.distinct()

    # reject items that are currently hidden

    # tbd
    # now=date()
    # qs = qs.exclude(Q(hide_before__le=now), Q(hide_after__ge=now))

    # reject items that are private (extra security mugtrap)

    qs = qs.exclude(status='X')<commit_msg>slight documentation of the security model<commit_after>#!/usr/bin/python
##
## Copyright 2009 <NAME> & <NAME>
##
## Licensed under the Apache License, Version 2.0 (the "License"); you
## may not use this file except in compliance with the License. You
## may obtain a copy of the License at
##
## http://www.apache.org/licenses/LICENSE-2.0
##
## Unless required by applicable law or agreed to in writing, software
## distributed under the License is distributed on an "AS IS" BASIS,
## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
## implied. See the License for the specific language governing
## permissions and limitations under the License.
##

from django.core.urlresolvers import reverse
from django.http import Http404, HttpResponse, HttpResponsePermanentRedirect
from django.shortcuts import render_to_response, get_object_or_404
from django.db.models import Q

import pymine.api.views as api
from pymine.api.models import Tag, Item, Relation, Comment, Vurl

from minekey import MineKey

##################################################################
##################################################################
##################################################################

# PRIORITIES:
#
# item.STATUS=PRIVATE trumps... 
# item.HIDDEN_TIME trumps...
# not:RELATION trumps...
# [OOB MINEKEY ACCESS (PUBLIC|SHARED)>] trumps...
# for:RELATION(PUBLIC|SHARED) trumps...
# exclude:TAG trumps...
# require:TAG trumps...
# intersection of ITEM(PUBLIC).EXPANDEDTAGCLOUD and RELATION.INTERESTS.

def demofeed(request, *args, **kwargs):

    # get RELATION
    r = Relation.objects.get(id=1)

    # select PUBLIC items where ITEM.TAG_CLOUD intersects RELATION.INTERESTS
    qs1 = Item.objects.none()
    # tbd

    # if RELATION.REQUIRES, reject items where ITEM.TAG_CLOUD fails to intersect it
    # tbd

    # reject items where ITEM.TAG_CLOUD intersects RELATION.EXCLUDES
    # tbd

    # select (PUBLIC|SHARED) items marked FOR:RELATION
    qs2 = r.items_explicitly_for.filter(Q(status='P') | Q(status='S'))

    # add the two above, together
    qs = qs1 | qs2

    # reject items marked NOT:RELATION
    # tbd

    # reject items that are currently HIDDEN
    # now=date()
    # qs = qs.exclude(Q(hide_before__gt=now), Q(hide_after__lte=now))

    # reject items that are PRIVATE
    qs = qs.exclude(status='X')

    # distinct
    qs = qs.distinct()
{'fraction_non_alphanumeric': 0.17881828316610926, 'fraction_numerical': 0.0084726867335563, 'mean_word_length': 4.277647058823529, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '5035738', 'n_tokens_mistral': 1397, 'n_tokens_neox': 1299, 'n_words': 421}