<commit_before># -*- coding: utf-8  -*-
import urllib2
import json
from post_office import mail


from django.http import HttpResponseRedirect
from django.utils import timezone

from core.utils import hindi_to_arabic
from events.models import Event, SessionRegistration
import clubs.utils

def can_evaluate_abstracts(user, event):
    if user.is_superuser:
        return True
    elif event.abstract_revision_team:
        return clubs.utils.is_team_coordinator_or_member(event.abstract_revision_team, user)
    else:
        return False

def check_if_closed(event):
    if event.registration_closing_date and \
       timezone.now() > event.registration_closing_date:
        return HttpResponseRedirect(reverse('events:registration_closed'))

def get_user_organizing_events(user):
    if not user.is_authenticated():
        return Event.objects.none()
    elif user.is_superuser:
        user_events = Event.objects.all()
    else:
        user_events = (Event.objects.filter(organizing_team__members=user) | \
                       Event.objects.filter(organizing_team__coordinator=user)).distinct()
    return user_events

def get_user_abstract_revision_events(user):
    if not user.is_authenticated():
        return Event.objects.none()
    elif user.is_superuser:
        user_events = Event.objects.all()
    else:
        user_events = (Event.objects.filter(abstract_revision_team__members=user) | \
                       Event.objects.filter(abstract_revision_team__coordinator=user)).distinct()
    return user_events

def get_user_attendance_events(user):
    if not user.is_authenticated():
        return Event.objects.none()
    elif user.is_superuser:
        user_events = Event.objects.all()
    else:
        user_events = (Event.objects.filter(attendance_team__members=user) | \
                       Event.objects.filter(attendance_team__coordinator=user)).distinct()
    return user_events

def get_user_admistrative_events(user):
    user_events = get_user_abstract_revision_events(user) | \
                  get_user_organizing_events(user) | \
                  get_user_abstract_revision_events(user)
    return user_events

def is_organizing_team_member(user, event):
    user_events = get_user_organizing_events(user)
    return user_events.filter(pk=event.pk).exists()

def is_attendance_team_member(user, event):
    user_events = get_user_attendance_events(user)
    return user_events.filter(pk=event.pk).exists()

def register_in_vma(session, registration):
    en_full_name = urllib2.quote(registration.get_en_full_name().replace(u'\u202a', '')
                                                                .replace(u'\u202b', '')
                                                                .replace(u'\u202c', '')
                                                                .replace(u'\u202d', '')
                                                                .encode("utf-8"))
    arabic_phone_number = hindi_to_arabic(registration.get_phone())
    phone_number = arabic_phone_number.replace(u'\u202a', '')\
                                      .replace(u'\u202b', '')\
                                      .replace(u'\u202c', '')\
                                      .replace(u'\u202d', '')\
                                      .replace(u'\xa0', '')\
                                      .replace(' ', '')\
                                      .replace('+', '')\
                                      .encode("utf-8")<commit_msg>Add attendance to user admin events<commit_after># -*- coding: utf-8  -*-
import urllib2
import json
from post_office import mail


from django.http import HttpResponseRedirect
from django.utils import timezone

from core.utils import hindi_to_arabic
from events.models import Event, SessionRegistration
import clubs.utils

def can_evaluate_abstracts(user, event):
    if user.is_superuser:
        return True
    elif event.abstract_revision_team:
        return clubs.utils.is_team_coordinator_or_member(event.abstract_revision_team, user)
    else:
        return False

def check_if_closed(event):
    if event.registration_closing_date and \
       timezone.now() > event.registration_closing_date:
        return HttpResponseRedirect(reverse('events:registration_closed'))

def get_user_organizing_events(user):
    if not user.is_authenticated():
        return Event.objects.none()
    elif user.is_superuser:
        user_events = Event.objects.all()
    else:
        user_events = (Event.objects.filter(organizing_team__members=user) | \
                       Event.objects.filter(organizing_team__coordinator=user)).distinct()
    return user_events

def get_user_abstract_revision_events(user):
    if not user.is_authenticated():
        return Event.objects.none()
    elif user.is_superuser:
        user_events = Event.objects.all()
    else:
        user_events = (Event.objects.filter(abstract_revision_team__members=user) | \
                       Event.objects.filter(abstract_revision_team__coordinator=user)).distinct()
    return user_events

def get_user_attendance_events(user):
    if not user.is_authenticated():
        return Event.objects.none()
    elif user.is_superuser:
        user_events = Event.objects.all()
    else:
        user_events = (Event.objects.filter(attendance_team__members=user) | \
                       Event.objects.filter(attendance_team__coordinator=user)).distinct()
    return user_events

def get_user_admistrative_events(user):
    user_events = get_user_abstract_revision_events(user) | \
                  get_user_organizing_events(user) | \
                  get_user_attendance_events(user)
    return user_events

def is_organizing_team_member(user, event):
    user_events = get_user_organizing_events(user)
    return user_events.filter(pk=event.pk).exists()

def is_attendance_team_member(user, event):
    user_events = get_user_attendance_events(user)
    return user_events.filter(pk=event.pk).exists()

def register_in_vma(session, registration):
    en_full_name = urllib2.quote(registration.get_en_full_name().replace(u'\u202a', '')
                                                                .replace(u'\u202b', '')
                                                                .replace(u'\u202c', '')
                                                                .replace(u'\u202d', '')
                                                                .encode("utf-8"))
    arabic_phone_number = hindi_to_arabic(registration.get_phone())
    phone_number = arabic_phone_number.replace(u'\u202a', '')\
                                      .replace(u'\u202b', '')\
                                      .replace(u'\u202c', '')\
                                      .replace(u'\u202d', '')\
                                      .replace(u'\xa0', '')\
                                      .replace(' ', '')\
                                      .replace('+', '')\
                                      .encode("utf-8")
{'fraction_non_alphanumeric': 0.09738683421390833, 'fraction_numerical': 0.00856775667571041, 'mean_word_length': 2.0854625550660795, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 30, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1948352', 'n_tokens_mistral': 1976, 'n_tokens_neox': 1906, 'n_words': 298}