def create_participant(participant): NewParticipant = Participant(participant_id=test_participants[participant]["participant_id"], participant_type=test_participants[participant]["participant_type"], first=test_participants[participant]["first"], last=test_participants[participant]["last"]) NewParticipant.save() serializer = ParticipantSerializer(NewParticipant) return JsonResponse(serializer.data, safe=False)
def register(request, trial): page_type = 'register' if trial == 'trial': trial_account = True else: trial_account = False if request.method == 'POST': user_form = UserRegisterForm(request.POST, label_suffix='') group_form = GroupRegisterForm(request.POST, label_suffix='') if user_form.is_valid() and group_form.is_valid(): # save each form password = user_form.cleaned_data['password1'] new_user = user_form.save() group = group_form.save() # associate the user with the group u = new_user group.users.add(u) # set the group as the user's current_group settings = UserSettings(user=u, current_group=group) settings.save() # generate a slug from the group name slug = slugify(group.name)[:20] group.slug = slug group.save() # set the account status to trial if required if trial_account == True: group.account_type = 'Trial' group.save() # save initial snapshots of new user and group details snapshot_user_details(u, password='******') snapshot_group_details(group) # log the new user in user = authenticate(username=new_user.username, password=password) login(request, user) # set the new user up as a participant participant = Participant(group=group, email=user.email, first_name=user.first_name, last_name=user.last_name) participant.save() # send the new user a welcome email send_welcome_email(group=group, user=user) return HttpResponseRedirect(reverse('welcome')) else: user_form = UserRegisterForm(label_suffix='') group_form = GroupRegisterForm(label_suffix='') return render( request, 'register.html', { 'group_form': group_form, 'page_type': page_type, 'trial_account': trial_account, 'user_form': user_form, })
def register(request, trial): page_type = 'register' if trial == 'trial': trial_account = True else: trial_account = False if request.method == 'POST': user_form = UserRegisterForm(request.POST, label_suffix='') group_form = GroupRegisterForm(request.POST, label_suffix='') if user_form.is_valid() and group_form.is_valid(): # save each form password = user_form.cleaned_data['password1'] new_user = user_form.save() group = group_form.save() # associate the user with the group u = new_user group.users.add(u) # set the group as the user's current_group settings = UserSettings(user=u, current_group=group) settings.save() # generate a slug from the group name slug = slugify(group.name)[:20] group.slug = slug group.save() # set the account status to trial if required if trial_account == True: group.account_type = 'Trial' group.save() # save initial snapshots of new user and group details snapshot_user_details(u, password='******') snapshot_group_details(group) # log the new user in user = authenticate(username=new_user.username, password=password) login(request, user) # set the new user up as a participant participant = Participant(group=group, email=user.email, first_name=user.first_name, last_name=user.last_name) participant.save() # send the new user a welcome email send_welcome_email(group=group, user=user) return HttpResponseRedirect(reverse('welcome')) else: user_form = UserRegisterForm(label_suffix='') group_form = GroupRegisterForm(label_suffix='') return render(request, 'register.html', { 'group_form': group_form, 'page_type': page_type, 'trial_account': trial_account, 'user_form': user_form, })
def process_file(self, reader): for artist_id, contest_id, country_id, song in reader: # Check if there is any data. if not (artist_id and contest_id and country_id and song): self.stdout.write( self.style.WARNING( f"There are some data missing {artist_id, contest_id, country_id, song}." )) continue # If there is Contest, we should check if there is a Country_ID and Artist_ID in db. if Contest.objects.filter(id=contest_id).exists(): if Country.objects.filter( id=country_id).exists() and Artist.objects.filter( id=artist_id).exists(): artist = Artist.objects.get(id=artist_id) contest = Contest.objects.get(id=contest_id) country = Country.objects.get(id=country_id) if Participant.objects.all().filter(artist=artist_id, contest=contest_id, country=country_id): self.stdout.write( self.style.WARNING( f"Record: {artist.name}, {song}, {country.name}, {contest.year} already in db. Skipped." )) else: # Save if validation was passed. p = Participant(artist=artist, contest=contest, country=country, song=song) p.save() self.stdout.write( self.style.SUCCESS( f"{artist.name}, {song}, {country.name}, {contest.year} saved to the Particpant table." )) else: self.stdout.write( self.style.WARNING( f"The Country or Artist with the IDs {country_id, artist_id} respectively " "do not exists in database. Skipped.")) else: self.stdout.write( self.style.WARNING( f"The Contest with the ID {contest_id} does not exists in database. Skipped." ))
def create_challenge_host_participant_team(challenge_host_team): """ Creates challenge host participant team and returns it. """ emails = challenge_host_team.get_all_challenge_host_email() team_name = "Host_{}_Team".format(random.randint(1, 100000)) participant_host_team = ParticipantTeam( team_name=team_name, created_by=challenge_host_team.created_by) participant_host_team.save() for email in emails: user = User.objects.get(email=email) host = Participant(user=user, status=Participant.ACCEPTED, team=participant_host_team) host.save() return participant_host_team
def register_participants(request, event=None, id=None): from participants.models import Participant from bookings.models import BookingLine from events.models import Event from vouchers.models import Voucher from browsersessions.models import BrowserSession from django.core.exceptions import ImproperlyConfigured, SuspiciousOperation from django.core.urlresolvers import reverse from django.http import HttpResponseRedirect try: event = Event.objects.get_bookable(request.session['event_id']) except Exception as e: raise SuspiciousOperation('invalid event', e) stages = RegistrationStages() stages.set_active(RegistrationStages.STAGE_PARTICIPANT) dbsession = BrowserSession.objects.get_session(request.session.session_key) entered_bookinglines = BookingLine.objects.filter( browser_session__name=request.session.session_key).exists() if entered_bookinglines: has_bookinglines = True else: has_bookinglines = False form = None instance_participant = None voucher = None instance_bookingline = None form_kwargs_participant = {} form_kwargs_bookingline = {} form_kwargs_bookingline['dbsession'] = dbsession; if id: try: instance_bookingline = BookingLine.objects.get(pk=id) except: # this happens if a BL is is deleted while it is in the edit id = None if instance_bookingline: form_kwargs_bookingline['instance'] = instance_bookingline instance_participant = instance_bookingline.participant form_kwargs_participant['instance'] = instance_participant if instance_bookingline.voucher: form_kwargs_bookingline['voucher_code'] = str(instance_bookingline.voucher) if request.method == 'POST': form_participant = ParticipantForm(request.POST,prefix='pp',**form_kwargs_participant) form_bookingline = BookingLineForm(request.POST,prefix='bl',**form_kwargs_bookingline) if form_bookingline.is_valid(): """does not mean that the voucher is valid: let us check that first """ voucher = None voucher_code = form_bookingline.cleaned_data.get('voucher_code') if voucher_code: try: voucher = Voucher.objects.get_voucher_by_code(event, voucher_code) if voucher.used_by and voucher.used_by <> instance: # TODO: "does not exist" if not in the same session to obscure codes? form_bookingline.add_error('voucher_code', 'This voucher is already in use') except Voucher.DoesNotExist: form_bookingline.add_error('voucher_code', 'This voucher code does not exist') """ now the form can be checked again and voucher can be used """ if form_bookingline.is_valid() and form_participant.is_valid(): first_name = form_participant.cleaned_data.get('first_name') last_name = form_participant.cleaned_data.get('last_name') email = form_participant.cleaned_data.get('email') mail_option = form_participant.cleaned_data.get('mail_option') ticket_type = form_bookingline.cleaned_data.get('ticket_type') if not instance_bookingline: instance_bookingline = BookingLine() instance_participant = Participant() else: instance_participant = instance_bookingline.participant instance_participant.first_name = first_name instance_participant.last_name = last_name instance_participant.email = email instance_participant.mail_option = mail_option instance_participant.save() instance_bookingline.participant = instance_participant instance_bookingline.ticket_type = ticket_type instance_bookingline.browser_session = dbsession instance_bookingline.voucher = voucher instance_bookingline.save() # bounce back to an empty form after saving bounce_target = reverse('register_participants') return HttpResponseRedirect(bounce_target) context = { 'form_pp': form_participant, 'form_bl': form_bookingline, 'event': event, 'has_bookinglines': has_bookinglines, 'stages': stages.as_list(), 'has_vat': True, } return render(request, 'ewtisite/register_participants.html', context) form_participant = ParticipantForm(prefix='pp',**form_kwargs_participant) form_bookingline = BookingLineForm(prefix='bl',**form_kwargs_bookingline) context = { 'form_pp': form_participant, 'form_bl': form_bookingline, 'has_bookinglines': has_bookinglines, 'participant': instance_participant, 'stages': stages.as_list(), 'has_vat': True, } return render(request, 'ewtisite/register_participants.html', context)
import datetime from paper.models import Paper, Journal, Affiliation, Author from session.models import Session, Location from participants.models import Participant from ratings.models import Rating ## participants f = open('/Users/dimitriosalikaniotis/Sites/llc/llc_site/llc/utils/participants.txt') for line in f: p = Participant() p.name = line.strip().split('\t')[1] p.save() f.close() ## affiliation f = open('/Users/dimitriosalikaniotis/Sites/llc/llc_site/llc/utils/affiliations.txt') for line in f: a = Affiliation() try: a.department = line.strip().split('\t')[1] except: pass try: a.university = line.strip().split('\t')[2] except:
def load_from_zip(cls, zip_file_path, challenge_host_team): from .utils import get_file_content from .serializers import ( ChallengePhaseCreateSerializer, DatasetSplitSerializer, LeaderboardSerializer, ZipChallengePhaseSplitSerializer, ZipChallengeSerializer, ) zip_ref = zipfile.ZipFile(zip_file_path, "r") BASE_LOCATION = tempfile.mkdtemp() zip_ref.extractall(BASE_LOCATION) zip_ref.close() for name in zip_ref.namelist(): if (name.endswith(".yaml") or name.endswith(".yml")) and ( not name.startswith("__MACOSX") ): # Ignore YAML File in __MACOSX Directory yaml_file = name extracted_folder_name = yaml_file.split(basename(yaml_file))[0] break else: raise Exception('No yaml file found in zip root!') with open(join(BASE_LOCATION, yaml_file), "r") as stream: yaml_file_data = yaml.safe_load(stream) evaluation_script = yaml_file_data["evaluation_script"] evaluation_script_path = join( BASE_LOCATION, extracted_folder_name, evaluation_script, ) # Check for evaluation script file in extracted zip folder. with open(evaluation_script_path, "rb") as challenge_evaluation_script: challenge_evaluation_script_file = ContentFile( challenge_evaluation_script.read(), evaluation_script_path) challenge_phases_data = yaml_file_data["challenge_phases"] for data in challenge_phases_data: test_annotation_file = data["test_annotation_file"] test_annotation_file_path = join( BASE_LOCATION, extracted_folder_name, test_annotation_file, ) image = yaml_file_data.get("image") if image and (image.endswith(".jpg") or image.endswith(".jpeg") or image.endswith(".png")): challenge_image_path = join(BASE_LOCATION, extracted_folder_name, image) if isfile(challenge_image_path): challenge_image_file = ContentFile( get_file_content(challenge_image_path, "rb"), image) else: challenge_image_file = None else: challenge_image_file = None challenge_description_file_path = join( BASE_LOCATION, extracted_folder_name, yaml_file_data["description"], ) if challenge_description_file_path.endswith(".html") and isfile( challenge_description_file_path): yaml_file_data["description"] = get_file_content( challenge_description_file_path, "rb").decode("utf-8") challenge_evaluation_details_file_path = join( BASE_LOCATION, extracted_folder_name, yaml_file_data["evaluation_details"], ) if challenge_evaluation_details_file_path.endswith(".html") and isfile( challenge_evaluation_details_file_path): yaml_file_data["evaluation_details"] = get_file_content( challenge_evaluation_details_file_path, "rb").decode("utf-8") else: yaml_file_data["evaluation_details"] = None challenge_terms_and_cond_file_path = join( BASE_LOCATION, extracted_folder_name, yaml_file_data["terms_and_conditions"], ) if challenge_terms_and_cond_file_path.endswith(".html") and isfile( challenge_terms_and_cond_file_path): yaml_file_data["terms_and_conditions"] = get_file_content( challenge_terms_and_cond_file_path, "rb").decode("utf-8") else: yaml_file_data["terms_and_conditions"] = None submission_guidelines_file_path = join( BASE_LOCATION, extracted_folder_name, yaml_file_data["submission_guidelines"], ) if submission_guidelines_file_path.endswith(".html") and isfile( submission_guidelines_file_path): yaml_file_data["submission_guidelines"] = get_file_content( submission_guidelines_file_path, "rb").decode("utf-8") else: yaml_file_data["submission_guidelines"] = None serializer = ZipChallengeSerializer( data=yaml_file_data, context={ "request": namedtuple('Request', 'method')(method='NOTGET'), "challenge_host_team": challenge_host_team, "image": challenge_image_file, "evaluation_script": challenge_evaluation_script_file, }, ) if serializer.is_valid(): serializer.save() challenge = serializer.instance queue_name = get_queue_name(challenge.title) challenge.queue = queue_name challenge.save() else: raise Exception(serializer.errors) # Create Leaderboard yaml_file_data_of_leaderboard = yaml_file_data["leaderboard"] leaderboard_ids = {} for data in yaml_file_data_of_leaderboard: serializer = LeaderboardSerializer(data=data) if serializer.is_valid(): serializer.save() leaderboard_ids[str(data["id"])] = serializer.instance.pk else: raise Exception(serializer.errors) # Create Challenge Phase challenge_phase_ids = {} for data in challenge_phases_data: # Check for challenge phase description file phase_description_file_path = join( BASE_LOCATION, extracted_folder_name, data["description"], ) if phase_description_file_path.endswith(".html") and isfile( phase_description_file_path): data["description"] = get_file_content( phase_description_file_path, "rb").decode("utf-8") else: data["description"] = None test_annotation_file = data["test_annotation_file"] data["slug"] = "{}-{}-{}".format( challenge.title.split(" ")[0].lower(), data["codename"].replace(" ", "-").lower(), challenge.pk, )[:198] if test_annotation_file: test_annotation_file_path = join( BASE_LOCATION, extracted_folder_name, test_annotation_file, ) if isfile(test_annotation_file_path): with open(test_annotation_file_path, "rb") as test_annotation_file: challenge_test_annotation_file = ContentFile( test_annotation_file.read(), test_annotation_file_path, ) serializer = ChallengePhaseCreateSerializer( data=data, context={ "challenge": challenge, "test_annotation": challenge_test_annotation_file, }, ) if serializer.is_valid(): serializer.save() challenge_phase_ids[str(data["id"])] = serializer.instance.pk else: raise Exception(serializer.errors) # Create Dataset Splits yaml_file_data_of_dataset_split = yaml_file_data["dataset_splits"] dataset_split_ids = {} for data in yaml_file_data_of_dataset_split: serializer = DatasetSplitSerializer(data=data) if serializer.is_valid(): serializer.save() dataset_split_ids[str(data["id"])] = serializer.instance.pk else: # Return error when dataset split name is not unique. raise Exception(serializer.errors) # Create Challenge Phase Splits challenge_phase_splits_data = yaml_file_data["challenge_phase_splits"] for data in challenge_phase_splits_data: challenge_phase = challenge_phase_ids[str( data["challenge_phase_id"])] leaderboard = leaderboard_ids[str(data["leaderboard_id"])] dataset_split = dataset_split_ids[str(data["dataset_split_id"])] visibility = data["visibility"] data = { "challenge_phase": challenge_phase, "leaderboard": leaderboard, "dataset_split": dataset_split, "visibility": visibility, } serializer = ZipChallengePhaseSplitSerializer(data=data) if serializer.is_valid(): serializer.save() else: raise Exception(serializer.errors) if not challenge.is_docker_based: # Add the Challenge Host as a test participant. emails = challenge_host_team.get_all_challenge_host_email() team_name = "Host_{}_Team".format(random.randint(1, 100000)) participant_host_team = ParticipantTeam( team_name=team_name, created_by=challenge_host_team.created_by, ) participant_host_team.save() for email in emails: user = User.objects.get(email=email) host = Participant( user=user, status=Participant.ACCEPTED, team=participant_host_team, ) host.save() challenge.participant_teams.add(participant_host_team) print("Success creating challenge") return challenge