Mercurial > public > sg101
changeset 29:74f04122295e
Initial integration of django-elsewhere.
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> </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 %}