# Path: hackday/common.py
# def common_env():
#     env = {
#         'nav_pages': get_nav_pages(),
#     }
#     return env
# 
# Path: hackday/charities/forms.py
# class SuggestCharityForm(forms.Form):
#     name = forms.CharField(label='Charity Name')
#     url = forms.URLField(label='Website')
#     description = forms.CharField(label='Description', widget=forms.Textarea)
# 
# Path: hackday/charities/models.py
# class Charity(models.Model):
#     name = models.CharField('name of charity', max_length=255, db_index=True,
#             unique=True)
#     url = models.CharField('url', max_length=255)
#     tax_id = models.CharField('tax id', max_length=10, blank=True, null=True)
#     description = models.TextField('description of charity')
#     status = models.CharField(max_length=1, choices=STATUS.CHOICES)
# 
#     attachments = models.ManyToManyField(Attachment,
#             related_name="%(app_label)s_%(class)s_attachments", blank=True)
#     images = models.ManyToManyField(ImageAttachment,
#             related_name="%(app_label)s_%(class)s_images", blank=True)
#     links = models.ManyToManyField(Link,
#             related_name="%(app_label)s_%(class)s_links", blank=True)
# 
#     suggester = models.ForeignKey(User)
# 
#     create_date = models.DateTimeField('date created', auto_now_add=True)
#     mod_date = models.DateTimeField('date modified', auto_now=True)
# 
#     def __unicode__(self):
#         return self.name
# 
#     class Meta:
#         verbose_name_plural = "Charities"
#         ordering = ['name']
# 
# class STATUS(object):
#     # Using the same char values as blog posts & wiki pages for consistency, but
#     # different verbose versions for clarity/semantic meaning.
#     PENDING = 'D'
#     APPROVED = 'P'
#     REJECTED = 'R'
#     DELETED = 'X'
# 
#     CHOICES = (
#         (PENDING, 'Pending Approval'),
#         (APPROVED, 'Approved'),
#         (REJECTED, 'Rejected'),
#         (DELETED, 'Deleted'),
#     )


from hackday.common import common_env
from hackday.charities.forms import SuggestCharityForm
from hackday.charities.models import Charity, STATUS
from django.http import HttpResponse
from django.shortcuts import render
from django.template import Context, loader
from django.contrib.auth.decorators import login_required
from django.db import IntegrityError
from django.core.urlresolvers import reverse


def index(request):
    charities = Charity.objects.filter(status=STATUS.APPROVED).order_by("name")
    env = common_env()
    env['charities'] = charities
    return render(request, 'charities/index.html', env)


@login_required()
def suggest(request):
    error_message = None

# Path: hackday/common.py
# def common_env():
#     env = {
#         'nav_pages': get_nav_pages(),
#     }
#     return env
# 
# Path: hackday/charities/forms.py
# class SuggestCharityForm(forms.Form):
#     name = forms.CharField(label='Charity Name')
#     url = forms.URLField(label='Website')
#     description = forms.CharField(label='Description', widget=forms.Textarea)
# 
# Path: hackday/charities/models.py
# class Charity(models.Model):
#     name = models.CharField('name of charity', max_length=255, db_index=True,
#             unique=True)
#     url = models.CharField('url', max_length=255)
#     tax_id = models.CharField('tax id', max_length=10, blank=True, null=True)
#     description = models.TextField('description of charity')
#     status = models.CharField(max_length=1, choices=STATUS.CHOICES)
# 
#     attachments = models.ManyToManyField(Attachment,
#             related_name="%(app_label)s_%(class)s_attachments", blank=True)
#     images = models.ManyToManyField(ImageAttachment,
#             related_name="%(app_label)s_%(class)s_images", blank=True)
#     links = models.ManyToManyField(Link,
#             related_name="%(app_label)s_%(class)s_links", blank=True)
# 
#     suggester = models.ForeignKey(User)
# 
#     create_date = models.DateTimeField('date created', auto_now_add=True)
#     mod_date = models.DateTimeField('date modified', auto_now=True)
# 
#     def __unicode__(self):
#         return self.name
# 
#     class Meta:
#         verbose_name_plural = "Charities"
#         ordering = ['name']
# 
# class STATUS(object):
#     # Using the same char values as blog posts & wiki pages for consistency, but
#     # different verbose versions for clarity/semantic meaning.
#     PENDING = 'D'
#     APPROVED = 'P'
#     REJECTED = 'R'
#     DELETED = 'X'
# 
#     CHOICES = (
#         (PENDING, 'Pending Approval'),
#         (APPROVED, 'Approved'),
#         (REJECTED, 'Rejected'),
#         (DELETED, 'Deleted'),
#     )


# Path: hackday/charities/views.py
from hackday.common import common_env
from hackday.charities.forms import SuggestCharityForm
from hackday.charities.models import Charity, STATUS
from django.http import HttpResponse
from django.shortcuts import render
from django.template import Context, loader
from django.contrib.auth.decorators import login_required
from django.db import IntegrityError
from django.core.urlresolvers import reverse



def index(request):
    charities = Charity.objects.filter(status=STATUS.APPROVED).order_by("name")
    env = common_env()
    env['charities'] = charities
    return render(request, 'charities/index.html', env)


@login_required()
def suggest(request):
    error_message = None

    env = common_env()