Re: interaction of django with paypal

2009-08-30 Thread Andy Shaw

orschiro wrote:
> Well and that is also the problem with my solution. Everyone who knows
> the URL can download the data without to pay before.
>
> What I'm now looking for is a possibility to inquire whether the
> customer has paid before he was visiting the download page.
Whilst you could check to make sure that the HTTP referrer is PayPal, 
this can easily be forged. What you probably want to do is use PayPal's 
IPN system[1], which will trigger a page on your site behind-the-scenes 
when someone has completed a transaction with you. I'd use that to 
trigger a key-based download system (i.e., the IPN callback generates a 
download key valid for 24 hours and emails it to the customer, and the 
download page requires a valid key). However, this means that the 
customer wouldn't get an instant download link.

[1]: https://www.paypal.com/ipn

-Andy

--~--~-~--~~~---~--~~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Concurrent applications

2005-08-17 Thread Andy Shaw

Is there any easy way to have two or more applications run
simultaneously? Having created one fully-working application, which
provides content for part of my site, I now want to construct another
which will provide site-global menus and other such features. However,
I see no easy way of working this into the rendering of the template
that the first app does.

The only possibility that I can see is this:
* Find a way to prevent django's template system from silently dropping
empty tags, and leave them in place instead
* Add a middleware layer that has a process_response hook, get it do
import and run the menu application, and use the template system to
replace the tags in the output of the previous step

This seems perhaps overcomplicated. Is there an easier way to go about
it; and if not, can anyone give me any pointers?

-Andy



Re: Concurrent applications

2005-08-18 Thread Andy Shaw


Matthew Marshall wrote:
For dynamic data that you need on every page, I would make a custom template 
tag.  Check this out for how to do it:

http://code.djangoproject.com/file/djangoproject.com/django_website/apps/blog/templatetags/latestblogentry.py

MWM


As it happens, I've just finished doing exactly that, using the 
django.templatetags.* modules for pointers. I'll write a page for the 
wiki this evening on the subject, 'cos I can't see it being a 
particularly unusual requirement, and documentation is good :)


-Andy


Re: CSS and PNG files in templates

2005-08-22 Thread Andy Shaw


Krzysztof Drozd wrote:

hi

i hawe make a template 'base.html' and i use it in my apps. but
'base.html' use
CSS and PNG files.

my app template use 'base.html' but can't find my CSS and PNG files.
what can i do? what in settings/template shuld i wrote?

a example...

kd.





You either need to serve the CSS file in a way that isn't being handled 
by django, or create a django application to serve CSS. Note that the 
same applies to image files, or any other media - the chances are they 
are static and should thus be served statically, but they could be 
generated (or merely output by) a django application.


On my server, which runs Apache, static media is served by using the 
following configuration directive:



SetHandler None


This means that anything in /static is served directly by apache and 
doesn't touch Django.


However, as my site is fairly fluid and different applications require 
different combinations of CSS (and I love the ability to edit CSS online 
as well as the actual pages of my site) I created a relatively simple 
single-model application, the details of which are below. Simply, it 
searches through the database for files to serve from the /css/ 
'directory' on the server, so my base template includes the CSS using 
the following line:






The important details of the CSS application are below. Note the 
somewhat hacky way the regex objects are compiled when the models module 
is imported and the models are generated. This is necessary because code 
in lambda functions isn't evaluated until the function is called and it 
is run, meaning that re objects are no longer in the code's scope. I'm 
still not happy with this, as it means that the useragents I can check 
for and the regexes that I use are statically emplaced into the code, 
but it will do until I find a better solution.


project/settings/urls/main.py:

...
urlpatterns = patterns('',
...
(r'^css/', include('project.apps.css.urls.css')),
...
)


project/apps/css/urls/css.py:

from django.conf.urls.defaults import *

urlpatterns = patterns('jaded.apps.css.views.css',
(r'^(?P[^/]+)/$', 'show_css'),
)


project/apps/css/models/css.py:

from django.core import meta
import re

BROWSER_CHOICES = (
(0, 'Default'),
(1, 'Internet Explorer'),
(2, 'Mozilla/Netscape'),
(3, 'Opera'),
)

uare = {1: re.compile('^Mozilla/*.* \((?!compatible;).*$').match,
2: re.compile('^.*Opera.*$').match,
3: re.compile('^Mozilla/.\.. \(compatible; MSIE .\..; .*$').match}

class Stylesheet(meta.Model):
fields = (
meta.IntegerField('browser', 'Browser class', 
choices=BROWSER_CHOICES),

meta.SlugField('slug', 'CSS Slug'),
meta.TextField('css', 'Cascading Stylesheet Instructions'),
)
unique_together = (
('slug', 'browser'),
)
admin = meta.Admin()

def get_bname(this):
if this.browser == 0:
return "Default"
if this.browser == 1:
return "Internet Explorer"
if this.browser == 2:
return "Mozilla/Netscape"
return "Opera"

def __repr__(this):
return this.slug + ": " + this.get_bname()

def _module_match_useragent_mozilla(query, matchobj=uare[1]):
return matchobj(query)

def _module_match_useragent_opera(query, matchobj=uare[2]):
return matchobj(query)

def _module_match_useragent_iexplore(query, matchobj=uare[3]):
return matchobj(query)


project/apps/css/views/css.py:

from django.utils.httpwrappers import HttpResponse
from django.models.css import stylesheets
from django.core.exceptions import Http404

def show_css(request, css_slug):
browsers = {0: 'Default', 1: 'Internet Explorer', 2: 
'Mozilla/Netscape', 3: 'Opera'}

user_agent = request.META['HTTP_USER_AGENT'].strip()
browser = 0
if stylesheets.match_useragent_mozilla(user_agent):
browser = 2
elif stylesheets.match_useragent_opera(user_agent):
browser = 3
elif stylesheets.match_useragent_iexplore(user_agent):
browser = 1
bName = browsers[browser]

stylesheet = None
try:
stylesheet = 
stylesheets.get_object(slug__exact=css_slug, browser__exact=browser)

except:
pass
if not stylesheet and browser:
try:
stylesheet = 
stylesheets.get_object(slug__exact=css_slug, browser__exact=0)

bName += " (using default)"
except:
pass
if not stylesheet:
raise Http404

css = "/* Stylesheet generated for %s\n Copyright (c) 2005 
Andrew Shaw. */\n\n\n" % bName

css += style

Re: CSS and PNG files in templates

2005-08-23 Thread Andy Shaw


Sam Newman wrote:


Or more simply put, the Django web server doesn't serve your media
(e.g. images, PNG, CSS) and there isn't a plan to (the related ticket
is marked as WONTFIX). Which majorly blows IMHO.


Yeah, that's slightly more to-the-point!

It does seem somewhat contradictory to refuse to let the built-in server 
serve static media in general whilst hacking it so that it does output 
the admin media. Presumably this is so that the admin CSS/Javascript is 
available, and so the admin works properly - but what happens when the 
same features are used in application views? The test server is no 
longer particularly useful to test applications with.


-Andy


Re: CSS and PNG files in templates

2005-08-23 Thread Andy Shaw


Jacob Kaplan-Moss wrote:
The point is that serving media from Django is a Bad Idea(tm), and  one 
of the philosophies behind Django is that we want to make it  easier to 
do the right thing than to do the wrong thing.  I'm not  going to go 
into why serving media from an application server is bad  unless someone 
really wants to discuss it; just trust me when I say  that in the long 
run you'll be much happier if you take the 30  seconds to set up a 
static directory or subdomain to serve media from.


That's exactly what I've done, and I understand why this is the sensible 
thing to do. But it would be useful to be able to run the development 
(built-in) server completely separately from the production server, yet 
still see all the relevant media (what the production page would look like).



That said...

It should be very easy to write a "static directory" view; something  
like the following should get you started::


I didn't actually think much about doing this. If you install that code 
as part of an application for the development server, won't it insert 
cruft into the database (specifically, a spurious entry in 'packages')?


Again, this is a BAD IDEA (and looking at the code should start to  tell 
you why), but if you don't care about doing it right the above  view 
should get you started.


