MangAdventure package

A simple manga hosting CMS written in Django.

Submodules

MangAdventure.converters module

Path converters used in URL patterns.

class MangAdventure.converters.FloatConverter[source]

Bases: object

Path converter that matches a float number.

regex = '\\d+(\\.\\d+)?'

str – The pattern to match.

to_python(value)[source]

Convert the matched string into the type that should be passed to the view function.

Parameters

value (str) – The matched string.

Return type

float

Returns

The match as a float.

to_url(value)[source]

Convert the Python type into a string to be used in the URL.

Parameters

value (str) – The matched string.

Return type

str

Returns

The match with trailing zeroes removed.

MangAdventure.fields module

Custom database models & model fields.

class MangAdventure.fields.TwitterField(*args, **kwargs)[source]

Bases: django.db.models.CharField

A CharField for Twitter usernames.

default_validators = (<MangAdventure.validators.TwitterNameValidator object>,)
class MangAdventure.fields.DiscordNameField(*args, **kwargs)[source]

Bases: django.db.models.CharField

A CharField for Discord usernames.

default_validators = (<MangAdventure.validators.DiscordNameValidator object>,)
class MangAdventure.fields.DiscordURLField(verbose_name=None, name=None, **kwargs)[source]

Bases: django.db.models.URLField

A CharField for Discord server URLs.

default_validators = (<MangAdventure.validators.DiscordServerValidator object>,)
class MangAdventure.fields.RedditField(*args, **kwargs)[source]

Bases: django.db.models.CharField

A CharField for Reddit names.

default_validators = (<MangAdventure.validators.RedditNameValidator object>,)

MangAdventure.filters module

A collection of filters used in the admin interface.

MangAdventure.filters.title_filter(title, klass=<class 'django.contrib.admin.filters.FieldListFilter'>)[source]

A FieldListFilter with a custom title.

Parameters
  • title (str) – The title of the filter.

  • klass (Type[FieldListFilter]) – The parent class of the filter. Must be a subclass of FieldListFilter.

Return type

Type[FieldListFilter]

Returns

A class that inherits from klass.

MangAdventure.filters.boolean_filter(title, param, names)[source]

A boolean SimpleListFilter.

Parameters
  • title (str) – The title of the filter.

  • param (str) – The name of the parameter to filter.

  • names (Tuple[str, str]) – The names for True and False respectively.

Return type

Type[SimpleListFilter]

Returns

A class that inherits from SimpleListFilter.

MangAdventure.filters.related_filter(title, *, klass=<class 'django.contrib.admin.filters.RelatedFieldListFilter'>)

A title_filter() for related fields.

Returns

A class that inherits from RelatedFieldListFilter.

MangAdventure.forms module

Custom form fields.

class MangAdventure.forms.TwitterField(*, max_length=None, min_length=None, strip=True, empty_value='', **kwargs)[source]

Bases: django.forms.CharField

A CharField for Twitter usernames.

default_validators = (<MangAdventure.validators.TwitterNameValidator object>,)
class MangAdventure.forms.DiscordURLField(**kwargs)[source]

Bases: django.forms.URLField

A URLField for Discord server URLs.

default_validators = (<MangAdventure.validators.DiscordServerValidator object>,)

MangAdventure.jsonld module

Functions used to generate JSON-LD objects.

MangAdventure.jsonld.schema(at_type, items)[source]

Generate an arbitrary JSON-LD object.

The object’s @context links to https://schema.org.

Parameters
  • at_type (str) – The @type of the object.

  • items (Dict[str, Any]) – The key-value pairs of the object.

Return type

Dict[str, Any]

Returns

A JSON-LD dictionary.

MangAdventure.jsonld.breadcrumbs(items)[source]

Generate a BreadcrumbList JSON-LD object.

Parameters

items (List[Tuple[str, str]]) – A list of ListItem tuples. The first element of each tuple is the name and the second is the item.

