forked from jarun/buku
-
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.
[jarun#676] [bukuserver API] improve api views
- Loading branch information
Showing
8 changed files
with
353 additions
and
249 deletions.
There are no files selected for viewing
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
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
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 |
---|---|---|
@@ -1,26 +1,69 @@ | ||
"""Forms module.""" | ||
# pylint: disable=too-few-public-methods, missing-docstring | ||
import wtforms | ||
from flask_wtf import FlaskForm | ||
from wtforms.fields import BooleanField, FieldList, StringField, TextAreaField, HiddenField | ||
from wtforms.validators import DataRequired, InputRequired, ValidationError | ||
from buku import DELIM, parse_tags | ||
|
||
def validate_tag(form, field): | ||
if DELIM in field.data: | ||
raise ValidationError("Tag must not contain delimiter ({})".format(DELIM)) | ||
|
||
|
||
class SearchBookmarksForm(FlaskForm): | ||
keywords = wtforms.FieldList(wtforms.StringField('Keywords'), min_entries=1) | ||
all_keywords = wtforms.BooleanField('Match all keywords') | ||
deep = wtforms.BooleanField('Deep search') | ||
regex = wtforms.BooleanField('Regex') | ||
keywords = FieldList(StringField('Keywords'), min_entries=1) | ||
all_keywords = BooleanField('Match all keywords') | ||
deep = BooleanField('Deep search') | ||
regex = BooleanField('Regex') | ||
|
||
|
||
class HomeForm(SearchBookmarksForm): | ||
keyword = wtforms.StringField('Keyword') | ||
keyword = StringField('Keyword') | ||
|
||
|
||
class BookmarkForm(FlaskForm): | ||
url = wtforms.StringField('Url', name='link', validators=[wtforms.validators.InputRequired()]) | ||
title = wtforms.StringField() | ||
tags = wtforms.StringField() | ||
description = wtforms.TextAreaField() | ||
fetch = wtforms.HiddenField(filters=[bool]) | ||
|
||
class ApiBookmarkForm(BookmarkForm): | ||
url = wtforms.StringField(validators=[wtforms.validators.DataRequired()]) | ||
url = StringField('Url', name='link', validators=[InputRequired()]) | ||
title = StringField() | ||
tags = StringField() | ||
description = TextAreaField() | ||
fetch = HiddenField(filters=[bool]) | ||
|
||
|
||
class ApiTagForm(FlaskForm): | ||
class Meta: | ||
csrf = False | ||
|
||
tags = FieldList( | ||
StringField(validators=[DataRequired(), validate_tag]), | ||
min_entries=1, | ||
) | ||
|
||
tags_str = None | ||
|
||
def process_data(self, data): | ||
tags = data.get('tags') | ||
if tags and not isinstance(tags, list): | ||
raise TypeError("List of tags expected.") | ||
super().process(data=data) | ||
if not self.validate(): | ||
raise ValueError("Input data not valid.") | ||
self.tags_str = None if tags is None else parse_tags([DELIM.join(tags)]) | ||
|
||
|
||
class ApiBookmarkCreateForm(ApiTagForm): | ||
|
||
class Meta: | ||
csrf = False | ||
|
||
url = StringField(validators=[DataRequired()]) | ||
title = StringField() | ||
description = StringField() | ||
|
||
tags = FieldList( | ||
StringField(validators=[validate_tag]), | ||
min_entries=0, | ||
) | ||
|
||
|
||
class ApiBookmarkEditForm(ApiBookmarkCreateForm): | ||
url = StringField() |
Oops, something went wrong.