# Generated by Django 2.2.15 on 2020-08-31 01:16

import django.core.validators
import django.db.models.deletion
from django.conf import settings
from django.db import migrations, models

import powerwiki.models


class Migration(migrations.Migration):

    initial = True

    dependencies = [
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
    ]

    operations = [
        migrations.CreateModel(
            name="Wiki",
            fields=[
                (
                    "id",
                    models.AutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                (
                    "title",
                    models.CharField(help_text="Title of the wiki", max_length=255),
                ),
                ("slug", models.SlugField(help_text="Slug for the wiki", unique=True)),
                (
                    "description",
                    models.TextField(blank=True, help_text="Description of wiki"),
                ),
                (
                    "perm_read",
                    models.IntegerField(
                        choices=[
                            (3, "Superusers only"),
                            (2, "Staff only"),
                            (1, "All users"),
                            (0, "Public"),
                        ],
                        default=3,
                        help_text="Default read permissions",
                        verbose_name="Read permission",
                    ),
                ),
                (
                    "perm_edit",
                    models.IntegerField(
                        choices=[
                            (3, "Superusers only"),
                            (2, "Staff only"),
                            (1, "All users"),
                            (0, "Public"),
                        ],
                        default=3,
                        help_text="Default edit permissions",
                        verbose_name="Edit permission",
                    ),
                ),
                (
                    "markup_engine",
                    models.CharField(
                        choices=[
                            (
                                "powerwiki.markup.rest.RestructuredText",
                                "reStructuredText",
                            ),
                            ("powerwiki.markup.md.Markdown", "Markdown"),
                            ("powerwiki.markup.plain.PlainText", "Plain text"),
                        ],
                        default="powerwiki.markup.rest.RestructuredText",
                        max_length=255,
                    ),
                ),
            ],
            options={"ordering": ("title",),},
        ),
        migrations.CreateModel(
            name="WikiPermissions",
            fields=[
                (
                    "id",
                    models.AutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                (
                    "can_read",
                    models.BooleanField(
                        default=True, help_text="User can read the wiki"
                    ),
                ),
                (
                    "can_edit",
                    models.BooleanField(
                        default=True, help_text="User can edit the wiki"
                    ),
                ),
                (
                    "user",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="wiki_permissions",
                        to=settings.AUTH_USER_MODEL,
                    ),
                ),
                (
                    "wiki",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="user_permissions",
                        to="powerwiki.Wiki",
                    ),
                ),
            ],
        ),
        migrations.AddField(
            model_name="wiki",
            name="users",
            field=models.ManyToManyField(
                related_name="wikis",
                through="powerwiki.WikiPermissions",
                to=settings.AUTH_USER_MODEL,
            ),
        ),
        migrations.CreateModel(
            name="Asset",
            fields=[
                (
                    "id",
                    models.AutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                ("name", models.SlugField(help_text="Internal name for the asset")),
                ("file", models.FileField(upload_to=powerwiki.models.asset_upload_to)),
                (
                    "wiki",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="assets",
                        to="powerwiki.Wiki",
                    ),
                ),
            ],
        ),
        migrations.CreateModel(
            name="Page",
            fields=[
                (
                    "id",
                    models.AutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                (
                    "title",
                    models.CharField(help_text="Title of the page", max_length=255),
                ),
                (
                    "path",
                    models.CharField(
                        help_text="Path for the page, under the wiki root",
                        max_length=100,
                        validators=[
                            django.core.validators.RegexValidator(
                                "^[a-z0-9][a-z0-9_\\-]*(/[a-z0-9][a-z0-9_\\-]*)*$",
                                "A path can only be lowercase, numbers, hyphens and underscores, using forward slashes to separate sub-pages, with each page starting with a lowercase or number.",
                                "invalid",
                            )
                        ],
                    ),
                ),
                (
                    "is_locked",
                    models.BooleanField(
                        default=False,
                        help_text="If locked, can only be edited by wiki admin",
                    ),
                ),
                ("content", models.TextField(blank=True, help_text="Page content")),
                (
                    "markup_engine",
                    models.CharField(
                        choices=[
                            (
                                "powerwiki.markup.rest.RestructuredText",
                                "reStructuredText",
                            ),
                            ("powerwiki.markup.md.Markdown", "Markdown"),
                            ("powerwiki.markup.plain.PlainText", "Plain text"),
                        ],
                        default="powerwiki.markup.rest.RestructuredText",
                        max_length=255,
                    ),
                ),
                (
                    "wiki",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="pages",
                        to="powerwiki.Wiki",
                    ),
                ),
            ],
            options={"ordering": ("title",), "unique_together": {("wiki", "path")},},
        ),
    ]
