from app.models import *
from app.querybuilder import QueryBuilder
from app.tasks.importtasks import importRepoScreenshot, updateMetaFromRelease
+from app.rediscache import has_key, set_key
from app.utils import *
from flask_wtf import FlaskForm
joinedload(Package.media_license), \
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:
package = query.first()
if package:
return retval
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)
title = db.Column(db.String(100), nullable=False)
- backgroundColor = db.Column(db.String(6), nullable=False)
- textColor = db.Column(db.String(6), nullable=False)
+ backgroundColor = 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"):
self.title = title
tags = [Tag.query.filter_by(name=tname).first() for tname in tags]
tags = [tag for tag in tags if tag is not None]
- # Hid
+ # Hide
hide_flags = args.getlist("hide")
self.title = title
</p>
<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 %}
<a class="list-group-item list-group-item-action"
href="{{ url_for('admin.create_edit_tag', name=t.name) }}">
- <span class="float-right badge badge-primary badge-pill">
- {{ t.packages | count }}
- </span>
- {{ t.title }}
+ <div class="row">
+ <div class="col-sm">
+ {{ 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>
{% endfor %}
</div>
--- /dev/null
+"""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')