# Path: server/constants.py
# CONTACT_TYPE_EMAIL = 'E'
# 
# Path: server/constants.py
# CONTACT_TYPE_JID = 'J'


from datetime import timedelta
from django.db.models import Q
from django.db.models.query import QuerySet
from django.utils import timezone
from server.constants import CONTACT_TYPE_EMAIL
from server.constants import CONTACT_TYPE_JID
        """Servers that only allow encrypted c2s/s2s connections."""
        return self.c2s_secure().s2s_secure()

    def tls(self):
        """Return servers that allow TLS connections."""
        return self.filter(c2s_starttls=True).filter(
            Q(c2s_tls_verified=True) | Q(ca__isnull=True))

    def verified(self):
        qs = self.filter(c2s_srv_records=True, s2s_srv_records=True).tls()

        return qs

    def moderated(self):
        return self.filter(moderated=True, user__email_confirmed=True, user__jid_confirmed=True)

    def for_moderation(self):
        """List all servers suitable for moderation.

        Lists servers that are unmoderated, have valid SRV records, a working SSL/TLS setup and are
        not yet moderated. It also excludes servers where the contact should be automatically
        verified but the user has failed to confirm this.
        """
        query = Q(contact_type=CONTACT_TYPE_JID) | Q(contact_type=CONTACT_TYPE_EMAIL)
        return self.verified().filter(moderated=None).exclude(query & Q(contact_verified=False))

    def jid(self, jid):
        return self.filter(contact_type=CONTACT_TYPE_JID, contact=jid)

    def email(self, email):

# Path: server/constants.py
# CONTACT_TYPE_EMAIL = 'E'
# 
# Path: server/constants.py
# CONTACT_TYPE_JID = 'J'


# Path: server/querysets.py
from datetime import timedelta
from django.db.models import Q
from django.db.models.query import QuerySet
from django.utils import timezone
from server.constants import CONTACT_TYPE_EMAIL
from server.constants import CONTACT_TYPE_JID

        """Servers that only allow encrypted c2s/s2s connections."""
        return self.c2s_secure().s2s_secure()

    def tls(self):
        """Return servers that allow TLS connections."""
        return self.filter(c2s_starttls=True).filter(
            Q(c2s_tls_verified=True) | Q(ca__isnull=True))

    def verified(self):
        qs = self.filter(c2s_srv_records=True, s2s_srv_records=True).tls()

        return qs

    def moderated(self):
        return self.filter(moderated=True, user__email_confirmed=True, user__jid_confirmed=True)

    def for_moderation(self):
        """List all servers suitable for moderation.

        Lists servers that are unmoderated, have valid SRV records, a working SSL/TLS setup and are
        not yet moderated. It also excludes servers where the contact should be automatically
        verified but the user has failed to confirm this.
        """
        query = Q(contact_type=CONTACT_TYPE_JID) | Q(contact_type=CONTACT_TYPE_EMAIL)
        return self.verified().filter(moderated=None).exclude(query & Q(contact_verified=False))

    def jid(self, jid):
        return self.filter(contact_type=CONTACT_TYPE_JID, contact=jid)

    def email(self, email):

        return self.filter(contact_type=CONTACT_TYPE_EMAIL, contact=email)