Skip to content

Commit

Permalink
feat: use a Custom User Model (#262)
Browse files Browse the repository at this point in the history
  • Loading branch information
engineervix committed Aug 15, 2021
1 parent bfed31f commit 9d0289b
Show file tree
Hide file tree
Showing 36 changed files with 2,177 additions and 1,755 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,12 @@ Simply choose one of the three and delete the others. If you don't like any of t
### ⌨️ to get started

1. ensure that you have [cookiecutter](https://github.com/audreyr/cookiecutter) installed on your computer
2. run `cookiecutter https://github.com/engineervix/cookiecutter-wagtail-vix.git` in your favourite shell. You’ll be prompted for some values, such as **project_name**, , **project_slug**, **email**, **wagtail_username** etc. A new wagtail project will be created in a folder named according to the **project_slug** at your current location.
2. run `cookiecutter https://github.com/engineervix/cookiecutter-wagtail-vix.git` in your favourite shell. You’ll be prompted for some values, such as **project_name**, , **project_slug**, **email**, **wagtail_user_email** etc. A new wagtail project will be created in a folder named according to the **project_slug** at your current location.
3. create a virtual environment for your project. `cd` into the project folder created above and install python dependencies: First, install [pip-tools](https://github.com/jazzband/pip-tools): `pip install pip-tools`, then run `pip-compile requirements.in` followed by `pip install -r requirements.txt`.
4. Now would be a good time to setup your postgres/postgis database and ensure that you update `DATABASE_URL` and the other environment variables in your `.env` files. The essential ones for starters are `RECAPTCHA_PUBLIC_KEY`, `RECAPTCHA_PRIVATE_KEY` and `MAPBOX_ACCESS_TOKEN`.
5. `export ENV_PATH=.envs/.dev.env`
6. `./manage.py migrate`
7. `./manage.py createsuperuser`. When prompted for a username, please use the **wagtail_username** you specified in step 2. This is important to ensure that you don't have issues when populating the database with initial data, which is tied to the username provided in step 2.
7. `./manage.py createsuperuser`. When prompted for an email address, please use the **wagtail_user_email** you specified in step 2. This is important to ensure that you don't have issues when populating the database with initial data, which is tied to the email address provided in step 2.
8. `./manage.py load_initial_data`
9. `yarn`
10. `gulp cp`
Expand Down
2 changes: 1 addition & 1 deletion cookiecutter.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@
"version": "0.1.0",
"timezone": "Africa/Lusaka",
"python_version": ["3.6", "3.7", "3.8", "3.9"],
"wagtail_username": "user"
"wagtail_user_email": "{{ cookiecutter.author_name.lower()|replace(' ', '-') }}@{{ cookiecutter.domain_name.lower()|replace(' ', '-') }}"
}
2 changes: 1 addition & 1 deletion hooks/post_gen_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ def main():
shutil.move(backups, os.path.join(PROJECT_DIRECTORY, ".backups/"))

print(
"Please ensure that you use {{ cookiecutter.wagtail_username }} as your username when you run `./manage.py createsuperuser`"
"Please ensure that you use {{ cookiecutter.wagtail_user_email }} as your email address when you run `./manage.py createsuperuser`"
)


Expand Down
2 changes: 1 addition & 1 deletion tests/test_cookiecutter_generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def context():
"domain_name": "example.com",
"version": "0.0.1",
"timezone": "Africa/Lusaka",
"wagtail_username": "somebody",
"wagtail_user_email": "somebody@example.com",
}


Expand Down
3 changes: 3 additions & 0 deletions {{cookiecutter.project_slug}}/config/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
# Application definition

INSTALLED_APPS = [
"{{cookiecutter.project_slug}}.users",
"{{cookiecutter.project_slug}}.base",
"{{cookiecutter.project_slug}}.home",
"{{cookiecutter.project_slug}}.blog",
Expand Down Expand Up @@ -269,6 +270,8 @@

MESSAGE_STORAGE = "django.contrib.messages.storage.session.SessionStorage"

AUTH_USER_MODEL = "users.User"

DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"

# Omitting the 'default' editor now leaves the original default editor intact,
Expand Down
3,594 changes: 1,930 additions & 1,664 deletions {{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/base/fixtures/data.json

Large diffs are not rendered by default.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Generated by Django 2.2.11 on 2020-03-15 17:51
# Generated by Django 3.2.6 on 2021-08-14 22:08

from django.db import migrations, models
import django.db.models.deletion
Expand All @@ -14,14 +14,14 @@ class Migration(migrations.Migration):
initial = True

dependencies = [
('wagtailimages', '0001_squashed_0021'),
('wagtailimages', '0023_add_choose_permissions'),
]

operations = [
migrations.CreateModel(
name='People',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('created', model_utils.fields.AutoCreatedField(default=django.utils.timezone.now, editable=False, verbose_name='created')),
('modified', model_utils.fields.AutoLastModifiedField(default=django.utils.timezone.now, editable=False, verbose_name='modified')),
('status', model_utils.fields.StatusField(choices=[('draft', 'draft'), ('published', 'published')], default='draft', max_length=100, no_check_for_status=True, verbose_name='status')),
Expand All @@ -35,7 +35,7 @@ class Migration(migrations.Migration):
('facebook', models.URLField(blank=True, help_text='(Optional) Enter Facebook Profile Link, for example: https://www.facebook.com/conrad.mbewe.1', max_length=254, verbose_name='Facebook Link')),
('twitter', models.URLField(blank=True, help_text='(Optional) Enter Twitter Profile Link, for example: https://twitter.com/voddiebaucham', max_length=254, verbose_name='Twitter Link')),
('linked_in', models.URLField(blank=True, help_text='(Optional) Enter LinkedIn Profile Link, for example: https://www.linkedin.com/in/justin-lupele-phd-31a35092', max_length=254, verbose_name='LinkedIn Link')),
('image', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to='wagtailimages.Image')),
('image', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to='wagtailimages.image')),
],
options={
'verbose_name': 'Person',
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Generated by Django 2.2.11 on 2020-03-15 17:51
# Generated by Django 3.2.6 on 2021-08-14 22:08

from django.db import migrations, models
import django.db.models.deletion
Expand All @@ -17,16 +17,16 @@ class Migration(migrations.Migration):
initial = True

dependencies = [
('wagtailcore', '0062_comment_models_and_pagesubscription'),
('wagtailimages', '0023_add_choose_permissions'),
('taggit', '0003_taggeditem_add_unique_index'),
('wagtailimages', '0001_squashed_0021'),
('wagtailcore', '0045_assign_unlock_grouppagepermission'),
]

operations = [
migrations.CreateModel(
name='ArticleIndexPage',
fields=[
('page_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='wagtailcore.Page')),
('page_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='wagtailcore.page')),
('introduction', models.TextField(help_text='Text to describe the page')),
],
options={
Expand All @@ -37,14 +37,14 @@ class Migration(migrations.Migration):
migrations.CreateModel(
name='ArticlePage',
fields=[
('page_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='wagtailcore.Page')),
('page_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='wagtailcore.page')),
('summary', models.TextField(help_text='Text to summarise / describe the article', verbose_name='Summary')),
('content', wagtail.core.fields.StreamField([('heading_block', wagtail.core.blocks.StructBlock([('heading_text', wagtail.core.blocks.CharBlock(classname='title', required=True)), ('size', wagtail.core.blocks.ChoiceBlock(blank=True, choices=[('', 'Select a header size'), ('h2', 'H2'), ('h3', 'H3'), ('h4', 'H4')], required=False))])), ('paragraph_block', wagtail.core.blocks.RichTextBlock(icon='fa-paragraph', template='blocks/paragraph_block.html')), ('image_block', wagtail.core.blocks.StructBlock([('image', wagtail.images.blocks.ImageChooserBlock(required=True)), ('caption', wagtail.core.blocks.CharBlock(required=False)), ('attribution', wagtail.core.blocks.CharBlock(required=False))])), ('block_quote', wagtail.core.blocks.StructBlock([('text', wagtail.core.blocks.TextBlock()), ('attribute_name', wagtail.core.blocks.CharBlock(blank=True, label='e.g. Mary Berry', required=False))])), ('embed_block', wagtail.embeds.blocks.EmbedBlock(help_text='Insert an embed URL e.g https://www.youtube.com/embed/SGJFWirQ3ks', icon='media', template='blocks/embed_block.html')), ('table', wagtail.contrib.table_block.blocks.TableBlock(template='blocks/table_block.html'))], blank=True, help_text='Leave this Blank if Article Type is "External Link"', null=True, verbose_name='Content')),
('content', wagtail.core.fields.StreamField([('heading_block', wagtail.core.blocks.StructBlock([('heading_text', wagtail.core.blocks.CharBlock(form_classname='title', required=True)), ('size', wagtail.core.blocks.ChoiceBlock(blank=True, choices=[('', 'Select a header size'), ('h2', 'H2'), ('h3', 'H3'), ('h4', 'H4')], required=False))])), ('paragraph_block', wagtail.core.blocks.RichTextBlock(icon='fa-paragraph', template='blocks/paragraph_block.html')), ('image_block', wagtail.core.blocks.StructBlock([('image', wagtail.images.blocks.ImageChooserBlock(required=True)), ('caption', wagtail.core.blocks.CharBlock(required=False)), ('attribution', wagtail.core.blocks.CharBlock(required=False))])), ('block_quote', wagtail.core.blocks.StructBlock([('text', wagtail.core.blocks.TextBlock()), ('attribute_name', wagtail.core.blocks.CharBlock(blank=True, label='e.g. Mary Berry', required=False))])), ('embed_block', wagtail.embeds.blocks.EmbedBlock(help_text='Insert an embed URL e.g https://www.youtube.com/embed/SGJFWirQ3ks', icon='media', template='blocks/embed_block.html')), ('table', wagtail.contrib.table_block.blocks.TableBlock(template='blocks/table_block.html'))], blank=True, help_text='Leave this Blank if Article Type is "External Link"', null=True, verbose_name='Content')),
('date_published', models.DateField(max_length=254, verbose_name='Article Date')),
('author', models.CharField(blank=True, max_length=254, null=True, verbose_name='Author')),
('article_type', models.CharField(choices=[('Shout', 'Announcement'), ('Post', 'Article'), ('Info', 'Notice'), ('URL', 'External Link'), ('Misc', 'Other')], max_length=5)),
('external_url', models.URLField(blank=True, help_text='Only Add Link if Article is an External Link', null=True, verbose_name='External Link')),
('cover_picture', models.ForeignKey(help_text='Landscape mode only; horizontal width between 1000px and 3000px.', null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to='wagtailimages.Image')),
('cover_picture', models.ForeignKey(help_text='Landscape mode only; horizontal width between 1000px and 3000px.', null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to='wagtailimages.image')),
],
options={
'abstract': False,
Expand All @@ -54,9 +54,9 @@ class Migration(migrations.Migration):
migrations.CreateModel(
name='ArticleTag',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('content_object', modelcluster.fields.ParentalKey(on_delete=django.db.models.deletion.CASCADE, related_name='tagged_items', to='blog.ArticlePage')),
('tag', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='blog_articletag_items', to='taggit.Tag')),
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('content_object', modelcluster.fields.ParentalKey(on_delete=django.db.models.deletion.CASCADE, related_name='tagged_items', to='blog.articlepage')),
('tag', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='blog_articletag_items', to='taggit.tag')),
],
options={
'abstract': False,
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Generated by Django 2.2.11 on 2020-03-15 17:51
# Generated by Django 3.2.6 on 2021-08-14 22:08

from django.db import migrations, models
import django.db.models.deletion
Expand All @@ -11,14 +11,14 @@ class Migration(migrations.Migration):
initial = True

dependencies = [
('wagtailcore', '0045_assign_unlock_grouppagepermission'),
('wagtailcore', '0062_comment_models_and_pagesubscription'),
]

operations = [
migrations.CreateModel(
name='ContactPage',
fields=[
('page_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='wagtailcore.Page')),
('page_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='wagtailcore.page')),
('address', models.TextField(blank=True)),
],
options={
Expand All @@ -29,10 +29,10 @@ class Migration(migrations.Migration):
migrations.CreateModel(
name='ContactPagePhoneNumber',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('sort_order', models.IntegerField(blank=True, editable=False, null=True)),
('phone_number', phonenumber_field.modelfields.PhoneNumberField(blank=True, max_length=128, region=None)),
('page', modelcluster.fields.ParentalKey(on_delete=django.db.models.deletion.CASCADE, related_name='phone_numbers', to='contact.ContactPage')),
('page', modelcluster.fields.ParentalKey(on_delete=django.db.models.deletion.CASCADE, related_name='phone_numbers', to='contact.contactpage')),
],
options={
'ordering': ['sort_order'],
Expand All @@ -42,10 +42,10 @@ class Migration(migrations.Migration):
migrations.CreateModel(
name='ContactPageEmailAddress',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('sort_order', models.IntegerField(blank=True, editable=False, null=True)),
('email_address', models.EmailField(blank=True, max_length=254)),
('page', modelcluster.fields.ParentalKey(on_delete=django.db.models.deletion.CASCADE, related_name='email_addresses', to='contact.ContactPage')),
('page', modelcluster.fields.ParentalKey(on_delete=django.db.models.deletion.CASCADE, related_name='email_addresses', to='contact.contactpage')),
],
options={
'ordering': ['sort_order'],
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Generated by Django 2.2.11 on 2020-03-15 17:51
# Generated by Django 3.2.6 on 2021-08-14 22:08

from django.db import migrations, models
import django.db.models.deletion
Expand All @@ -9,14 +9,14 @@ class Migration(migrations.Migration):
initial = True

dependencies = [
('wagtailcore', '0045_assign_unlock_grouppagepermission'),
('wagtailcore', '0062_comment_models_and_pagesubscription'),
]

operations = [
migrations.CreateModel(
name='AboutPage',
fields=[
('page_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='wagtailcore.Page')),
('page_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='wagtailcore.page')),
],
options={
'abstract': False,
Expand All @@ -26,7 +26,7 @@ class Migration(migrations.Migration):
migrations.CreateModel(
name='HomePage',
fields=[
('page_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='wagtailcore.Page')),
('page_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='wagtailcore.page')),
],
options={
'abstract': False,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import random
import wagtail_factories
from django.contrib.auth.models import User
import factory
from wagtail.core import blocks
from wagtail.contrib.table_block.blocks import TableBlock
Expand All @@ -12,6 +11,7 @@

from {{cookiecutter.project_slug}}.blog.models import ArticlePage, ArticleIndexPage

from {{cookiecutter.project_slug}}.users.models import User
from {{cookiecutter.project_slug}}.contact.models import ContactPage
from {{cookiecutter.project_slug}}.home.models import AboutPage, HomePage

Expand Down Expand Up @@ -51,7 +51,7 @@ class Meta:
class UserFactory(factory.django.DjangoModelFactory):
"""Factory for creating Django User objects"""

username = factory.Faker("user_name")
# username = factory.Faker("user_name")
email = factory.Faker("email")
first_name = factory.Faker("first_name")
last_name = factory.Faker("last_name")
Expand Down
Empty file.
Loading

0 comments on commit 9d0289b

Please sign in to comment.