# Path: remo/base/utils.py
# def get_object_or_none(model_class, **kwargs):
#     """Identical to get_object_or_404, except instead of returning Http404,
#     this returns None.
# 
#     """
#     try:
#         return model_class.objects.get(**kwargs)
#     except (model_class.DoesNotExist, model_class.MultipleObjectsReturned):
#         return None
# 
# Path: remo/voting/models.py
# class Vote(models.Model):
#     """Vote model."""
#     user = models.ForeignKey(User, related_name='votes')
#     poll = models.ForeignKey(Poll)
#     date_voted = models.DateField(auto_now_add=True)
# 
#     def __str__(self):
#         return u'{0} {1}'.format(self.user, self.poll)
# 
#     def save(self, *args, **kwargs):
#         if self.poll.automated_poll:
#             name = u'{0} {1}'.format(BUDGET_VOTE_ACTION, self.poll.bug.summary)
#         else:
#             name = u'{0} {1}'.format(VOTE_ACTION, self.poll.name)
# 
#         super(Vote, self).save(*args, **kwargs)
#         ActionItem.resolve(instance=self.poll, user=self.user, name=name)


from django.db.models import Q
from django.contrib.auth.models import User
from django_jinja import library
from remo.base.utils import get_object_or_none
from remo.voting.models import Vote
    try:
        val = (users_voted / voters_group) * 100
        return int(val)
    except ZeroDivisionError:
        return 0


@library.global_function
def user_has_poll_permissions(user, poll):
    """Check if a user's group has permissions for a specific poll."""

    if user.groups.filter(Q(id=poll.valid_groups.id)
                          | Q(name='Admin')).exists():
        return True
    return False


@library.global_function
def user_has_voted(user, poll):
    if Vote.objects.filter(poll=poll, user=user).exists():
        return True
    return False


@library.global_function
def get_nominee(full_name):
    first_name, last_name = full_name.rsplit(' ', 1)
    q_params = {'first_name': first_name,
                'last_name': last_name,
                'groups__name': 'Rep'}

# Path: remo/base/utils.py
# def get_object_or_none(model_class, **kwargs):
#     """Identical to get_object_or_404, except instead of returning Http404,
#     this returns None.
# 
#     """
#     try:
#         return model_class.objects.get(**kwargs)
#     except (model_class.DoesNotExist, model_class.MultipleObjectsReturned):
#         return None
# 
# Path: remo/voting/models.py
# class Vote(models.Model):
#     """Vote model."""
#     user = models.ForeignKey(User, related_name='votes')
#     poll = models.ForeignKey(Poll)
#     date_voted = models.DateField(auto_now_add=True)
# 
#     def __str__(self):
#         return u'{0} {1}'.format(self.user, self.poll)
# 
#     def save(self, *args, **kwargs):
#         if self.poll.automated_poll:
#             name = u'{0} {1}'.format(BUDGET_VOTE_ACTION, self.poll.bug.summary)
#         else:
#             name = u'{0} {1}'.format(VOTE_ACTION, self.poll.name)
# 
#         super(Vote, self).save(*args, **kwargs)
#         ActionItem.resolve(instance=self.poll, user=self.user, name=name)


# Path: remo/voting/templatetags/helpers.py
from django.db.models import Q
from django.contrib.auth.models import User
from django_jinja import library
from remo.base.utils import get_object_or_none
from remo.voting.models import Vote

    try:
        val = (users_voted / voters_group) * 100
        return int(val)
    except ZeroDivisionError:
        return 0


@library.global_function
def user_has_poll_permissions(user, poll):
    """Check if a user's group has permissions for a specific poll."""

    if user.groups.filter(Q(id=poll.valid_groups.id)
                          | Q(name='Admin')).exists():
        return True
    return False


@library.global_function
def user_has_voted(user, poll):
    if Vote.objects.filter(poll=poll, user=user).exists():
        return True
    return False


@library.global_function
def get_nominee(full_name):
    first_name, last_name = full_name.rsplit(' ', 1)
    q_params = {'first_name': first_name,
                'last_name': last_name,
                'groups__name': 'Rep'}

    user = get_object_or_none(User, **q_params)