mirror of
https://github.com/Xevion/v1.xevion.dev.git
synced 2025-12-08 08:09:03 -06:00
added search history table
This commit is contained in:
@@ -26,12 +26,13 @@ class User(UserMixin, db.Model):
|
||||
class Search(db.Model):
|
||||
id = db.Column(db.Integer, primary_key=True)
|
||||
exact_url = db.Column(db.String(160))
|
||||
query = db.Column(db.String(120))
|
||||
query_args = db.Column(db.String(120))
|
||||
timestamp = db.Column(db.DateTime, index=True, default=datetime.utcnow)
|
||||
user_id = db.Column(db.Integer, db.ForeignKey('user.id'))
|
||||
|
||||
def __repr__(self):
|
||||
return '<Post {}>'.format(self.query if len(self.query) < 10 else self.query[:10] + '...')
|
||||
return '<Search by {} @ {}>'.format(User.query.filter_by(id=self.user_id).first().username, self.timestamp)
|
||||
|
||||
|
||||
class Post(db.Model):
|
||||
id = db.Column(db.Integer, primary_key=True)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
from app import app, db
|
||||
from app.models import User
|
||||
from app.models import User, Search
|
||||
from app.forms import LoginForm, RegistrationForm
|
||||
from werkzeug.urls import url_parse
|
||||
from flask import render_template, redirect, url_for, flash, request, jsonify
|
||||
@@ -149,10 +149,10 @@ def hidden(id):
|
||||
count = min(25, count)
|
||||
else:
|
||||
count = min(50, count)
|
||||
print(request.args)
|
||||
# search = Search(query=)
|
||||
# db.session.add(search)
|
||||
# db.session.commit()
|
||||
# print(type(jsonify(request.args.to_dict())))
|
||||
search = Search(user_id=current_user.id, exact_url=str(request.url), query_args=json.dumps(request.args.to_dict()))
|
||||
db.session.add(search)
|
||||
db.session.commit()
|
||||
return render_template('hidden.html', title='Gelbooru Browser', data=data, tags=tags, page=page, count=count, base64=base64, showfull=showfull, showtags=showtags)
|
||||
|
||||
def base64ify(url):
|
||||
|
||||
1
app/tempCodeRunnerFile.py
Normal file
1
app/tempCodeRunnerFile.py
Normal file
@@ -0,0 +1 @@
|
||||
filter
|
||||
@@ -22,7 +22,7 @@
|
||||
<div class="container">
|
||||
<div class="columns is-mobile is-multiline is-centered">
|
||||
<!-- Optiosn Card -->
|
||||
<div class="column is-3">
|
||||
<div class="column is-4">
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
<div class="card-header-title">
|
||||
@@ -98,7 +98,7 @@
|
||||
<!-- End Options Card -->
|
||||
{% for image in data %}
|
||||
<!-- Card Content -->
|
||||
<div class="column is-3">
|
||||
<div class="column is-4">
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
<div class="card-header-title">
|
||||
|
||||
@@ -7,14 +7,33 @@
|
||||
<div class="column">
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
{% set result_count = current_user.search_history.all() | length %}
|
||||
<div class="card-header-title">
|
||||
<h1 class="title">Search History</h1>
|
||||
<div>Search History</div>
|
||||
<div style="padding: 0.3rem; font-weight: 100; font-size: 80%">{{ result_count }} result{% if result_count > 1 %}s{% endif %} found</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="card-content">
|
||||
{% for post in current_user.search_history %}
|
||||
Post : {{ post }}
|
||||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th><abbr title="Search ID">ID</abbr></th>
|
||||
<th>Exact URL</th>
|
||||
<th>Query Arguments</th>
|
||||
<th><abbr title="in UTC time">Timestamp</abbr></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for post in current_user.search_history | reverse %}
|
||||
<tr>
|
||||
<td>{{ post.id }}</td>
|
||||
<td>{{ post.exact_url }}</td>
|
||||
<td>{{ post.query_args }}</td>
|
||||
<td>{{ post.timestamp }} </td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
4
wsgi.py
4
wsgi.py
@@ -1,9 +1,9 @@
|
||||
from app import app, db
|
||||
from app.models import User, Post
|
||||
from app.models import User, Post, Search
|
||||
|
||||
@app.shell_context_processor
|
||||
def make_shell_context():
|
||||
return {'db' : db, 'User' : User, 'Post' : Post}
|
||||
return {'db' : db, 'User' : User, 'Post' : Post, 'Search' : Search}
|
||||
|
||||
if __name__ == "__main__":
|
||||
app.run(host="0.0.0.0")
|
||||
Reference in New Issue
Block a user