Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[0.3.0] Release from last cookiecutter template
- Loading branch information
Showing
42 changed files
with
1,615 additions
and
51 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
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
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
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,7 @@ | ||
from django.apps import AppConfig | ||
|
||
|
||
class djangoapp_sampleConfig(AppConfig): | ||
name = "djangoapp_sample" | ||
verbose_name = "Sveetch Django app sample" | ||
default_auto_field = "django.db.models.AutoField" |
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 |
---|---|---|
@@ -1,8 +1,10 @@ | ||
from .blog import BlogFactory | ||
from .article import ArticleFactory | ||
from .user import UserFactory | ||
|
||
|
||
__all__ = [ | ||
"BlogFactory", | ||
"ArticleFactory", | ||
"BlogFactory", | ||
"UserFactory", | ||
] |
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
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,69 @@ | ||
""" | ||
============ | ||
User factory | ||
============ | ||
""" | ||
import factory | ||
|
||
from django.apps import apps | ||
from django.conf import settings | ||
from django.db.models.signals import post_save | ||
|
||
|
||
def safe_get_user_model(): | ||
""" | ||
Safe loading of the User model, customized or not. | ||
""" | ||
user_app, user_model = settings.AUTH_USER_MODEL.split('.') | ||
return apps.get_registered_model(user_app, user_model) | ||
|
||
|
||
@factory.django.mute_signals(post_save) | ||
class UserFactory(factory.django.DjangoModelFactory): | ||
""" | ||
Factory to create an User object. | ||
""" | ||
first_name = factory.Faker("first_name") | ||
last_name = factory.Faker("last_name") | ||
username = factory.Sequence(lambda n: "demo-user-%d" % n) | ||
is_active = True | ||
is_staff = False | ||
is_superuser = False | ||
password = "secret" | ||
|
||
class Meta: | ||
model = safe_get_user_model() | ||
|
||
class Params: | ||
""" | ||
Declare traits that add relevant parameters for admin and superuser | ||
""" | ||
flag_is_admin = factory.Trait( | ||
is_superuser=False, | ||
is_staff=True, | ||
username=factory.Sequence(lambda n: "admin-%d" % n), | ||
) | ||
flag_is_superuser = factory.Trait( | ||
is_superuser=True, | ||
is_staff=True, | ||
username=factory.Sequence(lambda n: "superuser-%d" % n), | ||
) | ||
|
||
@factory.lazy_attribute | ||
def email(self): | ||
""" | ||
Email is automatically build from username | ||
""" | ||
return "%s@test.com" % self.username | ||
|
||
@classmethod | ||
def _create(cls, model_class, *args, **kwargs): | ||
""" | ||
Ensure the raw password gets set after the initial save | ||
""" | ||
password = kwargs.pop("password", None) | ||
obj = super(UserFactory, cls)._create(model_class, *args, **kwargs) | ||
obj.set_password(password) | ||
obj.save() | ||
return obj |
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,43 @@ | ||
# Generated by Django 3.1.13 on 2021-08-10 20:54 | ||
|
||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
import django.utils.timezone | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
initial = True | ||
|
||
dependencies = [ | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='Blog', | ||
fields=[ | ||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('title', models.CharField(default='', max_length=55, unique=True, verbose_name='title')), | ||
], | ||
options={ | ||
'verbose_name': 'Blog', | ||
'verbose_name_plural': 'Blogs', | ||
'ordering': ['title'], | ||
}, | ||
), | ||
migrations.CreateModel( | ||
name='Article', | ||
fields=[ | ||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('title', models.CharField(default='', max_length=150, verbose_name='title')), | ||
('content', models.TextField(blank=True, default='', verbose_name='content')), | ||
('publish_start', models.DateTimeField(db_index=True, default=django.utils.timezone.now, verbose_name='publication start')), | ||
('blog', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='djangoapp_sample.blog', verbose_name='Related blog')), | ||
], | ||
options={ | ||
'verbose_name': 'Article', | ||
'verbose_name_plural': 'Articles', | ||
'ordering': ['-publish_start'], | ||
}, | ||
), | ||
] |
Oops, something went wrong.