Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Staging #499

Merged
merged 8 commits into from
Feb 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
139 changes: 30 additions & 109 deletions reader/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,6 @@ def catchall(request, tref, sheet=None):
def reader_redirect(uref):
# Redirect to standard URLs
url = "/" + uref
print("url>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>", url)
response = redirect(iri_to_uri(url), permanent=True)
params = request.GET.urlencode()
response['Location'] += "?%s" % params if params else ""
Expand Down Expand Up @@ -1557,69 +1556,29 @@ def _get_text(oref, versionEn=versionEn, versionHe=versionHe, commentary=comment

return text

text_ref = Ref(tref)
text_title = text_ref.index.get_title("en")
if request.user.is_authenticated:
user_group_text_list = library.get_text_permission_group(request.user.email)
for user_text in user_group_text_list:
if text_title == user_text['title']:
if not multiple or abs(multiple) == 1:
text = _get_text(oref, versionEn=versionEn, versionHe=versionHe, commentary=commentary, context=context,
pad=pad,
alts=alts, wrapLinks=wrapLinks, layer_name=layer_name)
return jsonResponse(text, cb)
else:
# Return list of many sections
assert multiple != 0
direction = "next" if multiple > 0 else "prev"
target_count = abs(multiple)

current = 0
texts = []

while current < target_count:
text = _get_text(oref, versionEn=versionEn, versionHe=versionHe, commentary=commentary, context=context,
pad=pad,
alts=alts, wrapLinks=wrapLinks, layer_name=layer_name)
texts += [text]
if not text[direction]:
break
oref = Ref(text[direction])
current += 1
return jsonResponse(texts, cb)
if not multiple or abs(multiple) == 1:
text = _get_text(oref, versionEn=versionEn, versionHe=versionHe, commentary=commentary, context=context,
pad=pad,
alts=alts, wrapLinks=wrapLinks, layer_name=layer_name)
return jsonResponse(text, cb)
else:
email = request.GET.get("email", None)
group_text_list = library.get_text_permission_group(email)
for text in group_text_list:
if text_title == text['title']:
if not multiple or abs(multiple) == 1:
text = _get_text(oref, versionEn=versionEn, versionHe=versionHe, commentary=commentary, context=context,
pad=pad,
alts=alts, wrapLinks=wrapLinks, layer_name=layer_name)
return jsonResponse(text, cb)
else:
# Return list of many sections
assert multiple != 0
direction = "next" if multiple > 0 else "prev"
target_count = abs(multiple)

current = 0
texts = []

while current < target_count:
text = _get_text(oref, versionEn=versionEn, versionHe=versionHe, commentary=commentary, context=context,
pad=pad,
alts=alts, wrapLinks=wrapLinks, layer_name=layer_name)
texts += [text]
if not text[direction]:
break
oref = Ref(text[direction])
current += 1
return jsonResponse(texts, cb)


return jsonResponse({"error": f"You do not have access permission to this text"}, cb)

# Return list of many sections
assert multiple != 0
direction = "next" if multiple > 0 else "prev"
target_count = abs(multiple)
current = 0
texts = []
while current < target_count:
text = _get_text(oref, versionEn=versionEn, versionHe=versionHe, commentary=commentary, context=context,
pad=pad,
alts=alts, wrapLinks=wrapLinks, layer_name=layer_name)
texts += [text]
if not text[direction]:
break
oref = Ref(text[direction])
current += 1
return jsonResponse(texts, cb)

if request.method == "POST":
j = request.POST.get("json")
if not j:
Expand Down Expand Up @@ -1805,33 +1764,13 @@ def index_api(request, title, raw=False):
API for manipulating text index records (aka "Text Info")
"""
if request.method == "GET":
if request.user.is_authenticated:
user_group_text_list = library.get_text_permission_group(request.user.email)
for user_text in user_group_text_list:
if title == user_text['title']:
with_content_counts = bool(request.GET.get("with_content_counts", False))
i = library.get_index(title).contents(raw=raw, with_content_counts=with_content_counts)

if request.GET.get("with_related_topics", False):
i["relatedTopics"] = get_topics_for_book(title, annotate=True)

return jsonResponse(i, callback=request.GET.get("callback", None))
return jsonResponse({"error":f"Either Index is not available OR You are not allowed to access."}, callback=request.GET.get("callback", None))
else:
email = request.GET.get("email", None)
user_group_text_list = library.get_text_permission_group(email)
for user_text in user_group_text_list:
if title == user_text['title']:
with_content_counts = bool(request.GET.get("with_content_counts", False))
i = library.get_index(title).contents(raw=raw, with_content_counts=with_content_counts)

if request.GET.get("with_related_topics", False):
i["relatedTopics"] = get_topics_for_book(title, annotate=True)

return jsonResponse(i, callback=request.GET.get("callback", None))
return jsonResponse({"error":f"Either Index is not available OR You are not allowed to access."}, callback=request.GET.get("callback", None))


with_content_counts = bool(request.GET.get("with_content_counts", False))
i = library.get_index(title).contents(raw=raw, with_content_counts=with_content_counts)
if request.GET.get("with_related_topics", False):
i["relatedTopics"] = get_topics_for_book(title, annotate=True)
return jsonResponse(i, callback=request.GET.get("callback", None))


if request.method == "POST":
# use the update function if update is in the params
Expand Down Expand Up @@ -2376,26 +2315,8 @@ def versions_api(request, tref):
API for retrieving available text versions list of a ref.
"""
oref = Ref(tref)
email = request.GET.get("email", None)
versions = []
if request.user.is_authenticated:
group_text_list = library.get_text_permission_group(request.user.email)
for text in group_text_list:
if str(text['title']) == str(oref):

versions = oref.version_list()
return jsonResponse(versions, callback=request.GET.get("callback", None))
return jsonResponse(versions, callback=request.GET.get("callback", None))

else:
email = request.GET.get("email", None)
group_text_list = library.get_text_permission_group(email)
for text in group_text_list:
if str(text['title']) == str(oref):
versions = oref.version_list()
return jsonResponse(versions, callback=request.GET.get("callback", None))

return jsonResponse(versions, callback=request.GET.get("callback", None))
versions = oref.version_list()
return jsonResponse(versions, callback=request.GET.get("callback", None))


@catch_error_as_json
Expand Down
11 changes: 1 addition & 10 deletions sefaria/client/wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,10 +196,6 @@ def get_links(tref, with_text=True, with_sheet_links=False):
if node_depth is None or len(source_ref.sections) + 1 < node_depth:
continue

linkPos = (pos + 1) % 2
linkTref = link.refs[linkPos]
linkRef = Ref(linkTref)

com = format_link_object_for_client(link, False, nRef, pos)
except InputError:
logger.warning("Bad link: {} - {}".format(link.refs[0], link.refs[1]))
Expand Down Expand Up @@ -289,12 +285,7 @@ def get_links(tref, with_text=True, with_sheet_links=False):
com[versionAttr] = versions
com[licenseAttr] = licenses
com[vtitleInHeAttr] = versionTitlesInHebrew

user_email = get_current_user()
text_list = library.get_text_permission_group(user_email)
for text in text_list:
if linkRef.index.get_title("en") == text['title']:
links.append(com)
links.append(com)
except NoVersionFoundError as e:
logger.warning("Trying to get non existent text for ref '{}'. Link refs were: {}".format(top_nref, link.refs))
continue
Expand Down
18 changes: 3 additions & 15 deletions sefaria/model/category.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
from . import schema as schema
from . import text as text
from . import collection as collection
from sefaria.system.middleware import get_current_user


class Category(abstract.AbstractMongoRecord, schema.AbstractTitledOrTermedObject):
Expand Down Expand Up @@ -319,19 +318,9 @@ def _add_category(self, cat):
try:
from sefaria.model import library
tc = TocCategory(category_object=cat)
user_email = get_current_user()
all_cats = [] # store previously loaded path
text_list = library.get_text_permission_group(user_email)
for c in text_list:
cat_subsets = [c['category'][:i] for i in range(1, len(c['category']) + 1)]
if cat.path in cat_subsets and cat.path not in all_cats:
all_cats.append(cat.path)
parent = self._path_hash[tuple(cat.path[:-1])] if len(cat.path[:-1]) else self._root
parent.append(tc)
self._path_hash[tuple(cat.path)] = tc
# parent = self._path_hash[tuple(cat.path[:-1])] if len(cat.path[:-1]) else self._root
# parent.append(tc)
# self._path_hash[tuple(cat.path)] = tc
parent = self._path_hash[tuple(cat.path[:-1])] if len(cat.path[:-1]) else self._root
parent.append(tc)
self._path_hash[tuple(cat.path)] = tc
except KeyError:
logger.warning(f"Failed to find parent category for {'/'.join(cat.path)}")

Expand Down Expand Up @@ -519,7 +508,6 @@ def __init__(self, serial=None, **kwargs):
self.order = self._index_object.order[0]

def get_index_object(self):
print("index >>>>>>>>>>>>>>>>>>>>>>>>", self._index_object)
return self._index_object

optional_param_keys = [
Expand Down
6 changes: 3 additions & 3 deletions sefaria/model/text.py
Original file line number Diff line number Diff line change
Expand Up @@ -5077,7 +5077,7 @@ def set_last_cached_time(self):
self.last_cached = time.time() # just use the unix timestamp, we dont need any fancy timezone faffing, just objective point in time.
scache.set_shared_cache_elem("last_cached", self.last_cached)

def get_toc(self, rebuild=True):
def get_toc(self, rebuild=False):
"""
Returns the ToC Tree from the cache, DB or by generating it, as needed.
"""
Expand All @@ -5090,7 +5090,7 @@ def get_toc(self, rebuild=True):
self.set_last_cached_time()
return self._toc

def get_toc_json(self, rebuild=True):
def get_toc_json(self, rebuild=False):
"""
Returns as JSON representation of the ToC. This is generated on Library start up as an
optimization for the API, to allow retrieval of the data with a single call.
Expand All @@ -5104,7 +5104,7 @@ def get_toc_json(self, rebuild=True):
self.set_last_cached_time()
return self._toc_json

def get_toc_tree(self, rebuild=True, mobile=False):
def get_toc_tree(self, rebuild=False, mobile=False):
"""
:param mobile: (Aug 30, 2021) Added as a patch after navigation redesign launch. Currently only adds
'firstSection' to toc for mobile export. This field is no longer required on prod but is still required
Expand Down
2 changes: 1 addition & 1 deletion static/js/BookPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ class BookPage extends Component {
const heTitle = index ? index.heTitle : title;
const category = this.props.category;
const isDictionary = this.state.indexDetails && !!this.state.indexDetails.lexiconName;
const categories = Sefaria.index(this.props.title)? Sefaria.index(this.props.title).categories : [];
const categories = Sefaria.index(this.props.title).categories;
let currObjectVersions = this.state.currObjectVersions;
let catUrl;
if (category == "Commentary") {
Expand Down
1 change: 0 additions & 1 deletion static/js/ReaderApp.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -1109,7 +1109,6 @@ toggleSignUpModal(modalContentKind = SignUpModalKind.Default) {
this.showSaved();

} else if (path.match(/\/texts\/.+/)) {
console.log("my",path)
this.showLibrary(path.slice(7).split("/"));

} else if (path === "/collections") {
Expand Down
15 changes: 5 additions & 10 deletions static/js/TextColumn.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,11 @@ class TextColumn extends Component {

// Set on mount, so placeholders aren't rendered server side to prevent intial layout shift
this.setState({showScrollPlaceholders: true});
if (Sefaria.index(this.props.bookTitle)) {
const params = {
content_type: Sefaria.index(this.props.bookTitle).primary_category,
item_id: this.props.bookTitle
}
console.log("primary: ", Sefaria.index(this.props.bookTitle))
gtag("event", "select_content", params)
} else {
gtag("event", "select_content", {})
}
const params = {
content_type: Sefaria.index(this.props.bookTitle).primary_category,
item_id: this.props.bookTitle
}
gtag("event", "select_content", params)


this.node.addEventListener("scroll", this.handleScroll);
Expand Down