<html>
  <head>
    <meta content="text/html; charset=windows-1252"
      http-equiv="Content-Type">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    <font face="Arial">Thank you very much David!<br>
      <br>
      I'll be sure to check out SQLAlchemy and your blog as well!<br>
    </font><br>
    <div class="moz-cite-prefix">On 13.08.2015 14:13, David Nieder
      wrote:<br>
    </div>
    <blockquote cite="mid:55CC7BC2.5090109@gmx.de" type="cite">On
      11.08.2015 08:53, Alexandru wrote:
      <br>
      <blockquote type="cite">Hello everyone,
        <br>
      </blockquote>
      Hey!
      <br>
      Since no one responded yet, I try to give you an answer.
      <br>
      <br>
      <blockquote type="cite">
        <br>
        I've built a small Flask app that basically requires a a lot of
        database
        <br>
        interaction.
        <br>
      </blockquote>
      <br>
      If that's the case you really should look into an orm (e.g.
      SQLAlchemy).
      <br>
      <br>
      <blockquote type="cite">I'm almost done with it now, I just need a
        way for the user to sort the
        <br>
        information that's received from the database (order by name,
        price,
        <br>
        location, etc)
        <br>
        The problem is I'm not that good at coding yet and I'm not sure
        how to
        <br>
        go about doing this.
        <br>
        <br>
        I'm not going to paste my code here, to avoid clutter, so I'm
        going to
        <br>
        use Pastebin
        <br>
        <br>
        This is the section of code that interogates the DB:
        <br>
        <a class="moz-txt-link-freetext" href="http://pastebin.com/W76H0TSK">http://pastebin.com/W76H0TSK</a>
        <br>
        And this is the template portion of the code:
        <a class="moz-txt-link-freetext" href="http://pastebin.com/BsCHiU3z">http://pastebin.com/BsCHiU3z</a>
        <br>
        <br>
        I'm looking to insert anchors, or buttons, or something, into
        that
        <br>
        template that would allow the users to sort by (for example)
        pct_lucru
        <br>
        and/or data_expirarii and/or denumire_med.
        <br>
        <br>
        Any ideas for me? I'm kind of stumped.
        <br>
      </blockquote>
      <br>
      Well, you already have an ORDER clause in your sql-query. You just
      need to build the query more dynamically (meaning: depending on
      user input).
      <br>
      <br>
      You could have links in your template that look sth like this
      (maybe in the table head):
      <br>
      <br>
      <a href="{{ url_for('rezultate', order='pct_lucru-asc')
      }}">PUNCT LUCRU</a>
      <br>
      <br>
      Then in the 'rezultate'-function:
      <br>
      <br>
      if request.args.get('order') == 'pct_lucru-asc':
      <br>
          order_by = 'ORDER BY stocuri_disponibile.pct_lucru ASC'
      <br>
      else if request.args.get('order') == 'pct_lucru-desc':
      <br>
          order_by = 'ORDER BY stocuri_disponibile.pct_lucru DESC'
      <br>
      else:
      <br>
          order_by = 'ORDER BY stocuri_disponibile.denumire_med ASC'
      <br>
      <br>
      query  = 'SELECT [...] LIKE ? GROUP BY denumire_med '
      <br>
      query += order_by
      <br>
      query += ' LIMIT ? OFFSET ?'
      <br>
      <br>
      cur1 = g.db.execute(query, ...)
      <br>
      <br>
      That would be the basic idea, pretty straight forward. Just keep
      in mind to not include sth into the query that comes directly from
      the user.
      <br>
      Also: building sql statements like this isn't really fun. An orm
      can make your life a lot easier. If you are interested in an
      example, I have a simple blog software where I do sth similar
      (filter blog-posts) with sqlalchemy:
      <br>
<a class="moz-txt-link-freetext" href="https://github.com/davidnieder/blackboard-light/blob/master/app/query.py#L13">https://github.com/davidnieder/blackboard-light/blob/master/app/query.py#L13</a>
      <br>
      <br>
      <blockquote type="cite">
        <br>
        Cheers!
        <br>
        <br>
      </blockquote>
      Cheers mate!
      <br>
      I hope this was helpful
      <br>
      _______________________________________________
      <br>
      Flask mailing list
      <br>
      <a class="moz-txt-link-abbreviated" href="mailto:Flask@python.org">Flask@python.org</a>
      <br>
      <a class="moz-txt-link-freetext" href="https://mail.python.org/mailman/listinfo/flask">https://mail.python.org/mailman/listinfo/flask</a>
      <br>
    </blockquote>
    <br>
  </body>
</html>