# Path: screenchop/config.py
# HOST = config.get('app', 'HOST')
# PORT = int(config.get('app', 'PORT'))
# DEBUG = config.getboolean('app', 'DEBUG')
# TEMP_FILE_DIR = config.get('app', 'TEMP_FILE_DIR')
# SESSION_KEY = config.get('app', 'SESSION_KEY')
# DOMAIN_URL = config.get('app', 'DOMAIN_URL')
# SHORT_DOMAIN_URL = config.get('app', 'SHORT_DOMAIN_URL')
# ADMIN_EMAIL = config.get('app', 'ADMIN_EMAIL')
# EXCEPTION_EMAIL = config.get('app', 'EXCEPTION_EMAIL').split(',')
# CACHE_TYPE = config.get('caching', 'CACHE_TYPE')
# CACHE_SERVER_ADDRESS = config.get('caching', 'CACHE_SERVER_ADDRESS').split()
# CACHE_DEFAULT_TIMEOUT = config.getint('caching', 'CACHE_DEFAULT_TIMEOUT')
# MONGO_DATABASE = config.get('mongodb', 'DATABASE')
# MONGO_HOST = config.get('mongodb', 'HOST')
# MONGO_PORT = int(config.get('mongodb', 'PORT'))
# MONGO_USER = config.get('mongodb', 'USER')
# MONGO_PASS = config.get('mongodb', 'PASS')
# BUCKET_NAME = config.get('s3', 'BUCKET_NAME')
# AWS_ACCESS_KEY_ID = config.get('s3', 'AWS_ACCESS_KEY_ID')
# AWS_SECRET_ACCESS_KEY = config.get('s3', 'AWS_SECRET_ACCESS_KEY')
# S3_THUMBS_URL = config.get('s3', 'S3_THUMBS_URL')
# S3_MEDIUM_URL = config.get('s3', 'S3_MEDIUM_URL')
# S3_FULL_URL = config.get('s3', 'S3_FULL_URL')
# S3_AVATAR_URL = config.get('s3', 'S3_AVATAR_URL')
# REGISTRATION_LEVEL = config.get('registration', 'REGISTRATION_LEVEL')
# MAX_IMAGES_PER_ROW = int(config.get('gallery', 'MAX_IMAGES_PER_ROW'))
# HOME_MAX_IMAGES = int(config.get('gallery', 'HOME_MAX_IMAGES'))
# TAGGING_ENABLED = config.getboolean('gallery', 'TAGGING_ENABLED')
# ALLOWED_FILE_TYPES = config.get('upload', 'ALLOWED_FILE_TYPES').split(',')
# THUMB_MAX_WIDTH = int(config.get('upload', 'THUMB_MAX_WIDTH'))
# THUMB_MAX_HEIGHT = int(config.get('upload', 'THUMB_MAX_HEIGHT'))
# MEDIUM_MAX_WIDTH = int(config.get('upload', 'MEDIUM_MAX_WIDTH'))
# MEDIUM_MAX_HEIGHT = int(config.get('upload', 'MEDIUM_MAX_HEIGHT'))
# GOOGLE_ANALYTICS_ACCOUNT = config.get('marketing', 'GOOGLE_ANALYTICS_ACCOUNT')
# 
# Path: screenchop/forms.py
# class RegistrationForm(Form):
#     username = TextField('Username', [
#         validators.Length(min=3, max=20),
#         validators.Required(message='Username must be between 3 and 20 characters long.')])
#     password = PasswordField('New Password', [
#         validators.Required(message='Password required'),
#         validators.EqualTo('confirm', message='Passwords must match')
#     ])
#     if config.REGISTRATION_LEVEL == 'invite':
#         invite_code = TextField('Invitation Code', [validators.Required(message='Invitation code required')])
#     else:
#         pass
#     confirm = PasswordField('Repeat Password')
#     accept_tos = BooleanField('Terms of Service', [validators.Required(message='You must agree to the Terms of Service')])
# 
# class LoginForm(Form):
#     username = TextField('Username')
#     password = PasswordField('Password')
# 
# class EditPost(Form):
#     caption = TextAreaField('Caption', [
#         validators.Length(max=100, message='Max 100 characters')
#             ])
#     tags = TagListField('Tags')
# 
# class ReportPost(Form):
#     reason = TextAreaField('Reason', [
#         validators.Length(max=1000, message='Max 1000 characters')
#             ])
# 
# Path: screenchop/cache.py

