mirror of
https://github.com/minetest/contentdb.git
synced 2024-12-22 14:02:24 +01:00
Count tag views
This commit is contained in:
parent
8dd1cd9045
commit
9663e87838
@ -24,6 +24,7 @@ from . import bp
|
|||||||
from app.models import *
|
from app.models import *
|
||||||
from app.querybuilder import QueryBuilder
|
from app.querybuilder import QueryBuilder
|
||||||
from app.tasks.importtasks import importRepoScreenshot, updateMetaFromRelease
|
from app.tasks.importtasks import importRepoScreenshot, updateMetaFromRelease
|
||||||
|
from app.rediscache import has_key, set_key
|
||||||
from app.utils import *
|
from app.utils import *
|
||||||
|
|
||||||
from flask_wtf import FlaskForm
|
from flask_wtf import FlaskForm
|
||||||
@ -51,6 +52,19 @@ def list_all():
|
|||||||
joinedload(Package.media_license), \
|
joinedload(Package.media_license), \
|
||||||
subqueryload(Package.tags))
|
subqueryload(Package.tags))
|
||||||
|
|
||||||
|
edited = False
|
||||||
|
for tag in qb.tags:
|
||||||
|
edited = True
|
||||||
|
key = "tag-" + tag.name
|
||||||
|
if not has_key(key):
|
||||||
|
set_key(key, "true")
|
||||||
|
Tag.query.filter_by(id=tag.id).update({
|
||||||
|
"views": Tag.views + 1
|
||||||
|
})
|
||||||
|
|
||||||
|
if edited:
|
||||||
|
db.session.commit()
|
||||||
|
|
||||||
if qb.lucky:
|
if qb.lucky:
|
||||||
package = query.first()
|
package = query.first()
|
||||||
if package:
|
if package:
|
||||||
|
@ -804,11 +804,12 @@ class MetaPackage(db.Model):
|
|||||||
return retval
|
return retval
|
||||||
|
|
||||||
class Tag(db.Model):
|
class Tag(db.Model):
|
||||||
id = db.Column(db.Integer, primary_key=True)
|
id = db.Column(db.Integer, primary_key=True)
|
||||||
name = db.Column(db.String(100), unique=True, nullable=False)
|
name = db.Column(db.String(100), unique=True, nullable=False)
|
||||||
title = db.Column(db.String(100), nullable=False)
|
title = db.Column(db.String(100), nullable=False)
|
||||||
backgroundColor = db.Column(db.String(6), nullable=False)
|
backgroundColor = db.Column(db.String(6), nullable=False)
|
||||||
textColor = db.Column(db.String(6), nullable=False)
|
textColor = db.Column(db.String(6), nullable=False)
|
||||||
|
views = db.Column(db.Integer, nullable=False, default=0)
|
||||||
|
|
||||||
def __init__(self, title, backgroundColor="000000", textColor="ffffff"):
|
def __init__(self, title, backgroundColor="000000", textColor="ffffff"):
|
||||||
self.title = title
|
self.title = title
|
||||||
|
@ -24,7 +24,7 @@ class QueryBuilder:
|
|||||||
tags = [Tag.query.filter_by(name=tname).first() for tname in tags]
|
tags = [Tag.query.filter_by(name=tname).first() for tname in tags]
|
||||||
tags = [tag for tag in tags if tag is not None]
|
tags = [tag for tag in tags if tag is not None]
|
||||||
|
|
||||||
# Hid
|
# Hide
|
||||||
hide_flags = args.getlist("hide")
|
hide_flags = args.getlist("hide")
|
||||||
|
|
||||||
self.title = title
|
self.title = title
|
||||||
|
@ -14,13 +14,39 @@
|
|||||||
</p>
|
</p>
|
||||||
|
|
||||||
<div class="list-group">
|
<div class="list-group">
|
||||||
|
|
||||||
|
<div class="list-group-item">
|
||||||
|
<div class="row text-muted">
|
||||||
|
<div class="col-sm">
|
||||||
|
{{ _("Name") }}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<span class="col-sm-1 text-center">
|
||||||
|
{{ _("Views") }}
|
||||||
|
</span>
|
||||||
|
|
||||||
|
<div class="col-sm-1 text-center">
|
||||||
|
{{ _("Packages") }}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
{% for t in tags %}
|
{% for t in tags %}
|
||||||
<a class="list-group-item list-group-item-action"
|
<a class="list-group-item list-group-item-action"
|
||||||
href="{{ url_for('admin.create_edit_tag', name=t.name) }}">
|
href="{{ url_for('admin.create_edit_tag', name=t.name) }}">
|
||||||
<span class="float-right badge badge-primary badge-pill">
|
<div class="row">
|
||||||
{{ t.packages | count }}
|
<div class="col-sm">
|
||||||
</span>
|
{{ t.title }}
|
||||||
{{ t.title }}
|
</div>
|
||||||
|
|
||||||
|
<div class="col-sm-1 text-center">
|
||||||
|
{{ t.views }}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="col-sm-1 text-center">
|
||||||
|
{{ t.packages | count }}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</a>
|
</a>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</div>
|
</div>
|
||||||
|
24
migrations/versions/c5e4213721dd_.py
Normal file
24
migrations/versions/c5e4213721dd_.py
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
"""empty message
|
||||||
|
|
||||||
|
Revision ID: c5e4213721dd
|
||||||
|
Revises: 9832944cd1e4
|
||||||
|
Create Date: 2020-07-15 17:54:33.738132
|
||||||
|
|
||||||
|
"""
|
||||||
|
from alembic import op
|
||||||
|
import sqlalchemy as sa
|
||||||
|
|
||||||
|
|
||||||
|
# revision identifiers, used by Alembic.
|
||||||
|
revision = 'c5e4213721dd'
|
||||||
|
down_revision = '9832944cd1e4'
|
||||||
|
branch_labels = None
|
||||||
|
depends_on = None
|
||||||
|
|
||||||
|
|
||||||
|
def upgrade():
|
||||||
|
op.add_column('tag', sa.Column('views', sa.Integer(), nullable=False, server_default="0"))
|
||||||
|
|
||||||
|
|
||||||
|
def downgrade():
|
||||||
|
op.drop_column('tag', 'views')
|
Loading…
Reference in New Issue
Block a user