Ejemplo n.º 1
0
def rename_category(old, new):
    """
    Walk through all index records, replacing every category instance
    called 'old' with 'new'.
    """
    indices = IndexSet({"categories": old})

    assert indices.count(), "No categories named {}".format(old)

    for i in indices:
        i.categories = [new if cat == old else cat for cat in i.categories]
        i.save()

    summaries.update_summaries()
Ejemplo n.º 2
0
def refresh_all_states():
    indices = IndexSet()

    for index in indices:
        if index.is_commentary():
            c_re = "^{} on ".format(index.title)
            texts = VersionSet({"title": {"$regex": c_re}}).distinct("title")
            for text in texts:
                VersionState(text).refresh()
        else:
            VersionState(index).refresh()

    import sefaria.summaries as summaries
    summaries.update_summaries()
Ejemplo n.º 3
0
def rename_category(old, new):
    """
    Walk through all index records, replacing every category instance
    called 'old' with 'new'.
    """
    indices = IndexSet({"categories": old})

    assert indices.count(), "No categories named {}".format(old)

    for i in indices:
        i.categories = [new if cat == old else cat for cat in i.categories]
        i.save()

    summaries.update_summaries()
Ejemplo n.º 4
0
def refresh_all_states():
    indices = IndexSet()

    for index in indices:
        logger.debug(u"Rebuilding state for {}".format(index.title))
        try:
            if index.is_commentary():
                c_re = "^{} on ".format(index.title)
                texts = VersionSet({"title": {"$regex": c_re}}).distinct("title")
                for text in texts:
                    VersionState(text).refresh()
            else:
                VersionState(index).refresh()
        except Exception as e:
            logger.warning(u"Got exception rebuilding state for {}: {}".format(index.title, e))
            

    import sefaria.summaries as summaries
    summaries.update_summaries()
Ejemplo n.º 5
0
def refresh_all_states():
    indices = IndexSet()

    for index in indices:
        logger.debug(u"Rebuilding state for {}".format(index.title))
        try:
            if index.is_commentary():
                c_re = "^{} on ".format(index.title)
                texts = VersionSet({
                    "title": {
                        "$regex": c_re
                    }
                }).distinct("title")
                for text in texts:
                    VersionState(text).refresh()
            else:
                VersionState(index).refresh()
        except Exception as e:
            logger.warning(u"Got exception rebuilding state for {}: {}".format(
                index.title, e))

    import sefaria.summaries as summaries
    summaries.update_summaries()
Ejemplo n.º 6
0
anaBekhoach.categories = [u'Liturgy',u'Piyutim'] #why doesn't update() work on an instance?
anaBekhoach.save()

model.IndexSet({"title":{"$regex": "Rabbah?"}}).update({"categories": ['Midrash', 'Aggadic Midrash', 'Midrash Rabbah']})
#this one should not have been updated.
model.Index().update({'title': 'Tanna Debei Eliyahu Rabbah'}, {'categories': ['Midrash', 'Aggadic Midrash']})

model.IndexSet({'title': {"$regex" : 'Ein Yaakov'}}).update({'categories': ['Midrash', 'Aggadic Midrash']})

model.Index().update({'title': 'Midrash Tanchuma'}, {'categories': ['Midrash', 'Aggadic Midrash']})
model.Index().update({'title': 'Legends of the Jews'}, {'categories': ['Midrash', 'Aggadic Midrash']})
model.Index().update({'title': 'Midrash Mishlei'}, {'categories': ['Midrash', 'Aggadic Midrash']})
model.Index().update({'title': 'Pirkei Derabi Eliezer'}, {'categories': ['Midrash', 'Aggadic Midrash']})
model.Index().update({'title': 'Midrash on Proverbs'}, {'categories': ['Midrash', 'Aggadic Midrash']})
model.Index().update({'title': "Midrash B'not Zelophehad"}, {'categories': ['Midrash', 'Aggadic Midrash']})
model.Index().update({'title': 'Midrash Tehilim'}, {'categories': ['Midrash', 'Aggadic Midrash']})
model.Index().update({'title': 'Pesikta de rav kahana'}, {'categories': ['Midrash', 'Aggadic Midrash']})
model.Index().update({'title': 'The Fathers according to Rabbi Nathan'}, {'categories': ['Midrash', 'Aggadic Midrash']})
model.Index().update({'title': 'Yalkut Shimoni'}, {'categories': ['Midrash', 'Aggadic Midrash']})