Return type

Dict[str, Any]

Returns

A JSON-LD dictionary.

MangAdventure.jsonld.carousel(items)[source]

Generate an ItemList JSON-LD object.

Parameters

items (List[str]) – A list of ListItem urls

Return type

Dict[str, Any]

Returns

A JSON-LD dictionary.

MangAdventure.middleware module

Custom middleware.

class MangAdventure.middleware.BaseMiddleware(get_response=None)[source]

Bases: django.middleware.common.CommonMiddleware

CommonMiddleware with custom patches.

__call__(request)[source]

Patched to allow blocked user agents to view /robots.txt.

Parameters

request (HttpRequest) – The original request.

Return type

HttpResponse

Returns

The response to the request.

class MangAdventure.middleware.PreloadMiddleware(get_response)[source]

Bases: object

Middleware that allows for preloading resources.

Parameters

get_response (Callable[[HttpRequest], HttpResponse]) –

__call__(request)[source]

Add a Link header with preloadable resources to the response.

Parameters

request (HttpRequest) – The original request.

Return type

HttpResponse

Returns

The response to the request.

MangAdventure.search module

Functions used for searching.

MangAdventure.search.parse(request)[source]

Parse a request and return a namedtuple of search parameters.

Parameters

request (HttpRequest) – The original request.

Return type

_SearchParams

Returns

The parameters of the request.

MangAdventure.search.qsfilter(params)[source]

Create a queryset filter from the given search parameters.

Parameters

params (_SearchParams) – A namedtuple of parameters.

Return type

Q

Returns

The created queryset filter.

MangAdventure.search.query(params)[source]

Get a queryset of Series from the given search parameters.

Parameters

params (_SearchParams) – A namedtuple of parameters.

Return type

QuerySet

Returns

A queryset of series matching the given parameters.

MangAdventure.search.get_response(request)[source]

Get a queryset of Series from the given request.

Parameters

request (HttpRequest) – The original request.

Return type

QuerySet

Returns

A queryset of series matching the parameters of the request.

MangAdventure.settings module

MangAdventure.storage module

Custom storages.

class MangAdventure.storage.CDNStorage(*args, **kwargs)[source]

Bases: django.core.files.storage.FileSystemStorage

Storage class that may use an image CDN.

The options are statically, weserv & photon.

Parameters

fit (Optional[Tuple[int, int]]) – A tuple of width & height to fit the image in.

url(name)[source]

Return the URL where the contents of the file referenced by name can be accessed.

Parameters

name (str) – The name of the file.

Return type

str

Returns

The URL of the file.

MangAdventure.urls module

The root URLconf.

MangAdventure.urls.urlpatterns = [<URLPattern '' [name='index']>, <URLResolver <module 'config.urls' from '/home/docs/checkouts/readthedocs.org/user_builds/mangadventure/checkouts/latest/config/urls.py'> (None:None) ''>, <URLPattern 'search/' [name='search']>, <URLResolver <URLPattern list> (admin:admin) 'admin-panel/'>, <URLResolver <module 'reader.urls' from '/home/docs/checkouts/readthedocs.org/user_builds/mangadventure/checkouts/latest/reader/urls.py'> (reader:reader) 'reader/'>, <URLResolver <module 'api.urls' from '/home/docs/checkouts/readthedocs.org/user_builds/mangadventure/checkouts/latest/api/urls.py'> (api:api) 'api/'>, <URLResolver <module 'groups.urls' from '/home/docs/checkouts/readthedocs.org/user_builds/mangadventure/checkouts/latest/groups/urls.py'> (groups:groups) 'groups/'>, <URLResolver <module 'users.urls' from '/home/docs/checkouts/readthedocs.org/user_builds/mangadventure/checkouts/latest/users/urls.py'> (None:None) 'user/'>, <URLPattern 'opensearch.xml' [name='opensearch']>, <URLPattern 'contribute.json' [name='contribute']>, <URLPattern 'manifest.webmanifest' [name='manifest']>, <URLPattern 'robots.txt' [name='robots']>, <URLPattern 'releases.atom' [name='releases.atom']>, <URLPattern 'releases.rss' [name='releases.rss']>, <URLPattern 'library.atom' [name='library.atom']>, <URLPattern 'library.rss' [name='library.rss']>]

