changeset 29:74f04122295e

Initial integration of django-elsewhere.
author Brian Neal <bgneal@gmail.com>
date Sun, 03 May 2009 20:14:04 +0000
parents 04377c5bf912
children a39907cd63e2
files gpp/bio/templatetags/elsewhere_tags.py gpp/bio/urls.py gpp/bio/views.py gpp/settings.py gpp/templates/bio/edit_elsewhere.html gpp/templates/bio/edit_profile.html gpp/templates/bio/view_profile.html gpp/templates/elsewhere/links_list.html media/css/base.css media/elsewhere/aim.png media/elsewhere/bebo.png media/elsewhere/blip.png media/elsewhere/catster.png media/elsewhere/corkd.png media/elsewhere/delicious.png media/elsewhere/digg.png media/elsewhere/djangopeople.png media/elsewhere/dodgeball.png media/elsewhere/dogster.png media/elsewhere/dopplr.png media/elsewhere/facebook.png media/elsewhere/flickr.png media/elsewhere/fortythreethings.png media/elsewhere/foursquare.png media/elsewhere/gamercard.png media/elsewhere/github.png media/elsewhere/goodreads.png media/elsewhere/gtalk.png media/elsewhere/hi5.png media/elsewhere/icq.png media/elsewhere/instructables.png media/elsewhere/jaiku.png media/elsewhere/lastfm.png media/elsewhere/librarything.png media/elsewhere/linkedin.png media/elsewhere/livejournal.png media/elsewhere/magnolia.png media/elsewhere/metafilter.png media/elsewhere/mog.png media/elsewhere/msn.png media/elsewhere/multiply.png media/elsewhere/myspace.png media/elsewhere/netvibes.png media/elsewhere/newsvine.png media/elsewhere/ning.png media/elsewhere/orkut.png media/elsewhere/pandora.png media/elsewhere/plaxo.png media/elsewhere/pownce.png media/elsewhere/readernaut.png media/elsewhere/redbubble.png media/elsewhere/reddit.png media/elsewhere/seesmic.png media/elsewhere/shelfworthy.png media/elsewhere/skype.png media/elsewhere/sonicliving.png media/elsewhere/stumbleupon.png media/elsewhere/tabblo.png media/elsewhere/technorati.png media/elsewhere/tribe.png media/elsewhere/tumblr.png media/elsewhere/twitter.png media/elsewhere/upcoming.png media/elsewhere/ustream.png media/elsewhere/virb.png media/elsewhere/vox.png media/elsewhere/wakoopa.png media/elsewhere/yahoo.png media/elsewhere/youtube.png media/elsewhere/zooomr.png media/elsewhere/zune.png media/icons/link_edit.png media/icons/world.png
diffstat 73 files changed, 208 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/gpp/bio/templatetags/elsewhere_tags.py	Sun May 03 20:14:04 2009 +0000
@@ -0,0 +1,17 @@
+"""
+Template tags for the elsewhere application. 
+"""
+from django import template
+from django.conf import settings
+
+register = template.Library()
+
+
+@register.inclusion_tag('elsewhere/links_list.html', takes_context=True)
+def elsewhere_links(context, user):
+    return {
+        'social_nets': user.social_network_profiles.all(),
+        'ims': user.instant_messenger_profiles.all(),
+        'websites': user.website_profiles.all(),
+        'MEDIA_URL': context['MEDIA_URL'],
+    }
--- a/gpp/bio/urls.py	Wed Apr 22 00:34:42 2009 +0000
+++ b/gpp/bio/urls.py	Sun May 03 20:14:04 2009 +0000
@@ -8,6 +8,7 @@
     url(r'^me/$', 'my_profile', name='bio-me'),
     url(r'^view/(?P<username>\w{1,30})/$', 'view_profile', name='bio-view_profile'),
     url(r'^edit/$', 'edit_profile', name='bio-edit_profile'),
+    url(r'^edit/elsewhere/$', 'edit_elsewhere', name='bio-edit_elsewhere'),
     url(r'^avatar/$', 'change_avatar', name='bio-change_avatar'),
 )
 
--- a/gpp/bio/views.py	Wed Apr 22 00:34:42 2009 +0000
+++ b/gpp/bio/views.py	Sun May 03 20:14:04 2009 +0000
@@ -10,6 +10,10 @@
 from django.core.urlresolvers import reverse
 from django.contrib.auth.decorators import login_required
 
+from elsewhere.models import SocialNetworkForm
+from elsewhere.models import InstantMessengerForm
+from elsewhere.models import WebsiteForm
+
 from bio.models import UserProfile
 from bio.forms import UploadAvatarForm
 from bio.forms import EditUserForm
@@ -134,5 +138,66 @@
          }, 
         context_instance = RequestContext(request))
 
