# Path: profile/models.py
# class Profile(models.Model):
#     user = models.OneToOneField(User, on_delete=models.CASCADE)
#     full_name = models.TextField()
#     notifications = models.ForeignKey('profile.Notifications', on_delete=models.CASCADE)
#     subscriptions = models.ManyToManyField('petitions.Petition', related_name='profile_subscriptions', blank=True)
#     petitions_created = models.ManyToManyField('petitions.Petition', related_name='profile_petitions_created', blank=True)
#     petitions_signed = models.ManyToManyField('petitions.Petition', related_name='profile_petitions_signed', blank=True)
#     display_name = models.CharField(max_length=3, blank=True)
#     # 0 - Does not have access, 1 - Has Access
#     has_access = models.PositiveSmallIntegerField(default=1)
# 
#     def __unicode__(self):
#         return self.user.username
# 
# Path: petitions/models.py
# class Petition(models.Model):
#     title = models.CharField(max_length=80)
#     description = models.TextField()
#     tags = models.ManyToManyField('petitions.Tag')
#     author = models.ForeignKey(User, on_delete=models.PROTECT)
#     signatures = models.PositiveIntegerField(default=0)
#     created_at = models.DateTimeField()
#     # These states include: 0 - new (unpublished), 1 - published, 2 - removed (unpublished), 3 - Needs Review
#     status = models.PositiveSmallIntegerField(default=0)
#     expires = models.DateTimeField()
#     last_signed = models.DateTimeField(default=None, blank=True, null=True)
#     has_response = models.BooleanField(default=False)
#     response = models.ForeignKey('petitions.Response', default=None, blank=True, null=True, on_delete=models.SET_NULL)
#     in_progress = models.NullBooleanField()
#     updates = models.ManyToManyField('petitions.Update', default=None)
#     old_id = models.CharField(max_length=20, default=None, blank=True, null=True)
# 
#     def __str__(self):
#         return self.title
# 
# class Tag(models.Model):
#     name = models.CharField(max_length=50)
# 
#     def __str__(self):
#         return self.name
# 
# Path: profile/models.py
# class GlobalAlert(models.Model):
#     active = models.BooleanField(default=True)
#     content = models.TextField()


import json
import logging
import channels
import petitions.profanity
from collections import namedtuple
from datetime import timedelta
from profile.models import Profile
from django.conf import settings
from django.contrib.auth.decorators import login_required, user_passes_test
from django.contrib.auth.models import User
from django.contrib.postgres.search import (SearchQuery, SearchRank,
                                            SearchVector)
from django.db.models import F, Q
from django.http import HttpResponse, JsonResponse
from django.shortcuts import get_object_or_404, redirect, render
from django.utils import timezone
from django.views.decorators.http import require_POST
from asgiref.sync import async_to_sync
from petitions.models import Petition, Tag
from profile.models import GlobalAlert
from send_mail.tasks import *
        'generate_top_nav': CONFIG['generate_top_nav'],
        'analytics_id': settings.ANALYTICS
    }
    return render(request, 'news.html', data_object)


def maintenance(request):
    return render(request, 'Something_Special.html')


def petition(request, petition_id):
    """ Handles displaying A single petition.
    DB queried to get Petition object and User objects.
    User object queries retrieve author
    and list of all users who signed the petition.
    """
    # Get petition of given id, if not found, display 404
    petition = get_object_or_404(Petition, pk=petition_id)
    # Get author of the petition
    author = User.objects.get(pk=petition.author.id)
    user = request.user

    # Check if user is authenticated before querying
    curr_user_signed = user.profile.petitions_signed.filter(
        id=petition.id).exists() if user.is_authenticated else None

    # Get QuerySet of all users who signed this petition
    users_signed = Profile.objects.filter(petitions_signed=petition)

    # Get all of the current tags in pawprints.

# Path: profile/models.py
# class Profile(models.Model):
#     user = models.OneToOneField(User, on_delete=models.CASCADE)
#     full_name = models.TextField()
#     notifications = models.ForeignKey('profile.Notifications', on_delete=models.CASCADE)
#     subscriptions = models.ManyToManyField('petitions.Petition', related_name='profile_subscriptions', blank=True)
#     petitions_created = models.ManyToManyField('petitions.Petition', related_name='profile_petitions_created', blank=True)
#     petitions_signed = models.ManyToManyField('petitions.Petition', related_name='profile_petitions_signed', blank=True)
#     display_name = models.CharField(max_length=3, blank=True)
#     # 0 - Does not have access, 1 - Has Access
#     has_access = models.PositiveSmallIntegerField(default=1)
# 
#     def __unicode__(self):
#         return self.user.username
# 
# Path: petitions/models.py
# class Petition(models.Model):
#     title = models.CharField(max_length=80)
#     description = models.TextField()
#     tags = models.ManyToManyField('petitions.Tag')
#     author = models.ForeignKey(User, on_delete=models.PROTECT)
#     signatures = models.PositiveIntegerField(default=0)
#     created_at = models.DateTimeField()
#     # These states include: 0 - new (unpublished), 1 - published, 2 - removed (unpublished), 3 - Needs Review
#     status = models.PositiveSmallIntegerField(default=0)
#     expires = models.DateTimeField()
#     last_signed = models.DateTimeField(default=None, blank=True, null=True)
#     has_response = models.BooleanField(default=False)
#     response = models.ForeignKey('petitions.Response', default=None, blank=True, null=True, on_delete=models.SET_NULL)
#     in_progress = models.NullBooleanField()
#     updates = models.ManyToManyField('petitions.Update', default=None)
#     old_id = models.CharField(max_length=20, default=None, blank=True, null=True)
# 
#     def __str__(self):
#         return self.title
# 
# class Tag(models.Model):
#     name = models.CharField(max_length=50)
# 
#     def __str__(self):
#         return self.name
# 
# Path: profile/models.py
# class GlobalAlert(models.Model):
#     active = models.BooleanField(default=True)
#     content = models.TextField()


# Path: petitions/views.py
import json
import logging
import channels
import petitions.profanity
from collections import namedtuple
from datetime import timedelta
from profile.models import Profile
from django.conf import settings
from django.contrib.auth.decorators import login_required, user_passes_test
from django.contrib.auth.models import User
from django.contrib.postgres.search import (SearchQuery, SearchRank,
                                            SearchVector)
from django.db.models import F, Q
from django.http import HttpResponse, JsonResponse
from django.shortcuts import get_object_or_404, redirect, render
from django.utils import timezone
from django.views.decorators.http import require_POST
from asgiref.sync import async_to_sync
from petitions.models import Petition, Tag
from profile.models import GlobalAlert
from send_mail.tasks import *

        'generate_top_nav': CONFIG['generate_top_nav'],
        'analytics_id': settings.ANALYTICS
    }
    return render(request, 'news.html', data_object)


def maintenance(request):
    return render(request, 'Something_Special.html')


def petition(request, petition_id):
    """ Handles displaying A single petition.
    DB queried to get Petition object and User objects.
    User object queries retrieve author
    and list of all users who signed the petition.
    """
    # Get petition of given id, if not found, display 404
    petition = get_object_or_404(Petition, pk=petition_id)
    # Get author of the petition
    author = User.objects.get(pk=petition.author.id)
    user = request.user

    # Check if user is authenticated before querying
    curr_user_signed = user.profile.petitions_signed.filter(
        id=petition.id).exists() if user.is_authenticated else None

    # Get QuerySet of all users who signed this petition
    users_signed = Profile.objects.filter(petitions_signed=petition)

    # Get all of the current tags in pawprints.

    additional_tags = Tag.objects.all().exclude(