def thank_you(request, spot_id=None): try: back = request.GET['back'] validate_back_link(back) except: back = '/' return render_to_response('spacescout_web/suggest-thankyou.html', { 'back': back, }, context_instance=RequestContext(request))
def FavoritesView(request, template=None): try: back = request.GET['back'] validate_back_link(back) except: back = '/' return render_to_response(template, { 'locations': settings.SS_LOCATIONS, 'back': back }, context_instance=RequestContext(request))
def sorry(request, spot_id=None): share_variables = _share_variables(request, spot_id) try: back = request.GET['back'] validate_back_link(back) except: back = share_variables['back'] return render_to_response('spacescout_web/share-sorry.html', { 'problem': None, 'back': back }, context_instance=RequestContext(request))
def thank_you(request, spot_id=None): share_variables = _share_variables(request, spot_id) try: back = request.GET['back'] validate_back_link(back) except: back = share_variables['back'] return render_to_response('spacescout_web/share-thankyou.html', { 'spot_id': spot_id, 'back': back, }, context_instance=RequestContext(request))
def suggest(request, spot_id=None): if request.method == 'POST': form = SuggestForm(request.POST) try: back = request.POST['back'] validate_back_link(back) except: back = '/' if form.is_valid(): back = form.cleaned_data['back'] name = form.cleaned_data['name'] netid = form.cleaned_data['netid'] sender = form.cleaned_data['sender'] building = form.cleaned_data['building'] floor = form.cleaned_data['floor'] room_number = form.cleaned_data['room_number'] description = form.cleaned_data['description'] justification = form.cleaned_data['justification'] bot_test = form.cleaned_data['email_confirmation'] browser = request.META.get('HTTP_USER_AGENT', 'Unknown') subject = "[Suggestion] From %s" % (name) email_message = "A SpaceScout user has suggested the following space.\n\ \nSuggested Space:\n\ \nFrom: %s <%s>\n\ \nUW NetID: %s\n\ \nBuilding: %s\n\ \nFloor: %s\n\ \nRoom number: %s\n\ \nDescription: %s\n\ \nJustification: %s\n\ \nBrowser Type = %s" % (name, sender, netid, building, floor, room_number, description, justification, browser) if bot_test == '': try: if not hasattr(settings, 'FEEDBACK_EMAIL_RECIPIENT'): logger.error('Missing configuration: Set FEEDBACK_EMAIL_RECIPIENT for your site') send_mail(subject, email_message, sender, settings.FEEDBACK_EMAIL_RECIPIENT) except Exception as e: logger.error('Suggest failure: %s' % (e)) return HttpResponseRedirect('/sorry/') return HttpResponseRedirect('/thankyou/?back=' + urlquote(back)) else: try: back = request.GET['back'] validate_back_link(back) except: back = '/' form = SuggestForm(initial={'back': back}) return render_to_response('spacescout_web/suggest-form.html', { 'form': form, 'back': back, 'is_mobile': (request.MOBILE == 1), }, context_instance=RequestContext(request))
def share(request, spot_id=None): if request.method == 'POST': form = ShareForm(request.POST) try: back = request.POST['back'] validate_back_link(back) except: back = '/' if form.is_valid(): spot_id = form.cleaned_data['spot_id'] back = form.cleaned_data['back'] sender = form.cleaned_data['sender'] recipient = form.cleaned_data['recipient'] subject = form.cleaned_data['subject'] message = form.cleaned_data['message'] bot_test = form.cleaned_data['email_confirmation'] url = "{0}/api/v1/spot/{1}/share".format( settings.SS_WEB_SERVER_HOST, spot_id ) body = json.dumps({ 'to': recipient, 'from': sender, 'comment': message, 'subject': subject }) headers = { "X-OAuth-User": "******" % request.user.username, 'Content-Type': 'application/json', 'Accept': 'application/json' } consumer = oauth2.Consumer( key=settings.SS_WEB_OAUTH_KEY, secret=settings.SS_WEB_OAUTH_SECRET ) client = oauth2.Client(consumer) resp, content = client.request(url, method='PUT', body=body, headers=headers) if not (resp.status == 200 or resp.status == 201): logger.error('Share service failure %s: %s' % ( resp.status, url )) return HttpResponseRedirect('/share/sorry/') return HttpResponseRedirect( '/share/thankyou/?back=' + urlquote(back) ) else: # mask user from silliness try: back = request.GET['back'] validate_back_link(back) except: back = '/' if request.user and request.user.is_authenticated(): consumer = oauth2.Consumer( key=settings.SS_WEB_OAUTH_KEY, secret=settings.SS_WEB_OAUTH_SECRET ) client = oauth2.Client(consumer) url = "{0}/api/v1/user/me".format(settings.SS_WEB_SERVER_HOST) headers = { "X-OAuth-User": "******" % request.user.username, 'Content-Type': 'application/json', 'Accept': 'application/json' } resp, content = client.request(url, method='GET', headers=headers) sender = "%s@%s" % ( request.user.username, getattr(settings, 'SS_MAIL_DOMAIN', 'uw.edu') ) if resp.status == 200: me = content = json.loads(content) if 'email' in me and len(me['email']): sender = me['email'] else: sender = '' form = ShareForm(initial={ 'spot_id': spot_id, 'back': back, 'sender': sender, 'subject': 'Check out this space I found on SpaceScout', }) try: spot = Spot(spot_id).get() share_text = [spot["name"], spot["type"]] if ('extended_info' in spot and 'location_description' in spot['extended_info']): share_text.append(spot['extended_info']['location_description']) except SpotException as e: logger.error('Share failure for spot %s: %s' % (spot_id, e)) return render_to_response('spacescout_web/share-sorry.html', { 'problem': 'Sorry, but the space you wish ' 'to share does not exist.', 'back': back, }, context_instance=RequestContext(request)) share_url = 'http://%s/space/%s/%s' % (getattr( settings, 'SS_APP_SERVER', socket.gethostname()), spot_id, urlquote(spot["name"]) ) return render_to_response('spacescout_web/share-form.html', { 'form': form, 'back': back, 'spot_id': spot_id, 'share_text': share_text, 'share_url': share_url, 'hidden': ["spot_id", "back"], 'is_mobile': (request.MOBILE == 1), }, context_instance=RequestContext(request))
def share(request, spot_id=None): if request.method == 'POST': form = ShareForm(request.POST) try: back = request.POST['back'] validate_back_link(back) except: back = '/' if form.is_valid(): spot_id = form.cleaned_data['spot_id'] back = form.cleaned_data['back'] sender = form.cleaned_data['sender'] recipient = form.cleaned_data['recipient'] subject = form.cleaned_data['subject'] message = form.cleaned_data['message'] bot_test = form.cleaned_data['email_confirmation'] share = SpotShare(spot_id, request=request) try: share.put( to_email=recipient, from_email=sender, comment=message, subject=subject, ) except SpotException as ex: logger.error('Share service failure %s: spot_id=%s' % (ex.status_code, spot_id)) return HttpResponseRedirect('/share/sorry/') return HttpResponseRedirect('/share/thankyou/?back=' + urlquote(back)) else: # mask user from silliness try: back = request.GET['back'] validate_back_link(back) except: back = '/' if request.user and request.user.is_authenticated(): consumer = oauth2.Consumer(key=settings.SS_WEB_OAUTH_KEY, secret=settings.SS_WEB_OAUTH_SECRET) client = oauth2.Client(consumer) url = "{0}/api/v1/user/me".format(settings.SS_WEB_SERVER_HOST) headers = { "XOAUTH_USER": "******" % request.user.username, 'Content-Type': 'application/json', 'Accept': 'application/json' } resp, content = client.request(url, method='GET', headers=headers) sender = "%s@%s" % (request.user.username, getattr(settings, 'SS_MAIL_DOMAIN', 'uw.edu')) if resp.status == 200: me = content = json.loads(content) if 'email' in me and len(me['email']): sender = me['email'] else: sender = '' form = ShareForm( initial={ 'spot_id': spot_id, 'back': back, 'sender': sender, 'subject': 'Check out this space I found on SpaceScout', }) try: spot = Spot(spot_id, request=request).get() share_text = [spot["name"], spot["type"]] if 'extended_info' in spot and 'location_description' in spot[ 'extended_info']: share_text.append(spot['extended_info']['location_description']) except SpotException as e: logger.error('Share failure for spot %s: %s' % (spot_id, e)) return render_to_response('spacescout_web/share-sorry.html', { 'problem': 'Sorry, but the space you wish to share does not exist.', 'back': back, }, context_instance=RequestContext(request)) share_url = 'http://%s/space/%s/%s' % (getattr( settings, 'SS_APP_SERVER', socket.gethostname()), spot_id, urlquote(spot["name"])) return render_to_response('spacescout_web/share-form.html', { 'form': form, 'back': back, 'spot_id': spot_id, 'share_text': share_text, 'share_url': share_url, 'hidden': ["spot_id", "back"], 'is_mobile': (request.MOBILE == 1), }, context_instance=RequestContext(request))
def suggest(request, spot_id=None): if request.method == 'POST': form = SuggestForm(request.POST) try: back = request.POST['back'] validate_back_link(back) except: back = '/' if form.is_valid(): back = form.cleaned_data['back'] name = form.cleaned_data['name'] netid = form.cleaned_data['netid'] sender = form.cleaned_data['sender'] building = form.cleaned_data['building'] floor = form.cleaned_data['floor'] room_number = form.cleaned_data['room_number'] description = form.cleaned_data['description'] justification = form.cleaned_data['justification'] bot_test = form.cleaned_data['email_confirmation'] browser = request.META.get('HTTP_USER_AGENT', 'Unknown') subject = "[Suggestion] From %s" % (name) email_message = "A SpaceScout user has suggested the following space.\n\ \nSuggested Space:\n\ \nFrom: %s <%s>\n\ \nUW NetID: %s\n\ \nBuilding: %s\n\ \nFloor: %s\n\ \nRoom number: %s\n\ \nDescription: %s\n\ \nJustification: %s\n\ \nBrowser Type = %s" % ( name, sender, netid, building, floor, room_number, description, justification, browser) if bot_test == '': try: if not hasattr(settings, 'FEEDBACK_EMAIL_RECIPIENT'): logger.error( 'Missing configuration: Set FEEDBACK_EMAIL_RECIPIENT for your site' ) send_mail(subject, email_message, sender, settings.FEEDBACK_EMAIL_RECIPIENT) except Exception as e: logger.error('Suggest failure: %s' % (e)) return HttpResponseRedirect('/sorry/') return HttpResponseRedirect('/thankyou/?back=' + urlquote(back)) else: try: back = request.GET['back'] validate_back_link(back) except: back = '/' form = SuggestForm(initial={'back': back}) return render_to_response('spacescout_web/suggest-form.html', { 'form': form, 'back': back, 'is_mobile': (request.MOBILE == 1), }, context_instance=RequestContext(request))