# 
# Path: screenchop/util/mailer.py
# def send_contact_email(name, email, comment):
# def send_request_invite_email(email):
# def report_chop(chop, reason):


from flask import Flask
from flask import request, session, redirect, url_for
from flask import render_template, flash
from screenchop.models import *
from screenchop import config
from screenchop.forms import RegistrationForm, LoginForm, EditPost, ReportPost
from screenchop.sessions import *
from screenchop.cache import cache
from screenchop.util import mailer
from boto.s3.key import Key
import boto
    
    # Calculate total score of post
    score = int(chop.upvotes) - int(chop.downvotes)
    
    return render_template('main/chop.html', chop=chop, regForm=regForm,
                            loginForm=loginForm, editPostForm=editPostForm,
                            fullURL=fullURL, shortURL=shortURL, score=score,
                            vote=vote, tagging=tagging, tagable=tagable,
                            s3FullURL=s3FullURL, s3MediumURL=s3MediumURL,
                            s3ThumbsURL=s3ThumbsURL, star=star, user=user,
                            reportPostForm=reportPostForm)
                            
@requires_auth        
def delete_chop(filename):
    """ Controller to delete a chop post """ 
    
    # Query post
    chop = Post.objects.get(filename = filename)
    user = User.objects.get(username=session['username'])
    
    # User session is the submitter or a mod, then delete the post
    # otherwise, redirect with a flash message
    if session['username'] == chop.submitter or user.rank == 'mod':
        # Delete MongoDB post
        chop.delete()
        
        # Connect to S3 and delete all key objects
        conn = boto.connect_s3(config.AWS_ACCESS_KEY_ID,
                                 config.AWS_SECRET_ACCESS_KEY)
                                 

