Re: caching and "hello username" on each page

2007-07-28 Thread Nic James Ferrier

Bram - Smartelectronix <[EMAIL PROTECTED]> writes:

> I would LOVE to use caching for both anonymous and logged in users, but 
> the problem is that every page on our site (http://www.splicemusic.com) 
> has the typical "hello username | log out | ..." at the top of each page.
>
> Now, how can I possibly cache both anonymous and logged in users easily? 
>   I'm guessing that I would need to add @vary_on_cookie before for each 
> and every view?

If the username is the only thing you could store the username in a
cookie and have Javascript write it out. Then the page is completly
cacheable.

-- 
Nic Ferrier
http://www.tapsellferrier.co.uk   

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: Overriding the model's save() method

2007-07-23 Thread Nic James Ferrier

Chris Hoeppner <[EMAIL PROTECTED]> writes:

> If I get this right, you're saving the original file, and a separate
> thumb file. While this seems interesting, it's not what I want to
> implement. It's more of a bit of catching the incoming data and
> transforming it before it gets saved in the model instance.

I don't understand that... save the data into a file and then
transform it and save it again.

That's what jared's code did and what mine does.

-- 
Nic Ferrier
http://www.tapsellferrier.co.uk   

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: Overriding the model's save() method

2007-07-23 Thread Nic James Ferrier

Chris Hoeppner <[EMAIL PROTECTED]> writes:

> Maybe something like
>
> def save(self):
>   self.imageField = pil.thumbnail(self.imageField)
>
> Can't really tell if I'm on the right track here.

Search the list... I've got this from the list:


  IMAGE_SIZE = [300, 300]
  THUMBNAIL_SIZE = [100, 100]
  UPLOAD_TO="photos/%Y/%M%d"
  THUMBS_TO="thumbs/%Y/%M%d"

  class Mugshot(models.Model):
  """Represents a single picture of the user"""

  person = models.ForeignKey(Person)
  shot = models.ImageField(upload_to=UPLOAD_TO)
  thumb = models.ImageField(upload_to=THUMBS_TO, editable=False)
  name = models.CharField(maxlength=500, blank=True)

  def __str__(self):
  return self.name

  def get_url(self):
  try:
  m = re.match(settings.MEDIA_ROOT + "(.*)", 
self.get_shot_filename())
  return n.group(1)
  except:
  return self.get_shot_filename()


  # Django thumbs hack from super jared.
  #   http://superjared.com/entry/django-quick-tips-2-image-thumbnails/
  def save(self):
  logger = logging.getLogger("Mugshot.save")
  from PIL import Image
  if not self.thumb:
  self.save_thumb_file(self.get_shot_filename(), '')
  image = Image.open(self.get_shot_filename())
  # Convert to RGB if necessary
  # Thanks to Limodou on DjangoSnippets.org
  # http://www.djangosnippets.org/snippets/20/
  if image.mode not in ('L', 'RGB'):
  image = image.convert('RGB')

  cropped = utils.image_crop(image, IMAGE_SIZE)
  cropped.thumbnail(THUMBNAIL_SIZE, Image.ANTIALIAS)
  cropped.save(self.get_thumb_filename())

  # Save this photo instance
  super(Mugshot, self).save()

  # Now resize the main image
  image = Image.open(self.get_shot_filename())
  if image.mode not in ('L', 'RGB'):
  image = image.convert('RGB')

  cropped = utils.image_crop(image, IMAGE_SIZE)
  cropped.thumbnail(IMAGE_SIZE, Image.ANTIALIAS)
  cropped.save(self.get_shot_filename())

  class Admin:
  pass

-- 
Nic Ferrier
http://www.tapsellferrier.co.uk   

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: REST authentication with apache

2007-07-23 Thread Nic James Ferrier

"[EMAIL PROTECTED]" <[EMAIL PROTECTED]> writes:

> Hi,
> I'm trying to implement a REST service with django and I have a
> problem in authentication.
> My current approach is with .htaccess with apache password(Basic
> Authentication), simple and straight.
> But I want to validate users in django, with roles etc.
> I've tryed:
>
> 
> AuthType basic
> AuthName "example.com"
> Require valid-user
> 
>
> but the 'AUTH_TYPE' in request.META is None, so I can't get the user
> and password from user.

Can't you just read the base64 data from the auth header and decode
it?


-- 
Nic Ferrier
http://www.tapsellferrier.co.uk   

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: File upload using Flash

2007-07-23 Thread Nic James Ferrier

"[EMAIL PROTECTED]" <[EMAIL PROTECTED]> writes:

> Hi all,
>
> some time ago, probably on this list, someone posted a link to a
> component in Flash with which you could do file upload from Django.
> The component featured a progress bar.
>
> Does anybody have a link to it?

Not to hand... but it's a mootools extension. That should help you
find it.

-- 
Nic Ferrier
http://www.tapsellferrier.co.uk   

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: Django advocacy in a commercial environment

2007-07-20 Thread Nic James Ferrier

Rob Hudson <[EMAIL PROTECTED]> writes:

> Python and Django wouldn't be my concern when hiring new employees
> since they are easy to learn.  It's all the other stuff that comes
> with web development that together is harder to find (eg: valid
> (x)HTML, CSS, Javascript, database, source control, unix/linux, HTTP,
> etc.)

I agree with this. I'd be happy to teach anyone django and python. But
finding people who know about CSS differences between browsers - now
that is hard.

-- 
Nic Ferrier
http://www.tapsellferrier.co.uk   

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: html sanitizers

2007-07-13 Thread Nic James Ferrier

Brett Parker <[EMAIL PROTECTED]> writes:

> On Fri, Jul 13, 2007 at 11:18:18AM +0100, Nic James Ferrier wrote:
>> 
>> Derek Anderson <[EMAIL PROTECTED]> writes:
>> 
>> > hey all,
>> >
>> > could anyone point me to a python html sanitizer implementation (or 
>> > example)?  i don't mean to strip all html, just tags and attributes not 
>> > on a whitelist, such as I/B/A href/U/etc.
>> 
>> I use libxml2/libxslt, something like:
>> 
>>   doc = libxml2.htmlParseDoc(whatever, "utf8")
>>   result = libxslt.applyStylesheetFile(doc, "strip.xslt", {})
>> 
>> There are loads of ways of stripping in xslt depending on what you
>> want to do.
>
> Only works on well formed XHTML documents though... which although they
> should be the norm, really aren't!

No. In my example I deliberately used libxml2' HTML parser which is an
HTML parser not an XHTML parser.

It copes with non-well formed documents as well as all the usual
entity problems.


-- 
Nic Ferrier
http://www.tapsellferrier.co.uk   

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: html sanitizers

2007-07-13 Thread Nic James Ferrier

Derek Anderson <[EMAIL PROTECTED]> writes:

> hey all,
>
> could anyone point me to a python html sanitizer implementation (or 
> example)?  i don't mean to strip all html, just tags and attributes not 
> on a whitelist, such as I/B/A href/U/etc.

I use libxml2/libxslt, something like:

  doc = libxml2.htmlParseDoc(whatever, "utf8")
  result = libxslt.applyStylesheetFile(doc, "strip.xslt", {})

There are loads of ways of stripping in xslt depending on what you
want to do.
  

-- 
Nic Ferrier
http://www.tapsellferrier.co.uk   

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: Is django a good solution for non-CMS web-apps?

2007-06-29 Thread Nic James Ferrier

walterbyrd <[EMAIL PROTECTED]> writes:

> I have been reading that django is good for CMS type sites, but not
> especially good for other types of web applications. For example:
> financial applications. I have read that TurboGears is better for
> those other apps.

That seems like nonsense.

I am building 3 apps on django. None of them is a CMS.

I hate frameworks. But as frameworks go, django is a good one.

-- 
Nic Ferrier
http://www.tapsellferrier.co.uk   

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: lighttpd & fcgi

2007-06-24 Thread Nic James Ferrier

Nic James Ferrier <[EMAIL PROTECTED]> writes:

> "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> writes:
>
>> Yah, weird.
>>
>> Is there any advantage of using a socket or tcp?
>
> A unix socket might be _marginally_ faster.
>
> But TCP avoids ownership issues of sockets which are a pain in the
> butt.

I just found out that this:

   check-local => "disabled"

needs to be in the lighttpd conf even if you're using TCP.

eg:

   fastcgi.server = (
 "/somut.fcgi" => (
   "main" => (
 "host" => "127.0.0.1",
 "port" => ,
 "check-local" => "disable"
   )
 )   
)

-- 
Nic Ferrier
http://www.tapsellferrier.co.uk   

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: lighttpd & fcgi

2007-06-24 Thread Nic James Ferrier

"[EMAIL PROTECTED]" <[EMAIL PROTECTED]> writes:

> Yah, weird.
>
> Is there any advantage of using a socket or tcp?

A unix socket might be _marginally_ faster.

But TCP avoids ownership issues of sockets which are a pain in the
butt.


-- 
Nic Ferrier
http://www.tapsellferrier.co.uk   

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: lighttpd & fcgi

2007-06-24 Thread Nic James Ferrier

"[EMAIL PROTECTED]" <[EMAIL PROTECTED]> writes:

> I've been reading this to get lightTPD and fastcgi configured on my
> machine:
> http://www.djangoproject.com/documentation/fastcgi/
>
> There, it says to add this to your lighttpd.conf:
> 
> server.document-root = "/home/user/public_html"
> fastcgi.server = (
> "/mysite.fcgi" => (
> "main" => (
> # Use host / port instead of socket for TCP fastcgi
> # "host" => "127.0.0.1",
> # "port" => 3033,
> "socket" => "/home/user/mysite.sock",
> "check-local" => "disable",
> )
> ),
> )
> 
>
> I have run this call to start fastcgi
> python manage.py runfcgi method=threaded protocol=fastcgi
> host=127.0.0.1 port=3033
>
> Here is my question:
> The mysite.fcgi file doesn't matter, right? It doesn't have to exist
> as lightTPD knows about the fastcgi through the host and port
> settings, right?

I just found that it does.

lighttpd does a stat on that file before serving the request and if
it's not there lighttpd just returns 404. Put the file there and it'll
send the request.


NOTE: this ONLY happens when you're doing tcp based fcgi. When you're
doing unix socket stuff it just works and the dummy file doesn't need
to be present.

Wierd, eh?


-- 
Nic Ferrier
http://www.tapsellferrier.co.uk   

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: The going rate for Django-based web developers ...

2007-06-18 Thread Nic James Ferrier

ZebZiggle <[EMAIL PROTECTED]> writes:

> Strong python, javascript, CSS, postgres, jquery (or alike), debugging
> and lots of general experience in software development. And when I say
> CSS, I don't mean graphic design skills, but knowing how to take a
> graphic design and translate it into CSS. Someone that can take a
> concept and turn it into reality.

It's that CSS bit that I find difficult to find.

I have a good grasp of CSS... but I still can't do that very well
(takes me ages). The people who can are worth a good amount of money
(+$50 an hour).

-- 
Nic Ferrier
http://www.tapsellferrier.co.uk   

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



a diff for the fastcgi server to make umask settable

2007-06-07 Thread Nic James Ferrier

flup provides the umask init field so that you can change the mask of
a unix socket you're using to talk fast cgi.

Django doesn't seem to pass this through so I wrote this trival patch.

Someone might be interested.

Apologies if this is not the right place.


-- 
Nic Ferrier
http://www.tapsellferrier.co.uk   


--- /usr/share/python-support/python-django/django/core/servers/fastcgi.py~
+++ /usr/share/python-support/python-django/django/core/servers/fastcgi.py
@@ -39,6 +39,7 @@
   daemonize=BOOL   whether to detach from terminal.
   pidfile=FILE write the spawned process-id to this file.
   workdir=DIRECTORYchange to this directory when daemonizing
+  umask=NUMBER set the umask used to create the socket
 
 Examples:
   Run a "standard" fastcgi process on a file-descriptor
@@ -69,8 +70,13 @@
 'minspare': 2,
 'maxchildren': 50,
 'maxrequests': 0,
+'umask': None,
 }
 
