Skip to content

Commit

Permalink
Adding ability in the editor for a page to have multiple streams.
Browse files Browse the repository at this point in the history
JS is getting fairly complex so:
* Integrated Juicer and RequireJS
* Re-organized code into widgets (html, css, and js files)
  • Loading branch information
ozten committed Aug 20, 2010
1 parent c8227ec commit 73c818e
Show file tree
Hide file tree
Showing 48 changed files with 12,517 additions and 580 deletions.
6 changes: 5 additions & 1 deletion apps/lifestream/models.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class Stream(models.Model):
""" A stream is composed of Feeds. """ """ A stream is composed of Feeds. """
user = models.ForeignKey(User) user = models.ForeignKey(User)
name = models.CharField(max_length=140) name = models.CharField(max_length=140)
webpage = models.ForeignKey(Webpage) # Added in 0.6 migration
# StreamConfig # StreamConfig
config = models.TextField() config = models.TextField()
# StreamEditList # StreamEditList
Expand Down Expand Up @@ -146,7 +147,10 @@ def _recent_entries(user, stream, feed_id, count=150, only_visible=True):
query = (Entry.objects.order_by('-last_published_date') query = (Entry.objects.order_by('-last_published_date')
.filter(feed__user=user, .filter(feed__user=user,
feed__url_hash=a_feed_id, feed__url_hash=a_feed_id,
feed__streams__id = stream_id)) # TODO .... Why constrain by Stream? We want to reuse feeds, right?
# the cron somehow repairs the links betwee a feed and all the streams it lives in
feed__streams__id = stream_id
))
# Visible is special, we want to see hidden items in the editor # Visible is special, we want to see hidden items in the editor
if only_visible: if only_visible:
query = query.filter(streamentry__visible=True) query = query.filter(streamentry__visible=True)
Expand Down
23 changes: 19 additions & 4 deletions apps/patchouli_auth/preferences.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import simplejson import simplejson


import patchouli_auth.models import patchouli_auth.models
import lifestream.models


def getPreferences(user): def getPreferences(user):
# Put all known preferences here... # Put all known preferences here...
Expand Down Expand Up @@ -60,16 +61,30 @@ def getPageProperties(page):


'processing_js': '', 'processing_js': '',


'stream_names': [] 'stream_ids': []
} }


existingProps = simplejson.loads(page.config) existingProps = simplejson.loads(page.config)
pageProps.update(existingProps) pageProps.update(existingProps)
if 0 == len(pageProps['stream_names']): if 0 == len(pageProps['stream_ids']):
# This should be page.id instead # Repair and save
pageProps['stream_names'] = [page.name] streams = (lifestream.models.Stream.objects.all()
.order_by('id')
.filter(webpage__id = page.id))
for stream in streams:
pageProps['stream_ids'].append(stream.id)
savePageOrStreamProperties(page, pageProps)
return pageProps return pageProps


def removeStreamFromPage(webpage, stream):
props = getPageProperties(webpage)
if stream.id in props['stream_ids']:
props['stream_ids'].remove(stream.id)
savePageOrStreamProperties(webpage, props)
stream.delete()
return True
return False

def savePageOrStreamProperties(model, properties): def savePageOrStreamProperties(model, properties):
""" Given a Page or Stream model, persists the """ Given a Page or Stream model, persists the
properties """ properties """
Expand Down
5 changes: 2 additions & 3 deletions apps/patchouli_auth/templates/index.html
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -44,6 +44,5 @@ <h1>Welcome, did we get your profile info right?</h2>
{% endif %} {% endif %}


</div><!-- /#content --> </div><!-- /#content -->
<script src="/static/js/jquery-1.4.1.min.js" type="text/javascript"></script> <script src="/static/js/stream_editor.min.js" type="text/javascript"></script>
<script src="/static/js/stream_editor.js" type="text/javascript"></script> {% endblock %}
{% endblock %}
12 changes: 6 additions & 6 deletions apps/patchouli_auth/views.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ def account_checkauth(request):
if request.user.is_authenticated(): if request.user.is_authenticated():
manageUrl = "/manage/account/%s" % request.user.username.encode('utf-8') manageUrl = "/manage/account/%s" % request.user.username.encode('utf-8')
try: try:
stream = lifestream.models.Stream.objects.get(user__exact=request.user) _ = lifestream.models.Stream.objects.all().filter(user=request.user)
encoded_url = django.utils.encoding.iri_to_uri(manageUrl) encoded_url = django.utils.encoding.iri_to_uri(manageUrl)
resp = django.http.HttpResponseRedirect(encoded_url) resp = django.http.HttpResponseRedirect(encoded_url)
except lifestream.models.Stream.DoesNotExist: except lifestream.models.Stream.DoesNotExist:
log.debug("Account didn't exist") log.debug("Account didn't exist")
Expand Down Expand Up @@ -66,7 +66,7 @@ def profile(request, username):