+#######################################################################
 
-# vim: ts=4 sw=4
+@login_required
+def edit_elsewhere(request):
+    im_id = 'id_im_%s'  # to prevent duplicate ID in HTML output
+    if request.method == 'POST':
+        new_data = request.POST.copy()
+
+        # Add forms
+        if new_data.get('sn-form') or new_data.get('im-form') or new_data.get('w-form'):
+
+            if new_data.get('sn-form'):
+                sn_form = SocialNetworkForm(new_data)
+                im_form = InstantMessengerForm(auto_id=im_id)
+                w_form = WebsiteForm()
+                form = sn_form
+            elif new_data.get('im-form'):
+                sn_form = SocialNetworkForm()
+                im_form = InstantMessengerForm(new_data, auto_id=im_id)
+                w_form = WebsiteForm()
+                form = im_form
+            elif new_data.get('w-form'):
+                sn_form = SocialNetworkForm()
+                im_form = InstantMessengerForm(auto_id=im_id)
+                w_form = WebsiteForm(new_data)
+                form = w_form
+
+            if form.is_valid():
+                profile = form.save(commit=False)
+                profile.user = request.user
+                profile.save()
+                return HttpResponseRedirect(request.path)
+
+        # Delete forms
+        elif new_data.get('delete-sn-form') or new_data.get('delete-im-form') or new_data.get('delete-w-form'):
+            delete_id = request.POST['delete_id']
+
+            if new_data.get('delete-sn-form'):
+                request.user.social_network_profiles.get(id=delete_id).delete()
+            elif new_data.get('delete-im-form'):
+                request.user.instant_messenger_profiles.get(id=delete_id).delete()
+            elif new_data.get('delete-w-form'):
+                request.user.website_profiles.get(id=delete_id).delete()
+
+            return HttpResponseRedirect(request.path)
+
+        # WTF?
+        else:
+            return HttpResponseServerError
+
+    else:
+        # Create blank forms
+        sn_form = SocialNetworkForm()
+        im_form = InstantMessengerForm(auto_id=im_id)
+        w_form = WebsiteForm()
+
+    return render_to_response('bio/edit_elsewhere.html', {
+        'sn_form': sn_form, 
+        'im_form': im_form, 
+        'w_form': w_form,
+        }, 
+        context_instance=RequestContext(request))
+
--- a/gpp/settings.py	Wed Apr 22 00:34:42 2009 +0000
+++ b/gpp/settings.py	Sun May 03 20:14:04 2009 +0000
@@ -79,6 +79,7 @@
     # Always use forward slashes, even on Windows.
     # Don't forget to use absolute paths, not relative paths.
     os.path.join(project_path, 'templates'),
