Skip to content

example invite, pending confirmed

CarlFK edited this page Sep 13, 2010 · 2 revisions

This doesn’t work, but it is close. I am pretty sure it will be helpful for anyone else coming along.

Things it needs:
1. add to JoinInvitation
2. send invite
3. is there a better way to do form.user=request.user? adding it after the .save seems odd.
4. what’s a good way to delete confirmed and pendings? I couln’t figure out how to hook a form set to them without allowing edits, which seems bad.

from django import http, shortcuts, template
from django.contrib.auth.decorators import login_required
from django.forms.models import modelformset_factory

from friends.models import Contact,JoinInvitation

Contact_FormSet = modelformset_factory(Contact,
fields=(‘name’, ‘email’), extra=3)

@login_required
def user_friends_view(request):
“”“
main friends page
shows accepted, pending and a place to enter new
“”“

contacts=Contact.objects.filter(user=request.user) inviteds=JoinInvitation.objects.filter(from_user=request.user) if request.method == ‘POST’: contact_formset = Contact_FormSet(request.POST, queryset=Contact.objects.none(),) if contact_formset.is_valid(): for form in contact_formset.save(commit=False): form.user=request.user form.save() else: contact_formset = Contact_FormSet( queryset=Contact.objects.none(),) return shortcuts.render_to_response( ‘buddies/main.html’, locals(), context_instance=template.RequestContext(request))

here is my template, which needs to be escaped and the css stripped out. I’ll clean it up in the morning.

Buddies
    {% for contact in contacts %}

  • {{contact.name}}{{contact.email}}
  • {% endfor %}
Invite Friends
{{ contact_formset.management_form }}
    {% for form in contact_formset.forms %}

  • {{form.name}}

    {{form.email}}

    {{form.errors}}
  • {% endfor %}

Pending Requests


    {% for invite in inviteds %}

  • {{invite.name}}{{invite.email}}
  • {% endfor %}
Clone this wiki locally