def post(self, request, *args, **kwargs): """ Claims a tutee, only accessible for tutors. """ c = self.getContext(request) is_tutor = False if tutor(c['user'].username): is_tutor = True c.update({'tutor': is_tutor}) msg = 'Good news, your request has been accepted by ' +\ c['user'].first_name + " " + c['user'].last_name +\ ". They should be contacting you directly shortly" request_user_and_id = request.POST['choice'].split('?^?') requests = Request.objects.all() for req in requests: if req.user == request_user_and_id[0]: if req.id == int(request_user_and_id[1]): req.accepted_by = c['user'].username req.save() usr = Tutee.objects.get(user__username=req.user).user c.update({'target': req.user}) #Email the student emailer = emails() emailer.send_email(usr, msg, "Good News") c.update(csrf(request)) return render_to_response('email_tutee.html', c)
def post(self, request, *args, **kwargs): """ Allow a tutee to submit a help request. """ c = self.getContext(request) validate = validate_help_request(request.POST) if validate is not None: c.update(validate) c.update(csrf(request)) return render_to_response('request_help.html', c) fc = request.POST['for_class'] desc = request.POST['description'] d = request.POST['day'] t = request.POST['time'] users_requests = Request.objects.filter(user=c['user'].username) valid = True """ If the user has ten requests, then they are not able to create a new one. If the user has already requested help for a specific class then they are not able to request help for that class again """ if len(users_requests) < 11: for req in users_requests: if req.for_class == fc: c.update({'request_exists_error': 'A help request for this class already exists'}) valid = False else: valid = True elif len(users_requests) > 10: c.update({'too_many_error': 'You have too many open requests'}) valid = False if valid: helprequest = Request(user=c['user'].username, first_name=c['user'].first_name, last_name=c['user'].last_name, for_class=fc, description=desc, days=d, time=t) """ if a tutor is being specifically requested then they will recieve an email informing them of the request """ if 'specific_request' in request.POST: helprequest.requested = request.POST['requested'] helprequest.save() target = Tutee.objects.get(user__username=request.POST['requested']).user emailer = emails() message = 'You have been requested as a tutor by ' +\ c['user'].first_name + ' ' + c['user'].last_name +\ '. Log in to RPI Tutor Time to view their request.' emailer.send_email(target, message, 'Tutor Request') else: helprequest.save() c.update({ 'error': False, 'message': 'Request successfully submitted.' }) return render_to_response('display_message.html', c) return render_to_response('request_help.html', c)
def post(self, request, *args, **kwargs): # Error messages c = { 'password_error': '', 'username_error': '', 'email_error': '', 'firstname_error': '', 'lastname_error': '' } # Check if data is ok valid = validate_creation(request.POST) # If there was a dictionary returned, load the template with the error messages if valid is not None: c.update(valid) c.update(csrf(request)) return render_to_response('create_account.html', context_instance=RequestContext(request, c)) # Otherwise attempt to create an account and if we get an error, render the error message try: t = create_tutee(request.POST) except IntegrityError: c['username_error'] = 'Username already Exists' return render_to_response('create_account.html', context_instance=RequestContext(request, c)) # Account creation a success! Make an email message and send it out! msg = """<br /> Welcome to Tutor Time! Please click the link to verify your account.<br /> <a href="http://localhost:8000/verify_account/{0}">Verify the account</a>.<br /> If you cannot see the link above, please copy and paste the link below<br /> http://localhost:8000/verify_account/{0}<br /> """ emails().send_email(t.user, msg.format(t.verification_id), "Please verify your account") # Load success page c.update(csrf(request)) c.update({'message': 'Success! Please check your email for activation', 'error': False}) return render_to_response('display_message.html', context_instance=RequestContext(request, c))
def post(self, request, *args, **kwargs): """Page to allow a tutor to email their new tutee""" context = RequestContext(request) context.update(csrf(request)) target = Tutee.objects.get(user__username=request.POST['tutee']).user message = request.POST['message'] emailer = emails() emailer.send_email(target, message, "A Message from your Tutor") context.update({ 'error': False, 'message': 'Email successfully sent!' }) return render_to_response('display_message.html', context)