-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ac17731
commit 6d9db4e
Showing
31 changed files
with
322 additions
and
1,158 deletions.
There are no files selected for viewing
Empty file.
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,3 @@ | ||
from fake import FAKER | ||
|
||
png_bytes = FAKER.png() |
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,3 @@ | ||
from fake import FAKER | ||
|
||
png_bytes = FAKER.png(size=(500, 500), color=(127, 127, 127)) |
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,3 @@ | ||
from fake import FAKER | ||
|
||
png_file = FAKER.png_file() |
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,3 @@ | ||
from fake import FAKER | ||
|
||
png_file = FAKER.png_file(size=(500, 500), color=(127, 127, 127)) |
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,3 @@ | ||
from fake import FAKER, GraphicPdfGenerator | ||
|
||
pdf_bytes = FAKER.pdf(generator=GraphicPdfGenerator) |
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,3 @@ | ||
from fake import FAKER, GraphicPdfGenerator | ||
|
||
pdf_bytes = FAKER.pdf(nb_pages=100, generator=GraphicPdfGenerator) |
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,3 @@ | ||
from fake import FAKER, GraphicPdfGenerator | ||
|
||
pdf_file = FAKER.pdf_file(generator=GraphicPdfGenerator) |
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,3 @@ | ||
from fake import FAKER, GraphicPdfGenerator | ||
|
||
pdf_file = FAKER.pdf_file(nb_pages=100, generator=GraphicPdfGenerator) |
Empty file.
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,3 @@ | ||
from fake import FAKER, TextPdfGenerator | ||
|
||
pdf_bytes = FAKER.pdf(generator=TextPdfGenerator) |
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,4 @@ | ||
from fake import FAKER, TextPdfGenerator | ||
|
||
texts = FAKER.sentences() | ||
pdf_bytes = FAKER.pdf(texts=texts, generator=TextPdfGenerator) |
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,3 @@ | ||
from fake import FAKER, TextPdfGenerator | ||
|
||
pdf_bytes = FAKER.pdf(nb_pages=100, generator=TextPdfGenerator) |
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,3 @@ | ||
from fake import FAKER, TextPdfGenerator | ||
|
||
pdf_file = FAKER.pdf_file(generator=TextPdfGenerator) |
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,4 @@ | ||
from fake import FAKER, TextPdfGenerator | ||
|
||
texts = FAKER.sentences() | ||
pdf_file = FAKER.pdf_file(texts=texts, generator=TextPdfGenerator) |
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,3 @@ | ||
from fake import FAKER, TextPdfGenerator | ||
|
||
pdf_file = FAKER.pdf_file(nb_pages=100, generator=TextPdfGenerator) |
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,6 @@ | ||
from django.conf import settings | ||
from fake import FAKER, TextPdfGenerator, FileSystemStorage | ||
|
||
STORAGE = FileSystemStorage(root_path=settings.MEDIA_ROOT, rel_path="tmp") | ||
|
||
pdf_file = FAKER.pdf_file(generator=TextPdfGenerator, storage=STORAGE) |
9 changes: 9 additions & 0 deletions
9
docs/_static/examples/creating_pdf/text_pdf_file_pydantic_1.py
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,9 @@ | ||
from pathlib import Path | ||
from fake import FAKER, TextPdfGenerator, FileSystemStorage | ||
|
||
BASE_DIR = Path(__file__).resolve().parent.parent | ||
MEDIA_ROOT = BASE_DIR / "media" | ||
|
||
STORAGE = FileSystemStorage(root_path=MEDIA_ROOT, rel_path="tmp") | ||
|
||
pdf_file = FAKER.pdf_file(generator=TextPdfGenerator, storage=STORAGE) |
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,46 @@ | ||
from django.conf import settings | ||
from django.contrib.auth.models import User | ||
from fake import ( | ||
DjangoModelFactory, | ||
Factory, | ||
FileSystemStorage, | ||
SubFactory, | ||
pre_save, | ||
) | ||
|
||
from article.models import Article | ||
|
||
STORAGE = FileSystemStorage(root_path=settings.MEDIA_ROOT, rel_path="tmp") | ||
|
||
|
||
class UserFactory(DjangoModelFactory): | ||
username = Factory.username() | ||
first_name = Factory.first_name() | ||
last_name = Factory.last_name() | ||
email = Factory.email() | ||
last_login = Factory.date_time() | ||
is_superuser = False | ||
is_staff = False | ||
is_active = Factory.pybool() | ||
date_joined = Factory.date_time() | ||
|
||
class Meta: | ||
model = User | ||
|
||
@pre_save | ||
def __set_password(instance): | ||
instance.set_password("test") | ||
|
||
|
||
class ArticleFactory(DjangoModelFactory): | ||
title = Factory.sentence() | ||
slug = Factory.slug() | ||
content = Factory.text() | ||
image = Factory.png_file(storage=STORAGE) | ||
pub_date = Factory.date() | ||
safe_for_work = Factory.pybool() | ||
minutes_to_read = Factory.pyint(min_value=1, max_value=10) | ||
author = SubFactory(UserFactory) | ||
|
||
class Meta: | ||
model = Article |
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,19 @@ | ||
from django.conf import settings | ||
from django.db import models | ||
from django.utils import timezone | ||
|
||
|
||
class Article(models.Model): | ||
title = models.CharField(max_length=255) | ||
slug = models.SlugField(unique=True) | ||
content = models.TextField() | ||
image = models.ImageField(null=True, blank=True) | ||
pub_date = models.DateTimeField(default=timezone.now) | ||
safe_for_work = models.BooleanField(default=False) | ||
minutes_to_read = models.IntegerField(default=5) | ||
author = models.ForeignKey( | ||
settings.AUTH_USER_MODEL, on_delete=models.CASCADE | ||
) | ||
|
||
def __str__(self): | ||
return self.title |
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,41 @@ | ||
from pathlib import Path | ||
|
||
from fake import Factory, FileSystemStorage, ModelFactory, SubFactory | ||
|
||
from article.models import Article, User | ||
|
||
BASE_DIR = Path(__file__).resolve().parent.parent | ||
MEDIA_ROOT = BASE_DIR / "media" | ||
|
||
STORAGE = FileSystemStorage(root_path=MEDIA_ROOT, rel_path="tmp") | ||
|
||
|
||
class UserFactory(ModelFactory): | ||
id = Factory.pyint() | ||
username = Factory.username() | ||
first_name = Factory.first_name() | ||
last_name = Factory.last_name() | ||
email = Factory.email() | ||
last_login = Factory.date_time() | ||
is_superuser = False | ||
is_staff = False | ||
is_active = Factory.pybool() | ||
date_joined = Factory.date_time() | ||
|
||
class Meta: | ||
model = User | ||
|
||
|
||
class ArticleFactory(ModelFactory): | ||
id = Factory.pyint() | ||
title = Factory.sentence() | ||
slug = Factory.slug() | ||
content = Factory.text() | ||
image = Factory.png_file(storage=STORAGE) | ||
pub_date = Factory.date() | ||
safe_for_work = Factory.pybool() | ||
minutes_to_read = Factory.pyint(min_value=1, max_value=10) | ||
author = SubFactory(UserFactory) | ||
|
||
class Meta: | ||
model = Article |
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,36 @@ | ||
from datetime import datetime | ||
from typing import Optional | ||
|
||
from pydantic import BaseModel, Field | ||
|
||
|
||
class User(BaseModel): | ||
id: int | ||
username: str = Field(..., max_length=255) | ||
first_name: str = Field(..., max_length=255) | ||
last_name: str = Field(..., max_length=255) | ||
email: str = Field(..., max_length=255) | ||
password: Optional[str] = Field("", max_length=255) | ||
last_login: Optional[datetime] | ||
is_superuser: bool = Field(default=False) | ||
is_staff: bool = Field(default=False) | ||
is_active: bool = Field(default=True) | ||
date_joined: Optional[datetime] | ||
|
||
def __str__(self): | ||
return self.username | ||
|
||
|
||
class Article(BaseModel): | ||
id: int | ||
title: str = Field(..., max_length=255) | ||
slug: str = Field(..., max_length=255, unique=True) | ||
content: str | ||
image: Optional[str] = None # Use str to represent the image path or URL | ||
pub_date: datetime = Field(default_factory=datetime.now) | ||
safe_for_work: bool = False | ||
minutes_to_read: int = 5 | ||
author: User | ||
|
||
def __str__(self): | ||
return self.title |
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,41 @@ | ||
from pathlib import Path | ||
|
||
from fake import Factory, FileSystemStorage, SubFactory, TortoiseModelFactory | ||
|
||
from article.models import Article, User | ||
|
||
BASE_DIR = Path(__file__).resolve().parent.parent | ||
MEDIA_ROOT = BASE_DIR / "media" | ||
|
||
STORAGE = FileSystemStorage(root_path=MEDIA_ROOT, rel_path="tmp") | ||
|
||
|
||
class UserFactory(TortoiseModelFactory): | ||
id = Factory.pyint() | ||
username = Factory.username() | ||
first_name = Factory.first_name() | ||
last_name = Factory.last_name() | ||
email = Factory.email() | ||
last_login = Factory.date_time() | ||
is_superuser = False | ||
is_staff = False | ||
is_active = Factory.pybool() | ||
date_joined = Factory.date_time() | ||
|
||
class Meta: | ||
model = User | ||
|
||
|
||
class ArticleFactory(TortoiseModelFactory): | ||
id = Factory.pyint() | ||
title = Factory.sentence() | ||
slug = Factory.slug() | ||
content = Factory.text() | ||
image = Factory.png_file(storage=STORAGE) | ||
pub_date = Factory.date_time() | ||
safe_for_work = Factory.pybool() | ||
minutes_to_read = Factory.pyint(min_value=1, max_value=10) | ||
author = SubFactory(UserFactory) | ||
|
||
class Meta: | ||
model = Article |
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,36 @@ | ||
from datetime import datetime | ||
|
||
from tortoise import fields | ||
from tortoise.models import Model | ||
|
||
|
||
class User(Model): | ||
id = fields.IntField(pk=True) | ||
username = fields.CharField(max_length=255) | ||
first_name = fields.CharField(max_length=255) | ||
last_name = fields.CharField(max_length=255) | ||
email = fields.CharField(max_length=255) | ||
password = fields.CharField(max_length=255, null=True, blank=True) | ||
last_login = fields.DatetimeField(null=True, blank=True) | ||
is_superuser = fields.BooleanField(default=False) | ||
is_staff = fields.BooleanField(default=False) | ||
is_active = fields.BooleanField(default=True) | ||
date_joined = fields.DatetimeField(null=True, blank=True) | ||
|
||
def __str__(self): | ||
return self.title | ||
|
||
|
||
class Article(Model): | ||
id = fields.IntField(pk=True) | ||
title = fields.CharField(max_length=255) | ||
slug = fields.CharField(max_length=255, unique=True) | ||
content = fields.TextField() | ||
image = fields.TextField(null=True, blank=True) | ||
pub_date = fields.DatetimeField(default=datetime.now) | ||
safe_for_work = fields.BooleanField(default=False) | ||
minutes_to_read = fields.IntField(default=5) | ||
author = fields.ForeignKeyField("models.User", on_delete=fields.CASCADE) | ||
|
||
def __str__(self): | ||
return self.title |
Oops, something went wrong.