~martijnbraam/boarddb

This thread contains a patchset. You're looking at the original emails, but you may wish to use the patch review UI. Review patch
1

[PATCH] WIP: Implement board comparison page

Details
Message ID
<20220121122813.38228-1-raffaele.tranquillini@gmail.com>
DKIM signature
pass
Download raw message
Patch: +86 -0
---
 boarddb/__init__.py                 | 18 +++++++++
 boarddb/frontend/home.py            | 11 ++++++
 boarddb/templates/boardcompare.html | 57 +++++++++++++++++++++++++++++
 3 files changed, 86 insertions(+)
 create mode 100644 boarddb/templates/boardcompare.html

diff --git a/boarddb/__init__.py b/boarddb/__init__.py
index 54f80b5..cc27208 100644
--- a/boarddb/__init__.py
@@ -29,7 +29,25 @@ class SchemeFromProxy:
        return self.app(environ, start_response)


# TODO: unnecessary hack??  
from werkzeug.routing import BaseConverter

class PathVarArgsConverter(BaseConverter):
    """Convert the remaining path segments to a list"""

    def __init__(self, url_map):
        super(PathVarArgsConverter, self).__init__(url_map)
        self.regex = "(?:.*)"

    def to_python(self, value):
        return value.split(u"/")

    def to_url(self, value):
        return u"/".join(value)
# END TODO

app = Flask(__name__)
app.url_map.converters['varargs'] = PathVarArgsConverter
app.config.from_object(Config())
app.wsgi_app = SchemeFromProxy(app.wsgi_app)
db.init_app(app)
diff --git a/boarddb/frontend/home.py b/boarddb/frontend/home.py
index 0b603be..a41d85f 100644
--- a/boarddb/frontend/home.py
@@ -197,3 +197,14 @@ def home():
def view(slug):
    board = Board.query.filter_by(slug=slug).first()
    return render_template('board.html', board=board)

@blueprint_home.route('/compare/<varargs:slugs>')
def compare(slugs = None):
    boards = Board.query.filter(Board.slug.in_(slugs))
    columns_shown_stub = [
        ("name","Board"),
        ("manufacturer_id","Manufacturer"),
        ("soc_id","SoC"),
    ]
    # TODO: sanitize and redirect to canonical if needed, while preserving original order?
    return render_template('boardcompare.html', boards=boards,columns=columns_shown_stub)
diff --git a/boarddb/templates/boardcompare.html b/boarddb/templates/boardcompare.html
new file mode 100644
index 0000000..753b08c
--- /dev/null
@@ -0,0 +1,57 @@
{% extends "base.html" %}

{% block title %}
    Comparison: {% for board in boards %}{{ board.manufacturer.name }} {{ board.name }} {% if not loop.last %} vs. {% endif %}{% endfor %} 
{% endblock %}
{% block main %}
<TODO_move_to_head_and_fix_link rel="canonical" href="https://www.hackerboards.com/compare/{% for board in boards %}{{ board.slug }}{% if not loop.last %}/{% endif %}{% endfor %}/" />
    <h1>
    Board Comparison: 
    {% for board in boards %}
        {{ board.manufacturer.name }} {{ board.name }} {% if not loop.last %} vs. {% endif %}
    {% endfor %} 
    </h1>
    
                        {%if boards.count() < 10 %}
                            (+) Add board: 
                            <select>
                                <option>TODO-fix-this</option>
                            </select>
                            <button>Add</button>
                            {%endif%}
    <main>
        <div class="detail">
            <table>
                <tr>
                    <th> </th>
                    
                    {% for board in boards %}
                    <td>
                        <a href="{{ url_for('home.view', slug=board.slug) }}" class="image">
                            <img src="{{ url_for('image.thumbnail', id=board.id, size=80) }}" loading="lazy">
                            <br>
                            <strong>
                                {{board.manufacturer.name}} 
                                {{board.name}}
                            </strong>
                        </a>
                        (<a href="TODO_magichelperfunction">x</a>)
                    </td>
                    {% endfor %}
                </tr>
                {% for column in columns %}
                <tr>
                    <th>{{ column[1] }}</th>
                    
                    {% for board in boards %}
                    <td>
                            {{ board[column[0]] }}
                    </td>
                    {% endfor %}
                </tr>
                {% endfor %}
            </table>
        </div>
        
    </main>
{% endblock %}
-- 
2.34.1
Details
Message ID
<67e053a8-d8e7-5e96-dece-5044183ca632@brixit.nl>
In-Reply-To
<20220121122813.38228-1-raffaele.tranquillini@gmail.com> (view parent)
DKIM signature
missing
Download raw message
Nice

