Shopyo api#

Shopyo has some api which eases your life

api.assets#

api.assets.get_static(boxormodule, filename)[source]#

Generates url for static file, depending on debug mode being on or not

Parameters
  • boxormodule (String) – box or module name e.g. box__default/auth or someothermodule/

  • filename (String) – path of the file inside the box or module

Return type

URL for static file

api.assets.register_devstatic(app, modules_path)[source]#

Resgisters endpoint for serving files in debug mode

Parameters

app (Flask app) –

Return type

URL for static file in debug mode

api.constants#

api.database#

api.database.autoload_models(verbose=False)[source]#

Auto imports models from modules/ in desired file. Used so that flask_migrate does not miss models when migrating

Return type

None

api.email#

This file email.py contains functions for sending text and html rendered emails asynchronously

api.email.send_async_email(to, subject, template, from_email=None, **kwargs)[source]#

Sends email anachronously i.e the function is non blocking. Assume email template is valid i.e it can be rendered using flask’ render_template function and both .html and .txt email template files exits

Parameters
  • to (String) – recipient of the email

  • subject (String) – subject of the email

  • template (String) – template file path to be used in email body

  • from_email (String, optional) – sender of the email. If not set MAIL_DEFAULT_SENDER is used from config.

api.enhance#

api.enhance.base_context()[source]#

Used to define global template values

Returns

copy of dictionary

Return type

dict

api.file#

api.file.absdiroffile(filepath)[source]#

Gives absolute directory of file, normally expects __file__ as param

Parameters

filepath (str) – path of file

Returns

Absolute dir path of file

Return type

str

api.file.delete_file(path)[source]#
api.file.get_folders(path)[source]#
api.file.last_part_of_path(path)[source]#
api.file.path_exists(path)[source]#
api.file.trycopy(source, dest, verbose=False)[source]#

Non-ecursive copy of folder

Parameters
  • source (str) – source folder path

  • dest (str) – destination folder path

Return type

None

api.file.trycopytree(source, dest, verbose=False)[source]#

Recursive copy of folder

Parameters
  • source (str) – source folder path

  • dest (str) – destination folder path

Return type

None

api.file.trymkdir(path, verbose=False)[source]#

Creates dir at destination

Parameters

path (str) – path with folder already in

Return type

None

api.file.trymkfile(path, content, verbose=False)[source]#

Creates file

Parameters
  • path (str) – path to create file with filename included

  • content (str) – file content

Return type

None

api.file.tryrmcache(dir_name, verbose=False)[source]#

removes all __pycache__ starting from directory dir_name all the way to leaf directory

Parameters

dir_name (string) – path from where to start removing pycache

api.file.tryrmfile(path, verbose=False)[source]#

tries to remove file path and output message to stdin or stderr. Path must point to a file

Parameters

path (string) – path of the file to remove

Returns

returns true upon successful removal false otherwise

Return type

bool

api.file.tryrmtree(path, verbose=False)[source]#

Tries to removes an entire directory tree. Path must point to a directory. Outputs message to stdin or stderr

Parameters

path (string) – directory path to be removed

Returns

returns true upon successful return false otherwise

Return type

bool

api.file.unique_filename(fname)[source]#

api.forms#

api.forms.flash_errors(form)[source]#

Auto flash errors from WKHtml forms Reqwires base module or similar notification mechanism

Parameters

form (WKHtml form) –

Return type

None

api.html#

Used on flash flash(notify_success(‘mail sent!’))

api.html.notify(message, alert_type='primary')[source]#
Used with flash

flash(notify(‘blabla’))

Parameters
  • message (str) – message to be displayed

  • alert_type (str) – bootstrap class

Return type

None

api.html.notify_danger(message)[source]#
api.html.notify_info(message)[source]#
api.html.notify_success(message)[source]#
api.html.notify_warning(message)[source]#

api.info#

api.info.printinfo()[source]#

prints Shopyo copyright in ASCII art font

api.models#

DB-related helper utilities. Taken from database.py file at https://github.com/cookiecutter-flask/cookiecutter-flask

class api.models.CRUDMixin[source]#

Bases: object

Mixin that adds convenience methods for CRUD (create, read, update, delete) operations.

classmethod create(**kwargs)[source]#

Create a new record and save it in the database.

Returns

returns the created record

Return type

DB Class Object

delete(commit=True)[source]#

Remove the record from the database.

Parameters

commit (bool, optional) – flag whether to commit. Defaults to True.

Returns

returns the updated record if committed, None otherwise

Return type

Db Class object

save(commit=True)[source]#

Save the record.

Parameters

commit (bool, optional) – flag whether to commit. Defaults to True.