# Path: screenchop/config.py
# HOST = config.get('app', 'HOST')
# PORT = int(config.get('app', 'PORT'))
# DEBUG = config.getboolean('app', 'DEBUG')
# TEMP_FILE_DIR = config.get('app', 'TEMP_FILE_DIR')
# SESSION_KEY = config.get('app', 'SESSION_KEY')
# DOMAIN_URL = config.get('app', 'DOMAIN_URL')
# SHORT_DOMAIN_URL = config.get('app', 'SHORT_DOMAIN_URL')
# ADMIN_EMAIL = config.get('app', 'ADMIN_EMAIL')
# EXCEPTION_EMAIL = config.get('app', 'EXCEPTION_EMAIL').split(',')
# CACHE_TYPE = config.get('caching', 'CACHE_TYPE')
# CACHE_SERVER_ADDRESS = config.get('caching', 'CACHE_SERVER_ADDRESS').split()
# CACHE_DEFAULT_TIMEOUT = config.getint('caching', 'CACHE_DEFAULT_TIMEOUT')
# MONGO_DATABASE = config.get('mongodb', 'DATABASE')
# MONGO_HOST = config.get('mongodb', 'HOST')
# MONGO_PORT = int(config.get('mongodb', 'PORT'))
# MONGO_USER = config.get('mongodb', 'USER')
# MONGO_PASS = config.get('mongodb', 'PASS')
# BUCKET_NAME = config.get('s3', 'BUCKET_NAME')
# AWS_ACCESS_KEY_ID = config.get('s3', 'AWS_ACCESS_KEY_ID')
# AWS_SECRET_ACCESS_KEY = config.get('s3', 'AWS_SECRET_ACCESS_KEY')
# S3_THUMBS_URL = config.get('s3', 'S3_THUMBS_URL')
# S3_MEDIUM_URL = config.get('s3', 'S3_MEDIUM_URL')
# S3_FULL_URL = config.get('s3', 'S3_FULL_URL')
# S3_AVATAR_URL = config.get('s3', 'S3_AVATAR_URL')
# REGISTRATION_LEVEL = config.get('registration', 'REGISTRATION_LEVEL')
# MAX_IMAGES_PER_ROW = int(config.get('gallery', 'MAX_IMAGES_PER_ROW'))
# HOME_MAX_IMAGES = int(config.get('gallery', 'HOME_MAX_IMAGES'))
# TAGGING_ENABLED = config.getboolean('gallery', 'TAGGING_ENABLED')
# ALLOWED_FILE_TYPES = config.get('upload', 'ALLOWED_FILE_TYPES').split(',')
# THUMB_MAX_WIDTH = int(config.get('upload', 'THUMB_MAX_WIDTH'))
# THUMB_MAX_HEIGHT = int(config.get('upload', 'THUMB_MAX_HEIGHT'))
# MEDIUM_MAX_WIDTH = int(config.get('upload', 'MEDIUM_MAX_WIDTH'))
# MEDIUM_MAX_HEIGHT = int(config.get('upload', 'MEDIUM_MAX_HEIGHT'))
# GOOGLE_ANALYTICS_ACCOUNT = config.get('marketing', 'GOOGLE_ANALYTICS_ACCOUNT')
# 
# Path: screenchop/forms.py
# class RegistrationForm(Form):
#     username = TextField('Username', [
#         validators.Length(min=3, max=20),
#         validators.Required(message='Username must be between 3 and 20 characters long.')])
#     password = PasswordField('New Password', [
#         validators.Required(message='Password required'),
#         validators.EqualTo('confirm', message='Passwords must match')
#     ])
#     if config.REGISTRATION_LEVEL == 'invite':
#         invite_code = TextField('Invitation Code', [validators.Required(message='Invitation code required')])
#     else:
#         pass
#     confirm = PasswordField('Repeat Password')
#     accept_tos = BooleanField('Terms of Service', [validators.Required(message='You must agree to the Terms of Service')])
# 
# class LoginForm(Form):
#     username = TextField('Username')
#     password = PasswordField('Password')
# 
# class EditPost(Form):
#     caption = TextAreaField('Caption', [
#         validators.Length(max=100, message='Max 100 characters')
#             ])
#     tags = TagListField('Tags')
# 
# class ReportPost(Form):
#     reason = TextAreaField('Reason', [
#         validators.Length(max=1000, message='Max 1000 characters')
#             ])
# 
# Path: screenchop/cache.py

# 
# Path: screenchop/util/mailer.py
# def send_contact_email(name, email, comment):
# def send_request_invite_email(email):
# def report_chop(chop, reason):


# Path: screenchop/controllers/views/chops.py
from flask import Flask
from flask import request, session, redirect, url_for
from flask import render_template, flash
from screenchop.models import *
from screenchop import config
from screenchop.forms import RegistrationForm, LoginForm, EditPost, ReportPost
from screenchop.sessions import *
from screenchop.cache import cache
from screenchop.util import mailer
from boto.s3.key import Key
import boto

    
    # Calculate total score of post
    score = int(chop.upvotes) - int(chop.downvotes)
    
    return render_template('main/chop.html', chop=chop, regForm=regForm,
                            loginForm=loginForm, editPostForm=editPostForm,
                            fullURL=fullURL, shortURL=shortURL, score=score,
                            vote=vote, tagging=tagging, tagable=tagable,
                            s3FullURL=s3FullURL, s3MediumURL=s3MediumURL,
                            s3ThumbsURL=s3ThumbsURL, star=star, user=user,
                            reportPostForm=reportPostForm)
                            
@requires_auth        
def delete_chop(filename):
    """ Controller to delete a chop post """ 
    
    # Query post
    chop = Post.objects.get(filename = filename)
    user = User.objects.get(username=session['username'])
    
    # User session is the submitter or a mod, then delete the post
    # otherwise, redirect with a flash message
    if session['username'] == chop.submitter or user.rank == 'mod':
        # Delete MongoDB post
        chop.delete()
        
        # Connect to S3 and delete all key objects
        conn = boto.connect_s3(config.AWS_ACCESS_KEY_ID,
                                 config.AWS_SECRET_ACCESS_KEY)
                                 

        b = conn.get_bucket(config.BUCKET_NAME)