+# 'mode' added by nic on Thu Jun 7 13:25:07 BST 2007;
+# to communicate a mode for a unix socket to the flup fcgi backend
+
+
 def fastcgi_help(message=None):
 print FASTCGI_HELP
 if message:
@@ -127,6 +133,11 @@
 wsgi_opts['bindAddress'] = (options["host"], int(options["port"]))
 elif options["socket"] and not options["host"] and not options["port"]:
 wsgi_opts['bindAddress'] = options["socket"]
+if "umask" in options:
+try:
+wsgi_opts["umask"] = int(options["umask"])
+except ValueError:
+return fastcgi_help("If specified, umask should be an 
integer.")
 elif not options["socket"] and not options["host"] and not options["port"]:
 wsgi_opts['bindAddress'] = None
 else:



--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: Looking for Django Developers As Founders

2007-05-31 Thread Nic James Ferrier

Tim Chase <[EMAIL PROTECTED]> writes:

>>> Sorry, my email is
>>
>> Ermmm It tells us that in the mail header.
>
> But it doesn't tell us where this is geographically in the 
> header, the body, or in the follow-up email :)

It's in cyberspace, man.


-- 
Nic Ferrier
http://www.tapsellferrier.co.uk   

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: Looking for Django Developers As Founders

2007-05-31 Thread Nic James Ferrier