The main URL patterns.

MangAdventure.urls.handler400 = 'MangAdventure.views.handler400'

See MangAdventure.views.handler400().

MangAdventure.urls.handler403 = 'MangAdventure.views.handler403'

See MangAdventure.views.handler403().

MangAdventure.urls.handler404 = 'MangAdventure.views.handler404'

See MangAdventure.views.handler404().

MangAdventure.urls.handler500 = 'MangAdventure.views.handler500'

See MangAdventure.views.handler500().

MangAdventure.utils module

Various utility functions.

class MangAdventure.utils.HttpResponseUnauthorized(content=b'', realm='private', auth_type='Bearer', **kwargs)[source]

Bases: django.http.HttpResponse

A response class for HTTP 401.

Parameters
MangAdventure.utils.img_tag(obj, alt, height=0, width=0)[source]

Create an HTML <img> from an ImageField.

Parameters
  • obj (FieldFile) – An ImageFieldFile instance.

  • alt (str) – The alternate text of the tag.

  • height (int) – The height of the <img>. Unset if 0.

  • width (int) – The width of the <img>. Unset if 0.

Return type

str

Returns

An <img> tag with the given image.

MangAdventure.utils.natsort(original)[source]

Sort a list in natural order.

>>> sorted(map(str, range(12)))
['0', '1', '10', '11', '2', '3', '4', '5', '6', '7', '8', '9']
>>> natsort(map(str, range(12)))
['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11']
Parameters

original (Iterable[str]) – The original iterable.

Return type

List[str]

Returns

The sorted list.

MangAdventure.validators module

Custom validators.

class MangAdventure.validators.FileSizeValidator(*args, **kwargs)[source]

Bases: object

Validates that a file’s size is not greater than max_mb.

Parameters

max_mb (int) – The maximum size of the file in megabytes.

message = 'File too large. Maximum file size allowed is %(max)d MBs.'

str – The error message of the validator.

code = 'file_too_large'

str – The error code of the validator.

__call__(file)[source]

Call the validator on the given file.

Parameters

file (File) – The file to be validated.

Raises

ValidationError – If the file is too large.

__eq__(other)[source]

Check if this object is equal to another.

Parameters

other (Any) – Any other object.

Return type

bool

Returns

True if the objects are equal.

__hash__()[source]

Return the hash of the object.

Return type

int

Returns

An integer hash value.

deconstruct()

Return a 3-tuple of class import path, positional arguments, and keyword arguments.

class MangAdventure.validators.DiscordServerValidator(*args, **kwargs)[source]

Bases: django.core.validators.RegexValidator

Validates a Discord server URL.

regex = '^https://discord\\.(gg|me)/[A-Za-z0-9_%-]+$'
message = 'Invalid Discord server URL.'
code = 'invalid_discord_url'
MangAdventure.validators.zipfile_validator(file)[source]

Validate a zip file:

  • It must be a valid ZipFile.

  • It must only contain image files.

  • It cannot contain more than 1 subfolder.

Parameters

file (File) – The file to be validated.

Raises

ValidationError – If any of the validations failed.

class MangAdventure.validators.TwitterNameValidator(*args, **kwargs)[source]

Bases: django.core.validators.RegexValidator

Validates a Twitter name.

regex = '^[A-Za-z0-9_-]{1,15}$'
message = 'Invalid Twitter username.'
code = 'invalid_twitter_name'
class MangAdventure.validators.DiscordNameValidator(*args, **kwargs)[source]

