This repository has been archived by the owner on Aug 26, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 679
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3689 from mozilla/easy-ks-modules-957802
bug 957802 - import_kumascript_modules command
- Loading branch information
Showing
3 changed files
with
64 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
kuma/wiki/management/commands/import_kumascript_modules.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
""" | ||
Import KumaScript auto-loaded modules from production site. | ||
Run this when setting up a new dev box to get the latest required KumaScript | ||
modules from the production site. | ||
""" | ||
import requests | ||
|
||
from django.core.management.base import BaseCommand | ||
|
||
from kuma.users.models import User | ||
from kuma.wiki.exceptions import SlugCollision | ||
from kuma.wiki.models import Document, Revision | ||
|
||
KS_AUTOLOAD_MODULES = [ | ||
'Template:mdn:common', | ||
'Template:DekiScript:Date', | ||
'Template:DekiScript:Page', | ||
'Template:DekiScript:String', | ||
'Template:DekiScript:Uri', | ||
'Template:DekiScript:Web', | ||
'Template:DekiScript:Wiki', | ||
] | ||
|
||
RAW_TEMPLATE_URL = 'https://developer.mozilla.org/en-US/docs/%s?raw=1' | ||
|
||
|
||
class Command(BaseCommand): | ||
|
||
def handle(self, *args, **options): | ||
# get first user to be the creator | ||
u = User.objects.all()[0] | ||
loaded_docs = [] | ||
skipped_docs = [] | ||
|
||
for slug in KS_AUTOLOAD_MODULES: | ||
template_response = requests.get(RAW_TEMPLATE_URL % slug) | ||
doc = Document(title=slug, slug=slug, | ||
category=Document.CATEGORIES[0][0]) | ||
try: | ||
doc.save() | ||
loaded_docs.append(slug) | ||
except SlugCollision: | ||
# skip modules already in the db | ||
skipped_docs.append(slug) | ||
continue | ||
rev = Revision(document=doc, content=template_response.content, | ||
creator=u) | ||
rev.save() | ||
|
||
print "Loaded docs:" | ||
for slug in loaded_docs: | ||
print "%s" % slug | ||
print "\nSkipped docs that were already loaded:" | ||
for slug in skipped_docs: | ||
print "%s" % slug |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters