Skip to content

Commit

Permalink
chg: dev: match result view
Browse files Browse the repository at this point in the history
  • Loading branch information
rachmadaniHaryono committed Jul 19, 2018
1 parent 85050fc commit d903758
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 27 deletions.
36 changes: 34 additions & 2 deletions gbooru_images_download/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,11 +310,43 @@ class Url(Base):
tags = db.relationship(
'Tag', secondary=url_tags, lazy='subquery',
backref=db.backref('urls', lazy=True))
# hidden = db.Column(db.Boolean, default=False)

@hybrid_property
def ext(self):
ext = os.path.splitext(self.value.path.segments[-1])[1]
if ext.startswith('.'):
ext = ext[1:]
ext = ext.split('?')[0]
return ext

@hybrid_property
def filename(self):
url = str(self.value)
return os.path.splitext(os.path.basename(url))[0]
return os.path.splitext(self.value.path.segments[-1])[0]

@hybrid_property
def height(self):
size_name = 'height'
tags = self.tags
if not isinstance(tags, orm_attributes.InstrumentedAttribute):
tags = list(filter(
lambda x: x.namespace.alias == size_name or x.namespace.value == size_name,
tags
))
if tags:
return tags[0].value

@hybrid_property
def width(self):
size_name = 'width'
tags = self.tags
if not isinstance(tags, orm_attributes.InstrumentedAttribute):
tags = list(filter(
lambda x: x.namespace.alias == size_name or x.namespace.value == size_name,
tags
))
if tags:
return tags[0].value

@hybrid_property
def content_type(self):
Expand Down
61 changes: 36 additions & 25 deletions gbooru_images_download/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,34 +129,27 @@ def _order_by(self, query, joins, sort_joins, sort_field, sort_desc):
return query, joins
return res

def _url_formatter(self, context, model, name):
data = getattr(model, name)
res = '(ID:{}) {} {} {}'.format(
data.id,
Markup('<a class="{1}" href="{0}">{2}</a>'.format(
url_for('admin.url_redirect', u=model.url.value),
"btn view-details-btn btn-default",
"detail"
)),
Markup('<a class="{1}" href="{0}">{2}</a>'.format(
url_for('url.edit_view', id=model.id),
"btn btn-default",
"edit"
)),
Markup('<a href="{}">{}</a> ({})'.format(
data.value, basename(data.value.path.segments[-1]), data.value.host
)),
)
def _thumbnail_formatter(self, context, model, name):
if not model.thumbnail_url:
return res
res = Markup('<div {0}"><img {1} src="{2}"></div><div {3}>{4}</div>'.format(
'class="col-md-2"',
return
return Markup('<figure><img {} src="{}">{}</figure>'.format(
'style="max-width:100%"',
model.thumbnail_url.value,
'class="col-md-10"',
'<span style="word-wrap:break-word">{}</span>'.format(res)
Markup('<figcaption>{}</figcaption>'.format(
''.join([
Markup('<a class="{1}" href="{0}">{2}</a>'.format(
url_for('admin.url_redirect', u=model.url.value),
"btn view-details-btn btn-default",
"detail"
)),
Markup('<a class="{1}" href="{0}">{2}</a>'.format(
url_for('url.edit_view', id=model.id),
"btn btn-default",
"edit"
)),
])
))
))
return res

can_view_details = True
can_set_page_size = True
Expand All @@ -172,8 +165,25 @@ def _url_formatter(self, context, model, name):
column_formatters = {
'created_at': date_formatter,
'thumbnail_url': url_formatter,
'url': _url_formatter,
'thumbnail': _thumbnail_formatter,
'url': url_formatter,
}
column_labels = {
'url.value.netloc': 'Netloc',
'url.filename': 'Filename',
'url.ext': 'Ext',
'url.width': 'W',
'url.height': 'H',
}
column_list = (
'created_at',
'thumbnail',
'url.value.netloc',
'url.filename',
'url.ext',
'url.width',
'url.height',
)
column_sortable_list = ('created_at', 'url', 'thumbnail_url')
named_filter_urls = True
page_size = 100
Expand Down Expand Up @@ -565,6 +575,7 @@ def _content_type_formatter(self, context, model, name):
details_template = 'gbooru_images_download/url_details.html'
form_edit_rules = [
rules.FieldSet(('value', 'tags'), 'Url'),
# rules.FieldSet(('value', 'hidden', 'tags'), 'Url'),
rules.FieldSet(('match_results', 'thumbnail_match_results'), 'Match Result'),
rules.FieldSet(('responses', 'on_final_responses'), 'Response'),
]
Expand Down

0 comments on commit d903758

Please sign in to comment.