def my_messages_action(request): my_message_action_form = MyMessageActionForm(request.POST) my_messages_formset = formset_factory(MyMessageForm)(request.POST, request.FILES) if my_message_action_form.is_valid() and my_messages_formset.is_valid(): my_messages_ids_to_action = [mess_form.cleaned_data.get('id') for mess_form in my_messages_formset if mess_form.cleaned_data.get('selected')] if 'MARK_AS_READ' in my_message_action_form.cleaned_data.get('action'): message_history_mdl.mark_as_read(my_messages_ids_to_action) elif 'DELETE' in my_message_action_form.cleaned_data.get('action'): message_history_mdl.delete_my_messages(my_messages_ids_to_action) return HttpResponseRedirect(reverse('my_messages'))
def my_messages_index(request): person = mdl.person.find_by_user(request.user) my_messages = message_history_mdl.find_my_messages(person.id) my_messages_formset = None if not my_messages: messages.add_message(request, messages.INFO, _('No Messages')) else: my_messages_formset = get_messages_formset(my_messages) return render( request, "my_osis/my_messages.html", { 'my_messages_formset': my_messages_formset, 'my_message_action_form': MyMessageActionForm() })
def my_messages_index(request): person = mdl.person.find_by_user(request.user) my_messages = message_history_mdl.find_my_messages(person.id) my_messages_formset = None if not my_messages: messages.add_message(request, messages.INFO, _('no_messages')) else: initial_formset_content = [{'selected': False, 'subject': message_hist.subject, 'created': message_hist.created, 'id': message_hist.id, 'read': message_hist.read_by_user } for message_hist in my_messages] my_messages_formset = formset_factory(MyMessageForm, extra=0)(initial=initial_formset_content) return layout.render(request, "my_osis/my_messages.html", { 'my_messages_formset': my_messages_formset, 'my_message_action_form': MyMessageActionForm() })