Example #1
0
File: views.py Project: josben/flo
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))
Example #2
0
File: views.py Project: josben/flo
def createNotificationFromAdmin(request):
    if request.method == 'POST':
        form = NotificationFromAdminForm(request.POST)
        if form.is_valid():
            priority = form.cleaned_data['priority']
            owner = form.cleaned_data['owner']
            to_all = form.cleaned_data['to_all']
            only_guard = form.cleaned_data['only_guard']

            notification = form.save()

            if to_all:
                users = User.objects.filter(id__gt=0).filter(is_superuser=False).filter(~Q(username=request.user.username))
                for user in users:
                    notifications = Notifications(priority=priority,
                                                  owner=user,
                                                  sender=request.user,
                                                  notification=notification)
                    notifications.save()
                owner = 'Todos'
            elif only_guard:
                guards = Staff.objects.filter(is_guard=True).filter(is_user=True)
                users = User.objects.filter(staff__in=guards)
                for user in users:
                    notifications = Notifications(priority=priority,
                                                  owner=user,
                                                  sender=request.user,
                                                  notification=notification)
                    notifications.save()
                owner = 'todos los Guardias'

            else:
                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_admin_form.html', {'form': form},
                                      context_instance=RequestContext(request))
    else:
        form = NotificationFromAdminForm()
        return render_to_response('notifications_admin_form.html', {'form': form},
                                  context_instance=RequestContext(request))
Example #3
0
    def get(self, request, event_id, event_type):

        cons = Connection.objects.get(id=event_id)
        if event_type == 'accept':
            cons.accept()
            activity = Activity().get_activity(activity='connection', subtype='accept')
            description = cons.to_profile.username + ' ' + activity.verb
            message = 'You accepted the connection request'
        else:
            cons.reject()
            activity = Activity().get_activity(activity='connection', subtype='reject')
            description = cons.to_profile.username + ' ' + activity.verb
            message = 'You rejected the connection request'

        # for notification
        Notifications.notify(
            actor=cons.to_profile,
            recipient=cons.from_profile,
            activity_type=activity,
            event_id=cons.id,
            description=description
        )
        messages.success(self.request, message=message)
        return HttpResponseRedirect(reverse('profiles:suggestions'))