Bases: django.core.validators.RegexValidator

Validates a Discord name.

regex = '^.{1,32}#[0-9]{4}$'
message = 'Invalid Discord username and discriminator.'
code = 'invalid_discord_name'
class MangAdventure.validators.RedditNameValidator(*args, **kwargs)[source]

Bases: django.core.validators.RegexValidator

Validates a Reddit name.

regex = '^(/[ur]/)?[A-Za-z0-9_]{3,21}$'
message = 'Invalid Reddit username or subreddit name.'
code = 'invalid_reddit_name'

MangAdventure.views module

The main views and error handlers.

MangAdventure.views.index(request)[source]

View that serves the index page which shows the latest releases.

Parameters

request (HttpRequest) – The original request.

Return type

HttpResponse

Returns

A response with the rendered index.html template.

MangAdventure.views.search(request)[source]

View that serves a page used for searching for series.

Parameters

request (HttpRequest) – The original request.

Return type

HttpResponse

Returns

A response with the rendered search.html template.

MangAdventure.views.opensearch(request)[source]

View that serves the opensearch.xml file.

Parameters

request (HttpRequest) – The original request.

Return type

HttpResponse

Returns

A response with the rendered opensearch.xml template.

MangAdventure.views.robots(request)[source]

View that serves the robots.txt file.

Parameters

request (HttpRequest) – The original request.

Return type

HttpResponse

Returns

A response with the generated robots.txt file.

MangAdventure.views.contribute(request)[source]

View that serves the contribute.json file.

Parameters

request (HttpRequest) – The original request.

Return type

HttpResponse

Returns

A response with the contribute.json file.

MangAdventure.views.manifest(request)[source]

View that serves the manifest.webmanifest file.

Parameters

request (HttpRequest) – The original request.

Return type

HttpResponse

Returns

A response with the manifest.webmanifest file.

MangAdventure.views.handler400(request, exception=None, template_name='error.html')[source]

Handler for 400 responses.

Parameters
  • request (HttpRequest) – The original request.

  • exception (Optional[Exception]) – The exception that occurred.

  • template_name (str) – The name of the error template.

Return type

HttpResponse

Returns

A JsonResponse for API URLs, otherwise a response with the rendered error template.

MangAdventure.views.handler403(request, exception=None, template_name='error.html')[source]

Handler for 403 responses.

Parameters
  • request (HttpRequest) – The original request.

  • exception (Optional[Exception]) – The exception that occurred.

  • template_name (str) – The name of the error template.

Return type

HttpResponse

Returns

A JsonResponse for API URLs, otherwise a response with the rendered error template.

MangAdventure.views.handler404(request, exception=None, template_name='error.html')[source]

Handler for 404 responses.

Parameters
  • request (HttpRequest) – The original request.

  • exception (Optional[Exception]) – The exception that occurred.

  • template_name (str) – The name of the error template.

Return type

HttpResponse

Returns

A JsonResponse for API URLs, otherwise a response with the rendered error template.

MangAdventure.views.handler500(request, exception=None, template_name='error.html')[source]

Handler for 500 responses.

Parameters
  • request (HttpRequest) – The original request.

  • exception (Optional[Exception]) – The exception that occurred.

  • template_name (str) – The name of the error template.

Return type

HttpResponse

Returns

A JsonResponse for API URLs, otherwise a response with the rendered error template.

MangAdventure.widgets module

Custom form widgets.

class MangAdventure.widgets.TinyMCE(attrs={})[source]

Bases: django.forms.Textarea

A textarea Widget for TinyMCE.

Parameters

attrs (Dict[str, Any]) – A dictionary of the widget’s attributes.

class Media[source]

Bases: object

extend = False
js = ('https://cdn.jsdelivr.net/npm/tinymce@4.9.11/tinymce.min.js', 'scripts/tinymce-init.js')

MangAdventure.wsgi module