コード例 #1
0
 def form_valid(self, form):
     cig = form.save()
     cg = self.contactgroup
     contact = form.contact
     if cig:
         messages.add_message(
             self.request, messages.SUCCESS,
             _('Member {contact} of group {group} has been changed.')
             .format(contact=contact.name,
                     group=cg.name))
     else:
         messages.add_message(
             self.request, messages.SUCCESS,
             _('{contact} has been removed from group {group}.')
             .format(contact=contact.name,
                     group=cg.name))
     Contact.objects.check_login_created(self.request)
     hooks.membership_changed(self.request, contact, cg)
     return HttpResponseRedirect(cg.get_absolute_url())
コード例 #2
0
 def post(self, request, gid, cid):
     cg = self.contactgroup
     contact = get_object_or_404(Contact, pk=int(cid))
     if request.POST.get('membership_i', False):
         flags = '+i'
     elif request.POST.get('membership_m', False):
         flags = '+m'
     elif request.POST.get('membership_d', False):
         flags = '+d'
     elif request.POST.get('membership_D', False):
         flags = '+D'
     else:
         flags = '-midD'
     cg.set_member_1(request, contact, flags)
     note = request.POST.get('note', '')
     try:
         cig = ContactInGroup.objects.get(contact_id=cid, group_id=gid)
     except ContactInGroup.DoesNotExist:
         print('FIXME: No note possible when no direct membership')
     else:
         cig.note = note
         cig.save()
     hooks.membership_changed(request, contact, cg)
     return HttpResponseRedirect(request.POST['next_url'])