Skip to content

Commit

Permalink
Merge branch 'bug/sc-20301/non-normalized-dates-in-indices-and-perhap…
Browse files Browse the repository at this point in the history
…s' into normalizeddates
  • Loading branch information
stevekaplan123 committed Sep 13, 2023
2 parents 8fe2748 + f0aceac commit 755415d
Show file tree
Hide file tree
Showing 31 changed files with 1,157 additions and 592 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ node_modules
#####################
venv/
.python-version
.node-version

# Partner files #
#################
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,9 @@ data:
# GLOBAL_INTERRUPTING_MESSAGE = None
STRAPI_LOCATION = os.getenv("STRAPI_LOCATION")
STRAPI_PORT = os.getenv("STRAPI_PORT")
structlog.configure(
processors=[
structlog.stdlib.filter_by_level,
Expand Down
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"cheerio": "^0.22.0",
"classnames": "^2.2.5",
"cookie-parser": "^1.4.2",
"core-js": "^3.15.2",
"core-js": "^3.31.1",
"css-modules-require-hook": "^4.2.3",
"deep-merge": "^1.0.0",
"diff-match-patch": "^1.0.0",
Expand Down
38 changes: 0 additions & 38 deletions reader/browsertest/framework/elements.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,13 +344,6 @@ def scroll_nav_panel_to_bottom(self):
# Initial Setup
################

def set_modal_cookie(self):
# # set cookie to avoid popup interruption
# # We now longer set the welcomeToS2LoggedOut message by default.
# # TODO is this method still needed? YES
# pass
self.driver.add_cookie({"name": "welcomeToS2LoggedOut", "value": "true"})

def set_cookies_cookie(self):
# set cookie to avoid popup interruption
# We now longer set the welcomeToS2LoggedOut message by default.
Expand All @@ -364,37 +357,6 @@ def click_accept_cookies(self):
except NoSuchElementException:
pass

def close_modal_popup(self):
"""
:return: Boolean - did we manage to close the popup?
"""
message = self.driver.execute_script('return Sefaria.interruptingMessage')
if not message:
return True

time.sleep(3)
try:
self.driver.find_element_by_css_selector('#interruptingMessage #interruptingMessageClose')
self.click('#interruptingMessage #interruptingMessageClose')
return True
except NoSuchElementException:
pass

try:
self.driver.find_element_by_css_selector('#bannerMessageClose')
self.click('#bannerMessageClose')
return True
except NoSuchElementException:
return False

def close_popup_with_accept(self):
try:
alert = self.driver.switch_to.alert
alert.accept()
except NoAlertPresentException:
print('A <<NoAlertPresentException>> was thrown')
pass

# Login
#########

Expand Down
25 changes: 7 additions & 18 deletions reader/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
from sefaria.image_generator import make_img_http_response
import sefaria.tracker as tracker

from sefaria.settings import NODE_TIMEOUT, DEBUG, GLOBAL_INTERRUPTING_MESSAGE
from sefaria.settings import NODE_TIMEOUT, DEBUG
from sefaria.model.category import TocCollectionNode
from sefaria.model.abstract import SluggedAbstractMongoRecord
from sefaria.utils.calendars import parashat_hashavua_and_haftara
Expand Down Expand Up @@ -197,14 +197,14 @@ def base_props(request):

if request.user.is_authenticated:
profile = UserProfile(user_obj=request.user)
interrupting_message_dict = GLOBAL_INTERRUPTING_MESSAGE or {"name": profile.interrupting_message()}
user_data = {
"_uid": request.user.id,
"_email": request.user.email,
"_uses_new_editor": getattr(profile, "uses_new_editor", False),
"slug": profile.slug if profile else "",
"is_moderator": request.user.is_staff,
"is_editor": UserWrapper(user_obj=request.user).has_permission_group("Editors"),
"is_sustainer": profile.is_sustainer,
"full_name": profile.full_name,
"profile_pic_url": profile.profile_pic_url,
"is_history_enabled": profile.settings.get("reading_history", True),
Expand All @@ -216,8 +216,7 @@ def base_props(request):
"notificationCount": profile.unread_notification_count(),
"notifications": profile.recent_notifications().client_contents(),
"saved": {"loaded": False, "items": profile.get_history(saved=True, secondary=False, serialized=True, annotate=False)}, # saved is initially loaded without text annotations so it can quickly immediately mark any texts/sheets as saved, but marks as `loaded: false` so the full annotated data will be requested if the user visits the saved/history page
"last_place": profile.get_history(last_place=True, secondary=False, sheets=False, serialized=True),
"interruptingMessage": InterruptingMessage(attrs=interrupting_message_dict, request=request).contents(),
"last_place": profile.get_history(last_place=True, secondary=False, sheets=False, serialized=True)
}
else:
user_data = {
Expand All @@ -226,6 +225,7 @@ def base_props(request):
"slug": "",
"is_moderator": False,
"is_editor": False,
"is_sustainer": False,
"full_name": "",
"profile_pic_url": "",
"is_history_enabled": True,
Expand All @@ -237,8 +237,7 @@ def base_props(request):
"notificationCount": 0,
"notifications": [],
"saved": {"loaded": False, "items": []},
"last_place": [],
"interruptingMessage": InterruptingMessage(attrs=GLOBAL_INTERRUPTING_MESSAGE, request=request).contents(),
"last_place": []
}
user_data.update({
"last_cached": library.get_last_cached_time(),
Expand Down Expand Up @@ -3113,7 +3112,8 @@ def add_new_topic_api(request):

t.description_published = True
t.data_source = "sefaria" # any topic edited manually should display automatically in the TOC and this flag ensures this
t.change_description(data["description"], data.get("catDescription", None))
if "description" in data:
t.change_description(data["description"], data.get("categoryDescription", None))
t.save()

library.build_topic_auto_completer()
Expand Down Expand Up @@ -3166,8 +3166,6 @@ def topics_api(request, topic, v2=False):
topic_obj = Topic().load({'slug': topic_data["origSlug"]})
topic_data["manual"] = True
author_status_changed = (topic_data["category"] == "authors") ^ (topic_data["origCategory"] == "authors")
if topic_data["category"] == topic_data["origCategory"]:
topic_data.pop("category") # no need to check category in update_topic
topic_obj = update_topic(topic_obj, **topic_data)
if author_status_changed:
library.build_topic_auto_completer()
Expand Down Expand Up @@ -3770,15 +3768,6 @@ def my_profile(request):
url += "?tab=" + request.GET.get("tab")
return redirect(url)


def interrupting_messages_read_api(request, message):
if not request.user.is_authenticated:
return jsonResponse({"error": "You must be logged in to use this API."})
profile = UserProfile(id=request.user.id)
profile.mark_interrupting_message_read(message)
return jsonResponse({"status": "ok"})


@login_required
@ensure_csrf_cookie
def edit_profile(request):
Expand Down
36 changes: 22 additions & 14 deletions sefaria/helper/topic.py
Original file line number Diff line number Diff line change
Expand Up @@ -1060,35 +1060,43 @@ def update_authors_place_and_time(topic_obj, data, dataSource='learning-team-edi

return topic_obj

def update_properties(topic_obj, dataSource, k, v):
if v == '':
topic_obj.properties.pop(k, None)
else:
topic_obj.properties[k] = {'value': v, 'dataSource': dataSource}

def update_author_era(topic_obj, data, dataSource='learning-team-editing-tool'):
for k in ["birthYear", "deathYear"]:
year = data.get(k, '')
topic_obj.properties[k] = {'value': year, 'dataSource': dataSource}

prev_era = topic_obj.properties.get('era', {}).get('value')
if data.get('era', '') != '' and prev_era != data['era']:
topic_obj.properties['era'] = {'value': data['era'], 'dataSource': dataSource}
create_era_link(topic_obj, prev_era_to_delete=prev_era)
if k in data.keys(): # only change property value if key is in data, otherwise it indicates no change
year = data[k]
update_properties(topic_obj, dataSource, k, year)

if 'era' in data.keys(): # only change property value if key is in data, otherwise it indicates no change
prev_era = topic_obj.properties.get('era', {}).get('value')
era = data['era']
update_properties(topic_obj, dataSource, 'era', era)
if era != '':
create_era_link(topic_obj, prev_era_to_delete=prev_era)
return topic_obj


def update_topic(topic_obj, **kwargs):
"""
Can update topic object's title, hebrew title, category, description, and categoryDescription fields
:param topic_obj: (Topic) The topic to update
:param **kwargs can be title, heTitle, category, description, catDescription, and rebuild_toc where `title`, `heTitle`,
and `category` are strings. `description` and `catDescription` are dictionaries where the fields are `en` and `he`.
:param **kwargs can be title, heTitle, category, description, categoryDescription, and rebuild_toc where `title`, `heTitle`,
and `category` are strings. `description` and `categoryDescription` are dictionaries where the fields are `en` and `he`.
The `category` parameter should be the slug of the new category. `rebuild_topic_toc` is a boolean and is assumed to be True
:return: (model.Topic) The modified topic
"""
old_category = ""
orig_slug = topic_obj.slug

update_topic_titles(topic_obj, kwargs)
if kwargs.get('catSlug') == 'authors':
if kwargs.get('category') == 'authors':
topic_obj = update_authors_place_and_time(topic_obj, kwargs)

if 'category' in kwargs:
if 'category' in kwargs and kwargs['category'] != kwargs['origCategory']:
orig_link = IntraTopicLink().load({"linkType": "displays-under", "fromTopic": topic_obj.slug, "toTopic": {"$ne": topic_obj.slug}})
old_category = orig_link.toTopic if orig_link else Topic.ROOT
if old_category != kwargs['category']:
Expand All @@ -1098,8 +1106,8 @@ def update_topic(topic_obj, **kwargs):
topic_obj.data_source = "sefaria" # any topic edited manually should display automatically in the TOC and this flag ensures this
topic_obj.description_published = True

if "description" in kwargs:
topic_obj.change_description(kwargs["description"], kwargs.get("catDescription", None))
if "description" in kwargs or "categoryDescription" in kwargs:
topic_obj.change_description(kwargs.get("description", None), kwargs.get("categoryDescription", None))

topic_obj.save()

Expand Down
4 changes: 3 additions & 1 deletion sefaria/local_settings_ci.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
MAINTENANCE_MESSAGE = ""
GLOBAL_WARNING = False
GLOBAL_WARNING_MESSAGE = ""
# GLOBAL_INTERRUPTING_MESSAGE = None


SECRET_KEY = 'insert your long random secret key here !'
Expand Down Expand Up @@ -194,6 +193,9 @@
}
}

STRAPI_LOCATION = None
STRAPI_PORT = None

structlog.configure(
processors=[
structlog.stdlib.filter_by_level,
Expand Down
14 changes: 4 additions & 10 deletions sefaria/local_settings_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,16 +132,10 @@
DOWN_FOR_MAINTENANCE = False
MAINTENANCE_MESSAGE = ""

# GLOBAL_INTERRUPTING_MESSAGE = None
"""
GLOBAL_INTERRUPTING_MESSAGE = {
"name": "messageName",
"repetition": 1,
"is_fundraising": True,
"style": "modal" # "modal" or "banner"
"condition": {"returning_only": True}
}
"""
# Location of Strapi CMS instance
# For local development, Strapi is located at http://localhost:1337 by default
STRAPI_LOCATION = None
STRAPI_PORT = None


MANAGERS = ADMINS
Expand Down
1 change: 0 additions & 1 deletion sefaria/model/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
from .layer import Layer, LayerSet
from .notification import Notification, NotificationSet, GlobalNotification, GlobalNotificationSet
from .trend import get_session_traits
from .interrupting_message import InterruptingMessage
from .queue import IndexQueue, IndexQueueSet
from .lock import Lock, LockSet, set_lock, release_lock, check_lock, expire_locks
from .following import FollowRelationship, FollowersSet, FolloweesSet
Expand Down
81 changes: 0 additions & 81 deletions sefaria/model/interrupting_message.py

This file was deleted.

Loading

0 comments on commit 755415d

Please sign in to comment.