Skip to content
Browse files

Merge branch 'master' of git@github.com:pstoica/CorkBoardIt.git

  • Loading branch information...
2 parents d7d42b3 + fd6a9f7 commit 4a03529279cca805e0a9ffce6c29803c0cc2e133 @pstoica committed
View
50 corkboardit/corkboardit.py
@@ -76,6 +76,7 @@ def login():
cursor.execute("""SELECT *
FROM `User`
WHERE Email=%s
+
AND PIN=%s""",
(request.form['username'],
request.form['password']))
@@ -203,6 +204,53 @@ def add_pushpin():
flash("Some of your form data was invalid.", "error")
return render_template('add_pushpin.html', corkboards = corkboards)
+@app.route('/populartags')
+@login_required
+def popular_tags():
+ cursor = g.db.cursor()
+ cursor.execute(""" SELECT `Tag`, COUNT(PushPin) AS `PushPins`, COUNT(DISTINCT PushPin.CorkBoard) AS `UniqueCorkBoards`
+ FROM `Tag`
+ LEFT JOIN `PushPin`
+ ON Tag.PushPin = PushPin.ID
+ GROUP BY `Tag`
+ ORDER BY `PushPins` DESC, `UniqueCorkBoards` DESC
+ LIMIT 5 """)
+ tags = cursor.fetchall()
+ return render_template('popular_tags.html', tags = tags)
+
+@app.route('/search', methods=['POST', 'GET'])
+@login_required
+def search():
+ cursor = g.db.cursor()
+ if request.method == 'POST':
+ results = []
+ terms = request.form['search_terms'].strip()
+ for term in terms:
+ cursor.execute(""" SELECT Description AS Description, Link AS URL, CorkBoard.Title AS CorkBoard, User.Name AS Owner
+ FROM `PushPin`
+ LEFT JOIN `CorkBoard`
+ ON CorkBoard = CorkBoard.ID
+ LEFT JOIN `Tag`
+ ON Tag.PushPin = PushPin.ID
+ INNER JOIN `User`
+ ON CorkBoard.Email = User.Email
+ WHERE PushPin.Description LIKE '%s'
+ OR CorkBoard.Category LIKE '%s'
+ OR Tag.Tag LIKE '%s'
+ AND EXISTS
+ (SELECT *
+ FROM `PublicCB`
+ WHERE PublicCB.ID = PushPin.CorkBoard)
+ GROUP BY PushPin.Description, PushPin.Link, PushPin.CorkBoard
+ ORDER BY PushPin.Description ASC""" %(term, term, term))
+ result = cursor.fetchall()
+ results.append(result)
+ if len(results)>0:
+ i=0
+ #stuff will happen
+ return render_template('search.html', results = results)
+
+
@app.errorhandler(404)
def not_found(error):
return render_template('error.html'), 404
@@ -213,4 +261,4 @@ def not_found(error):
if __name__ == '__main__':
- app.run()
+ app.run()
View
3 corkboardit/templates/base.html
@@ -28,6 +28,7 @@
(url_for('index'), 'home', 'Home'),
(url_for('add_corkboard'), 'add_corkboard', 'Add CorkBoard'),
(url_for('add_pushpin'), 'add_pushpin', 'Add PushPin'),
+ (url_for('popular_tags'), 'popular_tags', 'Popular Tags'),
(url_for('logout'), 'logout', 'Logout')
] %}
{% endif %}
@@ -60,4 +61,4 @@
{% block content %}{% endblock %}
</div>
</body>
-</html>
+</html>
View
4 corkboardit/templates/index.html
@@ -33,7 +33,7 @@
</tbody>
</table>
<div class="well">
- <a href="{{ url_for('add_corkboard') }}"><button class="btn btn-primary">Popular Tags</button></a>
+ <a href="{{ url_for('add_corkboard') }}"><button class="btn btn-primary">Add CorkBoard</button></a>
</div>
</div>
</div>
@@ -74,4 +74,4 @@
</section>
</fieldset>
</form>
-{% endblock %}
+{% endblock %}
View
34 corkboardit/templates/popular_tags.html
@@ -0,0 +1,34 @@
+{% set active_page = 'popular_tags' %}
+{% extends 'base.html' %}
+{% block title %}Home{% endblock %}
+{% block content %}
+ <section id="popular-tags">
+ <div class="page-header">
+ <h1>Popular Tags</h1>
+ </div>
+ <div class="row">
+ <div class="span12">
+ <table class="table table-striped">
+ <thead>
+ <tr>
+ <th>Tag</th>
+ <th>PushPins</th>
+ <th>Unique CorkBoards</th>
+ </tr>
+ </thead>
+ <tbody>
+ {% for tag in tags %}
+ <tr>
+ <td>{{ tag.Tag }}</td>
+ <td>{{ tag.PushPins}}</td>
+ <td>{{ tag.UniqueCorkBoards }}</td>
+ </tr>
+ {% endfor %}
+ </tbody>
+ </table>
+ </div>
+ </div>
+ </section>
+ </fieldset>
+</form>
+{% endblock %}

0 comments on commit 4a03529

Please sign in to comment.
Something went wrong with that request. Please try again.