<commit_before>from string import join
import cStringIO
import hashlib
import io
import os
import re
from itertools import chain

from django.core.exceptions import ValidationError, ObjectDoesNotExist
from django.db import models

from guardian.shortcuts import get_objects_for_user, get_perms_for_model

import numpy
import fcm

from reflow.settings import MEDIA_ROOT


class ProtectedModel(models.Model):
    class Meta:
        abstract = True

    def has_view_permission(self, user):
        return False

    def has_add_permission(self, user):
        return False

    def has_modify_permission(self, user):
        return False

    def has_user_management_permission(self, user):
        return False


class ProjectManager(models.Manager):
    def get_user_projects(self, user):
        """
        Returns a list of projects for which the given user has any level of access,
        including any access to even a single site in the project. Do not use the method
        to determine whether a user has access to a particular project resource.
        """
        projects = get_objects_for_user(user, get_perms_for_model(Project).values_list('codename'), klass=Project)
        sites = get_objects_for_user(user, get_perms_for_model(Site).values_list('codename'), klass=Site)
        site_projects = Project.objects.filter(id__in=[i['project_id'] for i in sites])

        return list(chain(projects, site_projects))


class Project(ProtectedModel):
    project_name = models.CharField("Project Name", unique=True, null=False, blank=False, max_length=128)
    project_desc = models.TextField(
        "Project Description",
        null=True,
        blank=True,
        help_text="A short description of the project")

    objects = ProjectManager()

    class Meta:
        permissions = (
            ('view_project_data', 'View Project'),
            ('add_project_data', 'Add Project Data'),
            ('modify_project_data', 'Modify/Delete Project Data'),
            ('manage_project_users', 'Manage Project Users'),
        )

    def has_view_permission(self, user):


    def get_visit_type_count(self):
        return ProjectVisitType.objects.filter(project=self).count()

    def get_panel_count(self):<commit_msg>models.py: just check for view project data and view site data permissions to qualify as a project user<commit_after>from string import join
import cStringIO
import hashlib
import io
import os
import re
from itertools import chain

from django.core.exceptions import ValidationError, ObjectDoesNotExist
from django.db import models

from guardian.shortcuts import get_objects_for_user, get_perms_for_model

import numpy
import fcm

from reflow.settings import MEDIA_ROOT


class ProtectedModel(models.Model):
    class Meta:
        abstract = True

    def has_view_permission(self, user):
        return False

    def has_add_permission(self, user):
        return False

    def has_modify_permission(self, user):
        return False

    def has_user_management_permission(self, user):
        return False


class ProjectManager(models.Manager):
    def get_user_projects(self, user):
        """
        Returns a list of projects for which the given user has any level of access,
        including any access to even a single site in the project. Do not use the method
        to determine whether a user has access to a particular project resource.
        """
        projects = get_objects_for_user(user, 'view_project_data', klass=Project)
        sites = get_objects_for_user(user, 'view_site_data', klass=Site)
        site_projects = Project.objects.filter(id__in=[i['project_id'] for i in sites])

        return list(chain(projects, site_projects))


class Project(ProtectedModel):
    project_name = models.CharField("Project Name", unique=True, null=False, blank=False, max_length=128)
    project_desc = models.TextField(
        "Project Description",
        null=True,
        blank=True,
        help_text="A short description of the project")

    objects = ProjectManager()

    class Meta:
        permissions = (
            ('view_project_data', 'View Project'),
            ('add_project_data', 'Add Project Data'),
            ('modify_project_data', 'Modify/Delete Project Data'),
            ('manage_project_users', 'Manage Project Users'),
        )

    #def has_view_permission(self, user):


    def get_visit_type_count(self):
        return ProjectVisitType.objects.filter(project=self).count()

    def get_panel_count(self):
{'fraction_non_alphanumeric': 0.07873142603681525, 'fraction_numerical': 0.0013306719893546241, 'mean_word_length': 3.4346116027531957, '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': '471084', 'n_tokens_mistral': 1256, 'n_tokens_neox': 1219, 'n_words': 378}