bukuserver package
bukuserver.filters module
- class bukuserver.filters.BaseFilter(name, options=None, data_type=None, key_name=None)[source]
Bases:
flask_admin.model.filters.BaseFilter
- class bukuserver.filters.BookmarkBaseFilter(name, operation_text=None, apply_func=None, filter_type=None, options=None, data_type=None)[source]
- class bukuserver.filters.BookmarkBukuFilter(*args, **kwargs)[source]
- class bukuserver.filters.BookmarkField(value)[source]
Bases:
enum.EnumAn enumeration.
- DESCRIPTION = 4
- ID = 0
- TAGS = 3
- TITLE = 2
- URL = 1
- class bukuserver.filters.FilterType(value)[source]
Bases:
enum.EnumAn enumeration.
- BOTTOM_X = {'func': <function bottom_x_func>, 'text': 'bottom x'}
- EQUAL = {'func': <function equal_func>, 'text': 'equals'}
- GREATER = {'func': <function greater_func>, 'text': 'greater than'}
- IN_LIST = {'func': <function in_list_func>, 'text': 'in list'}
- NOT_EQUAL = {'func': <function not_equal_func>, 'text': 'not equal'}
- NOT_IN_LIST = {'func': <function not_in_list_func>, 'text': 'not in list'}
- SMALLER = {'func': <function smaller_func>, 'text': 'smaller than'}
- TOP_X = {'func': <function top_x_func>, 'text': 'top x'}
bukuserver.forms module
Forms module.
- class bukuserver.forms.BookmarkForm(*args, **kwargs)[source]
Bases:
flask_wtf.form.FlaskForm- description = <UnboundField(TextAreaField, (), {})>
- tags = <UnboundField(StringField, (), {})>
- title = <UnboundField(StringField, (), {})>
- url = <UnboundField(StringField, (), {'validators': [<wtforms.validators.DataRequired object>]})>
- class bukuserver.forms.HomeForm(*args, **kwargs)[source]
Bases:
bukuserver.forms.SearchBookmarksForm- keyword = <UnboundField(StringField, ('Keyword',), {})>
- class bukuserver.forms.SearchBookmarksForm(*args, **kwargs)[source]
Bases:
flask_wtf.form.FlaskForm- all_keywords = <UnboundField(BooleanField, ('Match all keywords',), {})>
- deep = <UnboundField(BooleanField, ('Deep search',), {})>
- keywords = <UnboundField(FieldList, (<UnboundField(StringField, ('Keywords',), {})>,), {'min_entries': 1})>
- regex = <UnboundField(BooleanField, ('Regex',), {})>
bukuserver.response module
bukuserver.server module
Server module.
- class bukuserver.server.ApiBookmarkRangeView[source]
Bases:
flask.views.MethodView- methods = {'DELETE', 'GET', 'PUT'}
A list of methods this view can handle.
- class bukuserver.server.ApiBookmarkSearchView[source]
Bases:
flask.views.MethodView- methods = {'DELETE', 'GET'}
A list of methods this view can handle.
- class bukuserver.server.ApiBookmarkView[source]
Bases:
flask.views.MethodView- methods = {'DELETE', 'GET', 'POST', 'PUT'}
A list of methods this view can handle.
- class bukuserver.server.ApiTagView[source]
Bases:
flask.views.MethodView- methods = {'GET', 'PUT'}
A list of methods this view can handle.
- class bukuserver.server.BookmarkletView[source]
Bases:
flask.views.MethodView- methods = {'GET'}
A list of methods this view can handle.
- bukuserver.server.get_bool_from_env_var(key: str, default_value: bool) bool[source]
Get bool value from env var.
- bukuserver.server.search_tag(db: buku.BukuDb, stag: Optional[str] = None, limit: Optional[int] = None) Tuple[List[str], Dict[str, int]][source]
search tag.
- db:
buku db instance
- stag:
search tag
- limit:
positive integer limit
- Returns
list of unique tags sorted alphabetically and dictionary of tag and its usage count
- Return type
tuple
- Raises
ValueError – if limit is not positive
bukuserver.views module
views module.
- class bukuserver.views.BookmarkModelView(*args, **kwargs)[source]
Bases:
flask_admin.model.base.BaseModelView- action_view()
Mass-model action view.
- ajax_lookup()
- ajax_update()
Edits a single column of a record in list view.
- can_set_page_size = True
Allows to select page size via dropdown list
- can_view_details = True
Setting this to true will enable the details view. This is recommended when there are too many columns to display in the list_view.
- column_filters = ['buku', 'id', 'url', 'title', 'tags']
Collection of the column filters.
Can contain either field names or instances of
BaseFilterclasses.Example:
class MyModelView(BaseModelView): column_filters = ('user', 'email')
- column_formatters = {'Entry': <function BookmarkModelView._list_entry>}
Dictionary of list view column formatters.
For example, if you want to show price multiplied by two, you can do something like this:
class MyModelView(BaseModelView): column_formatters = dict(price=lambda v, c, m, p: m.price*2)
or using Jinja2 macro in template:
from flask_admin.model.template import macro class MyModelView(BaseModelView): column_formatters = dict(price=macro('render_price')) # in template {% macro render_price(model, column) %} {{ model.price * 2 }} {% endmacro %}
The Callback function has the prototype:
def formatter(view, context, model, name): # `view` is current administrative view # `context` is instance of jinja2.runtime.Context # `model` is model instance # `name` is property name pass
- column_list = ['Entry']
Collection of the model field names for the list view. If set to None, will get them from the model.
For example:
class MyModelView(BaseModelView): column_list = ('name', 'last_name', 'email')
(Added in 1.4.0) SQLAlchemy model attributes can be used instead of strings:
class MyModelView(BaseModelView): column_list = ('name', User.last_name)
- When using SQLAlchemy models, you can reference related columns like this::
- class MyModelView(BaseModelView):
column_list = (‘<relationship>.<related column name>’,)
- create_form(obj=None)[source]
Instantiate model creation form and return it.
Override to implement custom behavior.
- create_modal = True
Setting this to true will display the create_view as a modal dialog.
- create_modal_template = 'bukuserver/bookmark_create_modal.html'
Default create modal template
- create_model(form)[source]
Create model from the form.
Returns the model instance if operation succeeded.
Must be implemented in the child class.
- Parameters
form – Form instance
- create_template = 'bukuserver/bookmark_create.html'
Default create template
- create_view()
Create model view
- delete_model(model)[source]
Delete model.
Returns True if operation succeeded.
Must be implemented in the child class.
- Parameters
model – Model instance
- delete_view()
Delete model view. Only POST method is allowed.
- details_modal = True
Setting this to true will display the details_view as a modal dialog.
- details_view()
Details model view
- edit_modal = True
Setting this to true will display the edit_view as a modal dialog.
- edit_modal_template = 'bukuserver/bookmark_edit_modal.html'
Default edit modal template
- edit_template = 'bukuserver/bookmark_edit.html'
Default edit template
- edit_view()
Edit model view
- export(export_type)
- get_list(page, sort_field, sort_desc, _, filters, page_size=None)[source]
Return a paginated and sorted list of models from the data source.
Must be implemented in the child class.
- Parameters
page – Page number, 0 based. Can be set to None if it is first page.
sort_field – Sort column name or None.
sort_desc – If set to True, sorting is in descending order.
search – Search query
filters – List of filter tuples. First value in a tuple is a search index, second value is a search value.
page_size – Number of results. Defaults to ModelView’s page_size. Can be overriden to change the page_size limit. Removing the page_size limit requires setting page_size to 0 or False.
- get_one(id)[source]
Return one model by its id.
Must be implemented in the child class.
- Parameters
id – Model id
- index_view()
List view
- named_filter_urls = True
Set to True to use human-readable names for filters in URL parameters.
False by default so as to be robust across translations.
Changing this parameter will break any existing URLs that have filters.
- scaffold_filters(name)[source]
Generate filter object for the given name
- Parameters
name – Name of the field
- scaffold_form()[source]
Create form.BaseForm inherited class from the model. Must be implemented in the child class.
- scaffold_list_columns()[source]
Return list of the model field names. Must be implemented in the child class.
Expected return format is list of tuples with field name and display text. For example:
['name', 'first_name', 'last_name']
- scaffold_list_form(widget=None, validators=None)[source]
Create form for the index_view using only the columns from self.column_editable_list.
- Parameters
widget – WTForms widget class. Defaults to XEditableWidget.
validators – form_args dict with only validators {‘name’: {‘validators’: [DataRequired()]}}
Must be implemented in the child class.
- scaffold_sortable_columns()[source]
Returns dictionary of sortable columns. Must be implemented in the child class.
Expected return format is a dictionary, where keys are field names and values are property names.
- update_model(form: bukuserver.forms.BookmarkForm, model: argparse.Namespace)[source]
Update model from the form.
Returns True if operation succeeded.
Must be implemented in the child class.
- Parameters
form – Form instance
model – Model instance
- class bukuserver.views.CustomAdminIndexView(name=None, category=None, endpoint=None, url=None, template='admin/index.html', menu_class_name=None, menu_icon_type=None, menu_icon_value=None)[source]
Bases:
flask_admin.base.AdminIndexView
- class bukuserver.views.TagModelView(*args, **kwargs)[source]
Bases:
flask_admin.model.base.BaseModelView- action_view()
Mass-model action view.
- ajax_lookup()
- ajax_update()
Edits a single column of a record in list view.
- can_create = False
Is model creation allowed
- can_set_page_size = True
Allows to select page size via dropdown list
- column_filters = ['name', 'usage_count']
Collection of the column filters.
Can contain either field names or instances of
BaseFilterclasses.Example:
class MyModelView(BaseModelView): column_filters = ('user', 'email')
- column_formatters = {'name': <function TagModelView._name_formatter>}
Dictionary of list view column formatters.
For example, if you want to show price multiplied by two, you can do something like this:
class MyModelView(BaseModelView): column_formatters = dict(price=lambda v, c, m, p: m.price*2)
or using Jinja2 macro in template:
from flask_admin.model.template import macro class MyModelView(BaseModelView): column_formatters = dict(price=macro('render_price')) # in template {% macro render_price(model, column) %} {{ model.price * 2 }} {% endmacro %}
The Callback function has the prototype:
def formatter(view, context, model, name): # `view` is current administrative view # `context` is instance of jinja2.runtime.Context # `model` is model instance # `name` is property name pass
- create_model(form)[source]
Create model from the form.
Returns the model instance if operation succeeded.
Must be implemented in the child class.
- Parameters
form – Form instance
- create_view()
Create model view
- delete_model(model)[source]
Delete model.
Returns True if operation succeeded.
Must be implemented in the child class.
- Parameters
model – Model instance
- delete_view()
Delete model view. Only POST method is allowed.
- details_view()
Details model view
- edit_view()
Edit model view
- export(export_type)
- get_list(page: int, sort_field: str, sort_desc: bool, search: Optional[Any], filters: List[Tuple[int, str, str]], page_size: Optional[int] = None) Tuple[int, List[types.SimpleNamespace]][source]
Return a paginated and sorted list of models from the data source.
Must be implemented in the child class.
- Parameters
page – Page number, 0 based. Can be set to None if it is first page.
sort_field – Sort column name or None.
sort_desc – If set to True, sorting is in descending order.
search – Search query
filters – List of filter tuples. First value in a tuple is a search index, second value is a search value.
page_size – Number of results. Defaults to ModelView’s page_size. Can be overriden to change the page_size limit. Removing the page_size limit requires setting page_size to 0 or False.
- get_one(id)[source]
Return one model by its id.
Must be implemented in the child class.
- Parameters
id – Model id
- index_view()
List view
- scaffold_filters(name)[source]
Generate filter object for the given name
- Parameters
name – Name of the field
- scaffold_form()[source]
Create form.BaseForm inherited class from the model. Must be implemented in the child class.
- scaffold_list_columns()[source]
Return list of the model field names. Must be implemented in the child class.
Expected return format is list of tuples with field name and display text. For example:
['name', 'first_name', 'last_name']
- scaffold_list_form(widget=None, validators=None)[source]
Create form for the index_view using only the columns from self.column_editable_list.
- Parameters
widget – WTForms widget class. Defaults to XEditableWidget.
validators – form_args dict with only validators {‘name’: {‘validators’: [DataRequired()]}}
Must be implemented in the child class.