Skip to content

Instantly share code, notes, and snippets.

@smn
Last active August 29, 2015 14:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save smn/5d71300ef8e2e016802a to your computer and use it in GitHub Desktop.
Save smn/5d71300ef8e2e016802a to your computer and use it in GitHub Desktop.
examples for how to interact with unicore content repos
/the_repository/
*.pyc
/ve/
/unicore/
/unicore-cms-content-ffl-tanzania/
{
"type": "record",
"namespace": "unicore.content.models",
"name": "Category",
"fields": [
{
"type": "string",
"name": "subtitle"
},
{
"type": "string",
"name": "language"
},
{
"type": "string",
"name": "title"
},
{
"type": "string",
"name": "id"
},
{
"type": "string",
"name": "source"
},
{
"type": "int",
"name": "position"
},
{
"type": "boolean",
"name": "featured_in_navbar"
},
{
"type": "string",
"name": "slug"
},
{
"type": "string",
"name": "image"
},
{
"type": "string",
"name": "image_host"
},
{
"type": "string",
"name": "uuid",
"aliases": [
"id"
]
}
]
}
$ ./clone-repo.sh
Cloning into 'unicore-cms-content-ffl-tanzania'...
remote: Counting objects: 6877, done.
remote: Compressing objects: 100% (830/830), done.
remote: Total 6877 (delta 371), reused 0 (delta 0)
Receiving objects: 100% (6877/6877), 1.55 MiB | 438.00 KiB/s, done.
Resolving deltas: 100% (3619/3619), done.
Checking connectivity... done.
unicore.content.models.Category: 20 updated, 0 removed.
unicore.content.models.Page: 146 updated, 0 removed.
git clone https://github.com/universalcore/unicore-cms-content-ffl-tanzania
PYTHONPATH=. eg-tools resync \
--git-path unicore-cms-content-ffl-tanzania \
--index-prefix unicore-cms-content-ffl-tanzania \
--model unicore.content.models.Category
PYTHONPATH=. eg-tools resync \
--git-path unicore-cms-content-ffl-tanzania \
--index-prefix unicore-cms-content-ffl-tanzania \
--model unicore.content.models.Page
>>> for category in workspace.S(Category).filter(title='diarrhoea'):
... print category.title, category.uuid
...
Diarrhoea 116e3cfd167340088d465880ce508a8d
Diarrhoea 68bc9bc3fff940faa8a85a49f6ab70dc
>>> for page in workspace.S(Page).filter(primary_category='116e3cfd167340088d465880ce508a8d'):
... print page.uuid, page.title
...
0802ba9f1cfb498196afaed48503ad9f A child's life is in danger if she or he has several watery stools within an hour or if there is blood in the stool. Immediate help from a trained health worker is needed.
356c933289aa48458faf7f2e866989cd A child with diarrhoea should receive oral rehydration salts (ORS) solution and a daily zinc supplement for 10–14 days. Diarrhoea medicines are generally ineffective and can be harmful.
dafec278033d4ce2a70ebbf3059fc66d Good hygiene practices and use of safe drinking water protect against diarrhoea. Hands should be thoroughly washed with soap and water or a substitute, such as ash and water, after defecating and afte
d5528140355c4ea3b26ddbaa2b03eeb8 Exclusive breastfeeding for the first six months of life and continued breastfeeding after six months can reduce the risks associated with diarrhoea. Immunization against rotavirus (where recommended
5c6eaa41494c476994dbda7d1e309149 To prevent diarrhoea, all faeces, including those of infants and young children, should be disposed of in a latrine or toilet or buried.
475e5d8a7f004969a2bfdc11a44150cb A child with diarrhoea needs to continue eating regularly. While recovering, she or he needs to be offered more food than usual to replenish the energy and nourishment lost due to the illness.
>>>
$ eg-tools load-schema Category.avro.json
# NOTE:
#
# This is an automatically generated Elasticgit Model definition
# from an Avro schema. Do not manually edit this file unless you
# absolutely know what you are doing.
#
# namespace: unicore.content.models
#
# VERSION INFO:
#
# package: elastic-git
# package_version: 0.2.10
# language_version: 2.7.6
#
from elasticgit import models
class Category(models.Model):
subtitle = models.TextField("""subtitle""")
language = models.TextField("""language""")
title = models.TextField("""title""")
id = models.TextField("""id""")
source = models.TextField("""source""")
position = models.IntegerField("""position""")
featured_in_navbar = models.BooleanField("""featured_in_navbar""")
slug = models.TextField("""slug""")
image = models.TextField("""image""")
image_host = models.TextField("""image_host""")
uuid = models.TextField("""uuid""", fallbacks=[models.SingleFieldFallback('id'),])
# create the directory for the Python module
mkdir -p unicore/content
# create empty __init__.py files in the directories, this makes
# them Python modules.
touch unicore/__init__.py
touch unicore/content/__init__.py
eg-tools load-schema \
Page.avro.json \
Category.avro.json \
--map-field uuid=elasticgit.models.UUIDField \
> ./unicore/content/models.py
# NOTE:
#
# This is an automatically generated Elasticgit Model definition
# from an Avro schema. Do not manually edit this file unless you
# absolutely know what you are doing.
#
# namespace: unicore.content.models
#
# VERSION INFO:
#
# package: elastic-git
# package_version: 0.2.10
# language_version: 2.7.6
#
from elasticgit import models
class Page(models.Model):
subtitle = models.TextField("""subtitle""")
description = models.TextField("""description""")
language = models.TextField("""language""")
title = models.TextField("""title""")
created_at = models.TextField("""created_at""")
published = models.BooleanField("""published""")
modified_at = models.TextField("""modified_at""")
linked_pages = models.ListField("""linked_pages""")
slug = models.TextField("""slug""")
content = models.TextField("""content""")
source = models.TextField("""source""")
featured = models.BooleanField("""featured""")
featured_in_category = models.BooleanField("""featured_in_category""")
id = models.TextField("""id""")
position = models.IntegerField("""position""")
primary_category = models.TextField("""primary_category""")
image = models.TextField("""image""")
image_host = models.TextField("""image_host""")
uuid = models.UUIDField("""uuid""", fallbacks=[models.SingleFieldFallback('id'),])
class Category(models.Model):
subtitle = models.TextField("""subtitle""")
language = models.TextField("""language""")
title = models.TextField("""title""")
id = models.TextField("""id""")
source = models.TextField("""source""")
position = models.IntegerField("""position""")
featured_in_navbar = models.BooleanField("""featured_in_navbar""")
slug = models.TextField("""slug""")
image = models.TextField("""image""")
image_host = models.TextField("""image_host""")
uuid = models.UUIDField("""uuid""", fallbacks=[models.SingleFieldFallback('id'),])
{
"namespace": "unicore.content.models",
"type": "record",
"name": "Page",
"fields": [
{
"type": "string",
"name": "subtitle"
},
{
"type": "string",
"name": "description"
},
{
"type": "string",
"name": "language"
},
{
"type": "string",
"name": "title"
},
{
"type": "string",
"name": "created_at"
},
{
"type": "boolean",
"name": "published"
},
{
"type": "string",
"name": "modified_at"
},
{
"type": "array",
"name": "linked_pages"
},
{
"type": "string",
"name": "slug"
},
{
"type": "string",
"name": "content"
},
{
"type": "string",
"name": "source"
},
{
"type": "boolean",
"name": "featured"
},
{
"type": "boolean",
"name": "featured_in_category"
},
{
"type": "string",
"name": "id"
},
{
"type": "int",
"name": "position"
},
{
"type": "string",
"name": "primary_category"
},
{
"type": "string",
"name": "image"
},
{
"type": "string",
"name": "image_host"
},
{
"type": "string",
"name": "uuid",
"aliases": [
"id"
]
}
]
}
virtualenv ve
source ve/bin/activate
pip install -r requirements.txt
$ PYTHONPATH=. eg-tools shell unicore-cms-content-ffl-tanzania
gitcategorymodel does not look like a models module.
gitpagemodel does not look like a models module.
Python 2.7.6 (default, Dec 22 2013, 09:30:03)
[GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.2.79)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> workspace
<elasticgit.manager.Workspace object at 0x10872c8d0>
>>> workspace.S(Page).count()
146
>>> workspace.S(Category).count()
20
>>>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment