Skip to content

Commit

Permalink
More on docs
Browse files Browse the repository at this point in the history
  • Loading branch information
barseghyanartur committed Nov 30, 2023
1 parent ac17731 commit 6d9db4e
Show file tree
Hide file tree
Showing 31 changed files with 322 additions and 1,158 deletions.
Empty file.
3 changes: 3 additions & 0 deletions docs/_static/examples/creating_image/png_bytes_1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from fake import FAKER

png_bytes = FAKER.png()
3 changes: 3 additions & 0 deletions docs/_static/examples/creating_image/png_bytes_2.py
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))
3 changes: 3 additions & 0 deletions docs/_static/examples/creating_image/png_file_1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from fake import FAKER

png_file = FAKER.png_file()
3 changes: 3 additions & 0 deletions docs/_static/examples/creating_image/png_file_2.py
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))
3 changes: 3 additions & 0 deletions docs/_static/examples/creating_pdf/graphic_pdf_bytes_1.py
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)
3 changes: 3 additions & 0 deletions docs/_static/examples/creating_pdf/graphic_pdf_bytes_2.py
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)
3 changes: 3 additions & 0 deletions docs/_static/examples/creating_pdf/graphic_pdf_file_1.py
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)
3 changes: 3 additions & 0 deletions docs/_static/examples/creating_pdf/graphic_pdf_file_2.py
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.
3 changes: 3 additions & 0 deletions docs/_static/examples/creating_pdf/text_pdf_bytes_1.py
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)
4 changes: 4 additions & 0 deletions docs/_static/examples/creating_pdf/text_pdf_bytes_2.py
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)
3 changes: 3 additions & 0 deletions docs/_static/examples/creating_pdf/text_pdf_bytes_3.py
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)
3 changes: 3 additions & 0 deletions docs/_static/examples/creating_pdf/text_pdf_file_1.py
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)
4 changes: 4 additions & 0 deletions docs/_static/examples/creating_pdf/text_pdf_file_2.py
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)
3 changes: 3 additions & 0 deletions docs/_static/examples/creating_pdf/text_pdf_file_3.py
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)
6 changes: 6 additions & 0 deletions docs/_static/examples/creating_pdf/text_pdf_file_django_1.py
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)
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)
46 changes: 46 additions & 0 deletions docs/_static/examples/factories/django_factories_1.py
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
19 changes: 19 additions & 0 deletions docs/_static/examples/factories/django_models_1.py
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
41 changes: 41 additions & 0 deletions docs/_static/examples/factories/pydantic_factories_1.py
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
36 changes: 36 additions & 0 deletions docs/_static/examples/factories/pydantic_models_1.py
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
41 changes: 41 additions & 0 deletions docs/_static/examples/factories/tortoise_factories_1.py
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
36 changes: 36 additions & 0 deletions docs/_static/examples/factories/tortoise_models_1.py
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
Loading

0 comments on commit 6d9db4e

Please sign in to comment.