mirror of
				https://git.wownero.com/wownero/YellWOWPages.git
				synced 2024-08-15 01:03:25 +00:00 
			
		
		
		
	turn search into include, limit user results, minimum term search 2, show date of address addition
This commit is contained in:
		
							parent
							
								
									37208b102b
								
							
						
					
					
						commit
						b13f03855d
					
				
					 10 changed files with 50 additions and 48 deletions
				
			
		| 
						 | 
					@ -1,5 +1,6 @@
 | 
				
			||||||
import os
 | 
					import os
 | 
				
			||||||
import logging
 | 
					import logging
 | 
				
			||||||
 | 
					from datetime import datetime
 | 
				
			||||||
import asyncio
 | 
					import asyncio
 | 
				
			||||||
 | 
					
 | 
				
			||||||
from quart import Quart, url_for, jsonify, render_template, session
 | 
					from quart import Quart, url_for, jsonify, render_template, session
 | 
				
			||||||
| 
						 | 
					@ -63,7 +64,8 @@ def create_app():
 | 
				
			||||||
        current_user = session.get('user')
 | 
					        current_user = session.get('user')
 | 
				
			||||||
        if current_user:
 | 
					        if current_user:
 | 
				
			||||||
            current_user = User(**current_user)
 | 
					            current_user = User(**current_user)
 | 
				
			||||||
        return dict(user=current_user, url_login=openid.endpoint_name_login)
 | 
					        now = datetime.now()
 | 
				
			||||||
 | 
					        return dict(user=current_user, url_login=openid.endpoint_name_login, year=now.year)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @app.before_serving
 | 
					    @app.before_serving
 | 
				
			||||||
    async def startup():
 | 
					    async def startup():
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -12,16 +12,24 @@ db = SqliteDatabase(settings.DB_PATH)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class User(pw.Model):
 | 
					class User(pw.Model):
 | 
				
			||||||
    id = pw.UUIDField(primary_key=True)
 | 
					    id = pw.UUIDField(primary_key=True)
 | 
				
			||||||
    created = pw.DateTimeField(default=datetime.now)
 | 
					    created: datetime = pw.DateTimeField(default=datetime.now)
 | 
				
			||||||
    username = pw.CharField(unique=True, null=False)
 | 
					    username = pw.CharField(unique=True, null=False)
 | 
				
			||||||
    address = pw.CharField(null=True)
 | 
					    address = pw.CharField(null=True)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @property
 | 
				
			||||||
 | 
					    def created_dt(self):
 | 
				
			||||||
 | 
					        return self.created.strftime('%Y-%m-%d')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @staticmethod
 | 
					    @staticmethod
 | 
				
			||||||
    async def search(needle) -> List['User']:
 | 
					    async def search(needle) -> List['User']:
 | 
				
			||||||
        needle = needle.replace("*", "")
 | 
					        needle = needle.replace("*", "")
 | 
				
			||||||
        if len(needle) <= 2:
 | 
					        if len(needle) <= 1:
 | 
				
			||||||
            raise Exception("need longer search term")
 | 
					            raise Exception("need longer search term")
 | 
				
			||||||
        return User.select().where(User.username % f"*{needle}*")
 | 
					
 | 
				
			||||||
 | 
					        return User.select().where(
 | 
				
			||||||
 | 
					            User.address.is_null(False),
 | 
				
			||||||
 | 
					            User.username % f"*{needle}*"
 | 
				
			||||||
 | 
					        )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def to_json(self, ignore_key=None):
 | 
					    def to_json(self, ignore_key=None):
 | 
				
			||||||
        data = {
 | 
					        data = {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -53,7 +53,7 @@ async def dashboard_address_post():
 | 
				
			||||||
async def search():
 | 
					async def search():
 | 
				
			||||||
    needle = request.args.get('username')
 | 
					    needle = request.args.get('username')
 | 
				
			||||||
    if needle:
 | 
					    if needle:
 | 
				
			||||||
        if len(needle) <= 2:
 | 
					        if len(needle) <= 1:
 | 
				
			||||||
            raise Exception("Search term needs to be longer")
 | 
					            raise Exception("Search term needs to be longer")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        users = [u for u in await User.search(needle)]
 | 
					        users = [u for u in await User.search(needle)]
 | 
				
			||||||
| 
						 | 
					@ -62,7 +62,11 @@ async def search():
 | 
				
			||||||
        else:
 | 
					        else:
 | 
				
			||||||
            return await render_template('search_results.html')
 | 
					            return await render_template('search_results.html')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    users = [u for u in User.select()]
 | 
					    q = User.select()
 | 
				
			||||||
 | 
					    q = q.where(User.address.is_null(False))
 | 
				
			||||||
 | 
					    q = q.limit(100)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    users = [u for u in q]
 | 
				
			||||||
    return await render_template('search.html', users=users)
 | 
					    return await render_template('search.html', users=users)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -77,7 +77,7 @@
 | 
				
			||||||
  </div>
 | 
					  </div>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  <div id="footer">
 | 
					  <div id="footer">
 | 
				
			||||||
      2022 - ... [the future is w0w]
 | 
					    {{ year }} - ... [the future is w0w]
 | 
				
			||||||
  </div>
 | 
					  </div>
 | 
				
			||||||
</body>
 | 
					</body>
 | 
				
			||||||
</html>
 | 
					</html>
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -9,7 +9,7 @@
 | 
				
			||||||
            <a href="{{ url_for('bp_routes.login') }}">Login</a>
 | 
					            <a href="{{ url_for('bp_routes.login') }}">Login</a>
 | 
				
			||||||
            {% else %}
 | 
					            {% else %}
 | 
				
			||||||
            <a href="{{ url_for('bp_routes.logout') }}">Logout</a>
 | 
					            <a href="{{ url_for('bp_routes.logout') }}">Logout</a>
 | 
				
			||||||
            <a href="{{ url_for('bp_routes.dashboard') }}">Dashboard</a>
 | 
					            <a href="{{ url_for('bp_routes.dashboard') }}">My Profile</a>
 | 
				
			||||||
            {% endif %}
 | 
					            {% endif %}
 | 
				
			||||||
            <a href="{{ url_for('bp_routes.search') }}">Yell<span>WOW</span>Page search</a>
 | 
					            <a href="{{ url_for('bp_routes.search') }}">Yell<span>WOW</span>Page search</a>
 | 
				
			||||||
            <a href="{{ url_for('bp_routes.about') }}">About</a>
 | 
					            <a href="{{ url_for('bp_routes.about') }}">About</a>
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										3
									
								
								yellow/templates/includes/search.html
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								yellow/templates/includes/search.html
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,3 @@
 | 
				
			||||||
 | 
					<form action="{{ url_for('bp_routes.search') }}" method="GET">
 | 
				
			||||||
 | 
					  <input type="text" name="username" placeholder="Search for an username...">
 | 
				
			||||||
 | 
					</form>
 | 
				
			||||||
							
								
								
									
										11
									
								
								yellow/templates/includes/user_results.html
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								yellow/templates/includes/user_results.html
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,11 @@
 | 
				
			||||||
 | 
					<div id="addresses">
 | 
				
			||||||
 | 
					  {% for user in users %}
 | 
				
			||||||
 | 
					  <article>
 | 
				
			||||||
 | 
					    <header>
 | 
				
			||||||
 | 
					      <em>{{user.username}}</em>
 | 
				
			||||||
 | 
					      <small style="float: right">Added: {{ user.created_dt }}</small>
 | 
				
			||||||
 | 
					    </header>
 | 
				
			||||||
 | 
					    <kbd>{{user.address}}</kbd>
 | 
				
			||||||
 | 
					  </article>
 | 
				
			||||||
 | 
					  {% endfor %}
 | 
				
			||||||
 | 
					</div>
 | 
				
			||||||
| 
						 | 
					@ -10,7 +10,13 @@
 | 
				
			||||||
    </main>
 | 
					    </main>
 | 
				
			||||||
    <div>
 | 
					    <div>
 | 
				
			||||||
        The first <img src="../../static/wownero.png" alt=""> addresses library -
 | 
					        The first <img src="../../static/wownero.png" alt=""> addresses library -
 | 
				
			||||||
        from the community to the community
 | 
					        from the community, for the community.
 | 
				
			||||||
 | 
					    </div>
 | 
				
			||||||
 | 
					    <br><br>
 | 
				
			||||||
 | 
					    <div style="margin-top:40px;">
 | 
				
			||||||
 | 
					      <a style="text-decoration: none;" href="{{ url_for('bp_routes.search') }}">
 | 
				
			||||||
 | 
					        <button style="max-width:320px;">start searching</button>
 | 
				
			||||||
 | 
					      </a>
 | 
				
			||||||
    </div>
 | 
					    </div>
 | 
				
			||||||
</div>
 | 
					</div>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -5,20 +5,9 @@
 | 
				
			||||||
</div>
 | 
					</div>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
<div id="main">
 | 
					<div id="main">
 | 
				
			||||||
  <form action="{{ url_for('bp_routes.search') }}" method="GET">
 | 
					  {% include 'includes/search.html' %}
 | 
				
			||||||
    <input type="text" name="username" placeholder="Search for an username...">
 | 
					 | 
				
			||||||
  </form>
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
  <div id="addresses">
 | 
					  {% include 'includes/user_results.html' %}
 | 
				
			||||||
    {% for user in users %}
 | 
					 | 
				
			||||||
    <article>
 | 
					 | 
				
			||||||
      <header>
 | 
					 | 
				
			||||||
        <em>{{user.username}}</em>
 | 
					 | 
				
			||||||
      </header>
 | 
					 | 
				
			||||||
      <kbd>{{user.address}}</kbd>
 | 
					 | 
				
			||||||
    </article>
 | 
					 | 
				
			||||||
    {% endfor %}
 | 
					 | 
				
			||||||
  </div>
 | 
					 | 
				
			||||||
</div>
 | 
					</div>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
<style>
 | 
					<style>
 | 
				
			||||||
| 
						 | 
					@ -43,12 +32,6 @@
 | 
				
			||||||
    display: none;
 | 
					    display: none;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  
 | 
					  
 | 
				
			||||||
  #footer {
 | 
					 | 
				
			||||||
    height: 12vh;
 | 
					 | 
				
			||||||
    width: 100%;
 | 
					 | 
				
			||||||
    text-align: center;
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  @media (max-width: 800px) {
 | 
					  @media (max-width: 800px) {
 | 
				
			||||||
    kbd {
 | 
					    kbd {
 | 
				
			||||||
      width: 100vw;
 | 
					      width: 100vw;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -5,25 +5,15 @@
 | 
				
			||||||
</div>
 | 
					</div>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
<div id="main">
 | 
					<div id="main">
 | 
				
			||||||
    <form action="{{ url_for('bp_routes.search') }}" method="GET">
 | 
					    {% include 'includes/search.html' %}
 | 
				
			||||||
        <input type="text" name="username" placeholder="Username to search">
 | 
					
 | 
				
			||||||
    </form>
 | 
					 | 
				
			||||||
    <br>
 | 
					    <br>
 | 
				
			||||||
    Result(s): {{users|length}}
 | 
					    Result(s): {{users|length}}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    {% if not users %}
 | 
					    {% if not users %}
 | 
				
			||||||
      <br>Nothing found...
 | 
					      <br>Nothing found...
 | 
				
			||||||
    {% else %}
 | 
					    {% else %}
 | 
				
			||||||
    <div id="addresses">
 | 
					      {% include 'includes/user_results.html' %}
 | 
				
			||||||
        {% for user in users %}
 | 
					 | 
				
			||||||
        <article>
 | 
					 | 
				
			||||||
            <header>
 | 
					 | 
				
			||||||
                <em>{{user.username}}</em>
 | 
					 | 
				
			||||||
            </header>
 | 
					 | 
				
			||||||
            <kbd>{{user.address}}</kbd>
 | 
					 | 
				
			||||||
        </article>
 | 
					 | 
				
			||||||
        {% endfor %}
 | 
					 | 
				
			||||||
    </div>
 | 
					 | 
				
			||||||
    {% endif %}
 | 
					    {% endif %}
 | 
				
			||||||
</div>
 | 
					</div>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -45,11 +35,6 @@
 | 
				
			||||||
    #addresses::-webkit-scrollbar{
 | 
					    #addresses::-webkit-scrollbar{
 | 
				
			||||||
        display: none;
 | 
					        display: none;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    #footer{
 | 
					 | 
				
			||||||
        height: 12vh;
 | 
					 | 
				
			||||||
        width: 100%;
 | 
					 | 
				
			||||||
        text-align: center;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    @media (max-width: 800px) {
 | 
					    @media (max-width: 800px) {
 | 
				
			||||||
        kbd{
 | 
					        kbd{
 | 
				
			||||||
            width: 100vw;
 | 
					            width: 100vw;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue