# HG changeset patch # User Brian Neal # Date 1241381644 0 # Node ID 74f04122295e5cd9b3ba3afba0fc88e9b535e4de # Parent 04377c5bf9124cdf00f6ddb082cda2e031cb4f0f Initial integration of django-elsewhere. diff -r 04377c5bf912 -r 74f04122295e gpp/bio/templatetags/elsewhere_tags.py --- /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'], + } diff -r 04377c5bf912 -r 74f04122295e gpp/bio/urls.py --- 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\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'), ) diff -r 04377c5bf912 -r 74f04122295e gpp/bio/views.py --- 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)) + diff -r 04377c5bf912 -r 74f04122295e gpp/settings.py --- 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', diff -r 04377c5bf912 -r 74f04122295e gpp/templates/bio/edit_elsewhere.html --- /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 %} +

Edit Your Elsewhere Links

+

Social Networks

+{% if request.user.social_network_profiles.all %} + +{% else %} +

No social network profiles.

+{% endif %} + +

Add a Social Network

+
+ {{ sn_form.as_p }} +

+
+
+

Instant Messengers

+{% if request.user.instant_messenger_profiles.all %} + +{% else %} +

No instant messenger profiles.

+{% endif %} + +

Add an Instant Messenger

+
+ {{ im_form.as_p }} +

+
+
+

Websites

+{% if request.user.website_profiles.all %} + +{% else %} +

No website profiles.

+{% endif %} + +

Add a Website

+
+ {{ w_form.as_p }} +

+
+
+

Back to Your Profile

+{% endblock %} diff -r 04377c5bf912 -r 74f04122295e gpp/templates/bio/edit_profile.html --- 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 @@ {{ user_form.as_table }} {{ profile_form.as_table }} + + + Edit Links + Edit Elsewhere Links + {% elsewhere_links user %} +   diff -r 04377c5bf912 -r 74f04122295e gpp/templates/bio/view_profile.html --- 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 %} {% if this_is_me %} -