Yeah, security flaws agogo. Mind you, I run the dev server on a port 
that's firewalled to local access only.


Anyway, I see your point, I'm just not sure that it applies in the 
development environment.


-Andy


Re: CSS and PNG files in templates

2005-08-23 Thread Andy Shaw


Bryan L. Fordham wrote:

Sure it's useful.  It's not unusual at all to have static content served
from a server that's designed for that (ie apache) even when you're running
a very expensive app server such as weblogic.



Okay, I was exaggerating somewhat. But as I see it, there are three 
basic choices for serving media:


* Configure your webserver so the media is served from a different 
subdomain, hardcode the domain name into your templates.


* Configure your webserver to run django apps on a different port, again 
hardcoding the domain name into the templates.


* Create a no-handler location on your webserver, so media doesn't go 
through the app server.


The first two of these involve including the domain name whenever media 
is to be inserted onto a page; something that I'm against (mostly 
because it seems redundant, and if the DN ever changes, finding all the 
instances would be annoying). The latter works fine, but the django 
development server has no access to the apache config, nor the media thus.


This has yet to prove to be a big problem for me; and as Jacob pointed 
out, writing code to display static files can be a nefarious task. So 
I'll probably just have to live with it.


-Andy


Model subclass accessing parent instances?

2005-10-04 Thread Andy Shaw


Hi all;

I'm experimenting with subclassing models at the moment. Specifically, 
I'm trying to add an optional element to the user class. The following 
code works fine:


from django.core import meta
from django.models.auth import User

class MyUser(User):
about = meta.TextField(blank=True, default='')
class META:
module_name = 'm_users'

...however, there are already some users in the auth.users table in the 
database. My question is: is there any easy way to get the new class to 
retrieve data from the old table, using the default string to populate 
the /about/ field?


I'm guessing that I could replace the module's get_object() somehow, but 
I don't really want to if I don't have to.


TIA,

-Andy


Re: site url

2005-10-20 Thread Andy Shaw


Kenneth Gonsalves wrote:

hi,
i know it must be somewhere, but cant find it. How do you refer to the 
site url in a template? Say my css file is in 
http://mysite.com/css/layout.css, to make this portable i would have to 
make the template as:


{{ site_url }}/css/layout.css. 
how do i do this?


Um... I don't know the actual answer to your question off the bat, but 
you can use an absolute URI that doesn't contain the site name:




Works for me...

-Andy


debug tag

2005-11-28 Thread Andy Shaw


