We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Add default project descriptions
In order to get `initdb` running on `core` we had to drop the project [descriptions] since these move to staticpages on core.  This bug is to add those back.

To achieve that initdb should create static pages for these default projects that contain the content previously held in the [descriptions](https://github.com/translate/pootle/blob/96edf539/pootle/core/initdb.py#L300-L306).


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `pootle/core/initdb.py`
Content:
```
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3 #
4 # Copyright 2013 Zuza Software Foundation
5 # Copyright 2014-2015 Evernote Corporation
6 #
7 # This file is part of Pootle.
8 #
9 # Pootle is free software; you can redistribute it and/or modify it under the
10 # terms of the GNU General Public License as published by the Free Software
11 # Foundation; either version 2 of the License, or (at your option) any later
12 # version.
13 #
14 # Pootle is distributed in the hope that it will be useful, but WITHOUT ANY
15 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
16 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
17 #
18 # You should have received a copy of the GNU General Public License along with
19 # Pootle; if not, see <http://www.gnu.org/licenses/>.
20 
21 
22 from django.contrib.auth import get_user_model
23 from django.contrib.auth.models import Permission
24 from django.contrib.contenttypes.models import ContentType
25 from django.utils.translation import ugettext_noop as _
26 
27 from pootle.core.models import Revision
28 from pootle_app.models import Directory
29 from pootle_app.models.permissions import PermissionSet, get_pootle_permission
30 from pootle_language.models import Language
31 from pootle_project.models import Project
32 
33 
34 def initdb():
35     """Populate the database with default initial data.
36 
37     This creates the default database to get a working Pootle installation.
38     """
39     create_revision()
40     create_essential_users()
41     create_root_directories()
42     create_template_languages()
43     create_terminology_project()
44     create_pootle_permissions()
45     create_pootle_permission_sets()
46 
47     create_default_projects()
48     create_default_languages()
49     create_default_admin()
50 
51 
52 def create_revision():
53     Revision.initialize()
54 
55 
56 def create_essential_users():
57     """Create the 'default' and 'nobody' User instances.
58 
59     These users are required for Pootle's permission system.
60     """
61     User = get_user_model()
62 
63     # The nobody user is used to represent an anonymous user in cases where
64     # we need to associate model information with such a user. An example is
65     # in the permission system: we need a way to store rights for anonymous
66     # users; thus we use the nobody user.
67     criteria = {
68         'username': u"nobody",
69         'full_name': u"any anonymous user",
70         'is_active': True,
71     }
72     nobody, created = User.objects.get_or_create(**criteria)
73     if created:
74         nobody.set_unusable_password()
75         nobody.save()
76 
77     # The 'default' user represents any valid, non-anonymous user and is used
78     # to associate information any such user. An example is in the permission
79     # system: we need a way to store default rights for users. We use the
80     # 'default' user for this.
81     #
82     # In a future version of Pootle we should think about using Django's
83     # groups to do better permissions handling.
84     criteria = {
85         'username': u"default",
86         'full_name': u"any authenticated user",
87         'is_active': True,
88     }
89     default, created = User.objects.get_or_create(**criteria)
90     if created:
91         default.set_unusable_password()
92         default.save()
93 
94     # The system user represents a system, and is used to
95     # associate updates done by bulk commands as update_stores.
96     criteria = {
97         'username': u"system",
98         'full_name': u"system user",
99         'is_active': True,
100     }
101     system, created = User.objects.get_or_create(**criteria)
102     if created:
103         system.set_unusable_password()
104         system.save()
105 
106 
107 def create_pootle_permissions():
108     """Create Pootle's directory level permissions."""
109 
110     args = {
111         'app_label': "pootle_app",
112         'model': "directory",
113     }
114     pootle_content_type, created = ContentType.objects.get_or_create(**args)
115     pootle_content_type.name = 'pootle'
116     pootle_content_type.save()
117 
118     # Create the permissions.
119     permissions = [
120         {
121             'name': _("Can access a project"),
122             'codename': "view",
123         },
124         {
125             'name': _("Cannot access a project"),
126             'codename': "hide",
127         },
128         {
129             'name': _("Can make a suggestion for a translation"),
130             'codename': "suggest",
131         },
132         {
133             'name': _("Can submit a translation"),
134             'codename': "translate",
135         },
136         {
137             'name': _("Can review translations"),
138             'codename': "review",
139         },
140         {
141             'name': _("Can administrate a translation project"),
142             'codename': "administrate",
143         },
144     ]
145 
146     criteria = {
147         'content_type': pootle_content_type,
148     }
149 
150     for permission in permissions:
151         criteria.update(permission)
152         obj, created = Permission.objects.get_or_create(**criteria)
153 
154 
155 def create_pootle_permission_sets():
156     """Create the default permission set for the 'nobody' and 'default' users.
157 
158     'nobody' is the anonymous (non-logged in) user, and 'default' is the logged
159     in user.
160     """
161     User = get_user_model()
162 
163     nobody = User.objects.get(username='nobody')
164     default = User.objects.get(username='default')
165 
166     view = get_pootle_permission('view')
167     suggest = get_pootle_permission('suggest')
168     translate = get_pootle_permission('translate')
169 
170     # Default permissions for tree root.
171     criteria = {
172         'user': nobody,
173         'directory': Directory.objects.root,
174     }
175     permission_set, created = PermissionSet.objects.get_or_create(**criteria)
176     if created:
177         permission_set.positive_permissions = [view, suggest]
178         permission_set.save()
179 
180     criteria['user'] = default
181     permission_set, created = PermissionSet.objects.get_or_create(**criteria)
182     if created:
183         permission_set.positive_permissions = [view, suggest, translate]
184         permission_set.save()
185 
186     # Default permissions for templates language.
187     # Override with no permissions for templates language.
188     criteria = {
189         'user': nobody,
190         'directory': Directory.objects.get(pootle_path="/templates/"),
191     }
192     permission_set, created = PermissionSet.objects.get_or_create(**criteria)
193     if created:
194         permission_set.positive_permissions = []
195         permission_set.save()
196 
197     criteria['user'] = default
198     permission_set, created = PermissionSet.objects.get_or_create(**criteria)
199     if created:
200         permission_set.positive_permissions = []
201         permission_set.save()
202 
203 
204 def require_english():
205     """Create the English Language item."""
206     criteria = {
207         'code': "en",
208         'fullname': u"English",
209         'nplurals': 2,
210         'pluralequation': "(n != 1)",
211     }
212     en, created = Language.objects.get_or_create(**criteria)
213     return en
214 
215 
216 def create_root_directories():
217     """Create the root Directory items."""
218     root, created = Directory.objects.get_or_create(name='')
219     projects, created = Directory.objects.get_or_create(name='projects',
220                                                         parent=root)
221 
222 
223 def create_template_languages():
224     """Create the 'templates' and English languages.
225 
226     The 'templates' language is used to give users access to the untranslated
227     template files.
228     """
229     templates, created = Language.objects.get_or_create(code="templates",
230                                                         fullname=u'Templates')
231     require_english()
232 
233 
234 def create_terminology_project():
235     """Create the terminology project.
236 
237     The terminology project is used to display terminology suggestions while
238     translating.
239     """
240     criteria = {
241         'code': "terminology",
242         'fullname': u"Terminology",
243         'source_language': require_english(),
244         'checkstyle': "terminology",
245     }
246     terminology, created = Project.objects.get_or_create(**criteria)
247 
248 
249 def create_default_projects():
250     """Create the default projects that we host.
251 
252     You might want to add your projects here, although you can also add things
253     through the web interface later.
254     """
255     from pootle_project.models import Project
256 
257     en = require_english()
258 
259     #criteria = {
260     #    'code': u"pootle",
261     #    'source_language': en,
262     #    'fullname': u"Pootle",
263     #    'description': ('<div dir="ltr" lang="en">Interface translations for '
264     #                    'Pootle.<br />See the <a href="http://'
265     #                    'pootle.locamotion.org">official Pootle server</a> '
266     #                    'for the translations of Pootle.</div>')
267     #    'checkstyle': "standard",
268     #    'localfiletype': "po",
269     #    'treestyle': "auto",
270     #}
271     #pootle = Project(**criteria)
272     #pootle.save()
273 
274     criteria = {
275         'code': u"tutorial",
276         'source_language': en,
277         'fullname': u"Tutorial",
278         'checkstyle': "standard",
279         'localfiletype': "po",
280         'treestyle': "auto",
281     }
282     tutorial = Project(**criteria)
283     tutorial.save()
284 
285 
286 def create_default_languages():
287     """Create the default languages."""
288     from translate.lang import data, factory
289 
290     from pootle_language.models import Language
291 
292     # import languages from toolkit
293     for code in data.languages.keys():
294         try:
295             tk_lang = factory.getlanguage(code)
296             criteria = {
297                 'code': code,
298                 'fullname': tk_lang.fullname,
299                 'nplurals': tk_lang.nplurals,
300                 'pluralequation': tk_lang.pluralequation,
301             }
302             try:
303                 criteria['specialchars'] = tk_lang.specialchars
304             except AttributeError:
305                 pass
306             lang, created = Language.objects.get_or_create(**criteria)
307         except:
308             pass
309 
310 
311 def create_default_admin():
312     """Create the default admin user for Pootle.
313 
314     You definitely want to change the admin account so that your default
315     install is not accessible with the default credentials. The users 'noboby'
316     and 'default' should be left as is.
317     """
318     User = get_user_model()
319 
320     criteria = {
321         'username': u"admin",
322         'full_name': u"Administrator",
323         'is_active': True,
324         'is_superuser': True,
325     }
326     admin = User(**criteria)
327     admin.set_password("admin")
328     admin.save()
329
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/pootle/core/initdb.py b/pootle/core/initdb.py
--- a/pootle/core/initdb.py
+++ b/pootle/core/initdb.py
@@ -29,6 +29,7 @@
 from pootle_app.models.permissions import PermissionSet, get_pootle_permission
 from pootle_language.models import Language
 from pootle_project.models import Project
+from staticpages.models import StaticPage as Announcement
 
 
 def initdb():
@@ -256,21 +257,6 @@
 
     en = require_english()
 
-    #criteria = {
-    #    'code': u"pootle",
-    #    'source_language': en,
-    #    'fullname': u"Pootle",
-    #    'description': ('<div dir="ltr" lang="en">Interface translations for '
-    #                    'Pootle.<br />See the <a href="http://'
-    #                    'pootle.locamotion.org">official Pootle server</a> '
-    #                    'for the translations of Pootle.</div>')
-    #    'checkstyle': "standard",
-    #    'localfiletype': "po",
-    #    'treestyle': "auto",
-    #}
-    #pootle = Project(**criteria)
-    #pootle.save()
-
     criteria = {
         'code': u"tutorial",
         'source_language': en,
@@ -282,6 +268,20 @@
     tutorial = Project(**criteria)
     tutorial.save()
 
+    criteria = {
+        'active': True,
+        'title': "Project instructions",
+        'body': ('<div dir="ltr" lang="en">Tutorial project where users can '
+                 'play with Pootle and learn more about translation and '
+                 'localisation.<br />For more help on localisation, visit the '
+                 '<a href="http://docs.translatehouse.org/projects/'
+                 'localization-guide/en/latest/guide/start.html">localisation '
+                 'guide</a>.</div>'),
+        'virtual_path': "announcements/projects/"+tutorial.code,
+    }
+    ann = Announcement(**criteria)
+    ann.save()
+
 
 def create_default_languages():
     """Create the default languages."""

{"golden_diff": "diff --git a/pootle/core/initdb.py b/pootle/core/initdb.py\n--- a/pootle/core/initdb.py\n+++ b/pootle/core/initdb.py\n@@ -29,6 +29,7 @@\n from pootle_app.models.permissions import PermissionSet, get_pootle_permission\n from pootle_language.models import Language\n from pootle_project.models import Project\n+from staticpages.models import StaticPage as Announcement\n \n \n def initdb():\n@@ -256,21 +257,6 @@\n \n     en = require_english()\n \n-    #criteria = {\n-    #    'code': u\"pootle\",\n-    #    'source_language': en,\n-    #    'fullname': u\"Pootle\",\n-    #    'description': ('<div dir=\"ltr\" lang=\"en\">Interface translations for '\n-    #                    'Pootle.<br />See the <a href=\"http://'\n-    #                    'pootle.locamotion.org\">official Pootle server</a> '\n-    #                    'for the translations of Pootle.</div>')\n-    #    'checkstyle': \"standard\",\n-    #    'localfiletype': \"po\",\n-    #    'treestyle': \"auto\",\n-    #}\n-    #pootle = Project(**criteria)\n-    #pootle.save()\n-\n     criteria = {\n         'code': u\"tutorial\",\n         'source_language': en,\n@@ -282,6 +268,20 @@\n     tutorial = Project(**criteria)\n     tutorial.save()\n \n+    criteria = {\n+        'active': True,\n+        'title': \"Project instructions\",\n+        'body': ('<div dir=\"ltr\" lang=\"en\">Tutorial project where users can '\n+                 'play with Pootle and learn more about translation and '\n+                 'localisation.<br />For more help on localisation, visit the '\n+                 '<a href=\"http://docs.translatehouse.org/projects/'\n+                 'localization-guide/en/latest/guide/start.html\">localisation '\n+                 'guide</a>.</div>'),\n+        'virtual_path': \"announcements/projects/\"+tutorial.code,\n+    }\n+    ann = Announcement(**criteria)\n+    ann.save()\n+\n \n def create_default_languages():\n     \"\"\"Create the default languages.\"\"\"\n", "issue": "Add default project descriptions\nIn order to get `initdb` running on `core` we had to drop the project [descriptions] since these move to staticpages on core.  This bug is to add those back.\n\nTo achieve that initdb should create static pages for these default projects that contain the content previously held in the [descriptions](https://github.com/translate/pootle/blob/96edf539/pootle/core/initdb.py#L300-L306).\n\n", "before_files": [{"content": "#!/usr/bin/env python\n# -*- coding: utf-8 -*-\n#\n# Copyright 2013 Zuza Software Foundation\n# Copyright 2014-2015 Evernote Corporation\n#\n# This file is part of Pootle.\n#\n# Pootle is free software; you can redistribute it and/or modify it under the\n# terms of the GNU General Public License as published by the Free Software\n# Foundation; either version 2 of the License, or (at your option) any later\n# version.\n#\n# Pootle is distributed in the hope that it will be useful, but WITHOUT ANY\n# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR\n# A PARTICULAR PURPOSE. See the GNU General Public License for more details.\n#\n# You should have received a copy of the GNU General Public License along with\n# Pootle; if not, see <http://www.gnu.org/licenses/>.\n\n\nfrom django.contrib.auth import get_user_model\nfrom django.contrib.auth.models import Permission\nfrom django.contrib.contenttypes.models import ContentType\nfrom django.utils.translation import ugettext_noop as _\n\nfrom pootle.core.models import Revision\nfrom pootle_app.models import Directory\nfrom pootle_app.models.permissions import PermissionSet, get_pootle_permission\nfrom pootle_language.models import Language\nfrom pootle_project.models import Project\n\n\ndef initdb():\n    \"\"\"Populate the database with default initial data.\n\n    This creates the default database to get a working Pootle installation.\n    \"\"\"\n    create_revision()\n    create_essential_users()\n    create_root_directories()\n    create_template_languages()\n    create_terminology_project()\n    create_pootle_permissions()\n    create_pootle_permission_sets()\n\n    create_default_projects()\n    create_default_languages()\n    create_default_admin()\n\n\ndef create_revision():\n    Revision.initialize()\n\n\ndef create_essential_users():\n    \"\"\"Create the 'default' and 'nobody' User instances.\n\n    These users are required for Pootle's permission system.\n    \"\"\"\n    User = get_user_model()\n\n    # The nobody user is used to represent an anonymous user in cases where\n    # we need to associate model information with such a user. An example is\n    # in the permission system: we need a way to store rights for anonymous\n    # users; thus we use the nobody user.\n    criteria = {\n        'username': u\"nobody\",\n        'full_name': u\"any anonymous user\",\n        'is_active': True,\n    }\n    nobody, created = User.objects.get_or_create(**criteria)\n    if created:\n        nobody.set_unusable_password()\n        nobody.save()\n\n    # The 'default' user represents any valid, non-anonymous user and is used\n    # to associate information any such user. An example is in the permission\n    # system: we need a way to store default rights for users. We use the\n    # 'default' user for this.\n    #\n    # In a future version of Pootle we should think about using Django's\n    # groups to do better permissions handling.\n    criteria = {\n        'username': u\"default\",\n        'full_name': u\"any authenticated user\",\n        'is_active': True,\n    }\n    default, created = User.objects.get_or_create(**criteria)\n    if created:\n        default.set_unusable_password()\n        default.save()\n\n    # The system user represents a system, and is used to\n    # associate updates done by bulk commands as update_stores.\n    criteria = {\n        'username': u\"system\",\n        'full_name': u\"system user\",\n        'is_active': True,\n    }\n    system, created = User.objects.get_or_create(**criteria)\n    if created:\n        system.set_unusable_password()\n        system.save()\n\n\ndef create_pootle_permissions():\n    \"\"\"Create Pootle's directory level permissions.\"\"\"\n\n    args = {\n        'app_label': \"pootle_app\",\n        'model': \"directory\",\n    }\n    pootle_content_type, created = ContentType.objects.get_or_create(**args)\n    pootle_content_type.name = 'pootle'\n    pootle_content_type.save()\n\n    # Create the permissions.\n    permissions = [\n        {\n            'name': _(\"Can access a project\"),\n            'codename': \"view\",\n        },\n        {\n            'name': _(\"Cannot access a project\"),\n            'codename': \"hide\",\n        },\n        {\n            'name': _(\"Can make a suggestion for a translation\"),\n            'codename': \"suggest\",\n        },\n        {\n            'name': _(\"Can submit a translation\"),\n            'codename': \"translate\",\n        },\n        {\n            'name': _(\"Can review translations\"),\n            'codename': \"review\",\n        },\n        {\n            'name': _(\"Can administrate a translation project\"),\n            'codename': \"administrate\",\n        },\n    ]\n\n    criteria = {\n        'content_type': pootle_content_type,\n    }\n\n    for permission in permissions:\n        criteria.update(permission)\n        obj, created = Permission.objects.get_or_create(**criteria)\n\n\ndef create_pootle_permission_sets():\n    \"\"\"Create the default permission set for the 'nobody' and 'default' users.\n\n    'nobody' is the anonymous (non-logged in) user, and 'default' is the logged\n    in user.\n    \"\"\"\n    User = get_user_model()\n\n    nobody = User.objects.get(username='nobody')\n    default = User.objects.get(username='default')\n\n    view = get_pootle_permission('view')\n    suggest = get_pootle_permission('suggest')\n    translate = get_pootle_permission('translate')\n\n    # Default permissions for tree root.\n    criteria = {\n        'user': nobody,\n        'directory': Directory.objects.root,\n    }\n    permission_set, created = PermissionSet.objects.get_or_create(**criteria)\n    if created:\n        permission_set.positive_permissions = [view, suggest]\n        permission_set.save()\n\n    criteria['user'] = default\n    permission_set, created = PermissionSet.objects.get_or_create(**criteria)\n    if created:\n        permission_set.positive_permissions = [view, suggest, translate]\n        permission_set.save()\n\n    # Default permissions for templates language.\n    # Override with no permissions for templates language.\n    criteria = {\n        'user': nobody,\n        'directory': Directory.objects.get(pootle_path=\"/templates/\"),\n    }\n    permission_set, created = PermissionSet.objects.get_or_create(**criteria)\n    if created:\n        permission_set.positive_permissions = []\n        permission_set.save()\n\n    criteria['user'] = default\n    permission_set, created = PermissionSet.objects.get_or_create(**criteria)\n    if created:\n        permission_set.positive_permissions = []\n        permission_set.save()\n\n\ndef require_english():\n    \"\"\"Create the English Language item.\"\"\"\n    criteria = {\n        'code': \"en\",\n        'fullname': u\"English\",\n        'nplurals': 2,\n        'pluralequation': \"(n != 1)\",\n    }\n    en, created = Language.objects.get_or_create(**criteria)\n    return en\n\n\ndef create_root_directories():\n    \"\"\"Create the root Directory items.\"\"\"\n    root, created = Directory.objects.get_or_create(name='')\n    projects, created = Directory.objects.get_or_create(name='projects',\n                                                        parent=root)\n\n\ndef create_template_languages():\n    \"\"\"Create the 'templates' and English languages.\n\n    The 'templates' language is used to give users access to the untranslated\n    template files.\n    \"\"\"\n    templates, created = Language.objects.get_or_create(code=\"templates\",\n                                                        fullname=u'Templates')\n    require_english()\n\n\ndef create_terminology_project():\n    \"\"\"Create the terminology project.\n\n    The terminology project is used to display terminology suggestions while\n    translating.\n    \"\"\"\n    criteria = {\n        'code': \"terminology\",\n        'fullname': u\"Terminology\",\n        'source_language': require_english(),\n        'checkstyle': \"terminology\",\n    }\n    terminology, created = Project.objects.get_or_create(**criteria)\n\n\ndef create_default_projects():\n    \"\"\"Create the default projects that we host.\n\n    You might want to add your projects here, although you can also add things\n    through the web interface later.\n    \"\"\"\n    from pootle_project.models import Project\n\n    en = require_english()\n\n    #criteria = {\n    #    'code': u\"pootle\",\n    #    'source_language': en,\n    #    'fullname': u\"Pootle\",\n    #    'description': ('<div dir=\"ltr\" lang=\"en\">Interface translations for '\n    #                    'Pootle.<br />See the <a href=\"http://'\n    #                    'pootle.locamotion.org\">official Pootle server</a> '\n    #                    'for the translations of Pootle.</div>')\n    #    'checkstyle': \"standard\",\n    #    'localfiletype': \"po\",\n    #    'treestyle': \"auto\",\n    #}\n    #pootle = Project(**criteria)\n    #pootle.save()\n\n    criteria = {\n        'code': u\"tutorial\",\n        'source_language': en,\n        'fullname': u\"Tutorial\",\n        'checkstyle': \"standard\",\n        'localfiletype': \"po\",\n        'treestyle': \"auto\",\n    }\n    tutorial = Project(**criteria)\n    tutorial.save()\n\n\ndef create_default_languages():\n    \"\"\"Create the default languages.\"\"\"\n    from translate.lang import data, factory\n\n    from pootle_language.models import Language\n\n    # import languages from toolkit\n    for code in data.languages.keys():\n        try:\n            tk_lang = factory.getlanguage(code)\n            criteria = {\n                'code': code,\n                'fullname': tk_lang.fullname,\n                'nplurals': tk_lang.nplurals,\n                'pluralequation': tk_lang.pluralequation,\n            }\n            try:\n                criteria['specialchars'] = tk_lang.specialchars\n            except AttributeError:\n                pass\n            lang, created = Language.objects.get_or_create(**criteria)\n        except:\n            pass\n\n\ndef create_default_admin():\n    \"\"\"Create the default admin user for Pootle.\n\n    You definitely want to change the admin account so that your default\n    install is not accessible with the default credentials. The users 'noboby'\n    and 'default' should be left as is.\n    \"\"\"\n    User = get_user_model()\n\n    criteria = {\n        'username': u\"admin\",\n        'full_name': u\"Administrator\",\n        'is_active': True,\n        'is_superuser': True,\n    }\n    admin = User(**criteria)\n    admin.set_password(\"admin\")\n    admin.save()\n", "path": "pootle/core/initdb.py"}], "after_files": [{"content": "#!/usr/bin/env python\n# -*- coding: utf-8 -*-\n#\n# Copyright 2013 Zuza Software Foundation\n# Copyright 2014-2015 Evernote Corporation\n#\n# This file is part of Pootle.\n#\n# Pootle is free software; you can redistribute it and/or modify it under the\n# terms of the GNU General Public License as published by the Free Software\n# Foundation; either version 2 of the License, or (at your option) any later\n# version.\n#\n# Pootle is distributed in the hope that it will be useful, but WITHOUT ANY\n# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR\n# A PARTICULAR PURPOSE. See the GNU General Public License for more details.\n#\n# You should have received a copy of the GNU General Public License along with\n# Pootle; if not, see <http://www.gnu.org/licenses/>.\n\n\nfrom django.contrib.auth import get_user_model\nfrom django.contrib.auth.models import Permission\nfrom django.contrib.contenttypes.models import ContentType\nfrom django.utils.translation import ugettext_noop as _\n\nfrom pootle.core.models import Revision\nfrom pootle_app.models import Directory\nfrom pootle_app.models.permissions import PermissionSet, get_pootle_permission\nfrom pootle_language.models import Language\nfrom pootle_project.models import Project\nfrom staticpages.models import StaticPage as Announcement\n\n\ndef initdb():\n    \"\"\"Populate the database with default initial data.\n\n    This creates the default database to get a working Pootle installation.\n    \"\"\"\n    create_revision()\n    create_essential_users()\n    create_root_directories()\n    create_template_languages()\n    create_terminology_project()\n    create_pootle_permissions()\n    create_pootle_permission_sets()\n\n    create_default_projects()\n    create_default_languages()\n    create_default_admin()\n\n\ndef create_revision():\n    Revision.initialize()\n\n\ndef create_essential_users():\n    \"\"\"Create the 'default' and 'nobody' User instances.\n\n    These users are required for Pootle's permission system.\n    \"\"\"\n    User = get_user_model()\n\n    # The nobody user is used to represent an anonymous user in cases where\n    # we need to associate model information with such a user. An example is\n    # in the permission system: we need a way to store rights for anonymous\n    # users; thus we use the nobody user.\n    criteria = {\n        'username': u\"nobody\",\n        'full_name': u\"any anonymous user\",\n        'is_active': True,\n    }\n    nobody, created = User.objects.get_or_create(**criteria)\n    if created:\n        nobody.set_unusable_password()\n        nobody.save()\n\n    # The 'default' user represents any valid, non-anonymous user and is used\n    # to associate information any such user. An example is in the permission\n    # system: we need a way to store default rights for users. We use the\n    # 'default' user for this.\n    #\n    # In a future version of Pootle we should think about using Django's\n    # groups to do better permissions handling.\n    criteria = {\n        'username': u\"default\",\n        'full_name': u\"any authenticated user\",\n        'is_active': True,\n    }\n    default, created = User.objects.get_or_create(**criteria)\n    if created:\n        default.set_unusable_password()\n        default.save()\n\n    # The system user represents a system, and is used to\n    # associate updates done by bulk commands as update_stores.\n    criteria = {\n        'username': u\"system\",\n        'full_name': u\"system user\",\n        'is_active': True,\n    }\n    system, created = User.objects.get_or_create(**criteria)\n    if created:\n        system.set_unusable_password()\n        system.save()\n\n\ndef create_pootle_permissions():\n    \"\"\"Create Pootle's directory level permissions.\"\"\"\n\n    args = {\n        'app_label': \"pootle_app\",\n        'model': \"directory\",\n    }\n    pootle_content_type, created = ContentType.objects.get_or_create(**args)\n    pootle_content_type.name = 'pootle'\n    pootle_content_type.save()\n\n    # Create the permissions.\n    permissions = [\n        {\n            'name': _(\"Can access a project\"),\n            'codename': \"view\",\n        },\n        {\n            'name': _(\"Cannot access a project\"),\n            'codename': \"hide\",\n        },\n        {\n            'name': _(\"Can make a suggestion for a translation\"),\n            'codename': \"suggest\",\n        },\n        {\n            'name': _(\"Can submit a translation\"),\n            'codename': \"translate\",\n        },\n        {\n            'name': _(\"Can review translations\"),\n            'codename': \"review\",\n        },\n        {\n            'name': _(\"Can administrate a translation project\"),\n            'codename': \"administrate\",\n        },\n    ]\n\n    criteria = {\n        'content_type': pootle_content_type,\n    }\n\n    for permission in permissions:\n        criteria.update(permission)\n        obj, created = Permission.objects.get_or_create(**criteria)\n\n\ndef create_pootle_permission_sets():\n    \"\"\"Create the default permission set for the 'nobody' and 'default' users.\n\n    'nobody' is the anonymous (non-logged in) user, and 'default' is the logged\n    in user.\n    \"\"\"\n    User = get_user_model()\n\n    nobody = User.objects.get(username='nobody')\n    default = User.objects.get(username='default')\n\n    view = get_pootle_permission('view')\n    suggest = get_pootle_permission('suggest')\n    translate = get_pootle_permission('translate')\n\n    # Default permissions for tree root.\n    criteria = {\n        'user': nobody,\n        'directory': Directory.objects.root,\n    }\n    permission_set, created = PermissionSet.objects.get_or_create(**criteria)\n    if created:\n        permission_set.positive_permissions = [view, suggest]\n        permission_set.save()\n\n    criteria['user'] = default\n    permission_set, created = PermissionSet.objects.get_or_create(**criteria)\n    if created:\n        permission_set.positive_permissions = [view, suggest, translate]\n        permission_set.save()\n\n    # Default permissions for templates language.\n    # Override with no permissions for templates language.\n    criteria = {\n        'user': nobody,\n        'directory': Directory.objects.get(pootle_path=\"/templates/\"),\n    }\n    permission_set, created = PermissionSet.objects.get_or_create(**criteria)\n    if created:\n        permission_set.positive_permissions = []\n        permission_set.save()\n\n    criteria['user'] = default\n    permission_set, created = PermissionSet.objects.get_or_create(**criteria)\n    if created:\n        permission_set.positive_permissions = []\n        permission_set.save()\n\n\ndef require_english():\n    \"\"\"Create the English Language item.\"\"\"\n    criteria = {\n        'code': \"en\",\n        'fullname': u\"English\",\n        'nplurals': 2,\n        'pluralequation': \"(n != 1)\",\n    }\n    en, created = Language.objects.get_or_create(**criteria)\n    return en\n\n\ndef create_root_directories():\n    \"\"\"Create the root Directory items.\"\"\"\n    root, created = Directory.objects.get_or_create(name='')\n    projects, created = Directory.objects.get_or_create(name='projects',\n                                                        parent=root)\n\n\ndef create_template_languages():\n    \"\"\"Create the 'templates' and English languages.\n\n    The 'templates' language is used to give users access to the untranslated\n    template files.\n    \"\"\"\n    templates, created = Language.objects.get_or_create(code=\"templates\",\n                                                        fullname=u'Templates')\n    require_english()\n\n\ndef create_terminology_project():\n    \"\"\"Create the terminology project.\n\n    The terminology project is used to display terminology suggestions while\n    translating.\n    \"\"\"\n    criteria = {\n        'code': \"terminology\",\n        'fullname': u\"Terminology\",\n        'source_language': require_english(),\n        'checkstyle': \"terminology\",\n    }\n    terminology, created = Project.objects.get_or_create(**criteria)\n\n\ndef create_default_projects():\n    \"\"\"Create the default projects that we host.\n\n    You might want to add your projects here, although you can also add things\n    through the web interface later.\n    \"\"\"\n    from pootle_project.models import Project\n\n    en = require_english()\n\n    criteria = {\n        'code': u\"tutorial\",\n        'source_language': en,\n        'fullname': u\"Tutorial\",\n        'checkstyle': \"standard\",\n        'localfiletype': \"po\",\n        'treestyle': \"auto\",\n    }\n    tutorial = Project(**criteria)\n    tutorial.save()\n\n    criteria = {\n        'active': True,\n        'title': \"Project instructions\",\n        'body': ('<div dir=\"ltr\" lang=\"en\">Tutorial project where users can '\n                 'play with Pootle and learn more about translation and '\n                 'localisation.<br />For more help on localisation, visit the '\n                 '<a href=\"http://docs.translatehouse.org/projects/'\n                 'localization-guide/en/latest/guide/start.html\">localisation '\n                 'guide</a>.</div>'),\n        'virtual_path': \"announcements/projects/\"+tutorial.code,\n    }\n    ann = Announcement(**criteria)\n    ann.save()\n\n\ndef create_default_languages():\n    \"\"\"Create the default languages.\"\"\"\n    from translate.lang import data, factory\n\n    from pootle_language.models import Language\n\n    # import languages from toolkit\n    for code in data.languages.keys():\n        try:\n            tk_lang = factory.getlanguage(code)\n            criteria = {\n                'code': code,\n                'fullname': tk_lang.fullname,\n                'nplurals': tk_lang.nplurals,\n                'pluralequation': tk_lang.pluralequation,\n            }\n            try:\n                criteria['specialchars'] = tk_lang.specialchars\n            except AttributeError:\n                pass\n            lang, created = Language.objects.get_or_create(**criteria)\n        except:\n            pass\n\n\ndef create_default_admin():\n    \"\"\"Create the default admin user for Pootle.\n\n    You definitely want to change the admin account so that your default\n    install is not accessible with the default credentials. The users 'noboby'\n    and 'default' should be left as is.\n    \"\"\"\n    User = get_user_model()\n\n    criteria = {\n        'username': u\"admin\",\n        'full_name': u\"Administrator\",\n        'is_active': True,\n        'is_superuser': True,\n    }\n    admin = User(**criteria)\n    admin.set_password(\"admin\")\n    admin.save()\n", "path": "pootle/core/initdb.py"}]}