def edit_letter(request, id): data = {} letter = Letter.objects.get(id=id) if not request.user in letter.owners.all(): messages.error(request, _(u"Zugriff verweigert!")) return redirect_to_prev_page(request) if not request.method == 'POST': letter_form = LetterForm(instance=letter) else: letter_form = LetterForm(request.POST, instance=letter) if letter_form.is_valid(): letter = letter_form.save() messages.success(request, _(u"Brief erfolgreich bearbeitet.")) return redirect(letter) else: messages.error(request, _(u"Es gibt noch Fehler im Formular.")) helper = FormHelper() helper.form_id = "foobar" helper.form_class = "search" submit = Submit("send", _(u"Speichern")) helper.add_input(submit) reset = Submit("reset", _(u"Zurücksetzen")) helper.add_input(reset) data['form'] = letter_form data['helper'] = helper data.update(csrf(request)) return render_to_response("lettr/edit_letter.html", data, context_instance=RequestContext(request))
def new_letter(request): data = {} if not request.method == 'POST': from datetime import date data = {'my_date':date.today(), } letter_form = LetterForm(data) letter_form.fields["sender"].queryset = Sender.objects.filter(owners__username=request.user.username) else: letter_form = LetterForm(request.POST) if letter_form.is_valid(): letter = letter_form.save() ownership = Ownership_Letter.objects.create(owner=request.user, letter=letter) return redirect(letter) else: messages.error(request, _(u"Es gibt noch Fehler im Formular.")) helper = FormHelper() helper.form_id = "foobar" helper.form_class = "search" submit = Submit("send", _(u"Absenden")) helper.add_input(submit) reset = Submit("reset", _(u"Zurücksetzen")) helper.add_input(reset) data['form'] = letter_form data['helper'] = helper data.update(csrf(request)) return render_to_response("lettr/new_letter.html", data, context_instance=RequestContext(request))