return render_to_response('index.html', return render_to_response('index.html',
{ 'show_delete': True, { 'show_delete': True,
'css_url': '/static/css/general-site.css', 'css_url': '/static/css/general-site.min.css',
'username': request.user.username, 'username': request.user.username,
'email': request.user.email, 'email': request.user.email,


Expand All @@ -92,7 +92,7 @@ def delete_profile(request, username):
else: else:
return render_to_response('confirm_delete.html', return render_to_response('confirm_delete.html',
{ {
'css_url': '/static/css/general-site.css', 'css_url': '/static/css/general-site.min.css',
'lang_dir': 'LTR', 'lang_dir': 'LTR',
'page_lang': 'en', 'page_lang': 'en',
}, },
Expand Down Expand Up @@ -135,7 +135,7 @@ def confirm_profile(request):
avatar_url = "http://www.gravatar.com/avatar/%s.jpg?d=monsterid&s=80" % gravatarHash avatar_url = "http://www.gravatar.com/avatar/%s.jpg?d=monsterid&s=80" % gravatarHash


return render_to_response('index.html', return render_to_response('index.html',
{ 'css_url': '/static/css/general-site.css', { 'css_url': '/static/css/general-site.min.css',
'username': request.user.username, 'username': request.user.username,
'email': request.user.email, 'email': request.user.email,


Expand Down Expand Up @@ -172,4 +172,4 @@ def session_status(request):
amstatus = "none;" amstatus = "none;"
resp = django.http.HttpResponse("X-Account-Managment-Status will be %s" % amstatus) resp = django.http.HttpResponse("X-Account-Managment-Status will be %s" % amstatus)
resp['X-Account-Management-Status'] = amstatus resp['X-Account-Management-Status'] = amstatus
return resp return resp
4 changes: 1 addition & 3 deletions apps/streamManager/templates/feed_editor.html
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -46,7 +46,5 @@ <h1>Edit Feed Details</h1>


</div><!-- #feed_preview --> </div><!-- #feed_preview -->
</div><!-- #feed_panel --> </div><!-- #feed_panel -->
<script type="text/javascript" src="/static/js/jquery-1.4.1.min.js"></script> <script src="/static/js/feed_editor.min.js" type="text/javascript"></script>
<script src="/static/js/feed_editor.js" type="text/javascript"></script>
<script src="/static/js/stream_editor.js" type="text/javascript"></script>
{% endblock %} {% endblock %}
38 changes: 20 additions & 18 deletions apps/streamManager/templates/stream_editor.html
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -6,61 +6,64 @@
<li>New Page</li> <li>New Page</li>
<li>All Pages</li> <li>All Pages</li>
</ul> </ul>

{% include 'widgets/add_stream_button.html' %}
{% endblock %} {% endblock %}


{% block content %} {% block content %}
<h1>Stream Editor</h1> <h1>Stream Editor</h1>
<div id="stream-editor-panel" lang="{{page_props.page_lang}}" dir="{{page_props.page_lang_dir}}"> <div id="stream-editor-panel" lang="{{page_props.page_lang}}" dir="{{page_props.page_lang_dir}}">
<ul class="tabs"> <ul class="tabs">
<li id="edit-stream" class="tab editor"><a href="#">Edit </a>{% if first_stream %}<strong id="stream{{first_stream.id}}" class="stream-name">{{first_stream.name}}</strong> Stream Page{% endif %}</li> <!-- TODO: Is stream1 used ? (first_stream.id). Change to page.id ? -->
<li id="edit-stream" class="tab editor"><a href="#">Edit </a>{% if first_stream %}<strong id="stream{{first_stream.id}}" class="page-name">{{page_name}}</strong> Stream Page{% endif %}</li>
<li id="design-stream" class="tab design xactive-tab"><a href="#">Design</a></li> <li id="design-stream" class="tab design xactive-tab"><a href="#">Design</a></li>
<li id="page-widgets" class="tab pagewidget active-tab"><a href="#">Page Widgets</a></li> <li id="page-widgets" class="tab pagewidget active-tab"><a href="#">Page Widgets</a></li>
{% if first_stream %}<li><a id="preview" href="/u/{{username}}/s/{{first_stream.name}}" target="_new" title="View your currenly published Stream in a new window">View</a></li>{% endif %} {% if first_stream %}<li><a id="preview" href="/u/{{username}}/s/{{page_name}}" target="_new" title="View your currenly published Stream in a new window">View</a></li>{% endif %}
</ul> </ul>
<!--------------------- Edit Stream Panel -------------------------> <!--------------------- Edit Stream Panel ------------------------->
<div id="edit-stream-panel" class="panel"> <div id="edit-stream-panel" class="panel">


{% for stream in streams %} {% for stream in streams %}
<div class="streams-panel"><!-- streams panel contains the metadata and preview --> <div class="streams-panel"><!-- streams panel contains the metadata and preview -->
<div class="stream-metadata-panel"> <div class="stream-metadata-panel">
<h2 class="new-feed">Add A Source</h2> <h2 class="new-feed">Add A Source</h2>
<p>Paste in the Url to a website or any Atom or RSS feed <img src="/static/img/feed-icon-14x14.png" width="14" height="14" alt="Feed Icon" />.</p> <p>Paste in the Url to a website or any Atom or RSS feed <img src="/static/img/feed-icon-14x14.png" width="14" height="14" alt="Feed Icon" />.</p>


<form id="add-url-form" action="/manage/urls/{{request.user.username}}" method="post"> <form class="add-url-form" action="/manage/urls/{{request.user.username}}" method="post">
<p><label for="id_url">Url:</label> <input id="id_url" type="text" name="url" maxlength="2048" /></p> <p><label for="id_url">Url:</label> <input class="id_url" type="text" name="url" maxlength="2048" /></p>
<p> <p>
<label for="id_streams">Streams:</label> <label for="id_streams">Streams:</label>
<input type="hidden" name="streams" id="id_streams" value="{{stream.name}}" /></p> <!-- TODO test add feed form -->
<input type="hidden" name="streams" class="id_streams" value="{{stream.id}}" /></p>
<input type="submit" value="Add Feed" /> <input type="submit" value="Add Feed" />
</p> </p>
</form> </form>


<h2>Stream Sources</h2> <h2>Stream Sources</h2>
<ul id="user_streams"> <ul class="user_streams">
{% for feed in stream.feeds %} {% for feed in stream.feeds %}
<li> <li>
<a href="{{ feed.url }}" class="stream-feed-source"> {% if feed.title %}{{ feed.title }}{% else %} {{ feed.url }} {% endif %}</a> <a href="{{ feed.url }}" class="stream-feed-source"> {% if feed.title %}{{ feed.title }}{% else %} {{ feed.url }} {% endif %}</a>
{% if not feed.enabled %} <strong title="{{feed.disabled_reason}}">Disabled</strong>{% endif %} {% if not feed.enabled %} <strong title="{{feed.disabled_reason}}">Disabled</strong>{% endif %}
<a href="/manage/account/{{username}}/stream/{{stream.id}}/feed/{{feed.pk}}" class="button">Edit</a> <a href="/manage/account/{{username}}/stream/{{stream.id}}/feed/{{feed.pk}}" class="button">Edit</a>
</li> </li>
{% empty %} {% empty %}
<li id="no-stream-feed-blurb"><a href="#" class="stream-feed-source"></a><a href="{{ feed.pk }}" class="feed-delete" title="Delete this feed."></a>You have no stream sources, add a new feed.</li> <li class="no-stream-feed-blurb"><a href="#" class="stream-feed-source"></a>You have no stream sources, add a new feed.
<!-- Empty case we have to add the stream and feed ids... and show -->
<a href="/manage/account/{{username}}/stream/" class="button" style="display:none">Edit</a></li>
{% endfor %} {% endfor %}


<li id="base-stream-feed-link" style="display:none"><a href="{{ feed.url }}" class="stream-feed-source">sample</a> <li class="base-stream-feed-link" style="display:none"><a href="{{ feed.url }}" class="stream-feed-source">sample</a>
<div class="feed-entries-visible-default shown" title="New Items are shown automatically"></div> <a href="#" class="feed-edit button" title="Edit this feed.">Edit</a></li>
<a href="#" class="feed-edit" title="Edit this feed.">Edit</a></li>
</ul> </ul>
<p>After 5 minutes, Feed entries should start appearing in <a href="/u/{{username}}/s/{{stream.name}}" target="_new" title="View your currenly published Stream in a new window">your stream.</a></p> <p>After 5 minutes, Feed entries should start appearing in <a href="/u/{{username}}/s/{{page_name}}" target="_new" title="View your currenly published Stream in a new window">your stream.</a></p>
{% include 'widgets/delete_stream_panel.html' %}
</div><!-- /.stream-metadata-panel --> </div><!-- /.stream-metadata-panel -->
<div class="stream-preview-panel"> <div class="stream-preview-panel">
{% include 'feed_editor_preview.html' %} {% include 'feed_editor_preview.html' %}
</div><!-- /.stream-preview-panel --> </div><!-- /.stream-preview-panel -->
</div><!-- /.streams-panel --> </div><!-- /.streams-panel -->
{% endfor %} {% endfor %}
<!-- div class="add-stream-panel">
<p class="callout">A page can have multiple streams. <a href="#todo" class="button">Add Another Stream</a>.</p>
</div -->
</div><!-- /#edit-stream-panel --> </div><!-- /#edit-stream-panel -->


<!--------------------- Page Widgets Panel -------------------------> <!--------------------- Page Widgets Panel ------------------------->
Expand Down Expand Up @@ -132,7 +135,7 @@ <h2>Page Widgets</h2>
</div><!-- /optional-widget --> </div><!-- /optional-widget -->


<div class="stream-icon"> <div class="stream-icon">
<h3>Your {{stream.name}} Stream</h3> <h3>Your {{page_name}} Stream</h3>
<img src="/static/img/StreamDiagram_25perc.jpg" width="76" height="95" /> <img src="/static/img/StreamDiagram_25perc.jpg" width="76" height="95" />
</div> </div>


Expand Down Expand Up @@ -212,6 +215,5 @@ <h2>Processing.js</h2>
</div><!-- /design-stream --> </div><!-- /design-stream -->
</div><!-- /stream-editor-panel --> </div><!-- /stream-editor-panel -->


<script src="/static/js/jquery-1.4.1.min.js" type="text/javascript"></script> <script src="/static/js/stream_editor.min.js" type="text/javascript"></script>
<script src="/static/js/stream_editor.js" type="text/javascript"></script>
{% endblock %} {% endblock %}
2 changes: 1 addition & 1 deletion apps/streamManager/templates/template.html
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<head> <head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" /> <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<title>{% block title %}SudoSocial{% endblock %}</title> <title>{% block title %}SudoSocial{% endblock %}</title>
<link href="/static/css/editor-stylo.css" type="text/css" rel="stylesheet"> <link href="/static/css/editor-stylo.min.css" type="text/css" rel="stylesheet">
{%block page_css_link %} {% endblock %} {%block page_css_link %} {% endblock %}
<link rel="icon" href="/static/img/favicon.png" type="image/png"> <link rel="icon" href="/static/img/favicon.png" type="image/png">
</head> </head>
Expand Down
5 changes: 5 additions & 0 deletions apps/streamManager/templates/widgets/add_stream_button.html
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,5 @@
<div class="add-stream-panel">
<p class="callout">A page can have multiple streams.</p>
<p><a href="/manage/streams/{{username}}/p/{{page_name}}" class="add-stream button">Add Another Stream</a>.</p>
<p class="creating">Creating Stream</p>
</div>
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1 @@
<p class="stream-delete-panel"><a href="{{stream.id}}" class="stream-delete button">Delete</a></p>
4 changes: 3 additions & 1 deletion apps/streamManager/urls.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
(r'^account/(?P<username>\w+)/stream/(?P<stream_id>\d+)/preview_feed/(?P<feed_id>\w+)$', 'views.preview_feed'), (r'^account/(?P<username>\w+)/stream/(?P<stream_id>\d+)/preview_feed/(?P<feed_id>\w+)$', 'views.preview_feed'),
(r'^stream/design$', 'views.manage_page_design'), (r'^stream/design$', 'views.manage_page_design'),
(r'^stream/(?P<username>\w+)/s/(?P<page_name>\w+)$', 'views.manage_page'), (r'^stream/(?P<username>\w+)/s/(?P<page_name>\w+)$', 'views.manage_page'),

(r'^stream/(?P<username>\w+)/sid/(?P<stream_id>\w+)$', 'views.stream'),
(r'^streams/(?P<username>\w+)/p/(?P<page_name>\w+)$', 'views.streams', {}, 'streams'),

(r'^page/(?P<page_name>\w+)$', 'views.manage_page_widgets'), (r'^page/(?P<page_name>\w+)$', 'views.manage_page_widgets'),


(r'^urls/(?P<username>\w+)$', 'views.urls'), (r'^urls/(?P<username>\w+)$', 'views.urls'),
Expand Down
Loading

0 comments on commit 73c818e

Please sign in to comment.