def index(request): form = EventForm() form.full_clean() targets = [] targets.append(MlistForm(auto_id = False)) context = { 'targets' : targets, 'form' : form, } return render(request, 'main/index.html', context)
def regist(request): logger = logging.getLogger('main.views') commitFlg = True new_event = None wmail = None form = EventForm(request.POST) if form.is_valid(): new_event = form.save() wmail = webmail(new_event) else: commitFlg = False targets = [] for (i, mail) in enumerate(request.POST.getlist('mail')): if len(mail) == 0: continue target = MlistForm({'mail':mail, 'event':new_event.pk}, auto_id = False) if new_event else MlistForm({'mail':mail, 'event': None}, auto_id = False) if target.is_valid(): target.save() wmail.add_to(mail) else: commitFlg = False targets.append(target) else: if len(targets) == 0: target = MlistForm({'mail': None, 'event': None}, auto_id = False) targets.append(target) commitFlg = False if not commitFlg or len(targets) == 0: transaction.rollback() return render(request, 'main/index.html', { 'form' : form, 'targets': targets }) transaction.commit() wmail.send() return HttpResponseRedirect('/main/event/' + new_event.identifier)