from django import forms from django.conf import settings from django.utils.translation import gettext_lazy as _ from django.contrib import admin from django.contrib.auth.models import Group from messages.utils import get_user_model User = get_user_model() if "notification" in settings.INSTALLED_APPS: from famdates.notification import models as notification else: notification = None from messages.models import Message class MessageAdminForm(forms.ModelForm): """ Custom AdminForm to enable messages to groups and all users. """ recipient = forms.ModelChoiceField( label=_('Recipient'), queryset=User.objects.all(), required=True) group = forms.ChoiceField(label=_('group'), required=False, help_text=_('Creates the message optionally for all users or a group of users.')) def __init__(self, *args, **kwargs): super(MessageAdminForm, self).__init__(*args, **kwargs) self.fields['group'].choices = self._get_group_choices()
from django.core.urlresolvers import reverse from django.conf import settings from rest_framework import viewsets, status, filters from rest_framework.response import Response from rest_framework.decorators import action from rest_framework.permissions import IsAuthenticated from rest_framework import generics from messages.models import Message from messages.forms import ComposeForm from messages.utils import format_quote, get_user_model, get_username_field from messages.serializers import DeleteSerializer, UnDeleteSerializer, ReplySerializer, InboxSerializer, ComposeSerializer from messages.serializers import TrashSerializer, SentSerializer, ConnectionSerializer from messages.permissions import IsAdminOrSelf User = get_user_model() from notifications import notify def compose(request, recipient=None, form_class=ComposeForm, template_name='messages/compose.html', success_url=None, recipient_filter=None): """ Displays and handles the ``form_class`` form to compose new messages. Required Arguments: None Optional Arguments: ``recipient``: username of a `django.contrib.auth` User, who should