Can anyone give me any pointers on where to look for the {% debug %} 
template tag implementation? For some reason, it's neither working 
within my template (it's actually causing an unrecognised tag error) and 
it doesn't show up in the admin tag docs, either.


(nb: I'm using the current development version.)

Thanks,

-Andy


Re: Managing static media urls

2006-01-14 Thread Andy Shaw

Amit Upadhyay wrote:
>  Static files are best served by basic http servers and not django.
> Django tries to support serving static files, but that is only for
> convenience in development. Just now I finished deploying a django
> project under mod_pythong/apache, and my approach was to setup a /static
> url pointing to a directory containing static files and I setup django's
> static file serving view for that, I did that till the development
> lasted, and then I moved it to apache, and put a:
> 
> 
>  SetHandler None
> 
> 

This is the exact approach that I use, but it doesn't avoid the issue
that Greg is talking about. That is; a series of static-file URLs are
likely to be associated with any given application, and the path to them
isn't necessarily going to be the same for each installation of that
application (because, amongst other reasons, there are many different
ways they could be deployed - as you've just shown).

Personally, I'm happy using root-relative URLs for the moment. The
resulting directory structure isn't overly complicated, so could be
easily replicated. However, I can think of a couple of approaches to
ease the problem:

1) Make it a standards that your apps will have all their media in
/static/appname/. This isn't hard to do, and produces an easily portable
directory tree. Root-relative (or absolute) again, though.

2) Create all your templates so that static media urls look like
"{{base_url}}/image.png". Define a constant at the top of the file
defining your views, and store the appropriate base URL in it. Pass this
constant into your template renderer. This means that where you are
storing your static files is only hardcoded once, and can easily be changed.

In fact, I think I've seen a couple of people write function decorators
and other nifty tricks specifically to do things like render templates
with additional variables... just a thought.

The problem with both of these approaches is that if you're
using an app (or several) that you haven't written yourself, they won't
necessarily follow this standard, and could conflict.

-Andy


Extending admin privileges

2006-01-23 Thread Andy Shaw

Hi all,

Quick query: is there an easy way to limit staff users so that they can
only alter records that belong to them? Specifically, so that only their
own records show up in the admin interface. All the relevant models have
an owner field that points to the correct user (via an intermediary
model in one case), and I've written some decidedly hacky views/model
validators that stop users altering other records, but they don't see
the error until they try to save their changes.

TIA,

-Andy


Re: How to find out id of the first record?

2006-03-08 Thread Andy Shaw

PythonistL wrote:
> Hi,
> is there a way how to find out id of the first record in a table?
> I will explain what I mean.
> When I insert the first record into a table the id is 1.
> when I insert next record, the id for this record will be 2.
> But if I delete the first record, the id of the first record will be 2
> .So, I need to find out the id of the first record.
> Is it possible?
> Thank you for help
> L.

As the ID field is auto-incremented, the earliest ('first') record will
be the one with the lowest ID. In python, you can determine this by
pulling all records from the database and finding the one with the
lowest ID, or you can write a custom SQL query to do the same thing. I
don't know if Django currently has a built-in feature to let you do
this, though it is possible that the database will return the records in
creation order anyway (someone correct me here).

-Andy

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



Re: How to find out id of the first record?

2006-03-08 Thread Andy Shaw

Andy Shaw wrote:
> lowest ID, or you can write a custom SQL query to do the same thing. I
> don't know if Django currently has a built-in feature to let you do
> this, though it is possible that the database will return the records in

Julio Nobrega wrote:
> first_record = models.get_list(order_by = ['id'], limit = 1)[0]
>
>   Maybe even .get_object() if it works with limit 1.

Laurent RAHUEL wrote:
> reqObs = something.get_list(order_by=('id',), limit=1)
> if reqObs:
>   firstOb = reqObs[0]

*slaps forehead* Naturally. Sorry, guys.

-Andy



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



Re: Subdomain/Accounts

2010-12-29 Thread Andy Shaw
Tim's solution would obviously work, but it sounds to me like you would 
need to manually configure a subdomain (including a copy of settings.py) 
for each user. Widoyo's solution (or rather, Ross Poulton's linked 
solution) would also work but requires quite a lot of boilerplate code 
in your views to retrieve the current username.


I don't know what web server you intend to use, but could you not handle 
the problem at this level by using URL rewriting? It shouldn't be hard 
to write a rule[1] to map http://myuser.mydomain.com/* to 
http://www.mydomain.com/user/myuser/*. Once you've done this, you can 
use standard a Django URLConf and not worry about what the actual domain 
name is :)


HTH,
-Andy

[1]: There's an example of what is essentially this rule for Apache 
here: 
http://muffinresearch.co.uk/archives/2006/08/20/redirecting-subdomains-to-directories-in-apache/




Tim Sawyer 
29 December 2010 17:58


I did this with one settings.py per subdomain, using the sites 
framework.  So each settings.py had a different SITE_ID.


Here's how to limit admin to a given user's records:

http://drumcoder.co.uk/blog/2010/oct/02/user-specific-data-admin/

This helps with droplists in admin:

http://drumcoder.co.uk/blog/2010/oct/02/limiting-records-django-admin/

The above posts also show how to use a manager to limit the records, 
so you can do


Blog.objects.all() to get all records across all sites, and
Blog.on_site.all() to get the records only for the current site.

Hope that helps,

Tim.





Parra 
23 December 2010 04:29


Hello,

I'm new to Django and thinking of using it for a project.

In this project, there will be accounts and each account will have a
subdomain.
Based on the subdomain/account, the user will just see the records
that belongs to them.
The tables will be unique for all accounts, so there should be a field
to identify the account/records

I think this is maybe a common task and that there is a "right" way to
do this...

Can someone give me some tips on where to get started with this ??

Thanks,

Marcello




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

<>