Skip to content

Commit 2d0d584

Browse files
committed
Merge branch 'master' into rtl-client
2 parents 580678f + 5eb3afb commit 2d0d584

File tree

9 files changed

+70
-55
lines changed

9 files changed

+70
-55
lines changed

scripts/scheduled/metrics.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@
2121
contributors = len(contributors)
2222

2323
# Number of Links
24-
links = db.links.count()
24+
links = db.links.count_documents({})
2525

2626
# Number of Source sheets
27-
sheets = db.sheets.count()
27+
sheets = db.sheets.count_documents({})
2828

2929
metrics = {
3030
"timestamp": datetime.datetime.now().replace(hour=0, minute=0, second=0, microsecond=0),
@@ -37,6 +37,6 @@
3737
}
3838

3939
try:
40-
db.metrics.save(metrics)
40+
db.metrics.insert_one(metrics)
4141
except DuplicateKeyError:
4242
pass

sefaria/model/text.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -1029,7 +1029,11 @@ class AbstractTextRecord(object):
10291029

10301030
def word_count(self):
10311031
""" Returns the number of words in this text """
1032-
return self.ja(remove_html=True).word_count()
1032+
try:
1033+
wc = self.ja(remove_html=True).word_count()
1034+
except AttributeError:
1035+
wc = 0
1036+
return wc
10331037

10341038
def char_count(self):
10351039
""" Returns the number of characters in this text """

sefaria/system/exceptions.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -108,5 +108,5 @@ def __init__(self, book_ref):
108108
f"'{book_ref}' is a \'complex\' book-level ref. We only support book-level "
109109
f"refs in cases of texts with a 'simple' structure. To learn more about the "
110110
f"structure of a text on Sefaria, "
111-
f"see: https://developers.sefaria.org/docs/the-schema-of-a-simple-text")
111+
f"see: https://developers.sefaria.org/docs/the-structure-of-a-simple-text")
112112
super().__init__(self.message)

static/js/NewsletterSignUpForm.jsx

