def post(self, request): uni_id = request.POST.get('university') university = University.objects.get(id=uni_id) if university: try: doer = Person.objects.get(user=request.user) log = Log(task='delete_university', value_before=str(university), value_after='None', person=f'{doer.name} {doer.last_name}', date=timezone.now()) log.save() university.delete() request.session['alert'] = { 'type': 'info', 'message': 'Organización eliminada exitosamente' } except: request.session['alert'] = { 'type': 'danger', 'message': 'Ocurrió un error al eliminar la organización' } redirect_url = reverse('administration:administracion-section') return HttpResponseRedirect(redirect_url)
def post(self, request): match_id = request.POST.get('match') winner_id = request.POST.get('winner') match = Match.objects.get(id=match_id) if match is not None: for m_t in match.teams.all(): team_id = m_t.team.id score_name = 'score-{}'.format(team_id) score = request.POST.get(score_name) if score != '': m_t.score = score m_t.save() else: redirect_url = reverse('match:matches-section') return HttpResponseRedirect(redirect_url) doer = Person.objects.get(user=request.user) log = Log(task='closed_match', value_before=match.closed, value_after='True', person=f'{doer.name} {doer.last_name}', date=timezone.now()) log.save() match.state = Match.PLAYED match.closed = True winner = Team.objects.get(id=winner_id) match.winner = winner match.save() redirect_url = reverse('match:matches-section') return HttpResponseRedirect(redirect_url)
def post(self, request): sport_id = request.POST.get('sport') sport = Sport.objects.get(id=sport_id) if sport: try: doer = Person.objects.get(user=request.user) log = Log(task='delete_sport', value_before=str(sport), value_after='None', person=f'{doer.name} {doer.last_name}', date=timezone.now()) log.save() sport.delete() request.session['alert'] = { 'type': 'info', 'message': 'Deporte elimnado exitosamente' } except: request.session['alert'] = { 'type': 'danger', 'message': 'Ocurrió un error al eliminar el deporte' } redirect_url = reverse('administration:administracion-section') return HttpResponseRedirect(redirect_url)
def post(self, request): team_id = request.POST.get('team') team = Team.objects.get(id=team_id) if team is not None: try: doer = Person.objects.get(user=request.user) log = Log(task='team_deleted', value_before=str(team), value_after='None', person=f'{doer.name} {doer.last_name}', date=timezone.now()) log.save() team.delete() request.session['alert'] = { 'type': 'info', 'message': 'Equipo eliminado con exito' } except: request.session['alert'] = { 'type': 'danger', 'message': 'Ocurrió un error al eliminar el equipo' } redirect_url = reverse('team:team-home') return HttpResponseRedirect(redirect_url)
def post(self, request): name = request.POST.get('name') gender = request.POST.get('gender') sport_type = request.POST.get('type') coord_id = request.POST.get('coordinator') try: AdminCreateSport.validateCharField(name, 'nombre', 2, 100) if gender == "------": raise ValueError('debe indicar un género') if sport_type == "------": raise ValueError('debe indicar el tipo de deporte') if coord_id == "------": raise ValueError('debe indicar un coordinador') except Exception as inst: print(type(inst)) print(inst.args) request.session['alert'] = { 'type': 'warning', 'message': 'Ocurrió un error al crear el deporte: ' + inst.args[0] } else: coordinator = Person.objects.get(id=coord_id) sport = Sport(name=name, gender=gender, sport_type=sport_type, coordinator=coordinator) try: sport.save() doer = Person.objects.get(user=request.user) log = Log(task='create_sport', value_before='None', value_after=str(sport), person=f'{doer.name} {doer.last_name}', date=timezone.now()) log.save() request.session['alert'] = { 'type': 'success', 'message': 'Deporte creado exitosamente' } except: sport.delete() request.session['alert'] = { 'type': 'danger', 'message': 'Ocurrió un error al crear el deporte' } redirect_url = reverse('administration:administracion-section') return HttpResponseRedirect(redirect_url)
def post(self, request): sport_id = request.POST.get('sport') teams = request.POST.getlist('team[]') length = request.POST.get('length') location_id = request.POST.get('location') date = request.POST.get('date') time = request.POST.get('time') d_t = '{} {}'.format(date, time) match_date = datetime.strptime(d_t, "%Y-%m-%d %H:%M") event = None if request.user.is_authenticated: if Person.objects.filter(user=request.user).exists(): person = Person.objects.get(user=request.user) event = person.event if len(teams) >= 2 and event is not None: sport = Sport.objects.get(id=sport_id) location = Location.objects.get(id=location_id) match = Match(location=location, sport=sport, event=event, length=length, date=match_date) match.save() match_teams = [] for team_id in teams: team = Team.objects.get(id=team_id) if team is not None: match_team = MatchTeam(team=team) match_team.save() match.teams.add(match_team) else: for m_t in match_teams: m_t.delete() match.delete() doer = Person.objects.get(user=request.user) log = Log(task='create_match', value_before='None', value_after=str(match), person=f'{doer.name} {doer.last_name}', date=timezone.now()) log.save() redirect_url = reverse('match:matches-section') return HttpResponseRedirect(redirect_url)
def post(self, request): name = request.POST.get('name') address = request.POST.get('address') uni_id = request.POST.get('university') try: AdminCreateLocation.validateCharField(name, 'nombre', 2, 100) AdminCreateLocation.validateCharField(address, 'dirección', 2, 200) if uni_id == "------": raise ValueError('debe elegir una organización') except Exception as inst: print(type(inst)) print(inst.args) request.session['alert'] = { 'type': 'warning', 'message': 'Ocurrió un error al crear el lugar: ' + inst.args[0] } else: university = University.objects.get(id=uni_id) location = Location(name=name, address=address, university=university) try: location.save() doer = Person.objects.get(user=request.user) log = Log(task='create_location', value_before='None', value_after=str(location), person=f'{doer.name} {doer.last_name}', date=timezone.now()) log.save() request.session['alert'] = { 'type': 'success', 'message': 'Lugar creado exitosamente' } except: location.delete() request.session['alert'] = { 'type': 'danger', 'message': 'Ocurrió un error al crear el lugar' } redirect_url = reverse('administration:administracion-section') return HttpResponseRedirect(redirect_url)
def post(self, request): name = request.POST.get('name') city = request.POST.get('city') short_name = request.POST.get('short-name') try: AdminCreateUniversity.validateCharField(name, 'nombre', 3, 100) AdminCreateUniversity.validateCharField(city, 'ciudad', 2, 30) AdminCreateUniversity.validateCharField(short_name, 'siglas', 1, 10) except Exception as inst: print(type(inst)) print(inst.args) request.session['alert'] = { 'type': 'warning', 'message': 'Ocurrió un error al crear la organización: ' + inst.args[0] } else: university = University(name=name, city=city, short_name=short_name) try: university.save() doer = Person.objects.get(user=request.user) log = Log(task='create_university', value_before='None', value_after=str(university), person=f'{doer.name} {doer.last_name}', date=timezone.now()) log.save() request.session['alert'] = { 'type': 'success', 'message': 'Organización creada exitosamente' } except: request.session['alert'] = { 'type': 'danger', 'message': 'Ocurrió un error al crear la organización' } university.delete() redirect_url = reverse('administration:administracion-section') return HttpResponseRedirect(redirect_url)
def post(self, request): match_id = request.POST.get('match') match = Match.objects.get(id=match_id) match.teams.all().delete() if match is not None: doer = Person.objects.get(user=request.user) log = Log(task='match_deleted', value_before=str(match), value_after='None', person=f'{doer.name} {doer.last_name}', date=timezone.now()) log.save() match.delete() redirect_url = reverse('match:matches-section') return HttpResponseRedirect(redirect_url)
def post(self, request): match_id = request.POST.get('match') match = Match.objects.get(id=match_id) if match is not None: doer = Person.objects.get(user=request.user) log = Log(task='started_match', value_before=match.state, value_after=Match.PLAYING, person=f'{doer.name} {doer.last_name}', date=timezone.now()) log.save() match.state = Match.PLAYING match.save() redirect_url = reverse('match:matches-section') return HttpResponseRedirect(redirect_url)
def post(self, request): match_id = request.POST.get('match') team_id = request.POST.get('team') comment = request.POST.get('comment') match = Match.objects.get(pk=match_id) match_team = match.teams.get(pk=team_id) doer = Person.objects.get(user=request.user) log = Log(task='match_add_comment', value_before='None', value_after=comment, person=f'{doer.name} {doer.last_name}', date=timezone.now()) log.save() match_team.comment = comment match_team.save() return HttpResponseRedirect(reverse('match:matches-section'))
def post(self, request): person_id = request.POST.get('user') person = Person.objects.get(id=person_id) myself = None if request.user.is_authenticated: if Person.objects.filter(user=request.user).exists(): myself = Person.objects.get(user=request.user) if person: if person != myself: doer = Person.objects.get(user=request.user) log = Log(task='delete_person', value_before=f'{person.name} {person.last_name}', value_after='None', person=f'{doer.name} {doer.last_name}', date=timezone.now()) log.save() person.delete() request.session['alert'] = { 'type': 'info', 'message': 'Usuario eliminado exitosamente' } else: request.session['alert'] = { 'type': 'danger', 'message': 'No puedes eliminarte a ti mismo' } else: request.session['alert'] = { 'type': 'warning', 'message': 'No se ha encontrado el usuario a eliminar' } redirect_url = reverse('administration:administracion-section') return HttpResponseRedirect(redirect_url)
def post(self, request): location_id = request.POST.get('id') name = request.POST.get('name') address = request.POST.get('address') uni_id = request.POST.get('university') try: AdminCreateLocation.validateCharField(name, 'nombre', 2, 100) AdminCreateLocation.validateCharField(address, 'dirección', 2, 200) if uni_id == "------": raise ValueError('debe elegir una organización') except Exception as inst: print(type(inst)) print(inst.args) request.session['alert'] = { 'type': 'warning', 'message': 'Ocurrió un error al actualizar la organización: ' + inst.args[0] } else: university = University.objects.get(id=uni_id) location = Location.objects.get(id=location_id) if university and location: if location.name != name: doer = Person.objects.get(user=request.user) log = Log(task='edit_location_name', value_before=location.name, value_after=name, person=f'{doer.name} {doer.last_name}', date=timezone.now()) log.save() location.name = name if location.address != address: doer = Person.objects.get(user=request.user) log = Log(task='edit_location_address', value_before=location.address, value_after=address, person=f'{doer.name} {doer.last_name}', date=timezone.now()) log.save() location.address = address if location.university != university: doer = Person.objects.get(user=request.user) log = Log(task='edit_location_university', value_before=str(location.university), value_after=str(university), person=f'{doer.name} {doer.last_name}', date=timezone.now()) log.save() location.university = university try: location.save() request.session['alert'] = { 'type': 'info', 'message': 'Lugar editado exitosamente' } except: request.session['alert'] = { 'type': 'danger', 'message': 'Ocurrió un error al editar el lugar' } redirect_url = reverse('administration:administracion-section') return HttpResponseRedirect(redirect_url)
def post(self, request): rut = request.POST.get('rut').strip() nombres = request.POST.get('nombres').strip() email = request.POST.get('email').strip() apellidos = request.POST.get('apellidos').strip() is_admin = request.POST.get('is_admin', False) == 'on' is_organizer = request.POST.get('is_organizer', False) == 'on' is_university_coordinator = request.POST.get('is_uni_coordinator', False) == 'on' is_sports_coordinator = request.POST.get('is_sports_coordinator', False) == 'on' event_id = request.POST.get('event') university_id = request.POST.get('university') phone = request.POST.get('phone').strip() try: event = Event.objects.get(id=event_id) university = University.objects.get(id=university_id) AdminCreatePerson.validateCharField(nombres, 'nombres', 2, 100) AdminCreatePerson.validateCharField(apellidos, 'apellidos', 2, 100) AdminCreatePerson.validateCharField(email, 'correo electronico', 3, 60) AdminCreatePerson.validateCharField(phone, 'telefono', 3, 20) ev = EmailValidator('correo invalido') ev(email) person = Person( event=event, name=nombres, last_name=apellidos, email=email, university=university, rut=rut, phone_number=phone, is_admin=is_admin, is_organizer=is_organizer, is_university_coordinator=is_university_coordinator, is_sports_coordinator=is_sports_coordinator) person.save() except IntegrityError as inst: print(type(inst)) print(inst.args) if "Person_person_email" in inst.args[0]: request.session['alert'] = { 'type': 'warning', 'message': 'Ocurrió un error al crear el usuario: correo duplicado' } if "Person_person_rut" in inst.args[0]: request.session['alert'] = { 'type': 'warning', 'message': 'Ocurrió un error al crear el usuario: rut duplicado' } except ValueError: person.delete() if event_id == "------" and university_id == "------": request.session['alert'] = { 'type': 'warning', 'message': 'Debes indicar una universidad y un evento al crear un usuario' } elif university_id == "------": request.session['alert'] = { 'type': 'warning', 'message': 'Debes indicar una universidad al crear un usuario' } else: request.session['alert'] = { 'type': 'warning', 'message': 'Debes indicar un evento al crear un usuario' } except Exception as inst: print(type(inst)) print(inst.args) request.session['alert'] = { 'type': 'warning', 'message': 'Ocurrió un error al crear el usuario: ' + inst.args[0] } else: doer = Person.objects.get(user=request.user) log = Log(task='create_person', value_before='-', value_after=f'{person.name} {person.last_name}', person=f'{doer.name} {doer.last_name}', date=timezone.now()) log.save() request.session['alert'] = { 'type': 'success', 'message': 'Usuario creado exitosamente' } redirect_url = reverse('administration:administracion-section') return HttpResponseRedirect(redirect_url)
def post(self, request): uni_id = request.POST.get('id') name = request.POST.get('name') city = request.POST.get('city') short_name = request.POST.get('short-name') uni = University.objects.get(id=uni_id) try: AdminEditUniversity.validateCharField(name, 'nombre', 3, 100) AdminEditUniversity.validateCharField(city, 'ciudad', 2, 30) AdminEditUniversity.validateCharField(short_name, 'siglas', 1, 10) except Exception as inst: print(type(inst)) print(inst.args) request.session['alert'] = { 'type': 'warning', 'message': 'Ocurrió un error al actualizar la organización: ' + inst.args[0] } else: if uni: if uni.name != name: doer = Person.objects.get(user=request.user) log = Log(task='edit_university_name', value_before=uni.name, value_after=name, person=f'{doer.name} {doer.last_name}', date=timezone.now()) log.save() uni.name = name if uni.city != city: doer = Person.objects.get(user=request.user) log = Log(task='edit_university_city', value_before=uni.city, value_after=city, person=f'{doer.name} {doer.last_name}', date=timezone.now()) log.save() uni.city = city if uni.short_name != short_name: doer = Person.objects.get(user=request.user) log = Log(task='edit_university_short_name', value_before=uni.short_name, value_after=short_name, person=f'{doer.name} {doer.last_name}', date=timezone.now()) log.save() uni.short_name = short_name try: uni.save() request.session['alert'] = { 'type': 'info', 'message': 'Organización editada exitosamente' } except: request.session['alert'] = { 'type': 'danger', 'message': 'Ocurrió un error al actualizar la organización' } redirect_url = reverse('administration:administracion-section') return HttpResponseRedirect(redirect_url)
def post(self, request): team_id = request.POST.get('id') uni_id = request.POST.get('university') sport_id = request.POST.get('sport') players = request.POST.getlist('player[]') captain_id = request.POST.get('edit-captain') event = None if request.user.is_authenticated: if Person.objects.filter(user=request.user).exists(): person = Person.objects.get(user=request.user) event = person.event num_players = len(players) if num_players > 0 and event is not None: coordinator = Person.objects.get(id=captain_id) university = University.objects.get(id=uni_id) team = Team.objects.get(id=team_id) team_saved = False try: if coordinator.university == university: team.coordinator = coordinator team_saved = True except: pass tm_to_del = PlayerTeam.objects.filter(team=team) if team_saved: team_players = [] players_to_save = [] for player_id in players: player = Person.objects.get(id=player_id) if player is not None: if player.university == university: player.is_player = True players_to_save.append(player) team_player = PlayerTeam(player=player, team=team) doer = Person.objects.get(user=request.user) log = Log(task='team_add_player', value_before=str(team), value_after=str(player), person=f'{doer.name} {doer.last_name}', date=timezone.now()) log.save() team_players.append(team_player) else: request.session['alert'] = { 'type': 'danger', 'message': 'Ocurrió un error al crear el equipo' } team_players = [] players_to_save = [] else: players_to_save = [] team_players = [] team.delete() request.session['alert'] = { 'type': 'danger', 'message': 'Ocurrió un error al crear el equipo' } saved_data = [] try: n_team_players = len(team_players) n_players_to_save = len(players_to_save) if n_team_players > 0 and n_players_to_save > 0: for tm in tm_to_del: tm.delete() for player in players_to_save: player.save() saved_data.append(player) for team_player in team_players: team_player.save() saved_data.append(team_player) team.save() request.session['alert'] = { 'type': 'success', 'message': 'Equipo modificado con éxito' } except: for data in saved_data: data.delete() request.session['alert'] = { 'type': 'danger', 'message': 'Ocurrió un error al crear el equipo' } else: request.session['alert'] = { 'type': 'danger', 'message': 'Ocurrió un error al crear el equipo' } redirect_url = reverse('team:team-home') return HttpResponseRedirect(redirect_url)
def post(self, request): sport_id = request.POST.get('id') name = request.POST.get('name') gender = request.POST.get('gender') sport_type = request.POST.get('type') coord_id = request.POST.get('coordinator') try: AdminCreateLocation.validateCharField(name, 'nombre', 2, 100) except Exception as inst: print(type(inst)) print(inst.args) request.session['alert'] = { 'type': 'warning', 'message': 'Ocurrió un error al actualizar el deporte: ' + inst.args[0] } else: sport = Sport.objects.get(id=sport_id) coordinator = Person.objects.get(id=coord_id) if sport and coordinator: if sport.name != name: doer = Person.objects.get(user=request.user) log = Log(task='edit_sport_name', value_before=sport.name, value_after=name, person=f'{doer.name} {doer.last_name}', date=timezone.now()) log.save() sport.name = name if sport.gender != gender: doer = Person.objects.get(user=request.user) log = Log(task='edit_sport_gender', value_before=sport.gender, value_after=gender, person=f'{doer.name} {doer.last_name}', date=timezone.now()) log.save() sport.gender = gender if sport.sport_type != sport_type: doer = Person.objects.get(user=request.user) log = Log(task='edit_sport_type', value_before=sport.sport_type, value_after=sport_type, person=f'{doer.name} {doer.last_name}', date=timezone.now()) log.save() sport.sport_type = sport_type if sport.coordinator != coordinator: doer = Person.objects.get(user=request.user) log = Log(task='edit_sport_coordinator', value_before=str(sport.coordinator), value_after=str(coordinator), person=f'{doer.name} {doer.last_name}', date=timezone.now()) log.save() sport.coordinator = coordinator try: sport.save() request.session['alert'] = { 'type': 'info', 'message': 'Deporte editado exitosamente' } except: request.session['alert'] = { 'type': 'danger', 'message': 'Ocurrió un error al editar el deporte' } redirect_url = reverse('administration:administracion-section') return HttpResponseRedirect(redirect_url)
def post(self, request): person_id = request.POST.get('id') rut = request.POST.get('rut').strip() nombres = request.POST.get('nombres').strip() email = request.POST.get('email').strip() apellidos = request.POST.get('apellidos').strip() is_admin = request.POST.get('is_admin', False) == 'on' is_organizer = request.POST.get('is_organizer', False) == 'on' is_university_coordinator = request.POST.get('is_uni_coordinator', False) == 'on' is_sports_coordinator = request.POST.get('is_sports_coordinator', False) == 'on' event_id = request.POST.get('event') university_id = request.POST.get('university') phone = request.POST.get('phone').strip() event = Event.objects.get(id=event_id) university = University.objects.get(id=university_id) person = Person.objects.get(id=person_id) try: AdminEditPerson.validateCharField(nombres, 'nombres', 2, 100) AdminEditPerson.validateCharField(apellidos, 'apellidos', 2, 100) AdminEditPerson.validateCharField(email, 'correo electronico', 3, 60) ev = EmailValidator('correo invalido') ev(email) AdminEditPerson.validateCharField(rut, 'RUT', 3, 13) AdminEditPerson.validateCharField(phone, 'telefono', 3, 20) except Exception as inst: print(type(inst)) print(inst.args) request.session['alert'] = { 'type': 'warning', 'message': 'Ocurrió un error al editar el usuario: ' + inst.args[0] } else: if person: if person.event != event: doer = Person.objects.get(user=request.user) log = Log(task='edit_person_event', value_before=str(person.event), value_after=str(Event.objects.get(pk=event.id)), person=f'{doer.name} {doer.last_name}', date=timezone.now()) log.save() person.event = event if person.name != nombres: doer = Person.objects.get(user=request.user) log = Log(task='edit_person_name', value_before=person.name, value_after=nombres, person=f'{doer.name} {doer.last_name}', date=timezone.now()) log.save() person.name = nombres if person.last_name != apellidos: doer = Person.objects.get(user=request.user) log = Log(task='edit_person_last_name', value_before=person.last_name, value_after=apellidos, person=f'{doer.name} {doer.last_name}', date=timezone.now()) log.save() person.last_name = apellidos if person.email != email: doer = Person.objects.get(user=request.user) log = Log(task='edit_person_email', value_before=person.email, value_after=email, person=f'{doer.name} {doer.last_name}', date=timezone.now()) log.save() person.email = email if person.university != university: doer = Person.objects.get(user=request.user) log = Log(task='edit_person_university', value_before=str(person.university), value_after=str( University.objects.get(pk=university.id)), person=f'{doer.name} {doer.last_name}', date=timezone.now()) log.save() person.university = university if person.rut != rut: doer = Person.objects.get(user=request.user) log = Log(task='edit_person_rut', value_before=person.rut, value_after=rut, person=f'{doer.name} {doer.last_name}', date=timezone.now()) log.save() person.rut = rut if person.phone_number != phone: doer = Person.objects.get(user=request.user) log = Log(task='edit_person_phone', value_before=person.phone_number, value_after=phone, person=f'{doer.name} {doer.last_name}', date=timezone.now()) log.save() person.phone_number = phone if person.is_admin != is_admin: doer = Person.objects.get(user=request.user) log = Log(task='edit_person_admin', value_before=person.is_admin, value_after=is_admin, person=f'{doer.name} {doer.last_name}', date=timezone.now()) log.save() person.is_admin = is_admin if person.is_organizer != is_organizer: doer = Person.objects.get(user=request.user) log = Log(task='edit_person_organizer', value_before=person.is_organizer, value_after=is_organizer, person=f'{doer.name} {doer.last_name}', date=timezone.now()) log.save() person.is_organizer = is_organizer if person.is_university_coordinator != is_university_coordinator: doer = Person.objects.get(user=request.user) log = Log(task='edit_person_university_coordinator', value_before=person.is_university_coordinator, value_after=is_university_coordinator, person=f'{doer.name} {doer.last_name}', date=timezone.now()) log.save() person.is_university_coordinator = is_university_coordinator if person.is_sports_coordinator != is_sports_coordinator: doer = Person.objects.get(user=request.user) log = Log(task='edit_person_sports_coordinator', value_before=person.is_sports_coordinator, value_after=is_sports_coordinator, person=f'{doer.name} {doer.last_name}', date=timezone.now()) log.save() person.is_sports_coordinator = is_sports_coordinator try: person.save() request.session['alert'] = { 'type': 'info', 'message': 'Usuario editado exitosamente' } except: request.session['alert'] = { 'type': 'danger', 'message': 'Ocurrió un error al editar el usuario' } redirect_url = reverse('administration:administracion-section') return HttpResponseRedirect(redirect_url)