On 1/21/22 13:28, Raffaele Tranquillini wrote:
> ---
>   boarddb/__init__.py                 | 18 +++++++++
>   boarddb/frontend/home.py            | 11 ++++++
>   boarddb/templates/boardcompare.html | 57 +++++++++++++++++++++++++++++
>   3 files changed, 86 insertions(+)
>   create mode 100644 boarddb/templates/boardcompare.html
>
> diff --git a/boarddb/__init__.py b/boarddb/__init__.py
> index 54f80b5..cc27208 100644
> --- a/boarddb/__init__.py
> +++ b/boarddb/__init__.py
> @@ -29,7 +29,25 @@ class SchemeFromProxy:
>           return self.app(environ, start_response)
>   
>   
> +# TODO: unnecessary hack??
This is not needed yes, you can skip this converter and use the path one
> +from werkzeug.routing import BaseConverter
> +
> +class PathVarArgsConverter(BaseConverter):
> +    """Convert the remaining path segments to a list"""
> +
> +    def __init__(self, url_map):
> +        super(PathVarArgsConverter, self).__init__(url_map)
> +        self.regex = "(?:.*)"
> +
> +    def to_python(self, value):
> +        return value.split(u"/")
> +
> +    def to_url(self, value):
> +        return u"/".join(value)
> +# END TODO
> +
>   app = Flask(__name__)
> +app.url_map.converters['varargs'] = PathVarArgsConverter
>   app.config.from_object(Config())
>   app.wsgi_app = SchemeFromProxy(app.wsgi_app)
>   db.init_app(app)
> diff --git a/boarddb/frontend/home.py b/boarddb/frontend/home.py
> index 0b603be..a41d85f 100644
> --- a/boarddb/frontend/home.py
> +++ b/boarddb/frontend/home.py
> @@ -197,3 +197,14 @@ def home():
>   def view(slug):
>       board = Board.query.filter_by(slug=slug).first()
>       return render_template('board.html', board=board)
> +
> +@blueprint_home.route('/compare/<varargs:slugs>')
instead of the custom converter this can be <path:slugs>, which allows / 
in the name, then it's just slugs.split('/') afterwards
> +def compare(slugs = None):
> +    boards = Board.query.filter(Board.slug.in_(slugs))
> +    columns_shown_stub = [
> +        ("name","Board"),
> +        ("manufacturer_id","Manufacturer"),
> +        ("soc_id","SoC"),
> +    ]
> +    # TODO: sanitize and redirect to canonical if needed, while preserving original order?
> +    return render_template('boardcompare.html', boards=boards,columns=columns_shown_stub)
> diff --git a/boarddb/templates/boardcompare.html b/boarddb/templates/boardcompare.html
> new file mode 100644
> index 0000000..753b08c
> --- /dev/null
> +++ b/boarddb/templates/boardcompare.html
> @@ -0,0 +1,57 @@
> +{% extends "base.html" %}
> +
> +{% block title %}
> +    Comparison: {% for board in boards %}{{ board.manufacturer.name }} {{ board.name }} {% if not loop.last %} vs. {% endif %}{% endfor %}
> +{% endblock %}
> +{% block main %}
> +<TODO_move_to_head_and_fix_link rel="canonical" href="https://www.hackerboards.com/compare/{% for board in boards %}{{ board.slug }}{% if not loop.last %}/{% endif %}{% endfor %}/" />
The <links> can be put in the {% block metadata %}{% endblock %} and it 
will be added to the <head> instead.
> +    <h1>
> +    Board Comparison:
> +    {% for board in boards %}
> +        {{ board.manufacturer.name }} {{ board.name }} {% if not loop.last %} vs. {% endif %}
> +    {% endfor %}
> +    </h1>
> +
> +                        {%if boards.count() < 10 %}
> +                            (+) Add board:
> +                            <select>
> +                                <option>TODO-fix-this</option>
> +                            </select>
> +                            <button>Add</button>
> +                            {%endif%}
> +    <main>
> +        <div class="detail">
> +            <table>
> +                <tr>
> +                    <th> </th>
> +
> +                    {% for board in boards %}
> +                    <td>
> +                        <a href="{{ url_for('home.view', slug=board.slug) }}" class="image">
> +                            <img src="{{ url_for('image.thumbnail', id=board.id, size=80) }}" loading="lazy">
> +                            <br>
> +                            <strong>
> +                                {{board.manufacturer.name}}
> +                                {{board.name}}
> +                            </strong>
> +                        </a>
> +                        (<a href="TODO_magichelperfunction">x</a>)
> +                    </td>
> +                    {% endfor %}
> +                </tr>
> +                {% for column in columns %}
> +                <tr>
> +                    <th>{{ column[1] }}</th>
> +
> +                    {% for board in boards %}
> +                    <td>
> +                            {{ board[column[0]] }}
> +                    </td>
> +                    {% endfor %}
> +                </tr>
> +                {% endfor %}
> +            </table>
> +        </div>
> +
> +    </main>
> +{% endblock %}
Reply to thread Export thread (mbox)