model.Index().update({'title': 'Sifra'}, {'categories': ['Midrash', 'Halachic Midrash']})
model.Index().update({'title': "Mekhilta d'Rabbi Yishmael"}, {'categories': ['Midrash', 'Halachic Midrash']})
model.Index().update({'title': 'Mekhilta'}, {'categories': ['Midrash', 'Halachic Midrash']})
model.Index().update({'title': 'Sifre Bamidbar'}, {'categories': ['Midrash', 'Halachic Midrash']})


# Rebuild counts docs, so they get the allVersionCounts field
update_counts()
update_summaries()
Ejemplo n.º 7
0
def rebuild_counts_and_toc(request):
    update_counts()
    update_summaries()
    return HttpResponseRedirect("/?m=Counts-&-TOC-Rebuilt")
Ejemplo n.º 8
0
def rebuild_toc(request):
    update_summaries()
    return HttpResponseRedirect("/?m=TOC-Rebuilt")
Ejemplo n.º 9
0
def reset_cache(request):
    update_summaries()
    return HttpResponse("Cache Reset")
Ejemplo n.º 10
0
def import_from_csv(filename, action="status", category="all"):
    existing_titles = []
    with open(filename, 'rb') as csvfile:
        rows = csv.reader(csvfile)
        header = rows.next()
        for text in rows:
            if not len(text[2]) or not len(text[9]):
                # Require a primary titl and something set in "ready to upload" field
                continue
            new_index = {
                "title":
                text[2].strip(),
                "sectionNames": [s.strip() for s in text[8].split(",")],
                "categories": [s.strip() for s in text[7].split(", ")],
                "titleVariants":
                [text[2].strip()] + [s.strip() for s in text[6].split(", ")],
            }
            if len(text[3]):
                new_index["heTitle"] = text[3].strip()
            if len(text[4]):
                new_index["transliteratedTitle"] = text[4].strip()
                new_index["titleVariants"] += [
                    new_index["transliteratedTitle"]
                ]
                new_index["titleVariants"] = [
                    v for v in new_index["titleVariants"] if v
                ]
            if len(text[10]):
                new_index["length"] = int(text[10])
            if len(text[12]):
                # Only import the last order field for now
                new_index["order"] = [map(int, text[12].split(","))[-1]]

            existing = db.index.find_one({"titleVariants": new_index["title"]})

            if action == "status":
                # Print information about texts listed
                if not existing:
                    print "NEW - " + new_index["title"]
                if existing:
                    if new_index["title"] == existing["title"]:
                        print "EXISTING - " + new_index["title"]
                    else:
                        print "EXISTING (title change) - " + new_index["title"]
                    existing_titles.append(existing["title"])

                validation = texts.validate_index(new_index)
                if "error" in validation:
                    print "*** %s" % validation["error"]

            # Add texts if their category is specified in command line
            if action in ("post", "update") and category:
                if category == "all" or category in new_index["categories"][:2]:
                    print "Saving %s" % new_index["title"]

                    if action == "update":
                        # TOOD remove any fields that have empty values like []
                        # before updating - don't overwrite with nothing
                        new_index.update(existing)

                    tracker.add(1, sefaria.model.index.Index, new_index)

            if action == "hebrew" and existing:
                if "heTitle" not in existing:
                    print "Missing Hebrew: %s" % (existing["title"])
                    existing_titles.append(existing["title"])

    if action == "status":
        indexes = db.index.find()
        for i in indexes:
            if i["title"] not in existing_titles:
                print "NOT ON SHEET - %s" % i["title"]

    if action == "hebrew":
        indexes = db.index.find()
        for i in indexes:
            if "heTitle" not in i and i["title"] not in existing_titles:
                print "Still no Hebrew:  %s" % i["title"]

    if action in ("post", "update"):
        summaries.update_summaries()
        summaries.save_toc_to_db()
Ejemplo n.º 11
0
def import_from_csv(filename, action="status", category="all"):
	existing_titles = []
	with open(filename, 'rb') as csvfile:
		rows = csv.reader(csvfile)
		header = rows.next()
		for text in rows:
			if not len(text[2]) or not len(text[9]): 
				# Require a primary titl and something set in "ready to upload" field
				continue	
			new_index = {
				"title": text[2].strip(),
				"sectionNames": [s.strip() for s in text[8].split(",")],
				"categories": [s.strip() for s in text[7].split(", ")],
				"titleVariants": [text[2].strip()] + [s.strip() for s in  text[6].split(", ")],
			}
			if len(text[3]):
				new_index["heTitle"] = text[3].strip()
			if len(text[4]):
				new_index["transliteratedTitle"] = text[4].strip()
				new_index["titleVariants"] += [new_index["transliteratedTitle"]]
				new_index["titleVariants"] = [v for v in new_index["titleVariants"] if v]
			if len(text[10]):
				new_index["length"] = int(text[10])
			if len(text[12]):
				# Only import the last order field for now
				new_index["order"] = [map(int, text[12].split(","))[-1]] 

			existing = db.index.find_one({"titleVariants": new_index["title"]})

			if action == "status":
				# Print information about texts listed
				if not existing:
					print "NEW - " + new_index["title"]
				if existing:
					if new_index["title"] == existing["title"]:
						print "EXISTING - " + new_index["title"]
					else:
						print "EXISTING (title change) - " + new_index["title"]
					existing_titles.append(existing["title"])

				validation = texts.validate_index(new_index)
				if "error" in validation:
					print "*** %s" % validation["error"]


			# Add texts if their category is specified in command line
			if action in ("post", "update") and category:
				if category == "all" or category in new_index["categories"][:2]:
					print "Saving %s" % new_index["title"]

					if action == "update":
						# TOOD remove any fields that have empty values like []
						# before updating - don't overwrite with nothing
						new_index.update(existing)

					texts.save_index(new_index, 1)
			

			if action == "hebrew" and existing:
				if "heTitle" not in existing:
					print "Missing Hebrew: %s" % (existing["title"])
					existing_titles.append(existing["title"])


	if action == "status":
		indexes = db.index.find()
		for i in indexes:
			if i["title"] not in existing_titles:
				print "NOT ON SHEET - %s" % i["title"]

	if action == "hebrew":
		indexes = db.index.find()
		for i in indexes:
			if "heTitle" not in i and i["title"] not in existing_titles:
				print "Still no Hebrew:  %s" % i["title"]

	if action in ("post", "update"):
		summaries.update_summaries()
		summaries.save_toc_to_db()
Ejemplo n.º 12
0
def reset_cache(request):
    update_summaries()
    return HttpResponse("Cache Reset")
Ejemplo n.º 13
0
                     {'categories': ['Midrash', 'Aggadic Midrash']})
model.Index().update({'title': 'Midrash Mishlei'},
                     {'categories': ['Midrash', 'Aggadic Midrash']})
model.Index().update({'title': 'Pirkei Derabi Eliezer'},
                     {'categories': ['Midrash', 'Aggadic Midrash']})
model.Index().update({'title': 'Midrash on Proverbs'},
                     {'categories': ['Midrash', 'Aggadic Midrash']})
model.Index().update({'title': "Midrash B'not Zelophehad"},
                     {'categories': ['Midrash', 'Aggadic Midrash']})
model.Index().update({'title': 'Midrash Tehilim'},
                     {'categories': ['Midrash', 'Aggadic Midrash']})
model.Index().update({'title': 'Pesikta de rav kahana'},
                     {'categories': ['Midrash', 'Aggadic Midrash']})
model.Index().update({'title': 'The Fathers according to Rabbi Nathan'},
                     {'categories': ['Midrash', 'Aggadic Midrash']})
model.Index().update({'title': 'Yalkut Shimoni'},
                     {'categories': ['Midrash', 'Aggadic Midrash']})

model.Index().update({'title': 'Sifra'},
                     {'categories': ['Midrash', 'Halachic Midrash']})
model.Index().update({'title': "Mekhilta d'Rabbi Yishmael"},
                     {'categories': ['Midrash', 'Halachic Midrash']})
model.Index().update({'title': 'Mekhilta'},
                     {'categories': ['Midrash', 'Halachic Midrash']})
model.Index().update({'title': 'Sifre Bamidbar'},
                     {'categories': ['Midrash', 'Halachic Midrash']})

# Rebuild counts docs, so they get the allVersionCounts field
update_counts()
update_summaries()