def send_custom_mail_view(request): context = {} form = SendCustomEmailForm() context['form'] = form teams = 0 participants = 0 if request.POST: form = SendCustomEmailForm(request.POST) if form.is_valid(): subject = form.cleaned_data.get('subject') content = form.cleaned_data.get('message') group = form.cleaned_data.get('group') applications = Application.objects.filter(application_status=group) for application in applications: ctx = {'message': content} teams += 1 for member in application.members.all(): ctx['user'] = member message = get_template('emails/custom_mail.html').render( ctx) recepient_list = [member.email] EmailThread(subject, message, recepient_list).start() participants += 1 context['message'] = 'Emails have been Sent to ' + str( participants) + ' Participants(' + str(teams) + ' teams)' return render(request, "messages.html", context) else: context['form'] = form else: context['form'] = form return render(request, 'custom_mails.html', context)
def send_accepted_email(request): context = {} applications = Application.objects.filter(application_status="Accepted", received_confirmation_mail=False) subject = "You've been accepted!!" teams = 0 participants = 0 for application in applications: teams += 1 print("mailing " + str(application.team.name)) for member in application.members.all(): ctx = { 'application': application, 'member': member, 'team': application.team.name } message = get_template('emails/application_accepted.html').render( ctx) recepient_list = [member.email] EmailThread(subject, message, recepient_list).start() participants += 1 print("Acceptace mail sent") application.received_confirmation_mail = True application.save() context['message'] = 'Emails have been Sent to ' + str( participants) + ' Participants(' + str(teams) + ' teams)' return render(request, "messages.html", context)
def submit_aplication_view(request): context = {} application = Application.objects.filter(members__id=request.user.id) if len(application) > 0: application = application[0] if request.user == application.team.admin: if len(application.members.all()) > 4: context[ 'message'] = "You can have a maximum of 4 people only in a team!!." return render(request, 'messages.html', context) # application.application_status = 'Submitted' # application.save() # elif len(application.members.all()) < 2: # context['message'] = "You need atleast 2 people in a team!!." # return render(request, 'messages.html', context) else: application.application_status = 'Submitted' application.save() ctx = { 'user': request.user, 'team_name': application.team.name, 'team_id': application.team.id, 'admin': application.team.admin.profile.name } recepient_list = [] for member in application.members.all(): recepient_list.append(member.email) message = get_template( 'emails/application_submitted_mail.html').render(ctx) # msg = EmailMessage( # "Application SUbmitted", # message, # '*****@*****.**', # recepient_list, # ) # msg.content_subtype = "html" # msg.send() subject = "Application Submitted" # recepient_list = [request.user.email] EmailThread(subject, message, recepient_list).start() print("Application Submission message sent") # context['message'] = "You need 4 people in a team to submit the application." # return render(request, 'messages.html', context) else: context['message'] = "Only Team Admin can submit the application" return render(request, 'messages.html', context) return redirect('home')
def send_wtlst_email(request): context = {} applications = Application.objects.filter(application_status="Waitinglist") subject = "Application review in progress" teams = 0 participants = 0 for application in applications: teams += 1 print("mailing " + str(application.team.name)) for member in application.members.all(): participants += 1 ctx = {'application': application, 'member': member} message = get_template( 'emails/application_waitinglist.html').render(ctx) recepient_list = [member.email] EmailThread(subject, message, recepient_list).start() print("Waiting List Mail sent") context['message'] = 'Emails have been Sent to ' + str( participants) + ' Participants(' + str(teams) + ' teams)' return render(request, "messages.html", context)
def send_not_submitted_email(request): context = {} applications = Application.objects.filter( application_status="Not Submitted") subject = "Knock Knock Did you forget to submit your application?" teams = 0 participants = 0 for application in applications: ctx = {} ctx['application'] = application teams += 1 print("mailing " + str(application.team.name)) for member in application.members.all(): participants += 1 ctx['member'] = member message = get_template( 'emails/not_submitted_reminder.html').render(ctx) recepient_list = [member.email] EmailThread(subject, message, recepient_list).start() print("Not SUbmitted Reminder Mail sent") context['message'] = 'Emails have been Sent to ' + str( participants) + ' Participants(' + str(teams) + ' teams)' return render(request, "messages.html", context)
def home(request): # create_team_view(request) context = {} no_teams_found = False try: profile = ParticipantProfile.objects.get(user=request.user) except ParticipantProfile.DoesNotExist: return redirect('profile-update') # print(application) # print(len(application)) if request.user.is_authenticated: application = Application.objects.filter(members__id=request.user.id) if not (len(application) == 0): application = application[0] context['application'] = application team = application.team print("team ind") user_has_team = True context['users_team'] = team else: team = Team(admin=request.user) print("team indaakki") # team.save() user_has_team = False # try: # application = application[0] # team = application.team # print("team ind") # user_has_team = True # context['users_team'] = team # except Team.DoesNotExist: # team = Team(admin = request.user) # print("team indaakki") # # team.save() # user_has_team = False # try: # application = Application.objects.get(team=team) # print("has team") # print(team.application_team.team.name) # except Application.DoesNotExist: # application = Application(team = team) # application.save() # application.members.add(request.user) # # application.save() # print("created Team") team_form = TeamCreateForm() context['team_form'] = team_form search_form = TeamSearchForm() context['search_form'] = search_form context['user_has_team'] = user_has_team # context['application'] = application if request.POST: # team_form = TeamCreateForm(request.POST) # search_form = TeamSearchForm(request.POST) if "create_team" in request.POST: team_form = TeamCreateForm(request.POST) if team_form.is_valid(): #TODO searching for teams to join if user_has_team: context['message'] = 'You already have a team!!' return render(request, 'messages.html', context) else: team = team_form.save(commit=False) team.admin = request.user # request.user.team.add(team) # team.strength = 1 # team.application_status = 'Not Submitted' team.save() try: application = Application.objects.get(team=team) print("has team") context['application'] = application print(team.application_team.team.name) except Application.DoesNotExist: application = Application(team=team) application.save() application.members.add(request.user) ctx = { 'user': request.user, 'team_name': application.team.name, "team_id": application.team.id } message = get_template( 'emails/team_created.html').render(ctx) # msg = EmailMessage( # "Team Created", # message, # '*****@*****.**', # [request.user.email], # ) # msg.content_subtype = "html" # msg.send() subject = "Team Created" recepient_list = [request.user.email] EmailThread(subject, message, recepient_list).start() print("Team Created message sent") # application.save() print("created Team") context['application'] = application # application = Application(team = team) # # application.save() # application.save() # application.members.add(request.user) # context['application'] = application # team = team_form.save() # request.user.team.add(team) # user_obj = team_form.save() # user_obj.team.add(team) # context['message'] = 'Team Created Successfully' # return render(request, 'home.html', context ) return redirect('home') else: context['team_form'] = team_form elif "search_team" in request.POST: # conext['search_performed'] = True search_form = TeamSearchForm(request.POST) if search_form.is_valid(): team_id = search_form.cleaned_data.get('team_id') try: searched_team = Team.objects.get(id=team_id) context['searched_team'] = searched_team except Team.DoesNotExist: no_teams_found = True context['no_teams_found'] = no_teams_found else: context['search_form'] = search_form # elif "accept_request" in request.POST: # try: # application = Application.objects.get(team=team) # # print("has team") # context['application'] = application # application.members.add(request.user) # application.save() # # request.user.request_team.request_status = "Accepted" # # request.user.join_request.request_status = "Accepted" # print(team.application_team.team.name) # except Application.DoesNotExist: # pass # elif "decline_request" in request.POST: # pass else: team_form = TeamCreateForm(initial={ # 'name': team.name, }) context['team_form'] = team_form search_form = TeamSearchForm(initial={}) context['search_form'] = search_form # try: # application = Application.objects.get(team=team) # # context['user_has_team'] = True # print("has team") # context['application'] = application # print(team.application_team.team.name) # except Application.DoesNotExist: # print("except of appli in end executed") # if team.admin == request.user: # join_requests = JoinRequest.objects.filter(team=team, request_status="Submitted") # context['join_requests'] = join_requests return render(request, 'home.html', context)
def submit_abstract_view(request): context = {} # application = request.user.application_set.all() applications = Application.objects.filter(members__id=request.user.id) if len(applications) > 0: application = applications[0] else: context[ 'message'] = 'The corresponding application could not be found!!' return render(request, 'messages.html', context) # abstract = Abstract.objects.get_or_create(application=application) if application.application_status == "Accepted": if request.user == application.team.admin: try: abstract = Abstract.objects.get(application=application) except Abstract.DoesNotExist: abstract = Abstract(application=application) # context['message'] = 'Abstract submission closed. You havent submitted an abstract. Please contact the organizers if you think this is a mistake' # return render(request, 'messages.html', context) # abstract.save() # if len(application)>0: # application = application[0] if request.POST: form = AbstractForm(request.POST, instance=abstract) context['form'] = form if form.is_valid(): abstract = form.save(commit=False) abstract.application = application abstract.save() ctx = { 'user': request.user, 'team_name': application.team.name, 'team_id': application.team.id, 'admin': application.team.admin.profile.name } # MAIL TO TEAM ADMIN NOTIFYING OF TEAM DELETE message1 = get_template( 'emails/abstract_submitted_admin_mail.html').render( ctx) # msg1 = EmailMessage( # "Team Deleted", # message1, # '*****@*****.**', # [application.team.admin.email], # ) # msg1.content_subtype = "html" # msg1.send() subject = "Project Abstract Submitted" recepient_list = [application.team.admin.email] EmailThread(subject, message1, recepient_list).start() print("Abstract Submission message sent to ADMIN") # MAIL TO MEMBER NOTIFYING TEAM DELETE message2 = get_template( 'emails/abstract_submitted_member_mail.html').render( ctx) recepient_list = [] for member in application.members.all(): if not (member == request.user): recepient_list.append(member.email) # msg2 = EmailMessage( # "Your Team was Deleted!", # message2, # '*****@*****.**', # recepient_list, # ) # msg2.content_subtype = "html" # msg2.send() subject = "Project Abstract Submitted" # recepient_list = [application.team.admin.email] EmailThread(subject, message2, recepient_list).start() print("Abstract Submission message sent to MEMBER") if application.abstract_submitted == False: application.abstract_submitted = True application.save() return redirect('home') else: context['form'] = form else: form = AbstractForm( initial={ 'problem_statement': abstract.problem_statement, 'project_title': abstract.project_title, 'abstract': abstract.abstract, }) context['form'] = form else: context[ 'message'] = "You are not the Admin of this team. Only Team admins can submit an abstract" return render(request, 'messages.html', context) else: context[ 'message'] = "Only accepted teams can submit a project abstract!!" return render(request, 'messages.html', context) return render(request, 'submissions/submit_abstract.html', context)
def join_team_view(request, team_id): context = {} team = get_object_or_404(Team, id=team_id) context['team'] = team try: application = Application.objects.get(team=team) context['application'] = application context['number_of_members'] = len(application.members.all()) if (request.user in application.members.all()): context['in_team'] = True else: if len(Application.objects.filter( members__id=request.user.id)) > 0: context['message'] = "You are already part of a team!!" return render(request, 'messages.html', context) else: if application.application_status == "Not Submitted": if len(application.members.all()) < 4: application.members.add(request.user) ctx = { 'user': request.user, 'team_name': application.team.name, 'team_id': application.team.id, 'admin': application.team.admin.profile.name } # MAIL TO TEAM ADMIN NOTIFYING OF NEW MEMBER JOINING message1 = get_template( 'emails/join_team_admin_mail.html').render(ctx) # msg1 = EmailMessage( # "New Memeber Notification", # message1, # '*****@*****.**', # [application.team.admin.email], # ) # msg1.content_subtype = "html" # msg1.send() subject = "New Memeber Notification" recepient_list = [application.team.admin.email] EmailThread(subject, message1, recepient_list).start() print("Team Join message sent to ADMIN") # MAIL TO PARTICIPANT CONFIRMING TEAM JOINING message2 = get_template( 'emails/join_team_member_mail.html').render(ctx) # msg2 = EmailMessage( # "Joined Team", # message2, # '*****@*****.**', # [request.user.email], # ) # msg2.content_subtype = "html" # msg2.send() subject = "Joined Team" recepient_list = [request.user.email] EmailThread(subject, message2, recepient_list).start() print("Team Join message sent to MEMBER") # return redirect('join_team') # return render(request, 'team_detail.html', context) # return team_detail_view(request, team_id) return redirect('home') else: context[ 'message'] = "This team already has 4 members. You cant join this team!" return render(request, 'messages.html', context) else: context[ 'message'] = "The Application for this team is already submitted. You can no longer Join this team." return render(request, 'messages.html', context) # try: # join_request = JoinRequest.objects.get(team=team, user=request.user) # context['sent_request'] = True # except JoinRequest.DoesNotExist: # join_request = JoinRequest(team=team, user=request.user, request_status='Submitted') # join_request.save() # context['sent_request'] = True # # print("has team") # context['application'] = application # # print(team.application_team.team.name) except Application.DoesNotExist: pass return render(request, 'team_detail.html', context)
def leave_team_view(request, team_id): context = {} team = get_object_or_404(Team, id=team_id) application = team.application_team # application = Application.objects.filter(members__id = request.user.id) # if not (len(application) == 0): # application = application[0] context['application'] = application # team = application.team ctx = { 'user': request.user, 'team_name': application.team.name, 'team_id': application.team.id, 'admin': application.team.admin.profile.name } if application.application_status == 'Not Submitted': if request.user == team.admin: # MAIL TO TEAM ADMIN NOTIFYING OF TEAM DELETE message1 = get_template( 'emails/delete_team_admin_mail.html').render(ctx) # msg1 = EmailMessage( # "Team Deleted", # message1, # '*****@*****.**', # [application.team.admin.email], # ) # msg1.content_subtype = "html" # msg1.send() subject = "Team Deleted" recepient_list = [application.team.admin.email] EmailThread(subject, message1, recepient_list).start() print("Team Delete message sent to ADMIN") # MAIL TO MEMBER NOTIFYING TEAM DELETE message2 = get_template( 'emails/delete_team_member_mail.html').render(ctx) recepient_list = [] for member in application.members.all(): if not (member == request.user): recepient_list.append(member.email) # msg2 = EmailMessage( # "Your Team was Deleted!", # message2, # '*****@*****.**', # recepient_list, # ) # msg2.content_subtype = "html" # msg2.send() subject = "Your Team was Deleted!" # recepient_list = [application.team.admin.email] EmailThread(subject, message2, recepient_list).start() print("Team Delete message sent to MEMBER") application.delete() context['application'] = None team.delete() context['team'] = None return redirect('home') else: application.members.remove(request.user) # MAIL TO TEAM ADMIN NOTIFYING OF NEW MEMBER JOINING message1 = get_template( 'emails/leave_team_admin_mail.html').render(ctx) # msg1 = EmailMessage( # "Member Leaving Team", # message1, # '*****@*****.**', # [application.team.admin.email], # ) # msg1.content_subtype = "html" # msg1.send() subject = "Member Leaving Team" recepient_list = [application.team.admin.email] EmailThread(subject, message1, recepient_list).start() print("Member Leaving message sent to ADMIN") # MAIL TO PARTICIPANT CONFIRMING TEAM JOINING message2 = get_template( 'emails/leave_team_member_mail.html').render(ctx) # msg2 = EmailMessage( # "You Left a Team", # message2, # '*****@*****.**', # [request.user.email], # ) # msg2.content_subtype = "html" # msg2.send() subject = "You Left a Team" recepient_list = [request.user.email] EmailThread(subject, message2, recepient_list).start() print("Team Leaving message sent to MEMBER") return redirect('home') else: context[ 'message'] = "The application is already submitted. You cannot leave the team now!!" return render(request, 'messages.html', context) return render(request, 'team_detail.html', context)
def participant_profile_creation_view(request): context = {} try: profile = request.user.profile except ParticipantProfile.DoesNotExist: profile = ParticipantProfile(user=request.user) # if request.user.has_profile: # profile = request.user.profile # else: # profile = ParticipantProfile(user = request.user) if request.POST: form = PartcicpantProfileForm(request.POST, instance=profile) if form.is_valid(): profile = form.save(commit=False) profile.user = request.user # profile.user.has_profile = True profile.save() if not profile.welcome_mail_sent: ctx = {'user': request.user} message = get_template('emails/welcome.html').render(ctx) subject = "Welcome to .hack();" recepient_list = [request.user.email] EmailThread(subject, message, recepient_list).start() profile.welcome_mail_sent = True profile.save() print("Welcome message sent") return redirect('home') else: context['form'] = form else: form = PartcicpantProfileForm( initial={ 'team_status': profile.team_status, 'name': profile.name, 'contact': profile.contact, 'dob': profile.dob, 'gender': profile.gender, 'projects': profile.projects, 'bio': profile.bio, 'tshirt_size': profile.tshirt_size, 'skills': profile.skills, 'educational_status': profile.educational_status, 'educational_institution': profile.educational_institution, 'field_of_study': profile.field_of_study, 'year_of_graduation': profile.year_of_graduation, 'is_ieee': profile.is_ieee, 'shipping_address': profile.shipping_address, 'state': profile.state, 'pin_code': profile.pin_code, 'avatar_choice': profile.avatar_choice, 'website_link': profile.website_link, 'github_profile_link': profile.github_profile_link, 'twitter_profile_link': profile.twitter_profile_link, 'linkedin_profile_link': profile.linkedin_profile_link, 'referral_id': profile.referral_id, }) context['form'] = form return render(request, 'create_profile.html', context)