+3-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export function NewsletterSignUpForm({
66
includeEducatorOption = true,
77
emailPlaceholder = {en: 'Sign up for Newsletter', he: "הרשמו לניוזלטר"},
88
subscribe=Sefaria.subscribeSefariaNewsletter, // function which sends form data to API to subscribe
9+
additionalNewsletterMailingLists = [],
910
}) {
1011
const [email, setEmail] = useState('');
1112
const [firstName, setFirstName] = useState('');
@@ -24,15 +25,15 @@ export function NewsletterSignUpForm({
2425
if (showNameInputs === true) { // submit
2526
if (firstName.length > 0 && lastName.length > 0) {
2627
setSubscribeMessage("Subscribing...");
27-
subscribe(firstName, lastName, email, educatorCheck).then(res => {
28+
subscribe(firstName, lastName, email, educatorCheck, additionalNewsletterMailingLists).then(res => {
2829
setSubscribeMessage("Subscribed! Welcome to our list.");
2930
Sefaria.track.event("Newsletter", "Subscribe from " + contextName, "");
3031
}).catch(error => {
3132
setSubscribeMessage(error?.message || "Sorry, there was an error.");
3233
setShowNameInputs(false);
3334
});
3435
} else {
35-
setSubscribeMessage("Please enter a valid first and last name");// get he copy
36+
setSubscribeMessage("Please enter a valid first and last name");
3637
}
3738
} else if (Sefaria.util.isValidEmailAddress(email)) {
3839
setShowNameInputs(true);

static/js/Promotions.jsx

+47-34
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import classNames from "classnames";
44
import Sefaria from "./sefaria/sefaria";
55
import {EnglishText, HebrewText, InterfaceText, OnInView} from "./Misc";
66
import $ from "./sefaria/sefariaJquery";
7+
import { NewsletterSignUpForm } from "./NewsletterSignUpForm";
78

89
const Promotions = () => {
910
const [inAppAds, setInAppAds] = useState(Sefaria._inAppAds); // local cache
@@ -36,6 +37,11 @@ const Promotions = () => {
3637
buttonIcon: sidebarAd.buttonIcon,
3738
buttonLocation: sidebarAd.buttonAboveOrBelow,
3839
hasBlueBackground: sidebarAd.hasBlueBackground,
40+
isNewsletterSubscriptionInputForm: sidebarAd.isNewsletterSubscriptionInputForm,
41+
newsletterMailingLists:
42+
sidebarAd.newsletterMailingLists?.data.map(
43+
(mailingLists) => mailingLists.attributes.newsletterName
44+
) ?? [],
3945
trigger: {
4046
showTo: sidebarAd.showTo,
4147
interfaceLang: "english",
@@ -209,40 +215,47 @@ const SidebarAd = React.memo(({ context, matchingAd }) => {
209215
);
210216
}
211217

212-
return (
213-
<OnInView onVisible={() => trackSidebarAdImpression(matchingAd)}>
214-
<div className={classes}>
215-
<h3
216-
className={context.interfaceLang === "hebrew" ? "int-he" : "int-en"}
217-
>
218-
{matchingAd.title}
219-
</h3>
220-
{matchingAd.buttonLocation === "below" ? (
221-
<>
222-
<p
223-
className={
224-
context.interfaceLang === "hebrew" ? "int-he" : "int-en"
225-
}
226-
>
227-
{matchingAd.bodyText}
228-
</p>
229-
{getButton()}
230-
</>
231-
) : (
232-
<>
233-
{getButton()}
234-
<p
235-
className={
236-
context.interfaceLang === "hebrew" ? "int-he" : "int-en"
237-
}
238-
>
239-
{matchingAd.bodyText}
240-
</p>
241-
</>
242-
)}
243-
</div>
244-
</OnInView>
245-
);
218+
const isHebrew = context.interfaceLang === "hebrew";
219+
const getLanguageClass = () => (isHebrew ? "int-he" : "int-en");
220+
221+
return (
222+
<OnInView onVisible={() => trackSidebarAdImpression(matchingAd)}>
223+
<div className={classes}>
224+
<h3 className={getLanguageClass()}>{matchingAd.title}</h3>
225+
{matchingAd.buttonLocation === "below" ? (
226+
matchingAd.isNewsletterSubscriptionInputForm ? (
227+
<>
228+
<p className={getLanguageClass()}>{matchingAd.bodyText}</p>
229+
<NewsletterSignUpForm
230+
context={"Sidebar Ad: " + context.keywordTargets.toString()}
231+
includeEducatorOption={false}
232+
additionalNewsletterMailingLists={matchingAd.newsletterMailingLists}
233+
/>
234+
</>
235+
) : (
236+
<>
237+
<p className={getLanguageClass()}>{matchingAd.bodyText}</p>
238+
{getButton()}
239+
</>
240+
)
241+
) : matchingAd.isNewsletterSubscriptionInputForm ? (
242+
<>
243+
<NewsletterSignUpForm
244+
context={"Sidebar Ad: " + context.keywordTargets.toString()}
245+
includeEducatorOption={false}
246+
additionalNewsletterMailingLists={matchingAd.newsletterMailingLists}
247+
/>
248+
<p className={getLanguageClass()}>{matchingAd.bodyText}</p>
249+
</>
250+
) : (
251+
<>
252+
{getButton()}
253+
<p className={getLanguageClass()}>{matchingAd.bodyText}</p>
254+
</>
255+
)}
256+
</div>
257+
</OnInView>
258+
);
246259
});
247260

248261
export { Promotions, GDocAdvertBox };

static/js/context.js

+8
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,14 @@ function StrapiDataProvider({ children }) {
163163
showTo
164164
startTime
165165
updatedAt
166+
isNewsletterSubscriptionInputForm
167+
newsletterMailingLists {
168+
data {
169+
attributes {
170+
newsletterName
171+
}
172+
}
173+
}
166174
}
167175
}
168176
}

static/js/sefaria/sefaria.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -764,12 +764,13 @@ Sefaria = extend(Sefaria, {
764764
Sefaria._portals[portalSlug] = response;
765765
return response;
766766
},
767-
subscribeSefariaNewsletter: async function(firstName, lastName, email, educatorCheck) {
767+
subscribeSefariaNewsletter: async function(firstName, lastName, email, educatorCheck, lists = []) {
768768
const payload = {
769769
language: Sefaria.interfaceLang === "hebrew" ? "he" : "en",
770770
educator: educatorCheck,
771771
firstName: firstName,
772772
lastName: lastName,
773+
...(lists?.length && { lists }),
773774
};
774775
return await Sefaria.apiRequestWithBody(`/api/subscribe/${email}`, null, payload);
775776
},

static/js/sefaria/strings.js

+1
Original file line numberDiff line numberDiff line change
@@ -502,6 +502,7 @@ const Strings = {
502502
"Please enter a valid email address.": 'כתובת הדוא"ל שהוזנה אינה תקינה.',
503503
"Subscribed! Welcome to our list.": "הרשמה בוצעה בהצלחה!",
504504
"Sorry, there was an error.": "סליחה, ארעה שגיאה",
505+
"Please enter a valid first and last name.": "נא להוסיף שם פרטי ושם משפחה.",
505506

506507
// Footer
507508
"Connect": "צרו קשר",

static/js/sefaria/util.js

-13
Original file line numberDiff line numberDiff line change
@@ -104,19 +104,6 @@ class Util {
104104
};
105105
const postData = {json: JSON.stringify(feedback)};
106106
$.post('/api/send_feedback', postData);
107-
}
108-
static subscribeToNbList(email, lists) {
109-
if (Sefaria.util.isValidEmailAddress(email)) {
110-
$.post("/api/subscribe/" + email + "?lists=" + lists, function(data) {
111-
if ("error" in data) {
112-
console.log(data.error);
113-
} else {
114-
console.log("Subscribed! Welcome to our list.");
115-
}
116-
}).error(data => console.log("Sorry, there was an error."));
117-
} else {
118-
console.log("not valid email address")
119-
}
120107
}
121108
static naturalTimePlural(n, singular, plural) {
122109
return n <= 1 ? singular : plural;

0 commit comments

Comments
 (0)