# Path: _15thnight/util.py
# def extend(dict1, dict2):
#     dict1.update(dict2)
#     return dict1
# 
# def to_local_datetime(dt):
#     """
#     datetime.isoformat does not append +0000 when using UTC, javascript
#     needs it, or the date is parsed as if it were in the local timezone
#     """
#     if not dt:
#         return None
#     ldt = dt.isoformat()
#     return ldt if ldt[-6] == "+" else "%s+0000" % ldt


import uuid
from datetime import datetime, timedelta
from flask import url_for
from sqlalchemy import (
    Column, DateTime, Enum, ForeignKey, Integer, String, Table, Text, desc,
    Boolean
)
from sqlalchemy.orm import backref, relationship
from werkzeug.security import check_password_hash, generate_password_hash
from _15thnight.database import Model
from _15thnight.util import extend, to_local_datetime
            .filter(ProviderNotified.provider_id == provider.id) \
            .order_by(desc(cls.created_at)) \
            .distinct().all()
        return [alert.to_provider_json(provider) for alert in alerts]

    @classmethod
    def get_responded_alerts_for_provider(cls, provider):
        alerts = Alert.query \
            .join(cls.responses) \
            .filter(Response.user_id == provider.id) \
            .order_by(desc(cls.created_at)) \
            .distinct().all()
        return [alert.to_provider_json(provider) for alert in alerts]

    def provider_has_permission(self, provider):
        """Checks if a provider was notified for this alert"""
        provider_ids = map(
            lambda notified: notified.provider_id, self.providers_notified)
        return provider.id in provider_ids

    def get_user_response(self, user):
        response = Response.get_by_user_and_alert(user, self)
        if response:
            return response
        return False

    def to_json(self):
        return dict(
            id=self.id,
            user=self.user,

# Path: _15thnight/util.py
# def extend(dict1, dict2):
#     dict1.update(dict2)
#     return dict1
# 
# def to_local_datetime(dt):
#     """
#     datetime.isoformat does not append +0000 when using UTC, javascript
#     needs it, or the date is parsed as if it were in the local timezone
#     """
#     if not dt:
#         return None
#     ldt = dt.isoformat()
#     return ldt if ldt[-6] == "+" else "%s+0000" % ldt


# Path: _15thnight/models.py
import uuid
from datetime import datetime, timedelta
from flask import url_for
from sqlalchemy import (
    Column, DateTime, Enum, ForeignKey, Integer, String, Table, Text, desc,
    Boolean
)
from sqlalchemy.orm import backref, relationship
from werkzeug.security import check_password_hash, generate_password_hash
from _15thnight.database import Model
from _15thnight.util import extend, to_local_datetime

            .filter(ProviderNotified.provider_id == provider.id) \
            .order_by(desc(cls.created_at)) \
            .distinct().all()
        return [alert.to_provider_json(provider) for alert in alerts]

    @classmethod
    def get_responded_alerts_for_provider(cls, provider):
        alerts = Alert.query \
            .join(cls.responses) \
            .filter(Response.user_id == provider.id) \
            .order_by(desc(cls.created_at)) \
            .distinct().all()
        return [alert.to_provider_json(provider) for alert in alerts]

    def provider_has_permission(self, provider):
        """Checks if a provider was notified for this alert"""
        provider_ids = map(
            lambda notified: notified.provider_id, self.providers_notified)
        return provider.id in provider_ids

    def get_user_response(self, user):
        response = Response.get_by_user_and_alert(user, self)
        if response:
            return response
        return False

    def to_json(self):
        return dict(
            id=self.id,
            user=self.user,

            created_at=to_local_datetime(self.created_at),