mirror of
https://github.com/zulip/zulip.git
synced 2025-11-04 22:13:26 +00:00
Add PEP-484 type annotations to zerver/models.py.
Done pair-programming with Guido.
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
from __future__ import absolute_import
|
from __future__ import absolute_import
|
||||||
|
from typing import *
|
||||||
|
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
@@ -29,7 +30,7 @@ import re
|
|||||||
import ujson
|
import ujson
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
bugdown = None
|
bugdown = None # type: Any
|
||||||
|
|
||||||
MAX_SUBJECT_LENGTH = 60
|
MAX_SUBJECT_LENGTH = 60
|
||||||
MAX_MESSAGE_LENGTH = 10000
|
MAX_MESSAGE_LENGTH = 10000
|
||||||
@@ -142,9 +143,10 @@ class Realm(models.Model):
|
|||||||
except IndexError:
|
except IndexError:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@deployment.setter
|
@deployment.setter # type: ignore # https://github.com/python/mypy/issues/220
|
||||||
def set_deployments(self, value):
|
def set_deployments(self, value):
|
||||||
self._deployments = [value]
|
# type: (Any) -> None
|
||||||
|
self._deployments = [value] # type: Any
|
||||||
|
|
||||||
def get_admin_users(self):
|
def get_admin_users(self):
|
||||||
# This method is kind of expensive, due to our complex permissions model.
|
# This method is kind of expensive, due to our complex permissions model.
|
||||||
@@ -269,7 +271,8 @@ def realm_filters_for_domain_remote_cache(domain):
|
|||||||
return filters
|
return filters
|
||||||
|
|
||||||
def all_realm_filters():
|
def all_realm_filters():
|
||||||
filters = defaultdict(list)
|
# type: () -> Dict[str, List[Tuple[str, str]]]
|
||||||
|
filters = defaultdict(list) # type: Dict[str, List[Tuple[str, str]]]
|
||||||
for realm_filter in RealmFilter.objects.all():
|
for realm_filter in RealmFilter.objects.all():
|
||||||
filters[realm_filter.realm.domain].append((realm_filter.pattern, realm_filter.url_format_string))
|
filters[realm_filter.realm.domain].append((realm_filter.pattern, realm_filter.url_format_string))
|
||||||
|
|
||||||
@@ -384,7 +387,7 @@ class UserProfile(AbstractBaseUser, PermissionsMixin):
|
|||||||
# [["social", "mit"], ["devel", "ios"]]
|
# [["social", "mit"], ["devel", "ios"]]
|
||||||
muted_topics = models.TextField(default=ujson.dumps([]))
|
muted_topics = models.TextField(default=ujson.dumps([]))
|
||||||
|
|
||||||
objects = UserManager()
|
objects = UserManager() # type: UserManager
|
||||||
|
|
||||||
def can_admin_user(self, target_user):
|
def can_admin_user(self, target_user):
|
||||||
"""Returns whether this user has permission to modify target_user"""
|
"""Returns whether this user has permission to modify target_user"""
|
||||||
@@ -719,8 +722,8 @@ class Message(models.Model):
|
|||||||
|
|
||||||
self.mentions_wildcard = False
|
self.mentions_wildcard = False
|
||||||
self.is_me_message = False
|
self.is_me_message = False
|
||||||
self.mentions_user_ids = set()
|
self.mentions_user_ids = set() # type: Set[int]
|
||||||
self.user_ids_with_alert_words = set()
|
self.user_ids_with_alert_words = set() # type: Set[int]
|
||||||
|
|
||||||
if not domain:
|
if not domain:
|
||||||
domain = self.sender.realm.domain
|
domain = self.sender.realm.domain
|
||||||
@@ -1170,6 +1173,7 @@ def get_realm(domain):
|
|||||||
|
|
||||||
def clear_database():
|
def clear_database():
|
||||||
pylibmc.Client(['127.0.0.1']).flush_all()
|
pylibmc.Client(['127.0.0.1']).flush_all()
|
||||||
|
model = None # type: Any
|
||||||
for model in [Message, Stream, UserProfile, Recipient,
|
for model in [Message, Stream, UserProfile, Recipient,
|
||||||
Realm, Subscription, Huddle, UserMessage, Client,
|
Realm, Subscription, Huddle, UserMessage, Client,
|
||||||
DefaultStream]:
|
DefaultStream]:
|
||||||
@@ -1212,7 +1216,8 @@ class UserPresence(models.Model):
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_status_dict_by_realm(realm_id):
|
def get_status_dict_by_realm(realm_id):
|
||||||
user_statuses = defaultdict(dict)
|
# type: (Any) -> Any
|
||||||
|
user_statuses = defaultdict(dict) # type: Dict[Any, Dict[Any, Any]]
|
||||||
|
|
||||||
query = UserPresence.objects.filter(
|
query = UserPresence.objects.filter(
|
||||||
user_profile__realm_id=realm_id,
|
user_profile__realm_id=realm_id,
|
||||||
|
|||||||
Reference in New Issue
Block a user