Ejemplo n.º 1
0
def home(request):
    form = DocumentForm(request.POST or None, request.FILES or None)
    if form.is_valid():
        instance = form.save(commit=False)
        a = User.objects.filter(id=2)
        print "***************************************"
        job = UserProfile.objects.get(user=request.user)
        print "job user", job.user
        instance.user = job
        instance.doc_type = instance.doc.url.split(".")[-1]
        instance.save()
        # a=UserProfile.objects.get(user=2)
        arg = {
            "recipient": a,
            "sender": request.user,
        }

        #notify_handler("has uploaded a document",arg)
        notify.connect(notify_handler,
                       dispatch_uid='notifications.models.notification')
        notify.send(request.user, recipient=a, verb="has uploaded a doc")
        #post_save.connect (sender=Notification)
        #print "Signal executed"
        if instance.doc.url.endswith(".pdf"):
            text = pdf_extractor(instance.doc.url)
            extractor(instance, text)
        elif instance.doc.url.endswith(".jpg"):
            text = pytesseract.image_to_string(Image.open(instance.doc.url))
            extractor(instance, text)
        elif instance.doc.url.endswith(".docx"):
            document_extractor(instance, instance.doc.url)
        elif instance.doc.url.endswith(".doc"):
            document_extractor(instance, instance.doc.url)
    context = {
        "form": form,
    }

    return render(request, 'accounts/home.html', context)
Ejemplo n.º 2
0
    """

    kwargs.pop('signal', None)
    recipient = kwargs.pop('recipient')
    actor = kwargs.pop('sender')
    newnotify = Notification(
        recipient = recipient,
        actor_content_type=ContentType.objects.get_for_model(actor),
        actor_object_id=actor.pk,
        verb=unicode(verb),
        public=bool(kwargs.pop('public', True)),
        description=kwargs.pop('description', None),
        timestamp=kwargs.pop('timestamp', now())
    )

    for opt in ('target', 'action_object'):
        obj = kwargs.pop(opt, None)
        if not obj is None:
            setattr(newnotify, '%s_object_id' % opt, obj.pk)
            setattr(newnotify, '%s_content_type' % opt,
                    ContentType.objects.get_for_model(obj))
    
    if len(kwargs) and EXTRA_DATA:
        newnotify.data = kwargs

    newnotify.save()


# connect the signal
notify.connect(notify_handler, dispatch_uid='notifications.models.notification')
Ejemplo n.º 3
0
	#if the messages has been sent 1 minute ago ignore the email sending
	lastsent = Notification.objects.filter(sender=sender, recipient=recipient, read=False).order_by('-timestamp')
	if lastsent.count() == 1:
		send_email(action=action, email=email, message=message, username=sender, msg_id=msg_id, pmsg_id=pmsg_id)
	else:
		seclastsent = lastsent[1]
		timelastsent = seclastsent.timestamp
		timesend = datetime.datetime.now(tz=pytz.UTC)
		timediff = timesend - timelastsent
		noofsec = timediff.seconds
		#change this back to 60 seconds when done
		if noofsec > 60:
			send_email(action=action, email=email, message=message, username=sender, msg_id=msg_id, pmsg_id=pmsg_id)


notify.connect(new_notification)


def send_email(action, email, message, username, msg_id, pmsg_id):

	action = action
	to_email = [email]
	message = str(message)

	msg = Message.objects.get(id=msg_id)
	msg = msg.content
	parent_msg = Message.objects.get(id=pmsg_id)

	msg_link = parent_msg.get_absolute_url()

	# retrieving the site
Ejemplo n.º 4
0
 def ready(self):
     from notifications.actions import action_handler
     notify.connect(action_handler, dispatch_uid='notifications.models')
                    sender_content_type = ContentType.objects.get_for_model(sender),
                    sender_object_id = sender.id,
                )
                for option in ("target", "action"):
                    #obj = kwargs.pop(option, None)
                    try:
                        obj = kwargs[option]
                        if obj is not None:
                            setattr(new_note, "%s_content_type" %option, ContentType.objects.get_for_model(obj))
                            setattr(new_note, "%s_object_id" %option, obj.id)
                    except:
                        pass
                new_note.save()
                print new_note
    else:
        new_note = Notification(
            recipient=recipient,
            verb = verb, # smart_text
            sender_content_type = ContentType.objects.get_for_model(sender),
            sender_object_id = sender.id,
        )
        for option in ("target", "action"):
            obj = kwargs.pop(option, None)
            if obj is not None:
                setattr(new_note, "%s_content_type" %option, ContentType.objects.get_for_model(obj))
                setattr(new_note, "%s_object_id" %option, obj.id)
        new_note.save()
        #print new_note

notify.connect(new_notification)