From 7c678a851ff699e40393f9cb52086eba7b543c16 Mon Sep 17 00:00:00 2001 From: Eric Barbour Date: Aug 10 2016 19:35:20 +0000 Subject: [PATCH 1/16] Naive implementaion of stream prototype --- diff --git a/hubs/app.py b/hubs/app.py index 067a3ad..4432e91 100755 --- a/hubs/app.py +++ b/hubs/app.py @@ -6,6 +6,7 @@ import os import urlparse import uuid +import bleach import flask import flask.json import fmn.lib @@ -103,7 +104,7 @@ def index(): if not authenticated(): return flask.redirect(flask.url_for('login')) - return flask.redirect(flask.url_for('hub', name=flask.g.auth.nickname)) + return flask.redirect(flask.url_for('stream', name=flask.g.auth.nickname)) @app.route('/groups') @@ -519,6 +520,42 @@ def login_required(function): return decorated_function +@app.route('//stream') +@app.route('//stream/') +@login_required +def stream(name): + feeds = [ + {'url': '', 'name': 'streamFeed', 'matches': []}, + {'url': '', 'name': 'actionsFeed', 'matches': []}, + {'url': '', 'name': 'mentionsFeed', 'matches': []}, + ] + saved = hubs.models.SavedNotification.by_username(session, name) + + return flask.render_template('stream.html', feeds=json.dumps(feeds), saved=saved) + + +@app.route('//notifications') +@app.route('//notifications/') +@login_required +def notifications(user): + if flask.request.method == 'GET': + notifications = hubs.models.SavedNotification.by_username(session, user) + notifications = [n.__json__() for n in notifications] + return json.dumps(notifications) + + if flask.request.method == 'POST': + markup = bleach.clean(flask.request.data['markup']) + link = bleach.clean(flask.request.data['link']) + icon = flask.request.data['icon'] + notification = hubs.models.SavedNotification( + username=user, + markup=markup, + link=link, + secondary_icon=icon + ) + session.add(notification) + session.commit() + return notification.__json__() @app.before_request def check_auth(): diff --git a/hubs/models.py b/hubs/models.py index ede60dc..c8021e4 100755 --- a/hubs/models.py +++ b/hubs/models.py @@ -28,12 +28,13 @@ import operator import os import random +import bleach import sqlalchemy as sa from sqlalchemy import create_engine from sqlalchemy.ext.declarative import declarative_base from sqlalchemy.orm import sessionmaker from sqlalchemy.orm import scoped_session -from sqlalchemy.orm import relation +from sqlalchemy.orm import relation, relationship from sqlalchemy.orm import backref import fedmsg @@ -353,6 +354,8 @@ class User(BASE): username = sa.Column(sa.Text, primary_key=True) fullname = sa.Column(sa.Text) created_on = sa.Column(sa.DateTime, default=datetime.datetime.utcnow) + saved_notifications = relationship('SavedNotification', backref='users', + lazy='dynamic') def __json__(self, session): return { @@ -478,3 +481,38 @@ class VisitCounter(BASE): session.add(self) session.commit() return self + + +class SavedNotification(BASE): + __tablename__ = 'savednotifications' + user = sa.Column(sa.Text, sa.ForeignKey('users.username')) + + idx = sa.Column(sa.Integer, primary_key=True) + markup = sa.Column(sa.Text) + link = sa.Column(sa.Text) + secondary_icon = sa.column(sa.Text) + created = sa.Column(sa.DateTime, default=datetime.datetime.utcnow) + + + def __init__(self, username=None, markup='', link='', secondary_icon=''): + self.user = username + self.markup = markup + self.link = link + self.secondary_icon = secondary_icon + + def __json__(self): + return { + 'idx': self.idx, + 'markup': bleach.linkify(self.markup), + 'link': bleach.linkify(self.link), + 'secondary_icon': self.secondary_icon, + 'created': self.created + } + + @classmethod + def by_username(cls, session, username): + return session.query(cls).filter_by(user=username) + + @classmethod + def all(cls, session): + return session.query(cls).all() diff --git a/hubs/templates/_messages.html b/hubs/templates/_messages.html new file mode 100644 index 0000000..7f942d3 --- /dev/null +++ b/hubs/templates/_messages.html @@ -0,0 +1,294 @@ +
+
+
+ + User avatar + +
+
+

+ This is some markup +

+
+
+
+
+
+
+ + User avatar + +
+
+

+ This is some markup +

+
+
+
+
+
+
+ + User avatar + +
+
+

+ This is some markup +

+
+
+
+
+
+
+ + User avatar + +
+
+

+ This is some markup +

+
+
+
+
+
+
+ + User avatar + +
+
+

+ This is some markup +

+
+
+
+
+
+
+ + User avatar + +
+
+

+ This is some markup +

+
+
+
+
+
+
+ + User avatar + +
+
+

+ This is some markup +

+
+
+
+
+
+
+ + User avatar + +
+
+

+ This is some markup +

+
+
+
+
+
+
+ + User avatar + +
+
+

+ This is some markup +

+
+
+
+
+
+
+ + User avatar + +
+
+

+ This is some markup +

+
+
+
+
+
+
+ + User avatar + +
+
+

+ This is some markup +

+
+
+
+
+
+
+ + User avatar + +
+
+

+ This is some markup +

+
+
+
+
+
+
+ + User avatar + +
+
+

+ This is some markup +

+
+
+
+
+
+
+ + User avatar + +
+
+

+ This is some markup +

+
+
+
+
+
+
+ + User avatar + +
+
+

+ This is some markup +

+
+
+
+
+
+
+ + User avatar + +
+
+

+ This is some markup +

+
+
+
+
+
+
+ + User avatar + +
+
+

+ This is some markup +

+
+
+
+
+
+
+ + User avatar + +
+
+

+ This is some markup +

+
+
+
+
+
+
+ + User avatar + +
+
+

+ This is some markup +

+
+
+
+
+
+
+ + User avatar + +
+
+

+ This is some markup +

+
+
+
+
+
+
+ + User avatar + +
+
+

+ This is some markup +

+
+
+
diff --git a/hubs/templates/includes/_library.html b/hubs/templates/includes/_library.html new file mode 100644 index 0000000..c4acbea --- /dev/null +++ b/hubs/templates/includes/_library.html @@ -0,0 +1,22 @@ +
+
+ My Library +
+ + + + +
+
+
+
+

+

  • Lorem
  • +
  • Ipsum
  • +
  • Sit
  • +
  • Amet
  • +

    +
    +
    +
    diff --git a/hubs/templates/includes/_searchstream.html b/hubs/templates/includes/_searchstream.html new file mode 100644 index 0000000..60b2caf --- /dev/null +++ b/hubs/templates/includes/_searchstream.html @@ -0,0 +1,7 @@ + +
    + + + + +
    diff --git a/hubs/templates/master.html b/hubs/templates/master.html index eae7c6f..1e19d91 100644 --- a/hubs/templates/master.html +++ b/hubs/templates/master.html @@ -66,6 +66,7 @@