control 3 лет назад
Родитель
Сommit
c5d8545500
6 измененных файлов с 83 добавлено и 30 удалено
  1. 24 13
      app/dashboards.py
  2. BIN
      app/database.db
  3. 11 3
      app/lib/collector.py
  4. 35 0
      app/lib/searcher.py
  5. 2 3
      app/templates/base.html
  6. 11 11
      app/templates/search.html

+ 24 - 13
app/dashboards.py

@@ -9,6 +9,7 @@ from . import dispatch
 from app.lib import clean_file as cf, tools
 from app.lib import collector
 from app.lib import stripe
+from app.lib import searcher
 
 from .forms import UPForm, PicForm, CAForm, BidForm, WalletForm, SearchForm
 
@@ -172,22 +173,27 @@ def create():
 @dashboards.route('/search', methods=['GET', 'POST'])
 @login_required
 def search():
-    ##:
     seform = SearchForm()
 
-    ##BUG: this may need to be on every view function for it to work...
-    if seform.validate_on_submit():
-        searchterm = seform.searchterm.data
-        if searchterm:
-            search_result = collector.search_art_objn(searchterm)
-            if search_result:
-                return render_template('search.html', user = current_user, seform = seform, sr = search_result)
-            search_result = collector.search_art_objc(searchterm)
-            if search_result:
-                return render_template('search.html', user = current_user, seform = seform, sr = search_result)
-                
+    se_r = searcher.searcher(seform)
+    #print(f'DEBUG (dash) se_r: {se_r}')##
+    sr = searcher.shammer(se_r)
+    #print(f'DEBUG (dash) sr: {sr}')##
+
+    # getting user's focus
+    if request.method == "POST":
+        focus_item = request.form.get('focus_but')
+        if focus_item and collector.check_art_listing(focus_item):
+            u_dbcall = User.query.filter_by(id=current_user.id).first()
+            u_dbcall.focus = focus_item
+            db.session.commit()
+            return redirect(url_for('dashboards.detail'))
+        elif focus_item and not collector.check_art_listing(focus_item):
+            # else if there's a click but no listing, don't do anything
+            flash('Auction page not available to items not for sale!', category='error')
 
-    return render_template('search.html', user = current_user, seform = seform)
+
+    return render_template('search.html', user = current_user, seform = seform, sr = sr)
 
 @dashboards.route('/detail', methods=['GET', 'POST'])
 @login_required
@@ -279,3 +285,8 @@ def hashchain():
     seform = SearchForm()
 
     return render_template('hash.html', user = current_user, hashchain = hashchain, txlist = txlist, seform = seform)
+
+@dashboards.route('/about', methods=['GET'])
+def about():
+    seform = SearchForm()
+    return render_template('about.html', user = current_user, seform = seform)

BIN
app/database.db


+ 11 - 3
app/lib/collector.py

@@ -6,6 +6,10 @@ from sqlalchemy import desc
 from app.models import User, Art, List, Bids
 
 def join_art_list_table():
+    # Creates a list of lists of all
+    # current art to listing relationship
+    # this is what happens when you don't
+    # pay attention to Db classes...
     listings = List.query.all()
     art = Art.query.all()
     user_list = User.query.all()
@@ -63,7 +67,10 @@ def check_art_listing(filehash):
     return False
 
 def find_user_obj(user_id):
-    user = User.query.filter_by(id = user_id).first()
+    if isinstance(user_id, int):
+        user = User.query.filter_by(id = user_id).first()
+    elif isinstance(user_id, str):
+        user = User.query.filter_by(username = user_id).first()
     return user
 
 def item_bid_hist(filehash):
@@ -90,13 +97,14 @@ def get_art_obj(filehash):
     art = Art.query.filter_by(filehash = filehash).first()
     return art
 
+##:
 def search_art_objn(artname):
     art = Art.query.filter_by(name = artname).first()
     print(f'DEBUG (collector: objn) art:{art}')##
     return art
 
-def search_art_objc(creator):
-    art = Art.query.filter_by(creator = creator).all()
+def search_art_objc(creator_id):
+    art = Art.query.filter_by(creator = creator_id).all()
     print(f'DEBUG (collector: objc) art:{art}')##
     return art
 

