<commit_before>from django.shortcuts import render
from django.db import models

from base.models import EventHappening, Unit, Event
from base.views_support import HttpJSONResponse


def events(request):
    events = []
    eh_qs = EventHappening.objects.all()
    eh_qs = eh_qs.filter(event__state_chief__in=(Event.STATE_ENABLED, Event.STATE_RESERVED))
    eh_qs = eh_qs.filter(event__state_activation=Event.ACTIVATION_ACTIVE)
    eh_qs = eh_qs.filter(event__state_subscription=Event.SUBSCRIPTION_OPEN)
    for eh in eh_qs:
        obj = eh.as_dict()
        events.append(obj)
    return HttpJSONResponse(events)

def units(request):
    units = []
    for unit in Unit.objects.all():
        units.append(unit.name)

    return HttpJSONResponse(units)<commit_msg>Aggiunto filtro per restringere gli eventi restituiti a quelli con posti liberi<commit_after>from django.shortcuts import render
from django.db import models

from base.models import EventHappening, Unit, Event
from base.views_support import HttpJSONResponse


def events(request):
    """
    Return all subscriptable events.
    """

    events = []
    eh_qs = EventHappening.objects.all()
    # Restrict to those enabled or reserved for chiefs
    eh_qs = eh_qs.filter(event__state_chief__in=(Event.STATE_ENABLED, Event.STATE_RESERVED))
    # Restrict to those actives
    eh_qs = eh_qs.filter(event__state_activation=Event.ACTIVATION_ACTIVE)
    # Restrict to those open for subscription
    eh_qs = eh_qs.filter(event__state_subscription=Event.SUBSCRIPTION_OPEN)
    for eh in eh_qs:
        # Restrict to those with available seats
        # I use properties!
        if eh.available_seats:
            obj = eh.as_dict()
            events.append(obj)
    return HttpJSONResponse(events)


def units(request):
    units = []
    for unit in Unit.objects.all():
        units.append(unit.name)

    return HttpJSONResponse(units)
{'fraction_non_alphanumeric': 0.0804416403785489, 'fraction_numerical': 0.0, 'mean_word_length': 3.7338308457711444, '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': '859639', 'n_tokens_mistral': 612, 'n_tokens_neox': 581, 'n_words': 141}