<commit_before>"""
Model for branding_stanford

This was implemented initially so that the list of course tiles could be
stored in this model.
"""
from django.conf import settings
from django.db import models

from config_models.models import ConfigurationModel
from opaque_keys.edx.django.models import CourseKeyField
from opaque_keys.edx.keys import CourseKey
from openedx.core.djangoapps.content.course_overviews.models import CourseOverview


class TileConfiguration(ConfigurationModel):
    """
        Stores a list of tiles presented on the front page.
    """
    site = models.CharField(max_length=32, default='default', blank=False)
    course_id = CourseKeyField(max_length=255, db_index=True)

    class Meta(ConfigurationModel.Meta):
        app_label = 'branding_stanford'

    def __unicode__(self):
        return u"{0} {1} {2}".format(self.site, self.course_id, self.enabled)


def get_visible_courses(org=None, filter_=None):
    """
    Get list of visible course tiles
    """
    if not settings.DISPLAY_COURSE_TILES:
        return []
    orgs = []
    if org:
        orgs.append(org)
    filtered_by_db = TileConfiguration.objects.filter(
        enabled=True,
    ).values('course_id').order_by('-change_date')
    courses = None
    if filtered_by_db:
        filtered_by_db_keys = frozenset([
            CourseKey.from_string(c['course_id'])
            for c in filtered_by_db
        ])
        courses = CourseOverview.get_all_courses(orgs=orgs, filter_=None)
        courses = [
            course
            for course in courses
            if course.id in filtered_by_db_keys
        ]<commit_msg>Fix branding_stanford home page tiles<commit_after>"""
Model for branding_stanford

This was implemented initially so that the list of course tiles could be
stored in this model.
"""
from django.conf import settings
from django.db import models

from config_models.models import ConfigurationModel
from opaque_keys.edx.django.models import CourseKeyField
from openedx.core.djangoapps.content.course_overviews.models import CourseOverview


class TileConfiguration(ConfigurationModel):
    """
        Stores a list of tiles presented on the front page.
    """
    site = models.CharField(max_length=32, default='default', blank=False)
    course_id = CourseKeyField(max_length=255, db_index=True)

    class Meta(ConfigurationModel.Meta):
        app_label = 'branding_stanford'

    def __unicode__(self):
        return u"{0} {1} {2}".format(self.site, self.course_id, self.enabled)


def get_visible_courses(org=None, filter_=None):
    """
    Get list of visible course tiles
    """
    if not settings.DISPLAY_COURSE_TILES:
        return []
    orgs = []
    if org:
        orgs.append(org)
    filtered_by_db = TileConfiguration.objects.filter(
        enabled=True,
    ).values('course_id').order_by('-change_date')
    courses = None
    if filtered_by_db:
        filtered_by_db_keys = frozenset([
            course['course_id']
            for course in filtered_by_db
        ])
        courses = CourseOverview.get_all_courses(orgs=orgs, filter_=None)
        courses = [
            course
            for course in courses
            if course.id in filtered_by_db_keys
        ]
{'fraction_non_alphanumeric': 0.0862708719851577, 'fraction_numerical': 0.004947433518862091, 'mean_word_length': 3.158097686375321, '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': '4615245', 'n_tokens_mistral': 968, 'n_tokens_neox': 948, 'n_words': 242}