# Path: spacescout_web/forms/contact.py
# class ContactForm(BaseForm):
#         name = forms.CharField(max_length=25,
#                                label="Your Name",
#                                error_messages={'required':
#                                                'Required field'})
#         sender = forms.EmailField(max_length=40,
#                                   label="Your Email (Optional)",
#                                   required=False)
#         # feedback_choice = forms.ChoiceField((
#         #    ('', 'Please Select One'),
#         #    ('feedback', 'Leave Feedback'),
#         #    ('problem', 'Report a Problem'),
#         #    ('feature request', 'Request a Feature')),
#         #    label="Feedback Choice")
#         message = forms.CharField(widget=forms.Textarea(attrs={'rows': 5}),
#                                   label="Your Message",
#                                   error_messages={'required':
#                                                   'Required field'})
#         email_confirmation = forms.CharField(required=False)
# 
# Path: spacescout_web/spot.py
# class Spot(object):
#     def __init__(self, spot_id):
#         self.spot_id = spot_id
# 
#     def get(self):
#         # Required settings for the client
#         if not hasattr(settings, 'SS_WEB_SERVER_HOST'):
#             raise(Exception("Required setting missing: SS_WEB_SERVER_HOST"))
#         if not hasattr(settings, 'SS_WEB_OAUTH_KEY'):
#             raise(Exception("Required setting missing: SS_WEB_OAUTH_KEY"))
#         if not hasattr(settings, 'SS_WEB_OAUTH_SECRET'):
#             raise(Exception("Required setting missing: SS_WEB_OAUTH_SECRET"))
# 
#         consumer = oauth2.Consumer(
#                                 key=settings.SS_WEB_OAUTH_KEY,
#                                 secret=settings.SS_WEB_OAUTH_SECRET
#                                 )
#         client = oauth2.Client(consumer)
# 
#         url = "{0}/api/v1/spot/{1}".format(
#                                     settings.SS_WEB_SERVER_HOST,
#                                     self.spot_id
#                                     )
# 
#         resp, content = client.request(url, 'GET')
# 
#         if resp.status != 200:
#             raise SpotException(resp.status, self.spot_id)
# 
#         spot = json.loads(content)
# 
#         types = []
#         for t in spot["type"]:
#             types.append(_(t))
# 
#         spot["type"] = ','.join(types)
#         modified_date = (
#                         spot["last_modified"][5:10] +
#                         '-' +
#                         spot["last_modified"][:4]
#                         )
#         spot["last_modified"] = re.sub('-', '/', modified_date)
# 
#         return spot
# 
# class SpotException(Exception):
#     """ Exception for invalid Spot.
#     """
#     def __init__(self, resp_status, spot_id):
#         self.resp_status = resp_status
#         self.spot_id = spot_id


from django.shortcuts import render_to_response, render
from django.template import RequestContext
from django.http import HttpResponseRedirect, Http404
from spacescout_web.forms.contact import ContactForm
from spacescout_web.spot import Spot, SpotException
from django.core.mail import send_mail
from django.conf import settings
import logging
import re
    except:
        back = contact_variables['back']

    return render_to_response('spacescout_web/contact-thankyou.html', {
        'spot_id': spot_id,
        'back': back,
    }, context_instance=RequestContext(request))


def sorry(request, spot_id=None):
    contact_variables = _contact_variables(request, spot_id)

    back = contact_variables['back']
    email = settings.FEEDBACK_EMAIL_RECIPIENT[0]
    # should maybe do something here ^. raise improperly configured exception
    # if there are no emails in the list in settings.py

    return render_to_response('spacescout_web/contact-sorry.html', {
        'spot_id': spot_id,
        'back': back,
        'email': email,
    }, context_instance=RequestContext(request))


def _contact_variables(request, spot_id):
    spot_name = 'Unknown'
    spot_description = ''

    if spot_id is not None:
        try:

# Path: spacescout_web/forms/contact.py
# class ContactForm(BaseForm):
#         name = forms.CharField(max_length=25,
#                                label="Your Name",
#                                error_messages={'required':
#                                                'Required field'})
#         sender = forms.EmailField(max_length=40,
#                                   label="Your Email (Optional)",
#                                   required=False)
#         # feedback_choice = forms.ChoiceField((
#         #    ('', 'Please Select One'),
#         #    ('feedback', 'Leave Feedback'),
#         #    ('problem', 'Report a Problem'),
#         #    ('feature request', 'Request a Feature')),
#         #    label="Feedback Choice")
#         message = forms.CharField(widget=forms.Textarea(attrs={'rows': 5}),
#                                   label="Your Message",
#                                   error_messages={'required':
#                                                   'Required field'})
#         email_confirmation = forms.CharField(required=False)
# 
# Path: spacescout_web/spot.py
# class Spot(object):
#     def __init__(self, spot_id):
#         self.spot_id = spot_id
# 
#     def get(self):
#         # Required settings for the client
#         if not hasattr(settings, 'SS_WEB_SERVER_HOST'):
#             raise(Exception("Required setting missing: SS_WEB_SERVER_HOST"))
#         if not hasattr(settings, 'SS_WEB_OAUTH_KEY'):
#             raise(Exception("Required setting missing: SS_WEB_OAUTH_KEY"))
#         if not hasattr(settings, 'SS_WEB_OAUTH_SECRET'):
#             raise(Exception("Required setting missing: SS_WEB_OAUTH_SECRET"))
# 
#         consumer = oauth2.Consumer(
#                                 key=settings.SS_WEB_OAUTH_KEY,
#                                 secret=settings.SS_WEB_OAUTH_SECRET
#                                 )
#         client = oauth2.Client(consumer)
# 
#         url = "{0}/api/v1/spot/{1}".format(
#                                     settings.SS_WEB_SERVER_HOST,
#                                     self.spot_id
#                                     )
# 
#         resp, content = client.request(url, 'GET')
# 
#         if resp.status != 200:
#             raise SpotException(resp.status, self.spot_id)
# 
#         spot = json.loads(content)
# 
#         types = []
#         for t in spot["type"]:
#             types.append(_(t))
# 
#         spot["type"] = ','.join(types)
#         modified_date = (
#                         spot["last_modified"][5:10] +
#                         '-' +
#                         spot["last_modified"][:4]
#                         )
#         spot["last_modified"] = re.sub('-', '/', modified_date)
# 
#         return spot
# 
# class SpotException(Exception):
#     """ Exception for invalid Spot.
#     """
#     def __init__(self, resp_status, spot_id):
#         self.resp_status = resp_status
#         self.spot_id = spot_id


# Path: spacescout_web/views/contact.py
from django.shortcuts import render_to_response, render
from django.template import RequestContext
from django.http import HttpResponseRedirect, Http404
from spacescout_web.forms.contact import ContactForm
from spacescout_web.spot import Spot, SpotException
from django.core.mail import send_mail
from django.conf import settings
import logging
import re

    except:
        back = contact_variables['back']

    return render_to_response('spacescout_web/contact-thankyou.html', {
        'spot_id': spot_id,
        'back': back,
    }, context_instance=RequestContext(request))


def sorry(request, spot_id=None):
    contact_variables = _contact_variables(request, spot_id)

    back = contact_variables['back']
    email = settings.FEEDBACK_EMAIL_RECIPIENT[0]
    # should maybe do something here ^. raise improperly configured exception
    # if there are no emails in the list in settings.py

    return render_to_response('spacescout_web/contact-sorry.html', {
        'spot_id': spot_id,
        'back': back,
        'email': email,
    }, context_instance=RequestContext(request))


def _contact_variables(request, spot_id):
    spot_name = 'Unknown'
    spot_description = ''

    if spot_id is not None:
        try:

            spot = Spot(spot_id).get()