Michael Lim <[EMAIL PROTECTED]> writes:

> Not in Google Groups. The email is masked off as shown in the reply
> thread shown below :-)

Bizarre!


-- 
Nic Ferrier
http://www.tapsellferrier.co.uk   

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: Looking for Django Developers As Founders

2007-05-31 Thread Nic James Ferrier

Michael Lim <[EMAIL PROTECTED]> writes:

> Hi all,
>
> Sorry, my email is
>
> lim  ck  michael  gmail  com

Ermmm It tells us that in the mail header.


-- 
Nic Ferrier
http://www.tapsellferrier.co.uk   

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: Very large scale sites in Django

2007-05-31 Thread Nic James Ferrier

Daniel Ellison <[EMAIL PROTECTED]> writes:

> On Thursday 31 May 2007 11:26:37 Nic James Ferrier wrote:
>> Daniel Ellison <[EMAIL PROTECTED]> writes:
>> > Sounds like this might end up being the highest-traffic Django site there
>> > is! :)
>>
>> Errr... I might be in competition with you there.
>>
>> /8->
>
> Fine. Sounds like this might end up being the second highest-traffic Django 
> site there is! :)
>
> What site do you run that gets > 400 hits per second, sustained? You could 
> definitely provide some sage advice!

I might be in competition with you to end up being the highest-traffic
django site there is.

