views: Rename *topic local variables to *topic_name.

This is preparatory work towards adding a Topic model.
We plan to use the local variable name as 'topic' for
the Topic model objects.

Currently, we use *topic as the local variable name for
topic names.

We rename local variables of the form *topic to *topic_name
so that we don't need to think about type collisions in
individual code paths where we might want to talk about both
Topic objects and strings for the topic name.
This commit is contained in:
Prakhar Pratyush
2024-01-13 18:32:59 +05:30
committed by Tim Abbott
parent 1eef052bd1
commit bc66eaee7d
3 changed files with 14 additions and 14 deletions

View File

@@ -137,7 +137,7 @@ def build_page_params_for_home_page_load(
insecure_desktop_app: bool, insecure_desktop_app: bool,
narrow: List[NarrowTerm], narrow: List[NarrowTerm],
narrow_stream: Optional[Stream], narrow_stream: Optional[Stream],
narrow_topic: Optional[str], narrow_topic_name: Optional[str],
first_in_realm: bool, first_in_realm: bool,
prompt_for_invites: bool, prompt_for_invites: bool,
needs_tutorial: bool, needs_tutorial: bool,
@@ -255,8 +255,8 @@ def build_page_params_for_home_page_load(
if max_message: if max_message:
page_params["max_message_id"] = max_message.id page_params["max_message_id"] = max_message.id
page_params["narrow_stream"] = narrow_stream.name page_params["narrow_stream"] = narrow_stream.name
if narrow_topic is not None: if narrow_topic_name is not None:
page_params["narrow_topic"] = narrow_topic page_params["narrow_topic"] = narrow_topic_name
page_params["narrow"] = [ page_params["narrow"] = [
dict(operator=term.operator, operand=term.operand) for term in narrow dict(operator=term.operator, operand=term.operand) for term in narrow
] ]

View File

@@ -110,7 +110,7 @@ def detect_narrowed_window(
narrow: List[NarrowTerm] = [] narrow: List[NarrowTerm] = []
narrow_stream = None narrow_stream = None
narrow_topic = request.GET.get("topic") narrow_topic_name = request.GET.get("topic")
if "stream" in request.GET: if "stream" in request.GET:
try: try:
@@ -121,9 +121,9 @@ def detect_narrowed_window(
narrow = [NarrowTerm(operator="stream", operand=narrow_stream.name)] narrow = [NarrowTerm(operator="stream", operand=narrow_stream.name)]
except Exception: except Exception:
logging.warning("Invalid narrow requested, ignoring", extra=dict(request=request)) logging.warning("Invalid narrow requested, ignoring", extra=dict(request=request))
if narrow_stream is not None and narrow_topic is not None: if narrow_stream is not None and narrow_topic_name is not None:
narrow.append(NarrowTerm(operator="topic", operand=narrow_topic)) narrow.append(NarrowTerm(operator="topic", operand=narrow_topic_name))
return narrow, narrow_stream, narrow_topic return narrow, narrow_stream, narrow_topic_name
def update_last_reminder(user_profile: Optional[UserProfile]) -> None: def update_last_reminder(user_profile: Optional[UserProfile]) -> None:
@@ -207,7 +207,7 @@ def home_real(request: HttpRequest) -> HttpResponse:
if need_accept_tos(user_profile): if need_accept_tos(user_profile):
return accounts_accept_terms(request) return accounts_accept_terms(request)
narrow, narrow_stream, narrow_topic = detect_narrowed_window(request, user_profile) narrow, narrow_stream, narrow_topic_name = detect_narrowed_window(request, user_profile)
if user_profile is not None: if user_profile is not None:
first_in_realm = realm_user_count(user_profile.realm) == 1 first_in_realm = realm_user_count(user_profile.realm) == 1
@@ -232,7 +232,7 @@ def home_real(request: HttpRequest) -> HttpResponse:
insecure_desktop_app=insecure_desktop_app, insecure_desktop_app=insecure_desktop_app,
narrow=narrow, narrow=narrow,
narrow_stream=narrow_stream, narrow_stream=narrow_stream,
narrow_topic=narrow_topic, narrow_topic_name=narrow_topic_name,
first_in_realm=first_in_realm, first_in_realm=first_in_realm,
prompt_for_invites=prompt_for_invites, prompt_for_invites=prompt_for_invites,
needs_tutorial=needs_tutorial, needs_tutorial=needs_tutorial,

View File

@@ -34,7 +34,7 @@ def fill_edit_history_entries(
""" """
prev_content = message.content prev_content = message.content
prev_rendered_content = message.rendered_content prev_rendered_content = message.rendered_content
prev_topic = message.topic_name() prev_topic_name = message.topic_name()
# Make sure that the latest entry in the history corresponds to the # Make sure that the latest entry in the history corresponds to the
# message's last edit time # message's last edit time
@@ -48,13 +48,13 @@ def fill_edit_history_entries(
"content": prev_content, "content": prev_content,
"rendered_content": prev_rendered_content, "rendered_content": prev_rendered_content,
"timestamp": edit_history_event["timestamp"], "timestamp": edit_history_event["timestamp"],
"topic": prev_topic, "topic": prev_topic_name,
"user_id": edit_history_event["user_id"], "user_id": edit_history_event["user_id"],
} }
if "prev_topic" in edit_history_event: if "prev_topic" in edit_history_event:
prev_topic = edit_history_event["prev_topic"] prev_topic_name = edit_history_event["prev_topic"]
formatted_entry["prev_topic"] = prev_topic formatted_entry["prev_topic"] = prev_topic_name
# Fill current values for content/rendered_content. # Fill current values for content/rendered_content.
if "prev_content" in edit_history_event: if "prev_content" in edit_history_event:
@@ -79,7 +79,7 @@ def fill_edit_history_entries(
"content": prev_content, "content": prev_content,
"rendered_content": prev_rendered_content, "rendered_content": prev_rendered_content,
"timestamp": datetime_to_timestamp(message.date_sent), "timestamp": datetime_to_timestamp(message.date_sent),
"topic": prev_topic, "topic": prev_topic_name,
"user_id": message.sender_id, "user_id": message.sender_id,
} }