+    '/home/brian/coding/python/django/django-elsewhere/elsewhere/templates',
 )
 
 TEMPLATE_CONTEXT_PROCESSORS = (
@@ -97,6 +98,7 @@
     'django.contrib.sessions',
     'django.contrib.sites',
     'django.contrib.markup',
+    'elsewhere',
     'tagging',
     'accounts',
     'bio',
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/gpp/templates/bio/edit_elsewhere.html	Sun May 03 20:14:04 2009 +0000
@@ -0,0 +1,78 @@
+{% extends 'bio/base.html' %}
+{% block title %}Edit Your Elsewhere Links{% endblock %}
+{% block content %}
+<h2>Edit Your Elsewhere Links</h2>
+<h3>Social Networks</h3>
+{% if request.user.social_network_profiles.all %}
+    <ul>
+    {% for profile in request.user.social_network_profiles.all %}
+        <li>
+        <img src="{{ MEDIA_URL }}elsewhere/{{ profile.icon_name }}" alt="{{ profile.name }}" />
+            <a href="{{ profile.url }}" rel="me">{{ profile.name }}</a>
+            <form id="delete-network-{{ profile.id }}" method="post" action=".">
+                <input type="hidden" name="delete_id" value="{{ profile.id }}" />
+                <input type="submit" name="delete-sn-form" value="Delete" class="button" />
+            </form>
+        </li>
+    {% endfor %}
+    </ul>
+{% else %}
+    <p>No social network profiles.</p>
+{% endif %}
+
+<h4>Add a Social Network</h4>
+<form method="post" action=".">
+    {{ sn_form.as_p }}
+    <p><input type="submit" name="sn-form" value="Add Social Network" class="button" /></p>
+</form>
+<hr />
+<h3>Instant Messengers</h3>
+{% if request.user.instant_messenger_profiles.all %}
+    <ul>
+    {% for profile in request.user.instant_messenger_profiles.all %}
+        <li>
+        <img src="{{ MEDIA_URL }}elsewhere/{{ profile.icon_name }}" alt="{{ profile.name }}" />
+            {{ profile.name }}: <a href="{{ profile.url }}">{{ profile.username }}</a>
+            <form id="delete-messenger-{{ profile.id }}" method="post" action=".">
+                <input type="hidden" name="delete_id" value="{{ profile.id }}" />
+                <input type="submit" name="delete-im-form" value="Delete" class="button" />
+            </form>
+        </li>
+    {% endfor %}
+    </ul>
+{% else %}
+    <p>No instant messenger profiles.</p>
+{% endif %}
+
+<h4>Add an Instant Messenger</h4>
+<form method="post" action=".">
+    {{ im_form.as_p }}
+    <p><input type="submit" name="im-form" value="Add Instant Messenger" class="button" /></p>
+</form>
+<hr />
+<h3>Websites</h3>
+{% if request.user.website_profiles.all %}
+    <ul>
+    {% for profile in request.user.website_profiles.all %}
+        <li>
+           <img src="{{ MEDIA_URL }}icons/world.png" alt="{{ profile.name }}" />
+            <a href="{{ profile.url }}" rel="me">{{ profile.name }}</a>
+            <form id="delete-website-{{ profile.id }}" method="post" action=".">
+                <input type="hidden" name="delete_id" value="{{ profile.id }}" />
+                <input type="submit" name="delete-w-form" value="Delete" class="button" />
+            </form>
+        </li>
+    {% endfor %}
+    </ul>
+{% else %}
+    <p>No website profiles.</p>
+{% endif %}
+
+<h4>Add a Website</h4>
+<form method="post" action=".">
+    {{ w_form.as_p }}
+    <p><input type="submit" name="w-form" value="Add Website" class="button" /></p>
+</form>
+<hr />
+<p><a href="{% url bio-edit_profile %}">Back to Your Profile</a></p>
+{% endblock %}
--- a/gpp/templates/bio/edit_profile.html	Wed Apr 22 00:34:42 2009 +0000
+++ b/gpp/templates/bio/edit_profile.html	Sun May 03 20:14:04 2009 +0000
@@ -1,5 +1,6 @@
 {% extends 'bio/base.html' %}
 {% load avatar_tags %}
+{% load elsewhere_tags %}
 {% block title %}Edit Profile{% endblock %}
 {% block custom_js %}
    {{ profile_form.media }}
@@ -17,6 +18,12 @@
    </tr>
    {{ user_form.as_table }}
    {{ profile_form.as_table }}
+   <tr>
+      <td>
+         <a href="{% url bio-edit_elsewhere %}"><img src="{{ MEDIA_URL }}icons/link_edit.png" alt="Edit Links" /></a>
+         <a href="{% url bio-edit_elsewhere %}">Edit Elsewhere Links</a></td>
+      <td>{% elsewhere_links user %}</td>
+   </tr>
    <tr><td>&nbsp;</td><td><input type="submit" name="submit_button" value="Save" />
          <input type="submit" name="submit_button" value="Cancel" /></td></tr>
 </table>
--- a/gpp/templates/bio/view_profile.html	Wed Apr 22 00:34:42 2009 +0000
+++ b/gpp/templates/bio/view_profile.html	Sun May 03 20:14:04 2009 +0000
@@ -1,5 +1,6 @@
 {% extends 'bio/base.html' %}
 {% load avatar_tags %}
+{% load elsewhere_tags %}
 {% block title %}User Profile for {{ subject.username }}{% endblock %}
 {% block content %}
 <div class="user_profile">
@@ -56,10 +57,11 @@
    {% if profile.signature_html %}
    <tr><th>Signature</th><td>{{ profile.signature_html|safe }}</td></tr>
    {% endif %}
+   <tr><th>Elsewhere</th><td>{% elsewhere_links subject %}</td></tr>
 </table>
 </div>
 {% if this_is_me %}
-<ul>
+<ul class="icon-list">
    <li><a href="{% url bio-edit_profile %}"><img src="{{ MEDIA_URL }}icons/application_edit.png" alt="Edit Profile" /></a>
    <a href="{% url bio-edit_profile %}">Edit Profile</a></li>
    <li><a href="{% url bio-change_avatar %}"><img src="{{ MEDIA_URL }}icons/image_edit.png" alt="Change Avatar" /></a>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/gpp/templates/elsewhere/links_list.html	Sun May 03 20:14:04 2009 +0000
@@ -0,0 +1,31 @@
+{% if social_nets or ims or websites %}
+<ul>
+   {% if social_nets %}
+   <li>Social Networks</li>
+   <ul class="icon-list">
+      {% for net in social_nets %}
+      <li><img src="{{ MEDIA_URL }}elsewhere/{{ net.icon_name }}" alt="{{ net.name }}" />
+      <a href="{{ net.url }}">{{ net.name }}</a></li>
+      {% endfor %}
+   </ul>
+   {% endif %}
+   {% if ims %}
+   <li>Instant Messengers</li>
+   <ul class="icon-list">
+      {% for im in ims %}
+      <li><img src="{{ MEDIA_URL }}elsewhere/{{ im.icon_name }}" alt="{{ im.name }}" />
+      <a href="{{ im.url }}">{{ im.name }}</a></li>
+      {% endfor %}
+   </ul>
+   {% endif %}
+   {% if ims %}
+   <li>Websites</li>
+   <ul class="icon-list">
+      {% for site in websites %}
+      <li><img src="{{ MEDIA_URL }}icons/world.png" alt="{{ site.name }}" />
+      <a href="{{ site.url }}">{{ site.name }}</a></li>
+      {% endfor %}
+   </ul>
+   {% endif %}
+</ul>
+{% endif %}
--- a/media/css/base.css	Wed Apr 22 00:34:42 2009 +0000
+++ b/media/css/base.css	Sun May 03 20:14:04 2009 +0000
@@ -128,3 +128,6 @@
    color: gray;
    text-align: right;
 }