Returns

returns the record saved to db session

Return type

Db Class object

update(commit=True, **kwargs)[source]#

Update specific fields of a record

Parameters

commit (bool, optional) – flag whether to commit. Defaults to True.

Returns

returns the updated record if committed, None otherwise

Return type

Db Class object

class api.models.PkModel(**kwargs)[source]#

Bases: api.models.YoModel

Base model class that includes CRUD convenience methods, plus adds a ‘primary key’ column named ‘id’.

classmethod create(**kwargs)#

Create a new record and save it in the database.

Returns

returns the created record

Return type

DB Class Object

delete(commit=True)#

Remove the record from the database.

Parameters

commit (bool, optional) – flag whether to commit. Defaults to True.

Returns

returns the updated record if committed, None otherwise

Return type

Db Class object

classmethod get_by_id(record_id)[source]#

Get record by ID.

Parameters

record_id (int) – ID of record to get

Returns

object identified by record_id if any, None otherwise

Return type

DB Class object

id = Column(None, Integer(), table=None, primary_key=True, nullable=False)#
metadata = MetaData()#
query: t.ClassVar[Query]#

A SQLAlchemy query for a model. Equivalent to db.session.query(Model). Can be customized per-model by overriding query_class.

Warning

The query interface is considered legacy in SQLAlchemy. Prefer using session.execute(select()) instead.

query_class#

alias of flask_sqlalchemy.query.Query

registry = <sqlalchemy.orm.decl_api.registry object>#
save(commit=True)#

Save the record.

Parameters

commit (bool, optional) – flag whether to commit. Defaults to True.

Returns

returns the record saved to db session

Return type

Db Class object

update(commit=True, **kwargs)#

Update specific fields of a record

Parameters

commit (bool, optional) – flag whether to commit. Defaults to True.

Returns

returns the updated record if committed, None otherwise

Return type

Db Class object

class api.models.YoModel(**kwargs)[source]#

Bases: api.models.CRUDMixin, sqlalchemy.orm.decl_api.Model

Base model class that includes CRUD convenience methods.

classmethod create(**kwargs)#

Create a new record and save it in the database.

Returns

returns the created record

Return type

DB Class Object

delete(commit=True)#

Remove the record from the database.

Parameters

commit (bool, optional) – flag whether to commit. Defaults to True.

Returns

returns the updated record if committed, None otherwise

Return type

Db Class object

metadata = MetaData()#
query: t.ClassVar[Query]#

A SQLAlchemy query for a model. Equivalent to db.session.query(Model). Can be customized per-model by overriding query_class.

Warning

The query interface is considered legacy in SQLAlchemy. Prefer using session.execute(select()) instead.

query_class#

alias of flask_sqlalchemy.query.Query

registry = <sqlalchemy.orm.decl_api.registry object>#
save(commit=True)#

Save the record.

Parameters

commit (bool, optional) – flag whether to commit. Defaults to True.

Returns

returns the record saved to db session

Return type

Db Class object

update(commit=True, **kwargs)#

Update specific fields of a record

Parameters

commit (bool, optional) – flag whether to commit. Defaults to True.

Returns

returns the updated record if committed, None otherwise

Return type

Db Class object

api.module#

class api.module.ModuleHelp(dunderfile, dundername)[source]#

Bases: object

context()[source]#
get_self_static(filename)[source]#
method(methodname)[source]#
redirect_url(url, **kwargs)[source]#
render(filename, **kwargs)[source]#

renders file.html found in module/templates/module/file.html

api.security#

api.security.get_safe_redirect(url)[source]#

Returns url for root path if url not safe

Parameters

url (String) – url

Return type

url or root page

api.security.is_safe_redirect_url(target)[source]#

Corresponds to Djangos is_safe_url

Parameters

target (String) – url

Return type

bool

api.templates#

api.templates.yo_render(template, context_dict)[source]#

Renders template.

Usage: yo_render(“index.html”, {“x”: 1, “y”: 2}) Same as render_template(“index.html”, x=1, y=2)

Parameters
  • template (String) – template accessing

  • context_dict (Dict) – Template values

Return type

html of template

api.validators#

api.validators.get_module_path_if_exists(name)[source]#
api.validators.is_alpha_num_underscore(name)[source]#

returns whether the given name contains only alphanumeric or underscore

Parameters

name (str) – to value to check for alphanumeric or underscore

Returns

returns True if name is alphanumeric, False otherwise

Return type

bool

api.validators.is_empty_str(string)[source]#
api.validators.is_valid_slug(text)[source]#
api.validators.is_valid_url(url)[source]#
api.validators.verify_slug(form, field)[source]#