<s> import csv <EOL> import datetime <EOL> import io <EOL> import re <EOL> import requests <EOL> from django . contrib import messages <EOL> from django . contrib . messages . views import SuccessMessageMixin <EOL> from django . contrib . auth import update_session_auth_hash <EOL> from django . contrib . auth . forms import SetPasswordForm , PasswordChangeForm <EOL> from django . contrib . auth . mixins import ( <EOL> LoginRequiredMixin , PermissionRequiredMixin , <EOL> ) <EOL> from django . core . urlresolvers import reverse , reverse_lazy <EOL> from django . core . exceptions import ( <EOL> ObjectDoesNotExist , <EOL> PermissionDenied , <EOL> ) <EOL> from django . core . mail import EmailMultiAlternatives <EOL> from django . conf import settings <EOL> from django . http import Http404 , HttpResponse , JsonResponse <EOL> from django . http import HttpResponseBadRequest <EOL> from django . db import IntegrityError , transaction <EOL> from django . db . models import Count , Q , F , Model , ProtectedError <EOL> from django . db . models import Case , When , Value , IntegerField <EOL> from django . shortcuts import redirect , render , get_object_or_404 <EOL> from django . template . loader import get_template <EOL> from django . views . generic import ListView , DetailView , TemplateView <EOL> from django . views . generic . edit import CreateView , UpdateView , ModelFormMixin <EOL> from django . contrib . auth . decorators import login_required , permission_required <EOL> from reversion . models import Revision <EOL> from reversion . revisions import get_for_object <EOL> from workshops . models import ( <EOL> Airport , <EOL> Award , <EOL> Badge , <EOL> Event , <EOL> Qualification , <EOL> Person , <EOL> Role , <EOL> Host , <EOL> Membership , <EOL> Tag , <EOL> Task , <EOL> EventRequest , <EOL> ProfileUpdateRequest , <EOL> TodoItem , <EOL> TodoItemQuerySet , <EOL> InvoiceRequest , <EOL> EventSubmission as EventSubmissionModel , <EOL> ) <EOL> from workshops . forms import ( <EOL> SearchForm , DebriefForm , InstructorsForm , PersonForm , PersonBulkAddForm , <EOL> EventForm , TaskForm , TaskFullForm , bootstrap_helper , bootstrap_helper_get , <EOL> bootstrap_helper_with_add , BadgeAwardForm , PersonAwardForm , <EOL> PersonPermissionsForm , bootstrap_helper_filter , PersonsSelectionForm , <EOL> PersonTaskForm , HostForm , SWCEventRequestForm , DCEventRequestForm , <EOL> ProfileUpdateRequestForm , PersonLookupForm , bootstrap_helper_wider_labels , <EOL> SimpleTodoForm , bootstrap_helper_inline_formsets , BootstrapHelper , <EOL> AdminLookupForm , ProfileUpdateRequestFormNoCaptcha , MembershipForm , <EOL> TodoFormSet , EventsSelectionForm , EventsMergeForm , InvoiceRequestForm , <EOL> InvoiceRequestUpdateForm , EventSubmitForm , EventSubmitFormNoCaptcha , <EOL> PersonsMergeForm , PersonCreateForm , <EOL> ) <EOL> from workshops . util import ( <EOL> upload_person_task_csv , verify_upload_person_task , <EOL> create_uploaded_persons_tasks , InternalError , <EOL> update_event_attendance_from_tasks , <EOL> WrongWorkshopURL , <EOL> generate_url_to_event_index , <EOL> find_tags_on_event_index , <EOL> find_tags_on_event_website , <EOL> parse_tags_from_event_website , <EOL> validate_tags_from_event_website , <EOL> assignment_selection , <EOL> get_pagination_items , <EOL> Paginator , <EOL> failed_to_delete , <EOL> assign , <EOL> merge_objects , <EOL> create_username , <EOL> ) <EOL> from workshops . filters import ( <EOL> EventFilter , HostFilter , PersonFilter , TaskFilter , AirportFilter , <EOL> EventRequestFilter , BadgeAwardsFilter , InvoiceRequestFilter , <EOL> EventSubmissionFilter , <EOL> ) <EOL> from api . views import ReportsViewSet <EOL> class CreateViewContext ( SuccessMessageMixin , CreateView ) : <EOL> """<STR_LIT>""" <EOL> success_message = '<STR_LIT>' <EOL> def get_context_data ( self , ** kwargs ) : <EOL> context = super ( CreateViewContext , self ) . get_context_data ( ** kwargs ) <EOL> context [ '<STR_LIT>' ] = self . model <EOL> if self . model and issubclass ( self . model , Model ) : <EOL> context [ '<STR_LIT:title>' ] = '<STR_LIT>' . format ( self . model . _meta . verbose_name ) <EOL> else : <EOL> context [ '<STR_LIT:title>' ] = '<STR_LIT>' <EOL> context [ '<STR_LIT>' ] = bootstrap_helper <EOL> return context <EOL> def get_success_message ( self , cleaned_data ) : <EOL> "<STR_LIT>" <EOL> return self . success_message . format ( cleaned_data , name = str ( self . object ) ) <EOL> class UpdateViewContext ( SuccessMessageMixin , UpdateView ) : <EOL> """<STR_LIT>""" <EOL> success_message = '<STR_LIT>' <EOL> def get_context_data ( self , ** kwargs ) : <EOL> context = super ( UpdateViewContext , self ) . get_context_data ( ** kwargs ) <EOL> context [ '<STR_LIT>' ] = self . model <EOL> context [ '<STR_LIT>' ] = self <EOL> context [ '<STR_LIT:title>' ] = str ( self . object ) <EOL> context [ '<STR_LIT>' ] = bootstrap_helper <EOL> return context <EOL> def get_success_message ( self , cleaned_data ) : <EOL> "<STR_LIT>" <EOL> return self . success_message . format ( cleaned_data , name = str ( self . object ) ) <EOL> class FilteredListView ( ListView ) : <EOL> paginator_class = Paginator <EOL> filter_class = None <EOL> queryset = None <EOL> def get_filter_data ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . request . GET <EOL> def get_queryset ( self ) : <EOL> """<STR_LIT>""" <EOL> self . filter = self . filter_class ( self . get_filter_data ( ) , <EOL> super ( ) . get_queryset ( ) ) <EOL> return self . filter <EOL> def get_context_data ( self , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> context = super ( ) . get_context_data ( ** kwargs ) <EOL> context [ '<STR_LIT>' ] = self . filter <EOL> context [ '<STR_LIT>' ] = bootstrap_helper_filter <EOL> return context <EOL> class EmailSendMixin ( ) : <EOL> email_fail_silently = True <EOL> email_kwargs = None <EOL> def get_subject ( self ) : <EOL> """<STR_LIT>""" <EOL> return "<STR_LIT>" <EOL> def get_body ( self ) : <EOL> """<STR_LIT>""" <EOL> return "<STR_LIT>" , "<STR_LIT>" <EOL> def prepare_email ( self ) : <EOL> """<STR_LIT>""" <EOL> subject = self . get_subject ( ) <EOL> body_txt , body_html = self . get_body ( ) <EOL> email = EmailMultiAlternatives ( subject , body_txt , <EOL> ** self . email_kwargs ) <EOL> email . attach_alternative ( body_html , '<STR_LIT>' ) <EOL> return email <EOL> def send_email ( self , email ) : <EOL> """<STR_LIT>""" <EOL> return email . send ( fail_silently = self . email_fail_silently ) <EOL> def form_valid ( self , form ) : <EOL> """<STR_LIT>""" <EOL> results = super ( ) . form_valid ( form ) <EOL> email = self . prepare_email ( ) <EOL> self . send_email ( email ) <EOL> return results <EOL> @ login_required <EOL> def dashboard ( request ) : <EOL> '''<STR_LIT>''' <EOL> current_events = ( <EOL> Event . objects . upcoming_events ( ) | Event . objects . ongoing_events ( ) <EOL> ) . active ( ) <EOL> uninvoiced_events = Event . objects . active ( ) . uninvoiced_events ( ) <EOL> unpublished_events = Event . objects . active ( ) . unpublished_events ( ) . select_related ( '<STR_LIT:host>' ) <EOL> assigned_to , is_admin = assignment_selection ( request ) <EOL> if assigned_to == '<STR_LIT>' : <EOL> current_events = current_events . filter ( assigned_to = request . user ) <EOL> uninvoiced_events = uninvoiced_events . filter ( assigned_to = request . user ) <EOL> unpublished_events = unpublished_events . filter ( <EOL> assigned_to = request . user ) <EOL> elif assigned_to == '<STR_LIT>' : <EOL> current_events = current_events . filter ( assigned_to__isnull = True ) <EOL> uninvoiced_events = uninvoiced_events . filter ( <EOL> assigned_to__isnull = True ) <EOL> unpublished_events = unpublished_events . filter ( <EOL> assigned_to__isnull = True ) <EOL> elif assigned_to == '<STR_LIT:all>' : <EOL> pass <EOL> context = { <EOL> '<STR_LIT:title>' : None , <EOL> '<STR_LIT>' : is_admin , <EOL> '<STR_LIT>' : assigned_to , <EOL> '<STR_LIT>' : current_events , <EOL> '<STR_LIT>' : uninvoiced_events , <EOL> '<STR_LIT>' : unpublished_events , <EOL> '<STR_LIT>' : TodoItemQuerySet . current_week_dates ( ) [ <NUM_LIT:0> ] , <EOL> '<STR_LIT>' : TodoItemQuerySet . next_week_dates ( ) [ <NUM_LIT:1> ] , <EOL> } <EOL> return render ( request , '<STR_LIT>' , context ) <EOL> @ login_required <EOL> def changes_log ( request ) : <EOL> log = Revision . objects . all ( ) . select_related ( '<STR_LIT:user>' ) . prefetch_related ( '<STR_LIT>' ) . order_by ( '<STR_LIT>' ) <EOL> log = get_pagination_items ( request , log ) <EOL> context = { <EOL> '<STR_LIT>' : log <EOL> } <EOL> return render ( request , '<STR_LIT>' , context ) <EOL> @ login_required <EOL> def all_hosts ( request ) : <EOL> '''<STR_LIT>''' <EOL> filter = HostFilter ( request . GET , queryset = Host . objects . all ( ) ) <EOL> hosts = get_pagination_items ( request , filter ) <EOL> context = { '<STR_LIT:title>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : hosts , <EOL> '<STR_LIT>' : filter , <EOL> '<STR_LIT>' : bootstrap_helper_filter } <EOL> return render ( request , '<STR_LIT>' , context ) <EOL> @ login_required <EOL> def host_details ( request , host_domain ) : <EOL> '''<STR_LIT>''' <EOL> host = Host . objects . get ( domain = host_domain ) <EOL> events = Event . objects . filter ( host = host ) <EOL> context = { '<STR_LIT:title>' : '<STR_LIT>' . format ( host ) , <EOL> '<STR_LIT:host>' : host , <EOL> '<STR_LIT>' : events } <EOL> return render ( request , '<STR_LIT>' , context ) <EOL> class HostCreate ( LoginRequiredMixin , PermissionRequiredMixin , <EOL> CreateViewContext ) : <EOL> permission_required = '<STR_LIT>' <EOL> model = Host <EOL> form_class = HostForm <EOL> template_name = '<STR_LIT>' <EOL> class HostUpdate ( LoginRequiredMixin , PermissionRequiredMixin , <EOL> UpdateViewContext ) : <EOL> permission_required = '<STR_LIT>' <EOL> model = Host <EOL> form_class = HostForm <EOL> slug_field = '<STR_LIT>' <EOL> slug_url_kwarg = '<STR_LIT>' <EOL> template_name = '<STR_LIT>' <EOL> @ login_required <EOL> @ permission_required ( '<STR_LIT>' , raise_exception = True ) <EOL> def host_delete ( request , host_domain ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> host = get_object_or_404 ( Host , domain = host_domain ) <EOL> host . delete ( ) <EOL> messages . success ( request , '<STR_LIT>' ) <EOL> return redirect ( reverse ( '<STR_LIT>' ) ) <EOL> except ProtectedError as e : <EOL> return failed_to_delete ( request , host , e . protected_objects ) <EOL> @ login_required <EOL> @ permission_required ( [ '<STR_LIT>' , '<STR_LIT>' ] , <EOL> raise_exception = True ) <EOL> def membership_create ( request , host_domain ) : <EOL> host = get_object_or_404 ( Host , domain = host_domain ) <EOL> form = MembershipForm ( initial = { '<STR_LIT:host>' : host } ) <EOL> if request . method == "<STR_LIT:POST>" : <EOL> form = MembershipForm ( request . POST ) <EOL> if form . is_valid ( ) : <EOL> form . save ( ) <EOL> messages . success ( request , <EOL> '<STR_LIT>' ) <EOL> return redirect ( reverse ( '<STR_LIT>' , args = [ host . domain ] ) ) <EOL> context = { <EOL> '<STR_LIT:title>' : '<STR_LIT>' . format ( host ) , <EOL> '<STR_LIT>' : form , <EOL> '<STR_LIT>' : bootstrap_helper , <EOL> } <EOL> return render ( request , '<STR_LIT>' , context ) <EOL> class MembershipUpdate ( LoginRequiredMixin , PermissionRequiredMixin , <EOL> UpdateViewContext ) : <EOL> permission_required = '<STR_LIT>' <EOL> model = Membership <EOL> form_class = MembershipForm <EOL> pk_url_kwarg = '<STR_LIT>' <EOL> template_name = '<STR_LIT>' <EOL> def get_success_url ( self ) : <EOL> return reverse ( '<STR_LIT>' , args = [ self . object . host . domain ] ) <EOL> @ login_required <EOL> @ permission_required ( '<STR_LIT>' , raise_exception = True ) <EOL> def membership_delete ( request , membership_id ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> membership = get_object_or_404 ( Membership , pk = membership_id ) <EOL> host = membership . host <EOL> membership . delete ( ) <EOL> messages . success ( request , '<STR_LIT>' ) <EOL> return redirect ( reverse ( '<STR_LIT>' , args = [ host . domain ] ) ) <EOL> except ProtectedError as e : <EOL> return failed_to_delete ( request , host , e . protected_objects ) <EOL> AIRPORT_FIELDS = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> @ login_required <EOL> def all_airports ( request ) : <EOL> '''<STR_LIT>''' <EOL> filter = AirportFilter ( request . GET , queryset = Airport . objects . all ( ) ) <EOL> airports = get_pagination_items ( request , filter ) <EOL> context = { '<STR_LIT:title>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : airports , <EOL> '<STR_LIT>' : filter , <EOL> '<STR_LIT>' : bootstrap_helper_filter } <EOL> return render ( request , '<STR_LIT>' , context ) <EOL> @ login_required <EOL> def airport_details ( request , airport_iata ) : <EOL> '''<STR_LIT>''' <EOL> airport = get_object_or_404 ( Airport , iata = airport_iata ) <EOL> context = { '<STR_LIT:title>' : '<STR_LIT>' . format ( airport ) , <EOL> '<STR_LIT>' : airport } <EOL> return render ( request , '<STR_LIT>' , context ) <EOL> class AirportCreate ( LoginRequiredMixin , PermissionRequiredMixin , <EOL> CreateViewContext ) : <EOL> permission_required = '<STR_LIT>' <EOL> model = Airport <EOL> fields = AIRPORT_FIELDS <EOL> template_name = '<STR_LIT>' <EOL> class AirportUpdate ( LoginRequiredMixin , PermissionRequiredMixin , <EOL> UpdateViewContext ) : <EOL> permission_required = '<STR_LIT>' <EOL> model = Airport <EOL> fields = AIRPORT_FIELDS <EOL> slug_field = '<STR_LIT>' <EOL> slug_url_kwarg = '<STR_LIT>' <EOL> template_name = '<STR_LIT>' <EOL> @ login_required <EOL> @ permission_required ( '<STR_LIT>' , raise_exception = True ) <EOL> def airport_delete ( request , airport_iata ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> airport = get_object_or_404 ( Airport , iata = airport_iata ) <EOL> airport . delete ( ) <EOL> messages . success ( request , '<STR_LIT>' ) <EOL> return redirect ( reverse ( '<STR_LIT>' ) ) <EOL> except ProtectedError as e : <EOL> return failed_to_delete ( request , airport , e . protected_objects ) <EOL> @ login_required <EOL> def all_persons ( request ) : <EOL> '''<STR_LIT>''' <EOL> filter = PersonFilter ( <EOL> request . GET , <EOL> queryset = Person . objects . all ( ) . defer ( '<STR_LIT>' ) <EOL> ) <EOL> instructors = Badge . objects . instructor_badges ( ) . values_list ( '<STR_LIT>' , flat = True ) <EOL> persons = get_pagination_items ( request , filter ) <EOL> context = { '<STR_LIT:title>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : persons , <EOL> '<STR_LIT>' : instructors , <EOL> '<STR_LIT>' : filter , <EOL> '<STR_LIT>' : bootstrap_helper_filter } <EOL> return render ( request , '<STR_LIT>' , context ) <EOL> @ login_required <EOL> def person_details ( request , person_id ) : <EOL> '''<STR_LIT>''' <EOL> person = get_object_or_404 ( Person , id = person_id ) <EOL> awards = person . award_set . all ( ) <EOL> tasks = person . task_set . all ( ) <EOL> lessons = person . lessons . all ( ) <EOL> domains = person . domains . all ( ) <EOL> context = { <EOL> '<STR_LIT:title>' : '<STR_LIT>' . format ( person ) , <EOL> '<STR_LIT>' : person , <EOL> '<STR_LIT>' : awards , <EOL> '<STR_LIT>' : tasks , <EOL> '<STR_LIT>' : lessons , <EOL> '<STR_LIT>' : domains , <EOL> } <EOL> return render ( request , '<STR_LIT>' , context ) <EOL> @ login_required <EOL> def person_bulk_add_template ( request ) : <EOL> '''<STR_LIT>''' <EOL> response = HttpResponse ( content_type = '<STR_LIT>' ) <EOL> response [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> writer = csv . writer ( response ) <EOL> writer . writerow ( Person . PERSON_TASK_UPLOAD_FIELDS ) <EOL> return response <EOL> @ login_required <EOL> @ permission_required ( '<STR_LIT>' , raise_exception = True ) <EOL> def person_bulk_add ( request ) : <EOL> if request . method == '<STR_LIT:POST>' : <EOL> form = PersonBulkAddForm ( request . POST , request . FILES ) <EOL> if form . is_valid ( ) : <EOL> charset = request . FILES [ '<STR_LIT:file>' ] . charset or settings . DEFAULT_CHARSET <EOL> stream = io . TextIOWrapper ( request . FILES [ '<STR_LIT:file>' ] . file , charset ) <EOL> try : <EOL> persons_tasks , empty_fields = upload_person_task_csv ( stream ) <EOL> except csv . Error as e : <EOL> messages . add_message ( <EOL> request , messages . ERROR , <EOL> "<STR_LIT>" . format ( e ) ) <EOL> except UnicodeDecodeError as e : <EOL> messages . add_message ( <EOL> request , messages . ERROR , <EOL> "<STR_LIT>" <EOL> . format ( charset ) ) <EOL> else : <EOL> if empty_fields : <EOL> msg_template = ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> msg = msg_template . format ( '<STR_LIT:U+002CU+0020>' . join ( empty_fields ) ) <EOL> messages . add_message ( request , messages . ERROR , msg ) <EOL> else : <EOL> request . session [ '<STR_LIT>' ] = persons_tasks <EOL> return redirect ( '<STR_LIT>' ) <EOL> else : <EOL> form = PersonBulkAddForm ( ) <EOL> context = { <EOL> '<STR_LIT:title>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : form , <EOL> '<STR_LIT>' : settings . DEFAULT_CHARSET , <EOL> } <EOL> return render ( request , '<STR_LIT>' , context ) <EOL> @ login_required <EOL> @ permission_required ( '<STR_LIT>' , raise_exception = True ) <EOL> def person_bulk_add_confirmation ( request ) : <EOL> """<STR_LIT>""" <EOL> persons_tasks = request . session . get ( '<STR_LIT>' ) <EOL> if not persons_tasks : <EOL> messages . warning ( request , "<STR_LIT>" ) <EOL> return redirect ( '<STR_LIT>' ) <EOL> if request . method == '<STR_LIT:POST>' : <EOL> personals = request . POST . getlist ( "<STR_LIT>" ) <EOL> families = request . POST . getlist ( "<STR_LIT>" ) <EOL> usernames = request . POST . getlist ( "<STR_LIT:username>" ) <EOL> emails = request . POST . getlist ( "<STR_LIT:email>" ) <EOL> events = request . POST . getlist ( "<STR_LIT>" ) <EOL> roles = request . POST . getlist ( "<STR_LIT>" ) <EOL> data_update = zip ( personals , families , usernames , emails , events , <EOL> roles ) <EOL> for k , record in enumerate ( data_update ) : <EOL> personal , family , username , email , event , role = record <EOL> persons_tasks [ k ] = { <EOL> '<STR_LIT>' : personal , <EOL> '<STR_LIT>' : family , <EOL> '<STR_LIT:username>' : username , <EOL> '<STR_LIT:email>' : email or None <EOL> } <EOL> persons_tasks [ k ] [ '<STR_LIT>' ] = event <EOL> persons_tasks [ k ] [ '<STR_LIT>' ] = role <EOL> persons_tasks [ k ] [ '<STR_LIT>' ] = None <EOL> request . session [ '<STR_LIT>' ] = persons_tasks <EOL> if request . POST . get ( '<STR_LIT>' , None ) : <EOL> any_errors = verify_upload_person_task ( persons_tasks ) <EOL> if any_errors : <EOL> messages . add_message ( request , messages . ERROR , <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> context = { '<STR_LIT:title>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : persons_tasks , <EOL> '<STR_LIT>' : any_errors } <EOL> return render ( request , '<STR_LIT>' , <EOL> context ) <EOL> elif ( request . POST . get ( '<STR_LIT>' , None ) and <EOL> not request . POST . get ( '<STR_LIT>' , None ) ) : <EOL> try : <EOL> verify_upload_person_task ( persons_tasks ) <EOL> persons_created , tasks_created = create_uploaded_persons_tasks ( persons_tasks ) <EOL> except ( IntegrityError , ObjectDoesNotExist , InternalError ) as e : <EOL> messages . add_message ( request , messages . ERROR , <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" . format ( e ) ) <EOL> any_errors = verify_upload_person_task ( persons_tasks ) <EOL> context = { '<STR_LIT:title>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : persons_tasks , <EOL> '<STR_LIT>' : any_errors } <EOL> return render ( request , <EOL> '<STR_LIT>' , <EOL> context , status = <NUM_LIT> ) <EOL> else : <EOL> request . session [ '<STR_LIT>' ] = None <EOL> messages . add_message ( <EOL> request , messages . SUCCESS , <EOL> '<STR_LIT>' <EOL> . format ( len ( persons_created ) , len ( tasks_created ) ) <EOL> ) <EOL> return redirect ( '<STR_LIT>' ) <EOL> else : <EOL> request . session [ '<STR_LIT>' ] = None <EOL> return redirect ( '<STR_LIT>' ) <EOL> else : <EOL> any_errors = verify_upload_person_task ( persons_tasks ) <EOL> context = { '<STR_LIT:title>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : persons_tasks , <EOL> '<STR_LIT>' : any_errors } <EOL> return render ( request , '<STR_LIT>' , <EOL> context ) <EOL> class PersonCreate ( LoginRequiredMixin , PermissionRequiredMixin , <EOL> CreateViewContext ) : <EOL> permission_required = '<STR_LIT>' <EOL> model = Person <EOL> form_class = PersonCreateForm <EOL> template_name = '<STR_LIT>' <EOL> def form_valid ( self , form ) : <EOL> """<STR_LIT>""" <EOL> self . object = form . save ( commit = False ) <EOL> self . object . username = create_username ( <EOL> personal = form . cleaned_data [ '<STR_LIT>' ] , <EOL> family = form . cleaned_data [ '<STR_LIT>' ] ) <EOL> self . object . save ( ) <EOL> for lesson in form . cleaned_data [ '<STR_LIT>' ] : <EOL> Qualification . objects . create ( lesson = lesson , person = self . object ) <EOL> response = super ( ModelFormMixin , self ) . form_valid ( form ) <EOL> success_message = self . get_success_message ( form . cleaned_data ) <EOL> if success_message : <EOL> messages . success ( self . request , success_message ) <EOL> return response <EOL> @ login_required <EOL> @ permission_required ( [ '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' ] , <EOL> raise_exception = True ) <EOL> def person_edit ( request , person_id ) : <EOL> person = get_object_or_404 ( Person , id = person_id ) <EOL> awards = person . award_set . order_by ( '<STR_LIT>' ) <EOL> tasks = person . task_set . order_by ( '<STR_LIT>' ) <EOL> person_form = PersonForm ( prefix = '<STR_LIT>' , instance = person ) <EOL> award_form = PersonAwardForm ( prefix = '<STR_LIT>' , initial = { <EOL> '<STR_LIT>' : datetime . date . today ( ) , <EOL> '<STR_LIT>' : person , <EOL> } ) <EOL> task_form = PersonTaskForm ( prefix = '<STR_LIT>' , initial = { '<STR_LIT>' : person } ) <EOL> if request . method == '<STR_LIT:POST>' : <EOL> if '<STR_LIT>' in request . POST : <EOL> award_form = PersonAwardForm ( request . POST , prefix = '<STR_LIT>' ) <EOL> if award_form . is_valid ( ) : <EOL> award = award_form . save ( ) <EOL> messages . success ( <EOL> request , <EOL> '<STR_LIT>' . format ( <EOL> person = str ( person ) , <EOL> badge = award . badge . title , <EOL> ) , <EOL> extra_tags = '<STR_LIT>' , <EOL> ) <EOL> return redirect ( request . path ) <EOL> else : <EOL> messages . error ( request , '<STR_LIT>' , <EOL> extra_tags = '<STR_LIT>' ) <EOL> elif '<STR_LIT>' in request . POST : <EOL> task_form = PersonTaskForm ( request . POST , prefix = '<STR_LIT>' ) <EOL> if task_form . is_valid ( ) : <EOL> task = task_form . save ( ) <EOL> messages . success ( <EOL> request , <EOL> '<STR_LIT>' <EOL> . format ( <EOL> person = str ( person ) , <EOL> role = task . role . name , <EOL> event = task . event . slug , <EOL> ) , <EOL> extra_tags = '<STR_LIT>' , <EOL> ) <EOL> return redirect ( request . path ) <EOL> else : <EOL> messages . error ( request , '<STR_LIT>' , <EOL> extra_tags = '<STR_LIT>' ) <EOL> else : <EOL> person_form = PersonForm ( request . POST , prefix = '<STR_LIT>' , <EOL> instance = person ) <EOL> if person_form . is_valid ( ) : <EOL> lessons = person_form . cleaned_data [ '<STR_LIT>' ] <EOL> Qualification . objects . filter ( person = person ) . delete ( ) <EOL> for lesson in lessons : <EOL> Qualification . objects . create ( person = person , lesson = lesson ) <EOL> del person_form . cleaned_data [ '<STR_LIT>' ] <EOL> person = person_form . save ( ) <EOL> messages . success ( <EOL> request , <EOL> '<STR_LIT>' . format ( <EOL> name = str ( person ) , <EOL> ) , <EOL> ) <EOL> return redirect ( person ) <EOL> else : <EOL> messages . error ( request , '<STR_LIT>' ) <EOL> context = { '<STR_LIT:title>' : '<STR_LIT>' . format ( str ( person ) ) , <EOL> '<STR_LIT>' : person_form , <EOL> '<STR_LIT:object>' : person , <EOL> '<STR_LIT>' : Person , <EOL> '<STR_LIT>' : awards , <EOL> '<STR_LIT>' : award_form , <EOL> '<STR_LIT>' : tasks , <EOL> '<STR_LIT>' : task_form , <EOL> '<STR_LIT>' : bootstrap_helper , <EOL> '<STR_LIT>' : bootstrap_helper_with_add , <EOL> } <EOL> return render ( request , '<STR_LIT>' , context ) <EOL> @ login_required <EOL> @ permission_required ( '<STR_LIT>' , raise_exception = True ) <EOL> def person_delete ( request , person_id ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> person = get_object_or_404 ( Person , pk = person_id ) <EOL> person . delete ( ) <EOL> messages . success ( request , '<STR_LIT>' ) <EOL> return redirect ( reverse ( '<STR_LIT>' ) ) <EOL> except ProtectedError as e : <EOL> return failed_to_delete ( request , person , e . protected_objects ) <EOL> class PersonPermissions ( LoginRequiredMixin , PermissionRequiredMixin , <EOL> UpdateViewContext ) : <EOL> permission_required = '<STR_LIT>' <EOL> model = Person <EOL> form_class = PersonPermissionsForm <EOL> pk_url_kwarg = '<STR_LIT>' <EOL> template_name = '<STR_LIT>' <EOL> @ login_required <EOL> def person_password ( request , person_id ) : <EOL> user = get_object_or_404 ( Person , pk = person_id ) <EOL> if not ( ( request . user == user ) or <EOL> ( request . user . has_perm ( '<STR_LIT>' ) ) ) : <EOL> raise PermissionDenied <EOL> Form = PasswordChangeForm <EOL> if request . user . is_superuser : <EOL> Form = SetPasswordForm <EOL> elif request . user . pk != user . pk : <EOL> raise PermissionDenied <EOL> if request . method == '<STR_LIT:POST>' : <EOL> form = Form ( user , request . POST ) <EOL> if form . is_valid ( ) : <EOL> form . save ( ) <EOL> update_session_auth_hash ( request , form . user ) <EOL> messages . success ( request , '<STR_LIT>' ) <EOL> return redirect ( reverse ( '<STR_LIT>' , args = [ user . id ] ) ) <EOL> else : <EOL> messages . error ( request , '<STR_LIT>' ) <EOL> else : <EOL> form = Form ( user ) <EOL> return render ( request , '<STR_LIT>' , { <EOL> '<STR_LIT>' : form , <EOL> '<STR_LIT>' : Person , <EOL> '<STR_LIT:object>' : user , <EOL> '<STR_LIT>' : bootstrap_helper , <EOL> '<STR_LIT:title>' : '<STR_LIT>' , <EOL> } ) <EOL> @ login_required <EOL> @ permission_required ( [ '<STR_LIT>' , '<STR_LIT>' ] , <EOL> raise_exception = True ) <EOL> def persons_merge ( request ) : <EOL> """<STR_LIT>""" <EOL> obj_a_pk = request . GET . get ( '<STR_LIT>' ) <EOL> obj_b_pk = request . GET . get ( '<STR_LIT>' ) <EOL> if not obj_a_pk or not obj_b_pk : <EOL> context = { <EOL> '<STR_LIT:title>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : PersonsSelectionForm ( ) , <EOL> '<STR_LIT>' : bootstrap_helper_get , <EOL> } <EOL> return render ( request , '<STR_LIT>' , context ) <EOL> obj_a = get_object_or_404 ( Person , pk = obj_a_pk ) <EOL> obj_b = get_object_or_404 ( Person , pk = obj_b_pk ) <EOL> form = PersonsMergeForm ( initial = dict ( person_a = obj_a , person_b = obj_b ) ) <EOL> if request . method == '<STR_LIT:POST>' : <EOL> form = PersonsMergeForm ( request . POST ) <EOL> if form . is_valid ( ) : <EOL> data = form . cleaned_data <EOL> obj_a = data [ '<STR_LIT>' ] <EOL> obj_b = data [ '<STR_LIT>' ] <EOL> if data [ '<STR_LIT:id>' ] == '<STR_LIT>' : <EOL> base_obj = obj_a <EOL> merging_obj = obj_b <EOL> base_a = True <EOL> else : <EOL> base_obj = obj_b <EOL> merging_obj = obj_a <EOL> base_a = False <EOL> easy = ( <EOL> '<STR_LIT:username>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:email>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT:url>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> ) <EOL> difficult = ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' ) <EOL> try : <EOL> merge_objects ( obj_a , obj_b , easy , difficult , choices = data , <EOL> base_a = base_a ) <EOL> except ProtectedError as e : <EOL> return failed_to_delete ( request , object = merging_obj , <EOL> protected_objects = e . protected_objects ) <EOL> else : <EOL> return redirect ( base_obj . get_absolute_url ( ) ) <EOL> context = { <EOL> '<STR_LIT:title>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : form , <EOL> '<STR_LIT>' : obj_a , <EOL> '<STR_LIT>' : obj_b , <EOL> } <EOL> return render ( request , '<STR_LIT>' , context ) <EOL> @ login_required <EOL> def all_events ( request ) : <EOL> '''<STR_LIT>''' <EOL> filter = EventFilter ( <EOL> request . GET , <EOL> queryset = Event . objects . all ( ) . defer ( '<STR_LIT>' ) <EOL> . prefetch_related ( '<STR_LIT:host>' , '<STR_LIT>' ) , <EOL> ) <EOL> events = get_pagination_items ( request , filter ) <EOL> context = { '<STR_LIT:title>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : events , <EOL> '<STR_LIT>' : filter , <EOL> '<STR_LIT>' : bootstrap_helper_filter } <EOL> return render ( request , '<STR_LIT>' , context ) <EOL> @ login_required <EOL> @ permission_required ( '<STR_LIT>' , raise_exception = True ) <EOL> def event_details ( request , event_ident ) : <EOL> '''<STR_LIT>''' <EOL> try : <EOL> event = Event . get_by_ident ( event_ident ) <EOL> except Event . DoesNotExist : <EOL> raise Http404 ( '<STR_LIT>' ) <EOL> tasks = Task . objects . filter ( event__id = event . id ) . select_related ( '<STR_LIT>' , '<STR_LIT>' ) . order_by ( '<STR_LIT>' ) <EOL> todos = event . todoitem_set . all ( ) <EOL> todo_form = SimpleTodoForm ( prefix = '<STR_LIT>' , initial = { <EOL> '<STR_LIT>' : event , <EOL> } ) <EOL> if request . method == "<STR_LIT:POST>" : <EOL> todo_form = SimpleTodoForm ( request . POST , prefix = '<STR_LIT>' , initial = { <EOL> '<STR_LIT>' : event , <EOL> } ) <EOL> if todo_form . is_valid ( ) : <EOL> todo = todo_form . save ( ) <EOL> messages . success ( <EOL> request , <EOL> '<STR_LIT>' . format ( <EOL> todo = str ( todo ) , <EOL> event = event . get_ident ( ) , <EOL> ) , <EOL> extra_tags = '<STR_LIT>' , <EOL> ) <EOL> return redirect ( reverse ( event_details , args = [ event_ident , ] ) ) <EOL> else : <EOL> messages . error ( request , '<STR_LIT>' , <EOL> extra_tags = '<STR_LIT>' ) <EOL> person_lookup_form = AdminLookupForm ( ) <EOL> if event . assigned_to : <EOL> person_lookup_form = AdminLookupForm ( <EOL> initial = { '<STR_LIT>' : event . assigned_to } <EOL> ) <EOL> person_lookup_helper = BootstrapHelper ( ) <EOL> person_lookup_helper . form_action = reverse ( '<STR_LIT>' , <EOL> args = [ event_ident ] ) <EOL> context = { <EOL> '<STR_LIT:title>' : '<STR_LIT>' . format ( event ) , <EOL> '<STR_LIT>' : event , <EOL> '<STR_LIT>' : tasks , <EOL> '<STR_LIT>' : todo_form , <EOL> '<STR_LIT>' : todos , <EOL> '<STR_LIT>' : bootstrap_helper , <EOL> '<STR_LIT>' : datetime . date . today ( ) , <EOL> '<STR_LIT>' : person_lookup_form , <EOL> '<STR_LIT>' : person_lookup_helper , <EOL> } <EOL> return render ( request , '<STR_LIT>' , context ) <EOL> @ login_required <EOL> def validate_event ( request , event_ident ) : <EOL> '''<STR_LIT>''' <EOL> try : <EOL> event = Event . get_by_ident ( event_ident ) <EOL> except Event . DoesNotExist : <EOL> raise Http404 ( '<STR_LIT>' ) <EOL> page_url = request . GET . get ( '<STR_LIT:url>' , None ) <EOL> if page_url is None : <EOL> page_url = event . url <EOL> page_url = page_url . strip ( ) <EOL> error_messages = [ ] <EOL> try : <EOL> response = requests . get ( page_url ) <EOL> response . raise_for_status ( ) <EOL> content = response . text <EOL> tags = find_tags_on_event_website ( content ) <EOL> if '<STR_LIT>' not in tags : <EOL> page_url , _ = generate_url_to_event_index ( page_url ) <EOL> response = requests . get ( page_url ) <EOL> if response . status_code == <NUM_LIT:200> : <EOL> content = response . text <EOL> tags = find_tags_on_event_index ( page_url ) <EOL> error_messages = validate_tags_from_event_website ( tags ) <EOL> except WrongWorkshopURL as e : <EOL> error_messages . append ( str ( e ) ) <EOL> except requests . exceptions . HTTPError as e : <EOL> error_messages . append ( <EOL> '<STR_LIT>' <EOL> . format ( page_url , e . response . status_code ) <EOL> ) <EOL> except ( requests . exceptions . ConnectionError , <EOL> requests . exceptions . Timeout ) : <EOL> error_messages . append ( "<STR_LIT>" ) <EOL> context = { <EOL> '<STR_LIT:title>' : '<STR_LIT>' . format ( event ) , <EOL> '<STR_LIT>' : event , <EOL> '<STR_LIT>' : page_url , <EOL> '<STR_LIT>' : error_messages , <EOL> } <EOL> return render ( request , '<STR_LIT>' , context ) <EOL> class EventCreate ( LoginRequiredMixin , PermissionRequiredMixin , <EOL> CreateViewContext ) : <EOL> permission_required = '<STR_LIT>' <EOL> model = Event <EOL> form_class = EventForm <EOL> template_name = '<STR_LIT>' <EOL> @ login_required <EOL> @ permission_required ( [ '<STR_LIT>' , '<STR_LIT>' ] , <EOL> raise_exception = True ) <EOL> def event_edit ( request , event_ident ) : <EOL> try : <EOL> event = Event . get_by_ident ( event_ident ) <EOL> tasks = event . task_set . order_by ( '<STR_LIT>' ) <EOL> except ObjectDoesNotExist : <EOL> raise Http404 ( "<STR_LIT>" ) <EOL> event_form = EventForm ( prefix = '<STR_LIT>' , instance = event ) <EOL> task_form = TaskForm ( prefix = '<STR_LIT>' , initial = { <EOL> '<STR_LIT>' : event , <EOL> } ) <EOL> if request . method == '<STR_LIT:POST>' : <EOL> if "<STR_LIT>" in request . POST : <EOL> task_form = TaskForm ( request . POST , prefix = '<STR_LIT>' ) <EOL> if task_form . is_valid ( ) : <EOL> task = task_form . save ( ) <EOL> messages . success ( <EOL> request , <EOL> '<STR_LIT>' . format ( <EOL> event = str ( event ) , <EOL> task = str ( task ) , <EOL> ) , <EOL> ) <EOL> update_event_attendance_from_tasks ( event ) <EOL> return redirect ( request . path ) <EOL> else : <EOL> messages . error ( request , '<STR_LIT>' ) <EOL> else : <EOL> event_form = EventForm ( request . POST , prefix = '<STR_LIT>' , <EOL> instance = event ) <EOL> if event_form . is_valid ( ) : <EOL> event = event_form . save ( ) <EOL> messages . success ( <EOL> request , <EOL> '<STR_LIT>' . format ( <EOL> name = str ( event ) , <EOL> ) , <EOL> ) <EOL> update_event_attendance_from_tasks ( event ) <EOL> return redirect ( event ) <EOL> else : <EOL> messages . error ( request , '<STR_LIT>' ) <EOL> context = { '<STR_LIT:title>' : '<STR_LIT>' . format ( event . get_ident ( ) ) , <EOL> '<STR_LIT>' : event_form , <EOL> '<STR_LIT:object>' : event , <EOL> '<STR_LIT>' : Event , <EOL> '<STR_LIT>' : tasks , <EOL> '<STR_LIT>' : task_form , <EOL> '<STR_LIT>' : bootstrap_helper , <EOL> '<STR_LIT>' : bootstrap_helper_with_add , <EOL> } <EOL> return render ( request , '<STR_LIT>' , context ) <EOL> @ login_required <EOL> @ permission_required ( '<STR_LIT>' , raise_exception = True ) <EOL> def event_delete ( request , event_ident ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> event = Event . get_by_ident ( event_ident ) <EOL> event . delete ( ) <EOL> messages . success ( request , <EOL> '<STR_LIT>' ) <EOL> return redirect ( reverse ( '<STR_LIT>' ) ) <EOL> except ObjectDoesNotExist : <EOL> raise Http404 ( "<STR_LIT>" ) <EOL> except ProtectedError as e : <EOL> return failed_to_delete ( request , event , e . protected_objects ) <EOL> @ login_required <EOL> def event_import ( request ) : <EOL> """<STR_LIT>""" <EOL> url = request . POST . get ( '<STR_LIT:url>' , '<STR_LIT>' ) . strip ( ) <EOL> if not url : <EOL> url = request . GET . get ( '<STR_LIT:url>' , '<STR_LIT>' ) . strip ( ) <EOL> try : <EOL> response = requests . get ( url ) <EOL> response . raise_for_status ( ) <EOL> content = response . text <EOL> tags = find_tags_on_event_website ( content ) <EOL> if '<STR_LIT>' not in tags : <EOL> index_url , repository = generate_url_to_event_index ( url ) <EOL> response = requests . get ( index_url ) <EOL> if response . status_code == <NUM_LIT:200> : <EOL> content = response . text <EOL> tags = find_tags_on_event_index ( content ) <EOL> if '<STR_LIT>' not in tags : <EOL> tags [ '<STR_LIT>' ] = repository <EOL> tags = parse_tags_from_event_website ( tags ) <EOL> return JsonResponse ( tags ) <EOL> except requests . exceptions . HTTPError as e : <EOL> return HttpResponseBadRequest ( <EOL> '<STR_LIT>' <EOL> . format ( url , e . response . status_code ) <EOL> ) <EOL> except requests . exceptions . RequestException : <EOL> return HttpResponseBadRequest ( '<STR_LIT>' ) <EOL> except WrongWorkshopURL as e : <EOL> return HttpResponseBadRequest ( str ( e ) ) <EOL> except KeyError : <EOL> return HttpResponseBadRequest ( '<STR_LIT>' ) <EOL> @ login_required <EOL> @ permission_required ( '<STR_LIT>' , raise_exception = True ) <EOL> def event_assign ( request , event_ident , person_id = None ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> event = Event . get_by_ident ( event_ident ) <EOL> assign ( request , event , person_id ) <EOL> return redirect ( reverse ( '<STR_LIT>' , args = [ event . get_ident ( ) ] ) ) <EOL> except Event . DoesNotExist : <EOL> raise Http404 ( "<STR_LIT>" ) <EOL> @ login_required <EOL> @ permission_required ( [ '<STR_LIT>' , '<STR_LIT>' ] , <EOL> raise_exception = True ) <EOL> def events_merge ( request ) : <EOL> """<STR_LIT>""" <EOL> obj_a_slug = request . GET . get ( '<STR_LIT>' ) <EOL> obj_b_slug = request . GET . get ( '<STR_LIT>' ) <EOL> if not obj_a_slug and not obj_b_slug : <EOL> context = { <EOL> '<STR_LIT:title>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : EventsSelectionForm ( ) , <EOL> '<STR_LIT>' : bootstrap_helper_get , <EOL> } <EOL> return render ( request , '<STR_LIT>' , context ) <EOL> obj_a = get_object_or_404 ( Event , slug = obj_a_slug ) <EOL> obj_b = get_object_or_404 ( Event , slug = obj_b_slug ) <EOL> form = EventsMergeForm ( initial = dict ( event_a = obj_a , event_b = obj_b ) ) <EOL> if request . method == "<STR_LIT:POST>" : <EOL> form = EventsMergeForm ( request . POST ) <EOL> if form . is_valid ( ) : <EOL> data = form . cleaned_data <EOL> obj_a = data [ '<STR_LIT>' ] <EOL> obj_b = data [ '<STR_LIT>' ] <EOL> if data [ '<STR_LIT:id>' ] == '<STR_LIT>' : <EOL> base_obj = obj_a <EOL> merging_obj = obj_b <EOL> base_a = True <EOL> else : <EOL> base_obj = obj_b <EOL> merging_obj = obj_a <EOL> base_a = False <EOL> easy = ( <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:start>' , '<STR_LIT:end>' , '<STR_LIT:host>' , <EOL> '<STR_LIT>' , '<STR_LIT:url>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT:address>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> ) <EOL> difficult = ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> try : <EOL> merge_objects ( obj_a , obj_b , easy , difficult , choices = data , <EOL> base_a = base_a ) <EOL> except ProtectedError as e : <EOL> return failed_to_delete ( request , object = merging_obj , <EOL> protected_objects = e . protected_objects ) <EOL> else : <EOL> return redirect ( base_obj . get_absolute_url ( ) ) <EOL> context = { <EOL> '<STR_LIT:title>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : obj_a , <EOL> '<STR_LIT>' : obj_b , <EOL> '<STR_LIT>' : form , <EOL> } <EOL> return render ( request , '<STR_LIT>' , context ) <EOL> @ login_required <EOL> @ permission_required ( '<STR_LIT>' , raise_exception = True ) <EOL> def event_invoice ( request , event_ident ) : <EOL> try : <EOL> event = Event . get_by_ident ( event_ident ) <EOL> except ObjectDoesNotExist : <EOL> raise Http404 ( "<STR_LIT>" ) <EOL> form = InvoiceRequestForm ( initial = dict ( <EOL> organization = event . host , date = event . start , event = event , <EOL> event_location = event . venue , amount = event . admin_fee , <EOL> ) ) <EOL> if request . method == '<STR_LIT:POST>' : <EOL> form = InvoiceRequestForm ( request . POST ) <EOL> if form . is_valid ( ) : <EOL> form . save ( ) <EOL> messages . success ( request , <EOL> '<STR_LIT>' <EOL> . format ( event . get_ident ( ) ) ) <EOL> return redirect ( reverse ( '<STR_LIT>' , <EOL> args = [ event . get_ident ( ) ] ) ) <EOL> else : <EOL> messages . error ( request , '<STR_LIT>' ) <EOL> context = { <EOL> '<STR_LIT>' : '<STR_LIT>' . format ( event . get_ident ( ) ) , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : event , <EOL> '<STR_LIT>' : form , <EOL> '<STR_LIT>' : bootstrap_helper , <EOL> } <EOL> return render ( request , '<STR_LIT>' , context ) <EOL> class AllInvoiceRequests ( LoginRequiredMixin , FilteredListView ) : <EOL> context_object_name = '<STR_LIT>' <EOL> template_name = '<STR_LIT>' <EOL> filter_class = InvoiceRequestFilter <EOL> queryset = InvoiceRequest . objects . all ( ) <EOL> def get_filter_data ( self ) : <EOL> data = self . request . GET . copy ( ) <EOL> data [ '<STR_LIT:status>' ] = data . get ( '<STR_LIT:status>' , '<STR_LIT>' ) <EOL> return data <EOL> def get_context_data ( self , ** kwargs ) : <EOL> context = super ( ) . get_context_data ( ** kwargs ) <EOL> context [ '<STR_LIT:title>' ] = '<STR_LIT>' <EOL> return context <EOL> class InvoiceRequestDetails ( LoginRequiredMixin , DetailView ) : <EOL> context_object_name = '<STR_LIT:object>' <EOL> template_name = '<STR_LIT>' <EOL> queryset = InvoiceRequest . objects . all ( ) <EOL> pk_url_kwarg = '<STR_LIT>' <EOL> def get_context_data ( self , ** kwargs ) : <EOL> context = super ( ) . get_context_data ( ** kwargs ) <EOL> context [ '<STR_LIT:title>' ] = '<STR_LIT>' . format ( self . get_object ( ) . pk ) <EOL> return context <EOL> class InvoiceRequestUpdate ( LoginRequiredMixin , PermissionRequiredMixin , <EOL> UpdateViewContext ) : <EOL> permission_required = '<STR_LIT>' <EOL> model = InvoiceRequest <EOL> form_class = InvoiceRequestUpdateForm <EOL> pk_url_kwarg = '<STR_LIT>' <EOL> template_name = '<STR_LIT>' <EOL> @ login_required <EOL> def all_tasks ( request ) : <EOL> '''<STR_LIT>''' <EOL> filter = TaskFilter ( <EOL> request . GET , <EOL> queryset = Task . objects . all ( ) . select_related ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> . defer ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> ) <EOL> tasks = get_pagination_items ( request , filter ) <EOL> context = { '<STR_LIT:title>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : tasks , <EOL> '<STR_LIT>' : filter , <EOL> '<STR_LIT>' : bootstrap_helper_filter } <EOL> return render ( request , '<STR_LIT>' , context ) <EOL> @ login_required <EOL> def task_details ( request , task_id ) : <EOL> '''<STR_LIT>''' <EOL> task = get_object_or_404 ( Task , pk = task_id ) <EOL> context = { '<STR_LIT:title>' : '<STR_LIT>' . format ( task ) , <EOL> '<STR_LIT>' : task } <EOL> return render ( request , '<STR_LIT>' , context ) <EOL> @ login_required <EOL> @ permission_required ( '<STR_LIT>' , raise_exception = True ) <EOL> def task_delete ( request , task_id , event_ident = None ) : <EOL> '''<STR_LIT>''' <EOL> t = get_object_or_404 ( Task , pk = task_id ) <EOL> t . delete ( ) <EOL> messages . success ( request , '<STR_LIT>' ) <EOL> if event_ident : <EOL> return redirect ( event_edit , event_ident ) <EOL> return redirect ( all_tasks ) <EOL> class TaskCreate ( LoginRequiredMixin , PermissionRequiredMixin , <EOL> CreateViewContext ) : <EOL> permission_required = '<STR_LIT>' <EOL> model = Task <EOL> form_class = TaskFullForm <EOL> template_name = '<STR_LIT>' <EOL> class TaskUpdate ( LoginRequiredMixin , PermissionRequiredMixin , <EOL> UpdateViewContext ) : <EOL> permission_required = '<STR_LIT>' <EOL> model = Task <EOL> form_class = TaskFullForm <EOL> pk_url_kwarg = '<STR_LIT>' <EOL> template_name = '<STR_LIT>' <EOL> @ login_required <EOL> @ permission_required ( '<STR_LIT>' , raise_exception = True ) <EOL> def award_delete ( request , award_id , person_id = None ) : <EOL> """<STR_LIT>""" <EOL> award = get_object_or_404 ( Award , pk = award_id ) <EOL> badge_name = award . badge . name <EOL> award . delete ( ) <EOL> messages . success ( request , '<STR_LIT>' , <EOL> extra_tags = '<STR_LIT>' ) <EOL> if person_id : <EOL> return redirect ( person_edit , person_id ) <EOL> return redirect ( reverse ( badge_details , args = [ badge_name ] ) ) <EOL> @ login_required <EOL> def all_badges ( request ) : <EOL> '''<STR_LIT>''' <EOL> badges = Badge . objects . order_by ( '<STR_LIT:name>' ) . annotate ( num_awarded = Count ( '<STR_LIT>' ) ) <EOL> context = { '<STR_LIT:title>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : badges } <EOL> return render ( request , '<STR_LIT>' , context ) <EOL> @ login_required <EOL> def badge_details ( request , badge_name ) : <EOL> '''<STR_LIT>''' <EOL> badge = get_object_or_404 ( Badge , name = badge_name ) <EOL> filter = BadgeAwardsFilter ( <EOL> request . GET , <EOL> queryset = badge . award_set . select_related ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> ) <EOL> awards = get_pagination_items ( request , filter ) <EOL> context = { '<STR_LIT:title>' : '<STR_LIT>' . format ( badge ) , <EOL> '<STR_LIT>' : badge , <EOL> '<STR_LIT>' : awards , <EOL> '<STR_LIT>' : filter , <EOL> '<STR_LIT>' : bootstrap_helper_filter } <EOL> return render ( request , '<STR_LIT>' , context ) <EOL> @ login_required <EOL> @ permission_required ( '<STR_LIT>' , raise_exception = True ) <EOL> def badge_award ( request , badge_name ) : <EOL> """<STR_LIT>""" <EOL> badge = get_object_or_404 ( Badge , name = badge_name ) <EOL> initial = { <EOL> '<STR_LIT>' : badge , <EOL> '<STR_LIT>' : datetime . date . today ( ) <EOL> } <EOL> if request . method == '<STR_LIT:GET>' : <EOL> form = BadgeAwardForm ( initial = initial ) <EOL> elif request . method == '<STR_LIT:POST>' : <EOL> form = BadgeAwardForm ( request . POST , initial = initial ) <EOL> if form . is_valid ( ) : <EOL> form . save ( ) <EOL> return redirect ( reverse ( '<STR_LIT>' , args = [ badge . name ] ) ) <EOL> context = { <EOL> '<STR_LIT:title>' : '<STR_LIT>' . format ( badge ) , <EOL> '<STR_LIT>' : badge , <EOL> '<STR_LIT>' : form , <EOL> '<STR_LIT>' : bootstrap_helper , <EOL> } <EOL> return render ( request , '<STR_LIT>' , context ) <EOL> @ login_required <EOL> def instructors ( request ) : <EOL> '''<STR_LIT>''' <EOL> instructor_badges = Badge . objects . instructor_badges ( ) <EOL> instructors = Person . objects . filter ( badges__in = instructor_badges ) . filter ( airport__isnull = False ) . select_related ( '<STR_LIT>' ) . prefetch_related ( '<STR_LIT>' ) <EOL> instructors = instructors . annotate ( <EOL> num_taught = Count ( <EOL> Case ( <EOL> When ( <EOL> task__role__name = '<STR_LIT>' , <EOL> then = Value ( <NUM_LIT:1> ) <EOL> ) , <EOL> output_field = IntegerField ( ) <EOL> ) <EOL> ) <EOL> ) <EOL> form = InstructorsForm ( ) <EOL> lessons = list ( ) <EOL> if '<STR_LIT>' in request . GET : <EOL> form = InstructorsForm ( request . GET ) <EOL> if form . is_valid ( ) : <EOL> data = form . cleaned_data <EOL> if data [ '<STR_LIT>' ] : <EOL> lessons = data [ '<STR_LIT>' ] <EOL> for lesson in lessons : <EOL> instructors = instructors . filter ( <EOL> qualification__lesson = lesson <EOL> ) <EOL> if data [ '<STR_LIT>' ] : <EOL> x = data [ '<STR_LIT>' ] . latitude <EOL> y = data [ '<STR_LIT>' ] . longitude <EOL> complex_F = ( ( F ( '<STR_LIT>' ) - x ) ** <NUM_LIT:2> <EOL> + ( F ( '<STR_LIT>' ) - y ) ** <NUM_LIT:2> ) <EOL> instructors = instructors . annotate ( distance = complex_F ) . order_by ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> if data [ '<STR_LIT>' ] and data [ '<STR_LIT>' ] : <EOL> x = data [ '<STR_LIT>' ] <EOL> y = data [ '<STR_LIT>' ] <EOL> complex_F = ( ( F ( '<STR_LIT>' ) - x ) ** <NUM_LIT:2> <EOL> + ( F ( '<STR_LIT>' ) - y ) ** <NUM_LIT:2> ) <EOL> instructors = instructors . annotate ( distance = complex_F ) . order_by ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> if data [ '<STR_LIT>' ] : <EOL> instructors = instructors . filter ( <EOL> airport__country__in = data [ '<STR_LIT>' ] <EOL> ) . order_by ( '<STR_LIT>' ) <EOL> if data [ '<STR_LIT>' ] : <EOL> instructors = instructors . filter ( gender = data [ '<STR_LIT>' ] ) <EOL> if data [ '<STR_LIT>' ] : <EOL> for badge in data [ '<STR_LIT>' ] : <EOL> instructors = instructors . filter ( badges__name = badge ) <EOL> instructors = get_pagination_items ( request , instructors ) <EOL> context = { <EOL> '<STR_LIT:title>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : form , <EOL> '<STR_LIT>' : instructors , <EOL> '<STR_LIT>' : lessons , <EOL> } <EOL> return render ( request , '<STR_LIT>' , context ) <EOL> @ login_required <EOL> def search ( request ) : <EOL> '''<STR_LIT>''' <EOL> term , hosts , events , persons , airports = '<STR_LIT>' , None , None , None , None <EOL> if request . method == '<STR_LIT:POST>' : <EOL> form = SearchForm ( request . POST ) <EOL> if form . is_valid ( ) : <EOL> term = form . cleaned_data [ '<STR_LIT>' ] <EOL> tokens = re . split ( '<STR_LIT>' , term ) <EOL> results = list ( ) <EOL> if form . cleaned_data [ '<STR_LIT>' ] : <EOL> hosts = Host . objects . filter ( <EOL> Q ( domain__contains = term ) | <EOL> Q ( fullname__contains = term ) | <EOL> Q ( notes__contains = term ) ) . order_by ( '<STR_LIT>' ) <EOL> results += list ( hosts ) <EOL> if form . cleaned_data [ '<STR_LIT>' ] : <EOL> events = Event . objects . filter ( <EOL> Q ( slug__contains = term ) | <EOL> Q ( notes__contains = term ) | <EOL> Q ( host__domain__contains = term ) | <EOL> Q ( host__fullname__contains = term ) | <EOL> Q ( url__contains = term ) | <EOL> Q ( contact__contains = term ) | <EOL> Q ( venue__contains = term ) | <EOL> Q ( address__contains = term ) <EOL> ) . order_by ( '<STR_LIT>' ) <EOL> results += list ( events ) <EOL> if form . cleaned_data [ '<STR_LIT>' ] : <EOL> if len ( tokens ) == <NUM_LIT:2> : <EOL> name1 , name2 = tokens <EOL> complex_q = ( <EOL> Q ( personal__contains = name1 ) & Q ( family__contains = name2 ) <EOL> ) | ( <EOL> Q ( personal__contains = name2 ) & Q ( family__contains = name1 ) <EOL> ) | Q ( email__contains = term ) | Q ( github__contains = term ) <EOL> persons = Person . objects . filter ( complex_q ) <EOL> else : <EOL> persons = Person . objects . filter ( <EOL> Q ( personal__contains = term ) | <EOL> Q ( family__contains = term ) | <EOL> Q ( email__contains = term ) | <EOL> Q ( github__contains = term ) ) . order_by ( '<STR_LIT>' ) <EOL> results += list ( persons ) <EOL> if form . cleaned_data [ '<STR_LIT>' ] : <EOL> airports = Airport . objects . filter ( <EOL> Q ( iata__contains = term ) | <EOL> Q ( fullname__contains = term ) ) . order_by ( '<STR_LIT>' ) <EOL> results += list ( airports ) <EOL> if len ( results ) == <NUM_LIT:1> : <EOL> return redirect ( results [ <NUM_LIT:0> ] . get_absolute_url ( ) ) <EOL> else : <EOL> form = SearchForm ( ) <EOL> context = { '<STR_LIT:title>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : form , <EOL> '<STR_LIT>' : bootstrap_helper , <EOL> '<STR_LIT>' : term , <EOL> '<STR_LIT>' : hosts , <EOL> '<STR_LIT>' : events , <EOL> '<STR_LIT>' : persons , <EOL> '<STR_LIT>' : airports } <EOL> return render ( request , '<STR_LIT>' , context ) <EOL> @ login_required <EOL> def instructors_by_date ( request ) : <EOL> '''<STR_LIT>''' <EOL> tasks = None <EOL> start_date = end_date = None <EOL> form = DebriefForm ( ) <EOL> if '<STR_LIT>' in request . GET and '<STR_LIT>' in request . GET : <EOL> form = DebriefForm ( request . GET ) <EOL> if form . is_valid ( ) : <EOL> start_date = form . cleaned_data [ '<STR_LIT>' ] <EOL> end_date = form . cleaned_data [ '<STR_LIT>' ] <EOL> rvs = ReportsViewSet ( ) <EOL> tasks = rvs . instructors_by_time_queryset ( start_date , end_date ) <EOL> context = { '<STR_LIT:title>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : form , <EOL> '<STR_LIT>' : bootstrap_helper_get , <EOL> '<STR_LIT>' : tasks , <EOL> '<STR_LIT>' : start_date , <EOL> '<STR_LIT>' : end_date } <EOL> return render ( request , '<STR_LIT>' , context ) <EOL> @ login_required <EOL> def export_badges ( request ) : <EOL> title = '<STR_LIT>' <EOL> json_link = reverse ( '<STR_LIT>' , kwargs = { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> yaml_link = reverse ( '<STR_LIT>' , kwargs = { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> context = { <EOL> '<STR_LIT:title>' : title , <EOL> '<STR_LIT>' : json_link , <EOL> '<STR_LIT>' : yaml_link , <EOL> } <EOL> return render ( request , '<STR_LIT>' , context ) <EOL> @ login_required <EOL> def export_instructors ( request ) : <EOL> title = '<STR_LIT>' <EOL> json_link = reverse ( '<STR_LIT>' , kwargs = { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> yaml_link = reverse ( '<STR_LIT>' , kwargs = { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> context = { <EOL> '<STR_LIT:title>' : title , <EOL> '<STR_LIT>' : json_link , <EOL> '<STR_LIT>' : yaml_link , <EOL> } <EOL> return render ( request , '<STR_LIT>' , context ) <EOL> @ login_required <EOL> def export_members ( request ) : <EOL> title = '<STR_LIT>' <EOL> json_link = reverse ( '<STR_LIT>' , kwargs = { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> yaml_link = reverse ( '<STR_LIT>' , kwargs = { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> context = { <EOL> '<STR_LIT:title>' : title , <EOL> '<STR_LIT>' : json_link , <EOL> '<STR_LIT>' : yaml_link , <EOL> } <EOL> return render ( request , '<STR_LIT>' , context ) <EOL> @ login_required <EOL> def workshops_over_time ( request ) : <EOL> '''<STR_LIT>''' <EOL> context = { <EOL> '<STR_LIT>' : reverse ( '<STR_LIT>' ) , <EOL> '<STR_LIT:title>' : '<STR_LIT>' , <EOL> } <EOL> return render ( request , '<STR_LIT>' , context ) <EOL> @ login_required <EOL> def learners_over_time ( request ) : <EOL> '''<STR_LIT>''' <EOL> context = { <EOL> '<STR_LIT>' : reverse ( '<STR_LIT>' ) , <EOL> '<STR_LIT:title>' : '<STR_LIT>' , <EOL> } <EOL> return render ( request , '<STR_LIT>' , context ) <EOL> @ login_required <EOL> def instructors_over_time ( request ) : <EOL> '''<STR_LIT>''' <EOL> context = { <EOL> '<STR_LIT>' : reverse ( '<STR_LIT>' ) , <EOL> '<STR_LIT:title>' : '<STR_LIT>' , <EOL> } <EOL> return render ( request , '<STR_LIT>' , context ) <EOL> @ login_required <EOL> def instructor_num_taught ( request ) : <EOL> '''<STR_LIT>''' <EOL> context = { <EOL> '<STR_LIT>' : reverse ( '<STR_LIT>' ) , <EOL> '<STR_LIT:title>' : '<STR_LIT>' , <EOL> } <EOL> return render ( request , '<STR_LIT>' , context ) <EOL> @ login_required <EOL> def all_activity_over_time ( request ) : <EOL> """<STR_LIT>""" <EOL> context = { <EOL> '<STR_LIT>' : reverse ( '<STR_LIT>' ) , <EOL> '<STR_LIT:title>' : '<STR_LIT>' , <EOL> } <EOL> return render ( request , '<STR_LIT>' , context ) <EOL> @ login_required <EOL> def workshop_issues ( request ) : <EOL> '''<STR_LIT>''' <EOL> events = Event . objects . active ( ) . past_events ( ) . annotate ( <EOL> num_instructors = Count ( <EOL> Case ( <EOL> When ( <EOL> task__role__name = '<STR_LIT>' , <EOL> then = Value ( <NUM_LIT:1> ) <EOL> ) , <EOL> output_field = IntegerField ( ) <EOL> ) <EOL> ) <EOL> ) <EOL> events = events . filter ( <EOL> Q ( attendance = None ) | Q ( attendance = <NUM_LIT:0> ) | <EOL> Q ( country = None ) | <EOL> Q ( venue = None ) | Q ( venue__exact = '<STR_LIT>' ) | <EOL> Q ( address = None ) | Q ( address__exact = '<STR_LIT>' ) | <EOL> Q ( latitude = None ) | Q ( longitude = None ) | <EOL> Q ( start__gt = F ( '<STR_LIT:end>' ) ) | <EOL> Q ( num_instructors = <NUM_LIT:0> ) <EOL> ) <EOL> assigned_to , is_admin = assignment_selection ( request ) <EOL> if assigned_to == '<STR_LIT>' : <EOL> events = events . filter ( assigned_to = request . user ) <EOL> elif assigned_to == '<STR_LIT>' : <EOL> events = events . filter ( assigned_to = None ) <EOL> elif assigned_to == '<STR_LIT:all>' : <EOL> pass <EOL> for e in events : <EOL> e . missing_attendance_ = ( not e . attendance ) <EOL> e . missing_location_ = ( <EOL> not e . country or not e . venue or not e . address or not e . latitude or <EOL> not e . longitude <EOL> ) <EOL> e . bad_dates_ = e . start and e . end and ( e . start > e . end ) <EOL> e . no_instructors_ = not e . num_instructors <EOL> context = { <EOL> '<STR_LIT:title>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : events , <EOL> '<STR_LIT>' : is_admin , <EOL> '<STR_LIT>' : assigned_to , <EOL> } <EOL> return render ( request , '<STR_LIT>' , context ) <EOL> @ login_required <EOL> def instructor_issues ( request ) : <EOL> '''<STR_LIT>''' <EOL> instructor_badges = Badge . objects . instructor_badges ( ) <EOL> instructors = Person . objects . filter ( badges__in = instructor_badges ) . filter ( airport__isnull = True ) <EOL> learner = Role . objects . get ( name = '<STR_LIT>' ) <EOL> ttt = Tag . objects . get ( name = '<STR_LIT>' ) <EOL> stalled = Tag . objects . get ( name = '<STR_LIT>' ) <EOL> trainees = Task . objects . filter ( event__tags__in = [ ttt ] , role = learner ) . exclude ( person__badges__in = instructor_badges ) . order_by ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) . select_related ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> pending_instructors = trainees . exclude ( event__tags = stalled ) <EOL> pending_instructors_person_ids = pending_instructors . values_list ( <EOL> '<STR_LIT>' , flat = True , <EOL> ) <EOL> stalled_instructors = trainees . filter ( event__tags = stalled ) . exclude ( person__id__in = pending_instructors_person_ids ) <EOL> context = { <EOL> '<STR_LIT:title>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : instructors , <EOL> '<STR_LIT>' : pending_instructors , <EOL> '<STR_LIT>' : stalled_instructors , <EOL> } <EOL> return render ( request , '<STR_LIT>' , context ) <EOL> @ login_required <EOL> def object_changes ( request , revision_id ) : <EOL> revision = get_object_or_404 ( Revision , pk = revision_id ) <EOL> current_version = revision . version_set . all ( ) [ <NUM_LIT:0> ] <EOL> obj = current_version . object <EOL> try : <EOL> previous_version = get_for_object ( obj ) . filter ( pk__lt = current_version . pk ) [ <NUM_LIT:0> ] <EOL> obj_prev = previous_version . object <EOL> except IndexError : <EOL> previous_version = current_version <EOL> obj_prev = obj <EOL> context = { <EOL> '<STR_LIT>' : obj_prev , <EOL> '<STR_LIT:object>' : obj , <EOL> '<STR_LIT>' : previous_version , <EOL> '<STR_LIT>' : current_version , <EOL> '<STR_LIT>' : revision , <EOL> '<STR_LIT:title>' : str ( obj ) , <EOL> } <EOL> if obj . __class__ == Person : <EOL> return render ( request , '<STR_LIT>' , context ) <EOL> elif obj . __class__ == Event : <EOL> return render ( request , '<STR_LIT>' , context ) <EOL> else : <EOL> context [ '<STR_LIT>' ] = obj . _meta . verbose_name <EOL> context [ '<STR_LIT>' ] = [ <EOL> f for f in obj . _meta . get_fields ( ) <EOL> if f . concrete and not f . is_relation <EOL> ] <EOL> return render ( request , '<STR_LIT>' , context ) <EOL> class SWCEventRequest ( EmailSendMixin , CreateViewContext ) : <EOL> model = EventRequest <EOL> form_class = SWCEventRequestForm <EOL> page_title = '<STR_LIT>' <EOL> template_name = '<STR_LIT>' <EOL> success_url = reverse_lazy ( '<STR_LIT>' ) <EOL> email_fail_silently = False <EOL> email_kwargs = { <EOL> '<STR_LIT:to>' : settings . REQUEST_NOTIFICATIONS_RECIPIENTS , <EOL> '<STR_LIT>' : None , <EOL> } <EOL> def get_success_message ( self , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> return '<STR_LIT>' <EOL> def get_context_data ( self , ** kwargs ) : <EOL> context = super ( ) . get_context_data ( ** kwargs ) <EOL> context [ '<STR_LIT:title>' ] = self . page_title <EOL> context [ '<STR_LIT>' ] = bootstrap_helper_wider_labels <EOL> return context <EOL> def get_subject ( self ) : <EOL> subject = ( <EOL> '<STR_LIT>' <EOL> ) . format ( <EOL> tag = self . object . workshop_type . upper ( ) , <EOL> country = self . object . country . name , <EOL> affiliation = self . object . affiliation , <EOL> ) <EOL> return subject <EOL> def get_body ( self ) : <EOL> link = self . object . get_absolute_url ( ) <EOL> link_domain = settings . SITE_URL <EOL> body_txt = get_template ( <EOL> '<STR_LIT>' <EOL> ) . render ( { <EOL> '<STR_LIT:object>' : self . object , <EOL> '<STR_LIT>' : link , <EOL> '<STR_LIT>' : link_domain , <EOL> } ) <EOL> body_html = get_template ( <EOL> '<STR_LIT>' <EOL> ) . render ( { <EOL> '<STR_LIT:object>' : self . object , <EOL> '<STR_LIT>' : link , <EOL> '<STR_LIT>' : link_domain , <EOL> } ) <EOL> return body_txt , body_html <EOL> def form_valid ( self , form ) : <EOL> """<STR_LIT>""" <EOL> data = form . cleaned_data <EOL> self . email_kwargs [ '<STR_LIT>' ] = ( data [ '<STR_LIT:email>' ] , ) <EOL> result = super ( ) . form_valid ( form ) <EOL> return result <EOL> class SWCEventRequestConfirm ( TemplateView ) : <EOL> """<STR_LIT>""" <EOL> template_name = '<STR_LIT>' <EOL> def get_context_data ( self , ** kwargs ) : <EOL> context = super ( ) . get_context_data ( ** kwargs ) <EOL> context [ '<STR_LIT:title>' ] = '<STR_LIT>' <EOL> return context <EOL> class DCEventRequest ( SWCEventRequest ) : <EOL> form_class = DCEventRequestForm <EOL> page_title = '<STR_LIT>' <EOL> form_template = '<STR_LIT>' <EOL> success_url = reverse_lazy ( '<STR_LIT>' ) <EOL> class DCEventRequestConfirm ( SWCEventRequestConfirm ) : <EOL> """<STR_LIT>""" <EOL> template_name = '<STR_LIT>' <EOL> @ login_required <EOL> def all_eventrequests ( request ) : <EOL> """<STR_LIT>""" <EOL> data = request . GET . copy ( ) <EOL> data [ '<STR_LIT>' ] = data . get ( '<STR_LIT>' , '<STR_LIT:true>' ) <EOL> data [ '<STR_LIT>' ] = data . get ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> filter = EventRequestFilter ( <EOL> data , <EOL> queryset = EventRequest . objects . all ( ) , <EOL> ) <EOL> eventrequests = get_pagination_items ( request , filter ) <EOL> context = { <EOL> '<STR_LIT:title>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : eventrequests , <EOL> '<STR_LIT>' : filter , <EOL> '<STR_LIT>' : bootstrap_helper_filter , <EOL> } <EOL> return render ( request , '<STR_LIT>' , context ) <EOL> class EventRequestDetails ( LoginRequiredMixin , DetailView ) : <EOL> queryset = EventRequest . objects . all ( ) <EOL> context_object_name = '<STR_LIT:object>' <EOL> template_name = '<STR_LIT>' <EOL> pk_url_kwarg = '<STR_LIT>' <EOL> def get_context_data ( self , ** kwargs ) : <EOL> context = super ( ) . get_context_data ( ** kwargs ) <EOL> context [ '<STR_LIT:title>' ] = '<STR_LIT>' . format ( self . get_object ( ) . pk ) <EOL> person_lookup_form = AdminLookupForm ( ) <EOL> if self . object . assigned_to : <EOL> person_lookup_form = AdminLookupForm ( <EOL> initial = { '<STR_LIT>' : self . object . assigned_to } <EOL> ) <EOL> person_lookup_helper = BootstrapHelper ( ) <EOL> person_lookup_helper . form_action = reverse ( '<STR_LIT>' , <EOL> args = [ self . object . pk ] ) <EOL> context [ '<STR_LIT>' ] = person_lookup_form <EOL> context [ '<STR_LIT>' ] = person_lookup_helper <EOL> return context <EOL> @ login_required <EOL> @ permission_required ( '<STR_LIT>' , raise_exception = True ) <EOL> def eventrequest_discard ( request , request_id ) : <EOL> """<STR_LIT>""" <EOL> eventrequest = get_object_or_404 ( EventRequest , active = True , pk = request_id ) <EOL> eventrequest . active = False <EOL> eventrequest . save ( ) <EOL> messages . success ( request , <EOL> '<STR_LIT>' ) <EOL> return redirect ( reverse ( '<STR_LIT>' ) ) <EOL> @ login_required <EOL> @ permission_required ( [ '<STR_LIT>' , '<STR_LIT>' ] , <EOL> raise_exception = True ) <EOL> def eventrequest_accept ( request , request_id ) : <EOL> """<STR_LIT>""" <EOL> eventrequest = get_object_or_404 ( EventRequest , active = True , pk = request_id ) <EOL> form = EventForm ( ) <EOL> if request . method == '<STR_LIT:POST>' : <EOL> form = EventForm ( request . POST ) <EOL> if form . is_valid ( ) : <EOL> event = form . save ( ) <EOL> event . request = eventrequest <EOL> event . save ( ) <EOL> eventrequest . active = False <EOL> eventrequest . save ( ) <EOL> return redirect ( reverse ( '<STR_LIT>' , <EOL> args = [ event . get_ident ( ) ] ) ) <EOL> else : <EOL> messages . error ( request , '<STR_LIT>' ) <EOL> context = { <EOL> '<STR_LIT:object>' : eventrequest , <EOL> '<STR_LIT>' : form , <EOL> } <EOL> return render ( request , '<STR_LIT>' , context ) <EOL> @ login_required <EOL> @ permission_required ( [ '<STR_LIT>' ] , raise_exception = True ) <EOL> def eventrequest_assign ( request , request_id , person_id = None ) : <EOL> """<STR_LIT>""" <EOL> event_req = get_object_or_404 ( EventRequest , pk = request_id ) <EOL> assign ( request , event_req , person_id ) <EOL> return redirect ( reverse ( '<STR_LIT>' , args = [ event_req . pk ] ) ) <EOL> def profileupdaterequest_create ( request ) : <EOL> """<STR_LIT>""" <EOL> form = ProfileUpdateRequestForm ( ) <EOL> form_helper = bootstrap_helper_wider_labels <EOL> page_title = '<STR_LIT>' <EOL> if request . method == '<STR_LIT:POST>' : <EOL> form = ProfileUpdateRequestForm ( request . POST ) <EOL> if form . is_valid ( ) : <EOL> form . save ( ) <EOL> context = { <EOL> '<STR_LIT:title>' : '<STR_LIT>' , <EOL> } <EOL> return render ( request , <EOL> '<STR_LIT>' , <EOL> context ) <EOL> else : <EOL> messages . error ( request , '<STR_LIT>' ) <EOL> context = { <EOL> '<STR_LIT:title>' : page_title , <EOL> '<STR_LIT>' : form , <EOL> '<STR_LIT>' : form_helper , <EOL> } <EOL> return render ( request , '<STR_LIT>' , context ) <EOL> class AllProfileUpdateRequests ( LoginRequiredMixin , ListView ) : <EOL> active_requests = True <EOL> context_object_name = '<STR_LIT>' <EOL> template_name = '<STR_LIT>' <EOL> def get_queryset ( self ) : <EOL> return ProfileUpdateRequest . objects . filter ( active = self . active_requests ) . order_by ( '<STR_LIT>' ) <EOL> def get_context_data ( self , ** kwargs ) : <EOL> context = super ( ) . get_context_data ( ** kwargs ) <EOL> context [ '<STR_LIT:title>' ] = '<STR_LIT>' <EOL> context [ '<STR_LIT>' ] = self . active_requests <EOL> return context <EOL> class AllClosedProfileUpdateRequests ( AllProfileUpdateRequests ) : <EOL> active_requests = False <EOL> @ login_required <EOL> def profileupdaterequest_details ( request , request_id ) : <EOL> update_request = get_object_or_404 ( ProfileUpdateRequest , <EOL> pk = request_id ) <EOL> person_selected = False <EOL> person = None <EOL> form = None <EOL> try : <EOL> person = Person . objects . get ( email = update_request . email ) <EOL> except Person . DoesNotExist : <EOL> try : <EOL> person = Person . objects . get ( personal = update_request . personal , <EOL> family = update_request . family ) <EOL> except ( Person . DoesNotExist , Person . MultipleObjectsReturned ) : <EOL> try : <EOL> form = PersonLookupForm ( request . GET ) <EOL> person = Person . objects . get ( pk = int ( request . GET [ '<STR_LIT>' ] ) ) <EOL> person_selected = True <EOL> except KeyError : <EOL> person = None <EOL> form = PersonLookupForm ( ) <EOL> except ( ValueError , Person . DoesNotExist ) : <EOL> person = None <EOL> if person : <EOL> person . has_instructor_badge = Award . objects . filter ( <EOL> badge__in = Badge . objects . instructor_badges ( ) , person = person <EOL> ) . exists ( ) <EOL> try : <EOL> airport = Airport . objects . get ( iata = update_request . airport_iata ) <EOL> except Airport . DoesNotExist : <EOL> airport = None <EOL> context = { <EOL> '<STR_LIT:title>' : ( '<STR_LIT>' <EOL> . format ( update_request . pk ) ) , <EOL> '<STR_LIT>' : update_request , <EOL> '<STR_LIT>' : person , <EOL> '<STR_LIT>' : form , <EOL> '<STR_LIT>' : person_selected , <EOL> '<STR_LIT>' : bootstrap_helper_get , <EOL> '<STR_LIT>' : airport , <EOL> } <EOL> return render ( request , '<STR_LIT>' , context ) <EOL> class ProfileUpdateRequestFix ( LoginRequiredMixin , PermissionRequiredMixin , <EOL> UpdateViewContext ) : <EOL> permission_required = '<STR_LIT>' <EOL> model = ProfileUpdateRequest <EOL> form_class = ProfileUpdateRequestFormNoCaptcha <EOL> pk_url_kwarg = '<STR_LIT>' <EOL> template_name = '<STR_LIT>' <EOL> @ login_required <EOL> @ permission_required ( '<STR_LIT>' , <EOL> raise_exception = True ) <EOL> def profileupdaterequest_discard ( request , request_id ) : <EOL> """<STR_LIT>""" <EOL> profileupdate = get_object_or_404 ( ProfileUpdateRequest , active = True , <EOL> pk = request_id ) <EOL> profileupdate . active = False <EOL> profileupdate . save ( ) <EOL> messages . success ( request , <EOL> '<STR_LIT>' ) <EOL> return redirect ( reverse ( '<STR_LIT>' ) ) <EOL> @ login_required <EOL> @ permission_required ( '<STR_LIT>' , <EOL> raise_exception = True ) <EOL> def profileupdaterequest_accept ( request , request_id , person_id = None ) : <EOL> """<STR_LIT>""" <EOL> profileupdate = get_object_or_404 ( ProfileUpdateRequest , active = True , <EOL> pk = request_id ) <EOL> airport = get_object_or_404 ( Airport , iata = profileupdate . airport_iata ) <EOL> if person_id is None : <EOL> person = Person ( ) <EOL> if not request . user . has_perm ( '<STR_LIT>' ) : <EOL> raise PermissionDenied <EOL> else : <EOL> person = get_object_or_404 ( Person , pk = person_id ) <EOL> person_name = str ( person ) <EOL> if not request . user . has_perm ( '<STR_LIT>' ) : <EOL> raise PermissionDenied <EOL> person . personal = profileupdate . personal <EOL> person . family = profileupdate . family <EOL> person . email = profileupdate . email <EOL> person . affiliation = profileupdate . affiliation <EOL> person . airport = airport <EOL> person . github = profileupdate . github <EOL> person . twitter = profileupdate . twitter <EOL> person . url = profileupdate . website <EOL> if profileupdate . occupation == '<STR_LIT>' : <EOL> person . occupation = profileupdate . occupation_other <EOL> else : <EOL> person . occupation = profileupdate . get_occupation_display ( ) <EOL> person . orcid = profileupdate . orcid <EOL> person . gender = profileupdate . gender <EOL> if not person . id : <EOL> person . save ( ) <EOL> person . domains = list ( profileupdate . domains . all ( ) ) <EOL> Qualification . objects . filter ( person = person ) . delete ( ) <EOL> Qualification . objects . bulk_create ( [ <EOL> Qualification ( person = person , lesson = L ) <EOL> for L in profileupdate . lessons . all ( ) <EOL> ] ) <EOL> person . save ( ) <EOL> profileupdate . active = False <EOL> profileupdate . save ( ) <EOL> if person_id is None : <EOL> messages . success ( request , <EOL> '<STR_LIT>' ) <EOL> else : <EOL> messages . success ( request , <EOL> '<STR_LIT>' . format ( person_name ) ) <EOL> return redirect ( person . get_absolute_url ( ) ) <EOL> class EventSubmission ( EmailSendMixin , CreateViewContext ) : <EOL> """<STR_LIT>""" <EOL> model = EventSubmissionModel <EOL> form_class = EventSubmitForm <EOL> template_name = '<STR_LIT>' <EOL> success_url = reverse_lazy ( '<STR_LIT>' ) <EOL> email_fail_silently = False <EOL> email_kwargs = { <EOL> '<STR_LIT:to>' : settings . REQUEST_NOTIFICATIONS_RECIPIENTS , <EOL> } <EOL> def get_success_message ( self , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> return '<STR_LIT>' <EOL> def get_context_data ( self , ** kwargs ) : <EOL> context = super ( ) . get_context_data ( ** kwargs ) <EOL> context [ '<STR_LIT:title>' ] = '<STR_LIT>' <EOL> context [ '<STR_LIT>' ] = bootstrap_helper_wider_labels <EOL> return context <EOL> def get_subject ( self ) : <EOL> return ( '<STR_LIT>' <EOL> . format ( self . object . contact_name ) ) <EOL> def get_body ( self ) : <EOL> link = self . object . get_absolute_url ( ) <EOL> link_domain = settings . SITE_URL <EOL> body_txt = get_template ( '<STR_LIT>' ) . render ( { <EOL> '<STR_LIT:object>' : self . object , <EOL> '<STR_LIT>' : link , <EOL> '<STR_LIT>' : link_domain , <EOL> } ) <EOL> body_html = get_template ( '<STR_LIT>' ) . render ( { <EOL> '<STR_LIT:object>' : self . object , <EOL> '<STR_LIT>' : link , <EOL> '<STR_LIT>' : link_domain , <EOL> } ) <EOL> return body_txt , body_html <EOL> class EventSubmissionConfirm ( TemplateView ) : <EOL> """<STR_LIT>""" <EOL> template_name = '<STR_LIT>' <EOL> def get_context_data ( self , ** kwargs ) : <EOL> context = super ( ) . get_context_data ( ** kwargs ) <EOL> context [ '<STR_LIT:title>' ] = '<STR_LIT>' <EOL> return context <EOL> class AllEventSubmissions ( LoginRequiredMixin , FilteredListView ) : <EOL> context_object_name = '<STR_LIT>' <EOL> template_name = '<STR_LIT>' <EOL> filter_class = EventSubmissionFilter <EOL> queryset = EventSubmissionModel . objects . all ( ) <EOL> def get_filter_data ( self ) : <EOL> data = self . request . GET . copy ( ) <EOL> data [ '<STR_LIT>' ] = data . get ( '<STR_LIT>' , '<STR_LIT:true>' ) <EOL> return data <EOL> def get_context_data ( self , ** kwargs ) : <EOL> context = super ( ) . get_context_data ( ** kwargs ) <EOL> context [ '<STR_LIT:title>' ] = '<STR_LIT>' <EOL> return context <EOL> class EventSubmissionDetails ( LoginRequiredMixin , DetailView ) : <EOL> context_object_name = '<STR_LIT:object>' <EOL> template_name = '<STR_LIT>' <EOL> queryset = EventSubmissionModel . objects . all ( ) <EOL> pk_url_kwarg = '<STR_LIT>' <EOL> def get_context_data ( self , ** kwargs ) : <EOL> context = super ( ) . get_context_data ( ** kwargs ) <EOL> context [ '<STR_LIT:title>' ] = '<STR_LIT>' . format ( <EOL> self . get_object ( ) . pk ) <EOL> person_lookup_form = AdminLookupForm ( ) <EOL> if self . object . assigned_to : <EOL> person_lookup_form = AdminLookupForm ( <EOL> initial = { '<STR_LIT>' : self . object . assigned_to } <EOL> ) <EOL> person_lookup_helper = BootstrapHelper ( ) <EOL> person_lookup_helper . form_action = reverse ( '<STR_LIT>' , <EOL> args = [ self . object . pk ] ) <EOL> context [ '<STR_LIT>' ] = person_lookup_form <EOL> context [ '<STR_LIT>' ] = person_lookup_helper <EOL> return context <EOL> class EventSubmissionFix ( LoginRequiredMixin , PermissionRequiredMixin , <EOL> UpdateViewContext ) : <EOL> permission_required = '<STR_LIT>' <EOL> model = EventSubmissionModel <EOL> form_class = EventSubmitFormNoCaptcha <EOL> pk_url_kwarg = '<STR_LIT>' <EOL> template_name = '<STR_LIT>' <EOL> @ login_required <EOL> @ permission_required ( [ '<STR_LIT>' , <EOL> '<STR_LIT>' ] , raise_exception = True ) <EOL> def eventsubmission_accept ( request , submission_id ) : <EOL> """<STR_LIT>""" <EOL> submission = get_object_or_404 ( EventSubmissionModel , active = True , <EOL> pk = submission_id ) <EOL> form = EventForm ( ) <EOL> if request . method == '<STR_LIT:POST>' : <EOL> form = EventForm ( request . POST ) <EOL> if form . is_valid ( ) : <EOL> event = form . save ( ) <EOL> submission . active = False <EOL> submission . save ( ) <EOL> return redirect ( reverse ( '<STR_LIT>' , <EOL> args = [ event . get_ident ( ) ] ) ) <EOL> else : <EOL> messages . error ( request , '<STR_LIT>' ) <EOL> context = { <EOL> '<STR_LIT:object>' : submission , <EOL> '<STR_LIT>' : form , <EOL> '<STR_LIT:title>' : '<STR_LIT>' , <EOL> } <EOL> return render ( request , '<STR_LIT>' , context ) <EOL> @ login_required <EOL> @ permission_required ( '<STR_LIT>' , raise_exception = True ) <EOL> def eventsubmission_discard ( request , submission_id ) : <EOL> """<STR_LIT>""" <EOL> submission = get_object_or_404 ( EventSubmissionModel , active = True , <EOL> pk = submission_id ) <EOL> submission . active = False <EOL> submission . save ( ) <EOL> messages . success ( request , <EOL> '<STR_LIT>' ) <EOL> return redirect ( reverse ( '<STR_LIT>' ) ) <EOL> @ login_required <EOL> @ permission_required ( [ '<STR_LIT>' ] , raise_exception = True ) <EOL> def eventsubmission_assign ( request , submission_id , person_id = None ) : <EOL> """<STR_LIT>""" <EOL> submission = get_object_or_404 ( EventSubmissionModel , pk = submission_id ) <EOL> assign ( request , submission , person_id ) <EOL> return redirect ( submission . get_absolute_url ( ) ) <EOL> @ login_required <EOL> @ permission_required ( '<STR_LIT>' , raise_exception = True ) <EOL> def todos_add ( request , event_ident ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> event = Event . get_by_ident ( event_ident ) <EOL> except Event . DoesNotExist : <EOL> raise Http404 ( '<STR_LIT>' ) <EOL> dt = datetime . datetime <EOL> timedelta = datetime . timedelta <EOL> initial = [ ] <EOL> base = dt . now ( ) <EOL> if not event . start or not event . end : <EOL> initial = [ <EOL> { <EOL> '<STR_LIT:title>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : dt . now ( ) + timedelta ( days = <NUM_LIT:30> ) , <EOL> '<STR_LIT>' : event , <EOL> } , <EOL> ] <EOL> formset = TodoFormSet ( queryset = TodoItem . objects . none ( ) , initial = initial + [ <EOL> { <EOL> '<STR_LIT:title>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : base + timedelta ( days = <NUM_LIT:7> ) , <EOL> '<STR_LIT>' : event , <EOL> } , <EOL> { <EOL> '<STR_LIT:title>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : base + timedelta ( days = <NUM_LIT> ) , <EOL> '<STR_LIT>' : event , <EOL> } , <EOL> { <EOL> '<STR_LIT:title>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : base + timedelta ( days = <NUM_LIT> ) , <EOL> '<STR_LIT>' : event , <EOL> } , <EOL> { <EOL> '<STR_LIT:title>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : base + timedelta ( days = <NUM_LIT> ) , <EOL> '<STR_LIT>' : event , <EOL> } , <EOL> { <EOL> '<STR_LIT:title>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : event . start - timedelta ( days = <NUM_LIT:7> ) if event . start else '<STR_LIT>' , <EOL> '<STR_LIT>' : event , <EOL> } , <EOL> { <EOL> '<STR_LIT:title>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : event . start - timedelta ( days = <NUM_LIT:1> ) if event . start else '<STR_LIT>' , <EOL> '<STR_LIT>' : event , <EOL> } , <EOL> { <EOL> '<STR_LIT:title>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : event . end + timedelta ( days = <NUM_LIT:2> ) if event . end else '<STR_LIT>' , <EOL> '<STR_LIT>' : event , <EOL> } , <EOL> { <EOL> '<STR_LIT:title>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : event . end + timedelta ( days = <NUM_LIT:7> ) if event . end else '<STR_LIT>' , <EOL> '<STR_LIT>' : event , <EOL> } , <EOL> { <EOL> '<STR_LIT:title>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : event . end + timedelta ( days = <NUM_LIT:7> ) if event . end else '<STR_LIT>' , <EOL> '<STR_LIT>' : event , <EOL> } , <EOL> ] ) <EOL> if request . method == '<STR_LIT:POST>' : <EOL> formset = TodoFormSet ( request . POST ) <EOL> if formset . is_valid ( ) : <EOL> formset . save ( ) <EOL> messages . success ( request , '<STR_LIT>' , <EOL> extra_tags = '<STR_LIT>' ) <EOL> return redirect ( reverse ( event_details , args = ( event . get_ident ( ) , ) ) ) <EOL> else : <EOL> messages . error ( request , '<STR_LIT>' ) <EOL> context = { <EOL> '<STR_LIT:title>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : formset , <EOL> '<STR_LIT>' : bootstrap_helper_inline_formsets , <EOL> '<STR_LIT>' : event , <EOL> } <EOL> return render ( request , '<STR_LIT>' , context ) <EOL> @ login_required <EOL> @ permission_required ( '<STR_LIT>' , raise_exception = True ) <EOL> def todo_mark_completed ( request , todo_id ) : <EOL> todo = get_object_or_404 ( TodoItem , pk = todo_id ) <EOL> todo . completed = True <EOL> todo . save ( ) <EOL> return HttpResponse ( ) <EOL> @ login_required <EOL> @ permission_required ( '<STR_LIT>' , raise_exception = True ) <EOL> def todo_mark_incompleted ( request , todo_id ) : <EOL> todo = get_object_or_404 ( TodoItem , pk = todo_id ) <EOL> todo . completed = False <EOL> todo . save ( ) <EOL> return HttpResponse ( ) <EOL> class TodoItemUpdate ( LoginRequiredMixin , PermissionRequiredMixin , <EOL> UpdateViewContext ) : <EOL> permission_required = '<STR_LIT>' <EOL> model = TodoItem <EOL> form_class = SimpleTodoForm <EOL> pk_url_kwarg = '<STR_LIT>' <EOL> template_name = '<STR_LIT>' <EOL> def get_success_url ( self ) : <EOL> return reverse ( '<STR_LIT>' , args = [ self . object . event . get_ident ( ) ] ) <EOL> def form_valid ( self , form ) : <EOL> """<STR_LIT>""" <EOL> self . object = form . save ( ) <EOL> response = super ( ModelFormMixin , self ) . form_valid ( form ) <EOL> success_message = self . get_success_message ( form . cleaned_data ) <EOL> if success_message : <EOL> messages . success ( self . request , success_message , extra_tags = '<STR_LIT>' ) <EOL> return response <EOL> @ login_required <EOL> @ permission_required ( '<STR_LIT>' , raise_exception = True ) <EOL> def todo_delete ( request , todo_id ) : <EOL> """<STR_LIT>""" <EOL> todo = get_object_or_404 ( TodoItem , pk = todo_id ) <EOL> event_ident = todo . event . get_ident ( ) <EOL> todo . delete ( ) <EOL> messages . success ( request , '<STR_LIT>' , <EOL> extra_tags = '<STR_LIT>' ) <EOL> return redirect ( event_details , event_ident ) <EOL> @ login_required <EOL> def duplicates ( request ) : <EOL> """<STR_LIT>""" <EOL> names_normal = set ( Person . objects . all ( ) . values_list ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> names_switched = set ( Person . objects . all ( ) . values_list ( '<STR_LIT>' , <EOL> '<STR_LIT>' ) ) <EOL> names = names_normal & names_switched <EOL> switched_criteria = Q ( id = <NUM_LIT:0> ) <EOL> for personal , family in names : <EOL> switched_criteria |= ( Q ( personal = personal ) & Q ( family = family ) ) <EOL> switched_persons = Person . objects . filter ( switched_criteria ) . order_by ( '<STR_LIT:email>' ) <EOL> duplicate_names = Person . objects . values ( '<STR_LIT>' , '<STR_LIT>' ) . order_by ( ) . annotate ( count_id = Count ( '<STR_LIT:id>' ) ) . filter ( count_id__gt = <NUM_LIT:1> ) <EOL> duplicate_criteria = Q ( id = <NUM_LIT:0> ) <EOL> for name in duplicate_names : <EOL> duplicate_criteria |= ( Q ( personal = name [ '<STR_LIT>' ] ) & <EOL> Q ( family = name [ '<STR_LIT>' ] ) ) <EOL> duplicate_persons = Person . objects . filter ( duplicate_criteria ) . order_by ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:email>' ) <EOL> context = { <EOL> '<STR_LIT:title>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : switched_persons , <EOL> '<STR_LIT>' : duplicate_persons , <EOL> } <EOL> return render ( request , '<STR_LIT>' , context ) </s>
