On Saturday 05 Apr 2008, Matthias Kestenholz wrote:
> On Sat, 2008-04-05 at 20:19 +0100, Tim Sawyer wrote:
> > Hi Folks,
> >
> > I'd like to have a site that gives away and sells PDFs, and tracks
> > downloads of those PDFs.  For example, I'd like to know the IP
> > address/useragent of who downloaded the free files, and I'd like to
> > record the same plus the logged in user for the pay ones (after
> > authenticating the user is allowed to download that file).
>
> You could try something like that:
>
> from django.http import HttpResponse
> from testing.models import DownloadCounter
>
> class MyFile(file):
>    def __init__(self, filename, *args, **kwargs):
>       self.filename = filename
>       super(MyFile, self).__init__(filename, *args, **kwargs)
>
>    def close(self):
>       super(MyFile, self).close()
>       cnt, created = DownloadCounter.objects.get_or_create(
>                      filename=self.filename, defaults={'count':0})
>       cnt.count += 1
>       cnt.save()
>
> def blah(request):
>    return HttpResponse(MyFile('views.py'),
>       mimetype='application/octet-stream')

Cheers everyone for your ideas, I'm going with the approach at the moment.

Thanks again,

Tim.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to