+ 35 - 0
app/lib/searcher.py

@@ -0,0 +1,35 @@
+from flask import render_template, flash
+from flask_login import current_user
+from app.lib import collector
+
+def searcher(seform):
+    listings = collector.join_art_list_table()
+    #print(f'DEBUG (searcher) searcher() RUNNING')##
+    if seform.validate_on_submit():
+        #print(f'DEBUG (searcher) seform: {seform}')##
+        searchterm = seform.searchterm.data
+        #print(f'DEBUG (searcher) searchterm: {searchterm}')##
+        if searchterm:
+            search_result = collector.search_art_objn(searchterm)
+            if search_result:
+                #print(f'DEBUG (searcher) search_result: {search_result}')##
+                return search_result
+            else:
+                st = collector.find_user_obj(searchterm)
+                if st:
+                    search_result = collector.search_art_objc(st.id)
+                    if search_result:
+                        #print(f'DEBUG (searcher) search_result: {search_result}')##
+                        return search_result
+                else:
+                    flash('Search error, try again or contact system administrators!', category='error')
+         
+def shammer(search_result):
+    # takes search result object and determines if to be added to list
+    if isinstance(search_result, list):
+        return search_result
+    else:
+        l = list()    
+        l.append(search_result)
+        return l
+

+ 2 - 3
app/templates/base.html

@@ -29,7 +29,6 @@
 <body>
     <nav class="navbar fixed-top navbar-expand-sm bg-white navbar-dark">
     <a class="navbar-brand" href="/"><img src="static/templates/navbar_icon.png" alt="web_icon" id="logo" width="60"/></a></a>      
-        <!-- Search Function for search Art-->
         <ul class="navbar-nav">
             {% if user.is_authenticated %} <!-- shows only if user is logged in -->
             <li class="nav-item">
@@ -60,11 +59,11 @@
         </ul>
         {% endif %}
         </ul>
+        <!-- Search Function for search Art-->
         {% if user.is_authenticated %}
         <div>
-            <form action="search" name="searchterm" class="input-group navbar-nav-middle flash_message_size">
+            <form action="search" method="POST" name="searchterm" class="input-group navbar-nav-middle flash_message_size">
                 {{ seform.hidden_tag() }}
-                <!--<input type="text" class="form-control" placeholder="Search Art">-->
                 {{ seform.searchterm(placeholder="Search for art", class="form-control") }}
                 {{ seform.submit(placeholder="Search", class="btn btn-secondary")}}
                 </div>

+ 11 - 11
app/templates/search.html

@@ -1,28 +1,28 @@
 {% extends "base.html" %}
 
 {% block content %}
-<p>Search Result</p>
+<p>Search Results</p>
 
 <div class="container">
     <div class="row row-cols-4">
-
+        {% if sr %}
+        {% for r in sr %}
+        {% if r.dname %}
         <div class="card col-md-3 grid-item shadow p-3 mb-5 bg-white rounded"  type="button">
-            <a href="detail"><img class="market_each_bid_image_size" src="static/repository/"></a>
+            <form method="POST">
+            <button name="focus_but" type="submit" class="btn btn-link" value="{{r.filehash}}"><img class="market_each_bid_image_size" src="static/repository/{{r.dname}}"></button>
             <div class="row" id="market_item_name_left">
+            </form>
                 <b></b>
             </div>
             <div class="row">
-                {% if sr %}
-                {{ sr.name }}
-                {% endif %}
-                <p id="market_item_text_left">Current Bid</b>
-                <p id="market_item_text_right">(Price) <span class="price-span">USD</span></b>
+                <p id="market_item_text_left">{{r.name}}</b>
             </div>
-            <div class="row">
-                <p id="market_item_text_left">Creator</b>
-                <p id="market_item_text_right"><img src="static/Creator_Icon/" height=25 width=25>(Creator Icon)(Creator Name)</b>
             </div>
         </div>
+        {% endif %}
+        {% endfor %}
+        {% endif %}
     </div>
   </div>