+ul.icon-list li {
+   list-style-type: none;
+}
Binary file media/elsewhere/aim.png has changed
Binary file media/elsewhere/bebo.png has changed
Binary file media/elsewhere/blip.png has changed
Binary file media/elsewhere/catster.png has changed
Binary file media/elsewhere/corkd.png has changed
Binary file media/elsewhere/delicious.png has changed
Binary file media/elsewhere/digg.png has changed
Binary file media/elsewhere/djangopeople.png has changed
Binary file media/elsewhere/dodgeball.png has changed
Binary file media/elsewhere/dogster.png has changed
Binary file media/elsewhere/dopplr.png has changed
Binary file media/elsewhere/facebook.png has changed
Binary file media/elsewhere/flickr.png has changed
Binary file media/elsewhere/fortythreethings.png has changed
Binary file media/elsewhere/foursquare.png has changed
Binary file media/elsewhere/gamercard.png has changed
Binary file media/elsewhere/github.png has changed
Binary file media/elsewhere/goodreads.png has changed
Binary file media/elsewhere/gtalk.png has changed
Binary file media/elsewhere/hi5.png has changed
Binary file media/elsewhere/icq.png has changed
Binary file media/elsewhere/instructables.png has changed
Binary file media/elsewhere/jaiku.png has changed
Binary file media/elsewhere/lastfm.png has changed
Binary file media/elsewhere/librarything.png has changed
Binary file media/elsewhere/linkedin.png has changed
Binary file media/elsewhere/livejournal.png has changed
Binary file media/elsewhere/magnolia.png has changed
Binary file media/elsewhere/metafilter.png has changed
Binary file media/elsewhere/mog.png has changed
Binary file media/elsewhere/msn.png has changed
Binary file media/elsewhere/multiply.png has changed
Binary file media/elsewhere/myspace.png has changed
Binary file media/elsewhere/netvibes.png has changed
Binary file media/elsewhere/newsvine.png has changed
Binary file media/elsewhere/ning.png has changed
Binary file media/elsewhere/orkut.png has changed
Binary file media/elsewhere/pandora.png has changed
Binary file media/elsewhere/plaxo.png has changed
Binary file media/elsewhere/pownce.png has changed
Binary file media/elsewhere/readernaut.png has changed
Binary file media/elsewhere/redbubble.png has changed
Binary file media/elsewhere/reddit.png has changed
Binary file media/elsewhere/seesmic.png has changed
Binary file media/elsewhere/shelfworthy.png has changed
Binary file media/elsewhere/skype.png has changed
Binary file media/elsewhere/sonicliving.png has changed
Binary file media/elsewhere/stumbleupon.png has changed
Binary file media/elsewhere/tabblo.png has changed
Binary file media/elsewhere/technorati.png has changed
Binary file media/elsewhere/tribe.png has changed
Binary file media/elsewhere/tumblr.png has changed
Binary file media/elsewhere/twitter.png has changed
Binary file media/elsewhere/upcoming.png has changed
Binary file media/elsewhere/ustream.png has changed
Binary file media/elsewhere/virb.png has changed
Binary file media/elsewhere/vox.png has changed
Binary file media/elsewhere/wakoopa.png has changed
Binary file media/elsewhere/yahoo.png has changed
Binary file media/elsewhere/youtube.png has changed
Binary file media/elsewhere/zooomr.png has changed
Binary file media/elsewhere/zune.png has changed
Binary file media/icons/link_edit.png has changed
Binary file media/icons/world.png has changed