Beispiel #1
0
def createNotification(request):
    if request.method == 'POST':
        form = NotificationForm(request.POST)
        if form.is_valid():
            priority = form.cleaned_data['priority']
            owner = form.cleaned_data['owner']
            notification = form.save()
            notifications = Notifications(priority=priority,
                                          owner=owner,
                                          sender=request.user,
                                          notification=notification)
            notifications.save()
            messages.add_message(request,
                                 messages.SUCCESS,
                                 'La notificacion se envio a %s' % owner)
            return HttpResponseRedirect(request.META.get('HTTP_REFERER'))

        else:
            messages.add_message(request,
                                 messages.ERROR,
                                 'Los datos que ingreso son incorrectos')
            return render_to_response('notifications_form.html', {'form': form},
                                      context_instance=RequestContext(request))
    else:
        form = NotificationForm()
        return render_to_response('notifications_form.html', {'form': form},
                                  context_instance=RequestContext(request))
Beispiel #2
0
class NotificationsListView(LoginRequiredMixin, ListView):
    model = Notification
    template_name = 'notifications/list.html'
    form_class = NotificationForm

    def get_context_data(self, **kwargs):
        context = super(NotificationsListView, self).get_context_data(**kwargs)
        context['notifications'] = self.notifications
        context['form'] = self.form
        if self.request.user.is_admin:
            context['users'] = CustomUser.objects.all()
        return context

    def dispatch(self, request, *args, **kwargs):
        notifications = Notification.objects.all()

        self.notifications = list()

        for notification in notifications:
            if notification.is_shared(request.user) == False and request.user.is_admin == False:
                continue
            if notification.is_archived(request.user) == True:
                continue
            self.notifications.append(notification)

        self.form = NotificationForm()

        if request.user.is_admin:
            self.users = CustomUser.objects.all()
        else:
            self.users = None

        return super(NotificationsListView, self).dispatch(request, *args, **kwargs)

    def post(self, request):
        self.form = NotificationForm(request.POST)
        if self.form.is_valid():
            instances = self.form.save(commit=True)

        return redirect('notifications')
Beispiel #3
0
    def dispatch(self, request, *args, **kwargs):
        notifications = Notification.objects.all()

        self.notifications = list()

        for notification in notifications:
            if notification.is_shared(request.user) == False and request.user.is_admin == False:
                continue
            if notification.is_archived(request.user) == True:
                continue
            self.notifications.append(notification)

        self.form = NotificationForm()

        if request.user.is_admin:
            self.users = CustomUser.objects.all()
        else:
            self.users = None

        return super(NotificationsListView, self).dispatch(request, *args, **kwargs)
Beispiel #4
0
def edit(request,notif_id):
    """
    Edit an existing individual notification.
    """

    notification = get_object_or_404(Notification,pk=notif_id)

    if request.POST:
        form = NotificationForm(request.POST, instance=notification,user=request.user)

        if form.is_valid():
            item = form.save(commit=False)
            item.title = form.cleaned_data['title']
            item.description = sanitizeHtml(form.cleaned_data['description'])
            item.author = request.user
            item.state = 'draft'
            item.save()
                        
            # Also move to queue or drafts if that submit button was clicked. 
            # enqueue() and endraft() take lists, not a single item, hence list notation
            if 'enqueue' in request.POST:
                enqueue(request,[notification,])
                return HttpResponseRedirect(reverse('notifications_queue'))

            if 'endraft' in request.POST:
                endraft(request,[notification,])
                return HttpResponseRedirect(reverse('notifications'))

            if 'trash' in request.POST:
                trash(request,[notification,])
                return HttpResponseRedirect(reverse('notifications_trash'))

            
            messages.success(request, "%s was changed." % item.title)


            return HttpResponseRedirect(reverse('notifications'))

    else:
        form = NotificationForm(instance=notification,user=request.user)

    return render_to_response('notifications/edit.html', locals(), context_instance=RequestContext(request))
Beispiel #5
0
def create(request):
    """
    Create a new notification
    """
    
    if request.POST:
        form = NotificationForm(request.POST,user=request.user)

        if form.is_valid():
            item = form.save(commit=False)
            item.title = form.cleaned_data['title']
            item.description = sanitizeHtml(form.cleaned_data['description'])
            item.author = request.user
            item.state = 'draft'
            item.save()
           
            messages.success(request, "Notification draft added.")  
            return HttpResponseRedirect(reverse('notifications'))            
        
    else:
        form = NotificationForm(user=request.user)
    
    return render_to_response('notifications/edit.html', locals(), context_instance=RequestContext(request)) 
Beispiel #6
0
    def post(self, request):
        self.form = NotificationForm(request.POST)
        if self.form.is_valid():
            instances = self.form.save(commit=True)

        return redirect('notifications')
Beispiel #7
0
        try:
            users = User.objects.all()
            for user in users:
                user_dict = model_to_dict(user)
                users_dict[user_dict['id']] = user_dict['username']
                num_users += 1
        except Exception, e:
            print(e)
            users = []

        NotificationRecipientsFormset = inlineformset_factory(Notification, NotificationRecipient, can_delete=False, extra=1)
        notification = Notification()
        notification_recipient = NotificationRecipient()

        if request.method == 'POST':
            notification_form = NotificationForm(request.POST, instance=notification)
            formset = NotificationRecipientsFormset(request.POST, instance=notification)
            if notification_form.is_valid() and formset.is_valid():
                n = notification_form.save()
                formset.save()
                print('saving form')
                if 'facebook' in request.POST:
                    n.facebook = True
                if 'twitter' in request.POST:
                    n.twitter = True
                n.save()
                return redirect('socialplatform.views.access_for_broadcast', n.id)
            else:
                print(notification_form.errors)
                print(formset.errors)
        else: