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

Qf siddur #789

Merged
merged 17 commits into from
Mar 23, 2022
Merged
Show file tree
Hide file tree
Changes from 16 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
3 changes: 3 additions & 0 deletions reader/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1935,12 +1935,15 @@ def _internal_do_delete(request, link_id_or_ref, uid):

j = json.loads(j)
skip_check = request.GET.get("skip_lang_check", 0)
override_preciselink = request.GET.get("override_preciselink", 0)
if isinstance(j, list):
res = []
for i in j:
try:
if skip_check:
i["_skip_lang_check"] = True
if override_preciselink:
i["_override_preciselink"] = True
retval = _internal_do_post(request, i, uid, **kwargs)
res.append({"status": "ok. Link: {} | {} Saved".format(retval["ref"], retval["anchorRef"])})
except Exception as e:
Expand Down
42 changes: 33 additions & 9 deletions sefaria/model/link.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,20 +90,39 @@ def _validate(self):
def _pre_save(self):
if getattr(self, "_id", None) is None:
# Don't bother saving a connection that already exists, or that has a more precise link already
if self.refs != sorted(self.refs) and hasattr(self, 'charLevelData'):
self.charLevelData.reverse()
orig_refs = self.refs
self.refs = sorted(self.refs) #make sure ref order is deterministic
if orig_refs != self.refs and getattr(self, "versions", False) and getattr(self, "displayedText", False):
#if reversed self.refs, make sure to reverse self.versions and self.displayedText
self.versions = self.versions[::-1]
self.displayedText = self.displayedText[::-1]
if self.refs != sorted(self.refs):
if hasattr(self, 'charLevelData'):
self.charLevelData.reverse()
if getattr(self, "versions", False) and getattr(self, "displayedText", False):
# if reversed self.refs, make sure to reverse self.versions and self.displayedText
self.versions = self.versions[::-1]
self.displayedText = self.displayedText[::-1]
self.refs = sorted(self.refs) # make sure ref order is deterministic
samelink = Link().load({"refs": self.refs})

if not samelink:
#check for samelink section level vs ranged ref
oref0 = text.Ref(self.refs[0])
oref1 = text.Ref(self.refs[1])
section0 = oref0.section_ref()
section1 = oref1.section_ref()
if oref0.is_range() and oref0.all_segment_refs() == section0.all_segment_refs():
samelink = Link.load({"$and": [{"refs": section0}, {"refs": self.refs[1]}]})
elif oref0.is_section_level():
ranged0 = text.Ref(f"{oref0.all_segment_refs()[0]}-{oref0.all_segment_refs()[-1]}")
samelink = Link.load({"$and": [{"refs": ranged0}, {"refs": self.refs[1]}]})
elif oref1.is_range() and oref1.all_segment_refs() == section1.all_segment_refs(): # this is an elif since it anyway overrides the samelink see note in 4 lines
samelink = Link.load({"$and": [{"refs": section1}, {"refs": self.refs[0]}]})
elif oref1.is_section_level():
ranged1 = text.Ref(f"{oref1.all_segment_refs()[0]}-{oref1.all_segment_refs()[-1]}")
samelink = Link.load({"$and": [{"refs": ranged1}, {"refs": self.refs[0]}]})
#note: The above code neglects the case where both refs in the link are section or ranged and there is a ranged/section link in the db with the opposite situation on both refs.

if samelink:
if hasattr(self, 'score') and hasattr(self, 'charLevelData'):
samelink.score = self.score
samelink.charLevelData = self.charLevelData
samelink.save()
raise DuplicateRecordError("Updated existing link with the new score and charLevelData data")

elif not self.auto and self.type and not samelink.type:
Expand All @@ -130,7 +149,12 @@ def _pre_save(self):

if preciselink:
# logger.debug("save_link: More specific link exists: " + link["refs"][1] + " and " + preciselink["refs"][1])
raise DuplicateRecordError("A more precise link already exists: {} - {}".format(preciselink.refs[0], preciselink.refs[1]))
if getattr(self, "_override_preciselink", False):
preciselink.delete()
self.generated_by = self.generated_by+'_preciselink_override'
#and the new link will be posted (supposedly)
else:
raise DuplicateRecordError("A more precise link already exists: {} - {}".format(preciselink.refs[0], preciselink.refs[1]))
# else: # this is a good new link

if not getattr(self, "_skip_lang_check", False):
Expand Down
5 changes: 3 additions & 2 deletions static/css/s2.css
Original file line number Diff line number Diff line change
Expand Up @@ -5171,7 +5171,7 @@ body .ui-autocomplete.dictionary-toc-autocomplete .ui-menu-item a.ui-state-focus
color: var(--inline-link-blue);
}
.segment .he sup {
font-size: 0.5em;
font-size: 0.6em;
}
.segment sup:hover {
text-decoration: underline;
Expand All @@ -5188,7 +5188,7 @@ body .ui-autocomplete.dictionary-toc-autocomplete .ui-menu-item a.ui-state-focus
.segment sup.itag {
text-decoration: none;
font-family: var(--hebrew-sans-serif-font-family);
font-size: 0.6em;
font-size: 0.5em;
line-height: 1;
color: var(--inline-link-blue);
}
Expand Down Expand Up @@ -6131,6 +6131,7 @@ body .ui-autocomplete.dictionary-toc-autocomplete .ui-menu-item a.ui-state-focus
.textListTextRangeBox {
position: relative;
}

.textListTextRangeBox .textRange{
margin-bottom: 0;
padding-bottom: 0;
Expand Down
5 changes: 3 additions & 2 deletions static/js/TextList.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import Sefaria from './sefaria/sefaria';
import PropTypes from 'prop-types';
import TextRange from './TextRange';
import Component from 'react-class';

import classNames from 'classnames';

class TextList extends Component {
constructor(props) {
Expand Down Expand Up @@ -216,7 +216,8 @@ class TextList extends Component {
key={i + link.anchorRef} />);
} else {
var hideTitle = link.category === "Commentary" && this.props.filter[0] !== "Commentary";
return (<div className="textListTextRangeBox" key={i + link.sourceRef}>
const classes = classNames({ textListTextRangeBox: 1, typeQF: link.type.startsWith('quotation_auto')});
return (<div className={classes} key={i + link.sourceRef}>
<TextRange
panelPosition ={this.props.panelPosition}
sref={link.sourceRef}
Expand Down