As to scaling advice... I've gone for the
REST/quite-a-few-machines/partitioned-resource-space approach. This
should mean that the machines we use are smaller than than normal
(maybe even VMs) and so we can have more of them.

We have yet to do scaling tests though. So I could still end up with
egg on my face (mmm! egg!)

-- 
Nic Ferrier
http://www.tapsellferrier.co.uk   

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: Very large scale sites in Django

2007-05-31 Thread Nic James Ferrier

Daniel Ellison <[EMAIL PROTECTED]> writes:

> Sounds like this might end up being the highest-traffic Django site there 
> is! :)

Errr... I might be in competition with you there.

/8->

-- 
Nic Ferrier
http://www.tapsellferrier.co.uk   

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: Moving Images to Amazon S3

2007-05-31 Thread Nic James Ferrier

"=?ISO-8859-1?Q?Fr=E9d=E9ric_Sidler?=" <[EMAIL PROTECTED]>
writes:

> openfount provide something that does the trick
> http://www.openfount.com/blog/s3dfs-for-ec2
>
> and adrian holovaty did something like that some weeks ago for
> chicagocrime.org
> http://www.holovaty.com/blog/archive/2006/04/07/0927

Yes. Implementing S3 at this level actually is not terribly hard... it
works quite well.

And there are good Python bindings for FUSE.


-- 
Nic Ferrier
http://www.tapsellferrier.co.uk   

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: Moving Images to Amazon S3

2007-05-31 Thread Nic James Ferrier

Kyle Fox <[EMAIL PROTECTED]> writes:

> The S3 API requires the file data to be in the format the
> open(myfile).read() returns (whatever that is).
>
> Is there a way to get the same data from an in-memory Image instance,
> so I don't need to save/re-read/delete each thumbnail file?

Surely the better way to do this is to just use FUSE or something to
map S3 into the filesystem?


-- 
Nic Ferrier
http://www.tapsellferrier.co.uk   

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Django users in London want to meet up for beers?

2007-05-15 Thread Nic James Ferrier

To talk django and python?

Anyone?

-- 
Nic Ferrier
http://www.tapsellferrier.co.uk   

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: adding XSLT templating to Django

2007-05-12 Thread Nic James Ferrier

Eugene Morozov <[EMAIL PROTECTED]> writes:

>> - there is proper separation between data and style, my JSON doesn't
>>   include any stylistic information, only stuff that describes the data
>
> I still think that your example is not the best. "div" and "span" has
> no semantic meaning, they're just HTML placeholders.

Well, ok. The reason for them is that you need them for structure. It
doesn't make sense to use another tag for some arbitary POSH.


>> - you get to use XSLT to turn the JSON into anything you want... you
>>   need Atom from a resource as well as HTML? Just have 2 different
>>   stylesheets but the same JSON.
>
> I think it is possible with plain Django templates, too. Just define 2
> different templates.

But then you're doing the python logic bits (for example, serializing
a seqence) more than once. With mine you only do the programming-y
bits once and then use XSLT to transform to whatever. The templates
are very simple then. I've used this approach in a couple of
frameworks.

> Your small framework could be really useful in some situations, I was
> just thinking about how to apply my XSLT knowledge to ease web
> development tasks. But I think that need better examples really
> showing benefits of XSLT approach. I was turned off by those HTML
> elements in JSON data immediately. Maybe this is just my personal
> opinion.

Maybe... I'm not sure what upsets you about them really.

The exact language you use is up to you... you can put whatever you
like in and it'll get turned into XML.

For example, this would output something like ATOM:

  tfxslt.send_json(HttpResponse(),
  {"feed":
[{"author":
  {"email": "[EMAIL PROTECTED]"}},
 {"published": "Sat May 12 22:57:26 BST 2007" },
 [{"item":
   {"summary": "a bit about this item"}}]]},
  "atom")

And of course... if you've got anything that can serialize any other
data structure to JSON then you can use that as well.

I'm really busy actually using my stuff at the mo... I'm hoping to try
and post it over this weekend on snippets.

-- 
Nic Ferrier
http://www.tapsellferrier.co.uk   

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: adding XSLT templating to Django

2007-05-12 Thread Nic James Ferrier

Eugene Morozov <[EMAIL PROTECTED]> writes:

> On 11 май, 13:23, Nic James Ferrier <[EMAIL PROTECTED]>
> wrote:
>> def user_alerts(request, user_name):
>> me = get_object_or_404(User, username=user_name)
>> alerts = Alert.objects.filter(user=me, seen=False)
>> return tfxslt.send_json(HttpResponse(),
>> { "div":
>>   [ { "abbr":
>>   { "@title": alert.created,
>> "span": alert.message }} for alert in 
>> alerts]},
>> xslt="user_alerts")
>>
>
> Sorry, I don't get the point. I think that XSLT is a way to separate
> presentation from data. But your json looks like some kind of HTML. I
> don't understand how this is better than existing Django templates.

It has several advantages:

- there is proper separation between data and style, my JSON doesn't
  include any stylistic information, only stuff that describes the data

- the JSON template *is* python, you can pretty much do anything with
  it: you can separate bits of the rendering with different methods,
  you can test it outside of Django, you can pass it around and
  process it with Python quite naturally.

- you get JSON output if you want it, direct from your view

- you get to use XSLT to turn the JSON into anything you want... you
  need Atom from a resource as well as HTML? Just have 2 different
  stylesheets but the same JSON.


The way I tend to use the templates is to output POSH (Plain Old
Semantic HTML) like JSON which will be transformed by XSLT into
display HTML/XHTML but you don't have to do it that way... the JSON
could be any old thing. 

I find it simpler to use POSH because I can mock up the POSH outside
of a programming language. I can even get designers to template the
POSH which they will then transform with XSLT.



> I know and use XSLT but usually for converting between different XML
> formats.

XSLT works very well as a dynamic transformation language. It is very
fast indeed and you can do so much with it. I don't understand why
anyone would want to use these hobbled little template languages
inside things like Django and Rails.

-- 
Nic Ferrier
http://www.tapsellferrier.co.uk   

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: First impression of django

2007-05-11 Thread Nic James Ferrier

"James Bennett" <[EMAIL PROTECTED]> writes:

> On 5/11/07, Nic James Ferrier <[EMAIL PROTECTED]> wrote:
>> Something needs to be done though... or ongoing maintenance of Django
>> apps is going to be really hard.
>
> I haven't found it terribly hard with a little coding discipline; the
> way we've handled it is to write the necessary SQL and commit it to
> our repository along with model changes, so we have a history of how
> the model has evolved over time. Some way of specifying "revision
> numbers" of models and having Django find the necessary SQL files to
> execute (where those files were manually constructed) is really all
> the automation I'd like to see :)

That works. Good plan. But it's getting away from the ORM principle
isn't it?

I don't mind that personally... I think that ORMs are over-rated
(hence my "I hate frameworks") but they sure do help with things like
form validation and such (because the necessary authoritative meta
data is in python rather than SQL).


-- 
Nic Ferrier
http://www.tapsellferrier.co.uk   

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



adding XSLT templating to Django

2007-05-11 Thread Nic James Ferrier

I've been using Django for a few weeks now and I have to say, despite
my general hatred of frameworks, I'm quite impressed with it. It is
very fast to get up and going, the ORM works pretty well. New forms
are really, really good.

I don't like learning new template languages though... so I plugged in
XSLT (which I know really well) and I thought people might be
interested in how I did that. So I thought I'd tell you here.

I've got a little but of python that renders JSON type structures to
simple XML. So what I do is have a function that I pass an
HttpResponse and some JSON and an XSLT filename and it:

- turns the JSON into XML
- loads the stylesheet from the XSLT filename
- pushes the XML through the XSLT
- collects the transformation and sends it to the HttpResponse

The description is all a bit academic. Here's an example from a real
app's views.py:

def user_ratings(request, user_name):
user = get_object_or_404(User, username=user_name)
return send_json(HttpResponse,
 { "abbr":
   { "@title": user_name,
 "div":
 { "@class": "ratings",
   "div":
   [ { "div": { "@class": "looks", "span": user.looks 
}},
 { "div": { "@class": "looks", "span": user.looks 
}} ]}}},
 xslt="user_ratings")

Here's another real example from the same app, with a generator:

def user_alerts(request, user_name):
me = get_object_or_404(User, username=user_name)
alerts = Alert.objects.filter(user=me, seen=False)
return tfxslt.send_json(HttpResponse(),
{ "div":
  [ { "abbr":
  { "@title": alert.created,
"span": alert.message }} for alert in 
alerts]},
xslt="user_alerts")

I think this works quite well;

- the programmatic template is actually python, albeit a specialized
  JSON syntax of python
- it's pretty clear what the template is going to result in, as XML
- it makes the XSLT pretty simple

I've used it on 3 very different projects now and it's been fine on
each one.


If there's any interest in this I'd consider trying to make my stuff
Django-fied enough to fit in sorta properly... maybe if you return a
special JSON/XSLT object to an HttpResponse or something.

If anyone wants the xslt/json module I'll post it somewhere. 


On another note is anyone interested in a London meet up? I'd love to
have a beer with a few other Django developers and chew the cud.

-- 
Nic Ferrier
http://www.tapsellferrier.co.uk   

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: How well should I know Python before using Django?

2007-05-09 Thread Nic James Ferrier

"Greg Donald" <[EMAIL PROTECTED]> writes:

>> 1) beginner
>> 2) intermediate
>> 3) expert
>
> 0) None
>
> But what about experience in other programming languages?  If you
> currently know zero programming languages, learning any new
> programming language or framework will require some significant
> effort.  IMO Python is an excellent first language.

I'd go along with that... actually when you're writing a Django app
you don't need to know much of anything except Django. It's pretty
declarative.


-- 
Nic Ferrier
http://www.tapsellferrier.co.uk   

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---