Interesting code abstraction Challenge

2009-10-22 Thread Jason Beaudoin

Why hello there,

I have been thinking over this system design for quite a while now,
and I'm still a bit unsure of the sensible way to properly (and
sufficiently) abstract the system - the django-way, so to speak. I am
very interested in what other folks have to say - maybe I have been
thinking about this too much, maybe I haven't crossed paths with the
techniques you would use, but I imagine that while a little
challenging, this is still a common situation.

Please share your crazy, genius ideas, reading tips, code snippets, etc  : )


Here is the general setup:

Client Servers <---> The Application in Question <---> Partner Applications

The main role of the webapp is to serve as a proxy application to many
other partner web applications - we receive requests from client
servers, work out the processing with one or more of our partner
applications, and return the results to the client server. All data
communication is done via predefined APIs, and each API is different..
we define the API our client servers use to send/receive requests to
us, we follow the APIs as defined by our partners to communicate with
their applications. In this way, our client servers are connected to
many similar applications through our one webapp.


Several baseline "rules", if you will:

 - The application receives specially formatted requests for
processing (via POSTs).
 - As stated, all requests are formatted as defined by our, or our
partner, APIs.
 - All incoming requests will need to be re-formatted before passing
on, as each API is different.
 - Some communication is handled via passing XML around, others aren't.
 - A few situations require additional user interaction


The Challenge, or Where I'm caught up:

The end points are easy, as the APIs need to be followed.
Re-formatting a request from our API to a partner's - and vice versa -
isn't really a problem either.. (if I wanted to do this the crappy
way, this could be written out for each conversion, but there are 10 -
20 conversions). The challenge I am trying to figure out is how to
abstract the re-formatting process to eliminate code duplication, as
our API and each partner API will be similar (in an abstract way).

What's difficult is that each API is different enough that it isn't a
straight up a --> b field name translation, the conversion mechanism
has to be pretty dynamic. To put specifics on it, differing field
names are one thing, but the APIs differ in the information they
require (field types, so to speak) - for example: additional fields
for some APIs, or a field in one API may be a combination of others in
another API, etc.


What I have in mind so far:

 - For each partner, define the list of fields required
 - Define translations for each field, with 3 parts: our field name
(or data source), the partner's field name, and a translation function
(with the appropriate conversion algorithm if necessary).
 - When a partner has a field that doesn't have an equivalent in our
system, define a function for generating the field's value.
 - Once we've converted the information, format the data as either XML
or ready for a URLencode to POST


Questions:

Am I on the right track here?
Should I be thinking about this differently?
How do I tie these translations into a generic process, with generic
code, leaving the specifics to these translation functions?
How the hell would you set this up? Even if I'm on the right path
here, I'm having difficulty envisioning the python code behind all of
this..


All ideas, feedback, input, comments, etc welcome!!


Regards,

~Jason

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



how to cut and paste image into django app

2009-10-22 Thread Margie Roginski

I have a django app that uses Eric Florenzano's threadedcomments app
to allow my users to comment on issues.  My users are asking for the
ability to cut and paste images into their comments.  They want to use
an windows app called mwsnap to basically snap images from their
desktop, then ctrl-v to copy the image into my django app.  Does
anyone know what sort of client side support is needed to do this?  I
am fairly adept at jquery/javascript, but haven't seen anything like
this though it does seem like a very reasonable request since they are
certainly able to cut and paste into Outlook this way.  However, when
I try to cut and paste this way into yahoo mail or gmail it doesn't
work, so perhaps this is a hard thing to do in a web app.  Any
pointers/suggesions would be much appreciated.

Thanks,

Margie

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



Re: Limit choices based on a foreign key

2009-10-22 Thread Tim Valenta

I would very much be interested in a solution to this problem.  I
can't yet understand why Django is so wonderful at so many things, yet
has absolutely no mechanism for this.  Every time there seems to be
hope of a working solution, it never works for inlines.

For the sake of painting up another example of what I understand to be
the same problem, I've got these models:

# models.py
class Company(models.Model):
# ...
class Contract(models.Model):
company = models.ForeignKey(Company)
locations = models.ManyToManyField('Location')
class Location(models.Model):
company = models.ForeignKey(Company)

# admin.py
class LocationInline(admin.TabularInline):
model = Location
class ContractInline(admin.TabularInline):
model = Contract
class CompanyAdmin(admin.ModelAdmin):
inlines = (ContractInline, LocationInline)


This creates a problem when setting up the Admin for Company, because
it has inlines for both Contract and Location, and Contract's m2m
options for Location are not properly filtered according to the
Company that you're currently editing.

Is there anyone out there who knows of something straightforward to
satisfy this badly needed shortcut? Every "solution" I find doesn't
really deal with the Admin site, and it involves sketchy views that
try to use middleware to catch the object pk out of the URL.  totally
not ideal.

Back when I made PHP admins for this sort of thing, this was
considered basic functionality! In fact, it was always automatic, and
had to be disabled if you really didn't want it!

I've seen stranded unanswered posts on this subject for 3 years!  We
need a solution!  I just can't figure out anything that doesn't
require digging into the guts of the code and adding a new shortcut
API method on admin.ModelAdmin / TabularInline to help achieve this
goal.

Tim

On Oct 12, 9:36 am, Christian Wittwer  wrote:
> Ok, I found a way, but it's still not perfect.
>
> class GoalForm(forms.ModelForm):
>
>     class Meta:
>         model = Goal
>
>     def __init__(self, *args, **kwargs):
>         super(GoalForm, self).__init__(*args, **kwargs)
>         self.fields['goal_scorer'].queryset =
> Player.objects.filter(gameroster__game=self.instance.game)
>
> class GoalInline(admin.TabularInline):
>     model = Goal
>     extra = 4
>     #form= GoalForm
>
> class GameAdmin(admin.ModelAdmin):
>     list_display = ('date_time', 'home_team', 'opponent_team',
> 'is_home_game', 'season', 'league', 'type', 'result')
>     list_filter = ['league', 'season']
>     inlines = [GameRosterInline, GoalInline, PenaltyInline]
>     ordering       = ('date_time',)
>
> That works as long as I edit the model game not inline. The selection
> of player gets limited as I want.
> When I try to edit it inline in the game, the GoalForm seems not to
> work. It's going to be ignored.
> When I try to comment in "form= GoalForm", the whole app doesn't run
> anymore. I got a DoesNotExist exception, but I think this is because
> it can't register theform..
>
> Any ideas who to activate my customformfor the inline mode?
>
> Chris
>
> 2009/10/12 Christian Wittwer :
>
>
>
> > Hi,
> > I have a question regarding the admin interface of django.
>
> > My models
>
> > class Team(models.Model):
> >    name = models.CharField(max_length=10)
>
> > class Player(models.Model):
> >    lastname = models.CharField(max_length=60)
>
> > class Goal(models.Model):
> >    game = models.ForeignKey(Game)
> >    goal_scorer =
> > models.ForeignKey(Player,related_name='goal_scorer',blank=True,null=True)
>
> > class Game(models.Model):
> >    home_team = models.ForeignKey(Team,related_name='home_team')
>
> > class GameRoster(models.Model):
> >    player = models.ForeignKey(Player)
> >    game = models.ForeignKey(Game)
>
> > Each Goal is scored by a Player in a Game. I'm using a inlineformto
> > insert goals for a game.
> > The players are somehow connected to the team (gameroster), and
> > therefore to the game.
>
> > I found the place to hook in to limit the choices of player.
>
> > class GoalInline(admin.TabularInline):
> >    model = Goal
> >    extra = 4
>
> >    def formfield_for_foreignkey(self, db_field, request, **kwargs):
> >        if db_field.name == "goal_scorer":
> >            kwargs["queryset"] =
> > Player.objects.filter(gameroster__game=self.game)
> >            return db_field.formfield(**kwargs)
>
> >        return super(GoalInline,
> > self).formfield_for_foreignkey(db_field, request, **kwargs)
>
> > The missing point is now: How to access game, which is connected to
> > the goal to limit the players?
> > I tried self.game as you can see, but that doesn't work.
> > How can I access the model from within this function?
>
> > Chris
--~--~-~--~~~---~--~~
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 

Re: Debugging SQL Queries: Correlating with Python Code

2009-10-22 Thread Russell Keith-Magee

On Fri, Oct 23, 2009 at 11:03 AM, Brian Neal  wrote:
>
> Currently I am keeping an eye on SQL queries by displaying at the
> bottom of my base template sql_queries. I'm seeing some queries that
> look kind of strange to me, and I was wondering if there was a way to
> somehow correlate the queries with my app's Python code.
>
> For example, amongst the SQL queries on one of my pages, I see this
> curious pair:
>
> SELECT (1) AS `a` FROM `forums_topic` WHERE `forums_topic`.`id` = 10
> UPDATE `forums_topic` SET `forum_id` = 4, `name` = Split Test #1,
> `creation_date` = 2009-10-19 21:45:05, `user_id` = 2, `view_count` =
> 28, `sticky` = False, `locked` = False, `post_count` = 7,
> `update_date` = 2009-10-22 20:46:11, `last_post_id` = 34 WHERE
> `forums_topic`.`id` = 10
>
> I *think* these two queries are coming from this code:
>
> topic.view_count += 1
> topic.save()
>
> but I'm not sure. Is there a debugging technique or tool that could
> tell me what line in the user code the SQL came from?

There's nothing built into Django to help out here.

> I'm curious what the SELECT (1) is doing and where it came from. Is
> Django's ORM checking to see if the topic object exists before
> updating it?

Correct. Django does a select to determine if it needs to do an INSERT
or UPDATE when the save() is called. If you use force_insert or
force_update as an argument to save, you can override this behaviour.
Predictably, using these flags forces the use of INSERT or UPDATE in
save(), removing the need for the select but introducing the
possibility of error if the relevant object does (or doesn't) exist.

Yours,
Russ Magee %-)

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



If search string contains a number ... Do this ...

2009-10-22 Thread The Danny Bos

Hey guys,

In a view, is there a way to check if a search/querystring has a
number in it?

If number in string:
do this
otherwise:
do this instead ...



Any ideas?
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Debugging SQL Queries: Correlating with Python Code

2009-10-22 Thread Brian Neal

Currently I am keeping an eye on SQL queries by displaying at the
bottom of my base template sql_queries. I'm seeing some queries that
look kind of strange to me, and I was wondering if there was a way to
somehow correlate the queries with my app's Python code.

For example, amongst the SQL queries on one of my pages, I see this
curious pair:

SELECT (1) AS `a` FROM `forums_topic` WHERE `forums_topic`.`id` = 10
UPDATE `forums_topic` SET `forum_id` = 4, `name` = Split Test #1,
`creation_date` = 2009-10-19 21:45:05, `user_id` = 2, `view_count` =
28, `sticky` = False, `locked` = False, `post_count` = 7,
`update_date` = 2009-10-22 20:46:11, `last_post_id` = 34 WHERE
`forums_topic`.`id` = 10

I *think* these two queries are coming from this code:

topic.view_count += 1
topic.save()

but I'm not sure. Is there a debugging technique or tool that could
tell me what line in the user code the SQL came from?

I'm curious what the SELECT (1) is doing and where it came from. Is
Django's ORM checking to see if the topic object exists before
updating it?

Thanks,
BN

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



Re: displaying posted data

2009-10-22 Thread Dhruv Adhia
Allright, working :)

Thank you all!
Dhruv Adhia
http://thirdimension.com



On Thu, Oct 22, 2009 at 4:09 PM, Dhruv Adhia  wrote:

> Just ignore past messages. I got successful posting of data from unity to
> django localhost server. Now I am creating POST request from unity thats why
> I am doing request.POST if condition.
>
> I could see that through print statements inside this code
>
>  if request.POST:
>name = request.POST['name']
>print name
>score = request.POST['score']
>print score
>hash = request.POST['hash']
>print hash
>
> before there was no output. So now I am sure that I am getting values.
>
> Can anybody help in storing name and score into database?
>
> i have models setup as follows.
>
> from django.db import models
> # Create your models here.
>
> class Scores(models.Model):
> name = models.CharField(max_length=100)
> score = models.IntegerField()
>
> class Meta:
> verbose_name_plural ="Scores"
>
> Thanks a ton!
>
> Dhruv Adhia
> http://thirdimension.com
>
>
>
> On Thu, Oct 22, 2009 at 2:54 PM, Dhruv Adhia  wrote:
>
>> here is the version I thought should have worked, but its not quite there
>>
>> def add_score(request):
>>#response_dict ={}
>>secret_key = "asdf789as7df89asdf87ds89a8f7sfd8"
>> name =""
>> score=0
>> hash=""
>>
>> # getting the posted data
>>if request.GET:
>>name = request.POST['name']
>>print name
>>score = request.POST['score']
>>print score
>>hash = request.POST['hash']
>>print hash
>>#leaderboard = {'name': name, 'score': score, 'hash': hash}
>>
>>  #hashlib stuff for encryption
>>m = hashlib.md5()
>>m.update(name+str(score)+secret_key)
>>real_hash = m.hexdigest()
>>
>>   #storing it into database
>>if real_hash == hash:
>># store the name and score into the database
>>leaderboard = Scores(name = request.POST['name'] ,score =
>> request.POST['score'])
>>leaderboard.save
>>
>>leaderboard = Scores.objects.all()
>>return render_to_response('add_score.html', {'leaderboard':
>> leaderboard})
>>
>>
>> This version does not do what i wanted it do. which is 1) Read the posted
>> data 2) Store it into database
>>
>> Any help would be appreciated.
>>
>> Thanks
>>
>> Dhruv Adhia
>> http://thirdimension.com
>>
>>
>>
>> On Thu, Oct 22, 2009 at 1:05 PM, Dhruv Adhia  wrote:
>>
>>> Allright, I get that part.
>>>
>>> the url is coming from unity
>>>
>>> javascript part inside unity
>>>
>>> the part in bold is doing the post data.
>>>
>>> private var secretKey="mySecretKey";
>>> function postScore(name, score) {
>>> //This connects to a server side php script that will add the name
>>> and score to a MySQL DB.
>>> // Supply it with a string representing the players name and the
>>> players score.
>>> var hash=Md5.Md5Sum(name +""+ score + ""+ secretKey);
>>>
>>> *var highscore_url = addScoreUrl + "name=" + WWW.EscapeURL(name) +
>>> "=" + score + "=" + hash;
>>>
>>> // Post the URL to the site and create a download object to get the
>>> result.
>>> hs_post = WWW(highscore_url);*
>>> yield hs_post; // Wait until the download is done
>>> if(hs_post.error) {
>>> print("There was an error posting the high score: " +
>>> hs_post.error);
>>> }
>>> }
>>>
>>>
>>> >>
>>> $db = mysql_connect('mysql_host', 'mysql_user', 'mysql_password'
>>> ) or die ('Could not
>>> connect: ' . mysql_error());
>>> mysql_select_db('my_database') or 
>>> die
>>> ('Could not select database');
>>>
>>> // Strings must be escaped to prevent SQL injection attack.
>>> $name = mysql_real_escape_string($_GET['name'], $db);
>>> $score = mysql_real_escape_string($_GET['score'], $db);
>>> $hash = $_GET['hash'];
>>>
>>> $secretKey="mySecretKey"; # Change this value to match the value
>>> stored in the client javascript below
>>>
>>> $real_hash = md5($name . $score . $secretKey);
>>> if($real_hash == $hash) {
>>> // Send variables for the MySQL database class.
>>> $query = "insert into scores values (NULL, '$name',
>>> '$score');";
>>> $result = mysql_query($query) or 
>>> die
>>> ('Query failed: ' . mysql_error());
>>> }
>>>  ?>
>>>
>>> This is the php side of things that I found online. Basically I am trying
>>> to convert that to python code as you can see.
>>>
>>> I wrote the getting part of the data and the rest is what I am working on
>>> right now.
>>>
>>> It would be nice,
>>>
>>> if I could read values sent by unity(which is fine) and store them into
>>> database rather than just displaying.
>>>
>>> Thanks Karen.
>>>
>>> Dhruv Adhia
>>> http://thirdimension.com
>>>

Re: Redirects on HTTPS

2009-10-22 Thread Graham Dumpleton

The easier thing to do and which works for both HTTP and HTTPS is to
have have any front end web server such as nginx which is handling the
actual request set a special header when request came via HTTPS. In
Apache configuration you then use mod_setenvif to set HTTPS variable.

As an example, WebFaction has front end nginx web server which handles
HTTPS. They set a range of headers which include:

  X-Forwarded-Proto=https

On the Apache side, you then add directive:

  SetEnvIf X-Forwarded-Proto https HTTPS=1

The HTTPS variable is picked up as being special by mod_wsgi and it
will fixup wsgi.url_scheme in WSGI environment and Django then uses
it.

This way you don't need to fiddle anything in the Django stack.

For recent one click installs at WebFaction it will do both nginx and
Apache configuration automatically. If older one click install, you
will need to add the Apache configuration bit plus perhaps load
mod_setenvif.

Graham

On Oct 22, 11:57 pm, Tom Evans  wrote:
> On Thu, 2009-10-22 at 12:45 +0100, Tim Sawyer wrote:
> > Hi,
>
> > I have a django app that works fine using http.  We have a requirement to
> > serve the entire site using https, which is being done at the proxy level
> > - so the Apache that my django is running inside (mod_wsgi) doesn't know
> > about the https.
>
> > I have a problem with using HttpResponseRedirect - the redirect is
> > changing the URL to be http.  Everything else about the URL is right.
>
> > How do I fix this, and have the redirect go to https?
>
> > Thanks,
>
> > Tim.
>
> I use middleware to update the request to think it came in over https.
> This is an extremely cut down version of what we use, but if _every_
> request is SSL it should work fine (not all our requests are SSL, and
> not every view requires SSL, so ours is a lot more complex in deciding
> whether to monkey patch).
>
> class SSLMiddleware(object):
>
>   def process_request(self, request):
>       # request.is_secure() looks in os.environ to see whether request is SSL
>       # Unfortunately, once you look in os.environ, you can't change it...
>       # Therefore, we have to monkey patch that function, we know this is SSL
>       request.is_secure = lambda: True
>
> Cheers
>
> Tom
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Passing Parameter to form in inlineformset_factory

2009-10-22 Thread Andew Gee

Hi,


I have the following Form defined

class MyForm(ModelForm)

  def __init__(self, readOnly=False, *args, **kwargs):
  if readOnly:
 Do stuff to make the inputs readonly

MyForm works perfectly when I instantiate it in the view as a form
form = MyForm(readOnly=True, instance=ModelA)

but when I try to use it in the inlineformset_factory I get the error

NoneType object is not callable.

I know the problem id the way I am using the MyForm in the inline call
because I get the same error if I do either of the following

Formset = inlineformset_factory(ModelA, ModelB form=MyForm
(readOnly=True))
Formset = inlineformset_factory(ModelA, ModelB form=MyForm())

but it works if I do

Formset = inlineformset_factory(ModelA, ModelB form=MyForm)

obviously the readOnly param defaults to False and my inputs are not
changed.

Does anyone know how I can pass the readOnly param to MyForm using the
inlineformset_factory or how else I can achieve what I want?

Thanks
Andrew


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



Re: displaying posted data

2009-10-22 Thread Dhruv Adhia
Just ignore past messages. I got successful posting of data from unity to
django localhost server. Now I am creating POST request from unity thats why
I am doing request.POST if condition.

I could see that through print statements inside this code

 if request.POST:
   name = request.POST['name']
   print name
   score = request.POST['score']
   print score
   hash = request.POST['hash']
   print hash

before there was no output. So now I am sure that I am getting values.

Can anybody help in storing name and score into database?

i have models setup as follows.

from django.db import models
# Create your models here.

class Scores(models.Model):
name = models.CharField(max_length=100)
score = models.IntegerField()

class Meta:
verbose_name_plural ="Scores"

Thanks a ton!

Dhruv Adhia
http://thirdimension.com



On Thu, Oct 22, 2009 at 2:54 PM, Dhruv Adhia  wrote:

> here is the version I thought should have worked, but its not quite there
>
> def add_score(request):
>#response_dict ={}
>secret_key = "asdf789as7df89asdf87ds89a8f7sfd8"
> name =""
> score=0
> hash=""
>
> # getting the posted data
>if request.GET:
>name = request.POST['name']
>print name
>score = request.POST['score']
>print score
>hash = request.POST['hash']
>print hash
>#leaderboard = {'name': name, 'score': score, 'hash': hash}
>
>  #hashlib stuff for encryption
>m = hashlib.md5()
>m.update(name+str(score)+secret_key)
>real_hash = m.hexdigest()
>
>   #storing it into database
>if real_hash == hash:
># store the name and score into the database
>leaderboard = Scores(name = request.POST['name'] ,score =
> request.POST['score'])
>leaderboard.save
>
>leaderboard = Scores.objects.all()
>return render_to_response('add_score.html', {'leaderboard':
> leaderboard})
>
>
> This version does not do what i wanted it do. which is 1) Read the posted
> data 2) Store it into database
>
> Any help would be appreciated.
>
> Thanks
>
> Dhruv Adhia
> http://thirdimension.com
>
>
>
> On Thu, Oct 22, 2009 at 1:05 PM, Dhruv Adhia  wrote:
>
>> Allright, I get that part.
>>
>> the url is coming from unity
>>
>> javascript part inside unity
>>
>> the part in bold is doing the post data.
>>
>> private var secretKey="mySecretKey";
>> function postScore(name, score) {
>> //This connects to a server side php script that will add the name and
>> score to a MySQL DB.
>> // Supply it with a string representing the players name and the
>> players score.
>> var hash=Md5.Md5Sum(name +""+ score + ""+ secretKey);
>>
>> *var highscore_url = addScoreUrl + "name=" + WWW.EscapeURL(name) +
>> "=" + score + "=" + hash;
>>
>> // Post the URL to the site and create a download object to get the
>> result.
>> hs_post = WWW(highscore_url);*
>> yield hs_post; // Wait until the download is done
>> if(hs_post.error) {
>> print("There was an error posting the high score: " +
>> hs_post.error);
>> }
>> }
>>
>>
>> >
>> $db = mysql_connect('mysql_host', 'mysql_user', 'mysql_password')
>> or die ('Could not
>> connect: ' . mysql_error());
>> mysql_select_db('my_database') or 
>> die
>> ('Could not select database');
>>
>> // Strings must be escaped to prevent SQL injection attack.
>> $name = mysql_real_escape_string($_GET['name'], $db);
>> $score = mysql_real_escape_string($_GET['score'], $db);
>> $hash = $_GET['hash'];
>>
>> $secretKey="mySecretKey"; # Change this value to match the value
>> stored in the client javascript below
>>
>> $real_hash = md5($name . $score . $secretKey);
>> if($real_hash == $hash) {
>> // Send variables for the MySQL database class.
>> $query = "insert into scores values (NULL, '$name',
>> '$score');";
>> $result = mysql_query($query) or 
>> die
>> ('Query failed: ' . mysql_error());
>> }
>>  ?>
>>
>> This is the php side of things that I found online. Basically I am trying
>> to convert that to python code as you can see.
>>
>> I wrote the getting part of the data and the rest is what I am working on
>> right now.
>>
>> It would be nice,
>>
>> if I could read values sent by unity(which is fine) and store them into
>> database rather than just displaying.
>>
>> Thanks Karen.
>>
>> Dhruv Adhia
>> http://thirdimension.com
>>
>>
>>
>> On Thu, Oct 22, 2009 at 12:46 PM, Karen Tracey wrote:
>>
>>> On Thu, Oct 22, 2009 at 3:25 PM, Dhruv Adhia  wrote:
>>>
 Yep and sorry I am bit new to this stuff, I mistook 69 for 200. This
 explained it
 

Re: admin actions bar in django 1.1

2009-10-22 Thread kkerbel

fixed it...it was a template issue.

On Oct 22, 9:10 am, kkerbel  wrote:
> I think I found the problem...I have some files missing in my media
> folder...namely 'actions.js'...I'm assuming adding this back will fix
> my problem...if I could just figure out how to get my site to read the
> media directory to begin with.  ha.
>
> On Oct 21, 4:53 pm,kkerbel wrote:
>
>
>
> > it doesn't appear to be working for any apps.  everything else on the
> > admin page shows fine to my knowledge...just not the admin actions
> > bar.
>
> > On Oct 21, 4:47 pm,kkerbel wrote:
>
> > > within the templates folder for my app (events in this case)...I just
> > > have a folder named events containing templates for the pages...I do
> > > not have any admin template mods.
>
> > > On Oct 21, 12:47 pm, Peter Bengtsson  wrote:
>
> > > > What customizations have your done in the templates/admin/ folder of
> > > > the app that isn't working?
>
> > > > On 21 Oct, 17:22,kkerbel wrote:
>
> > > > > i upgraded django 1.0.2 to 1.1 stable and I cannot see the admin
> > > > > actions bar in one of my apps...or any of them for that matter.  My
> > > > > fresh install of 1.1 has the bar, however, I can't seem to find the
> > > > > discrepancy between the two installs.  Have any of you experienced
> > > > > this?  Thanks!
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: base.css not being included

2009-10-22 Thread kkerbel

Nevermind...i fixed it.  The previous programmer had copied the
templates into the project.

On Oct 22, 3:59 pm, kkerbel  wrote:
> Hello all...
>
> I upgraded from django 1.0 to 1.1.1 and when I copied the new admin
> media folder into my apache media root...the only css that loads when
> I visit the main admin page is dashboard.css which basically just
> gives me text.  It appears that base.css needs to be loaded as well
> since that's what happens on my fresh django install.  I guess I'm
> missing where the file is not being included.  Any thoughts?  Any help
> is greatly appreciated...thanks!
>
> Kit
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: edit fieldset.html template

2009-10-22 Thread onoxo

some hint?

On Oct 22, 12:28 pm, onoxo  wrote:
> is there some kind of manual/procedure to use objects in template
> pages?
>
> On Oct 21, 10:40 pm, onoxo  wrote:
>
>
>
> > hi!
> > i have a model and I'm using it as inline in admin site. here is the
> > code:
>
> > models.py
>
> > class PhotoItem(models.Model):
> >     order = models.IntegerField(blank = True, null = True)
> >     itemset = models.ForeignKey('PhotoSet', related_name='photoset')
> >     item = models.ForeignKey('Photo', related_name='photoitem')
>
> > admin.py
>
> > class PhotoItemInline(admin.StackedInline):
> >     model = PhotoItem
> >     ordering = ['order']
> >     raw_id_fields = ['item']
> >     extra = 5
>
> > i want to use value (item.image) from PhotoItem object (witch is a
> > string that represents s path to image) in "templates/admin/includes/
> > fieldset.html" template. the problem is that i dont know how to refer
> > to that attribute (item.image) when I'm in html.
> > since i'm designer i'll show you what i need, this is the picture of
> > field that i need to create in inlines (this is done in filebrowser
> > app):http://vedran.webfactional.com/kontenjner/fb.png
>
> >  i've try to put this on many places:
> > item.image
> > but it's not working.
>
> > could someone please help me with this one?
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: displaying posted data

2009-10-22 Thread Dhruv Adhia
here is the version I thought should have worked, but its not quite there

def add_score(request):
   #response_dict ={}
   secret_key = "asdf789as7df89asdf87ds89a8f7sfd8"
name =""
score=0
hash=""

# getting the posted data
   if request.GET:
   name = request.POST['name']
   print name
   score = request.POST['score']
   print score
   hash = request.POST['hash']
   print hash
   #leaderboard = {'name': name, 'score': score, 'hash': hash}

 #hashlib stuff for encryption
   m = hashlib.md5()
   m.update(name+str(score)+secret_key)
   real_hash = m.hexdigest()

  #storing it into database
   if real_hash == hash:
   # store the name and score into the database
   leaderboard = Scores(name = request.POST['name'] ,score =
request.POST['score'])
   leaderboard.save

   leaderboard = Scores.objects.all()
   return render_to_response('add_score.html', {'leaderboard': leaderboard})


This version does not do what i wanted it do. which is 1) Read the posted
data 2) Store it into database

Any help would be appreciated.

Thanks

Dhruv Adhia
http://thirdimension.com



On Thu, Oct 22, 2009 at 1:05 PM, Dhruv Adhia  wrote:

> Allright, I get that part.
>
> the url is coming from unity
>
> javascript part inside unity
>
> the part in bold is doing the post data.
>
> private var secretKey="mySecretKey";
> function postScore(name, score) {
> //This connects to a server side php script that will add the name and
> score to a MySQL DB.
> // Supply it with a string representing the players name and the
> players score.
> var hash=Md5.Md5Sum(name +""+ score + ""+ secretKey);
>
> *var highscore_url = addScoreUrl + "name=" + WWW.EscapeURL(name) +
> "=" + score + "=" + hash;
>
> // Post the URL to the site and create a download object to get the
> result.
> hs_post = WWW(highscore_url);*
> yield hs_post; // Wait until the download is done
> if(hs_post.error) {
> print("There was an error posting the high score: " +
> hs_post.error);
> }
> }
>
>
> 
> $db = mysql_connect('mysql_host', 'mysql_user', 'mysql_password')
> or die ('Could not
> connect: ' . mysql_error());
> mysql_select_db('my_database') or 
> die
> ('Could not select database');
>
> // Strings must be escaped to prevent SQL injection attack.
> $name = mysql_real_escape_string($_GET['name'], $db);
> $score = mysql_real_escape_string($_GET['score'], $db);
> $hash = $_GET['hash'];
>
> $secretKey="mySecretKey"; # Change this value to match the value
> stored in the client javascript below
>
> $real_hash = md5($name . $score . $secretKey);
> if($real_hash == $hash) {
> // Send variables for the MySQL database class.
> $query = "insert into scores values (NULL, '$name',
> '$score');";
> $result = mysql_query($query) or 
> die
> ('Query failed: ' . mysql_error());
> }
>  ?>
>
> This is the php side of things that I found online. Basically I am trying
> to convert that to python code as you can see.
>
> I wrote the getting part of the data and the rest is what I am working on
> right now.
>
> It would be nice,
>
> if I could read values sent by unity(which is fine) and store them into
> database rather than just displaying.
>
> Thanks Karen.
>
> Dhruv Adhia
> http://thirdimension.com
>
>
>
> On Thu, Oct 22, 2009 at 12:46 PM, Karen Tracey  wrote:
>
>> On Thu, Oct 22, 2009 at 3:25 PM, Dhruv Adhia  wrote:
>>
>>> Yep and sorry I am bit new to this stuff, I mistook 69 for 200. This
>>> explained it
>>> http://cwiki.apache.org/GMOxSAMPLES/using-asynchronous-http-client.data/s200.log
>>>
>>> so for '?' then should my url pattern for add_Score look like this
>>>   (r'^add_score/?', 'carbon_chaos.highscore.views.add_score'),
>>>
>>>
>>>
>> No, query strings don't play any part in the url matching.  You might want
>> to add a $ to the end of your existing pattern, to indicate that the inbound
>> URL path must end after the slash after add_score...as it is your requested
>> URL is only matching because that $ is missing from your pattern, allowing
>> any URL path that starts with add_score/ to get routed to your add_score
>> view, even if there is more after the add_score/ element of the URL path.
>>
>> What you need to do to be able to access the query string values from the
>> request.GET dictionary is change whatever is generating that URL to generate
>> it properly, with the ? separating the URL path from the query string.  But
>> near as I can tell you have not said anything about where that URL is coming
>> from, so I don't know what to tell you tot fix.  You need the request coming
>> in to the server to have the ? in its proper place, you do not need the ? in
>> 

base.css not being included

2009-10-22 Thread kkerbel

Hello all...

I upgraded from django 1.0 to 1.1.1 and when I copied the new admin
media folder into my apache media root...the only css that loads when
I visit the main admin page is dashboard.css which basically just
gives me text.  It appears that base.css needs to be loaded as well
since that's what happens on my fresh django install.  I guess I'm
missing where the file is not being included.  Any thoughts?  Any help
is greatly appreciated...thanks!

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



Re: displaying posted data

2009-10-22 Thread Dhruv Adhia
Allright, I get that part.

the url is coming from unity

javascript part inside unity

the part in bold is doing the post data.

private var secretKey="mySecretKey";
function postScore(name, score) {
//This connects to a server side php script that will add the name and
score to a MySQL DB.
// Supply it with a string representing the players name and the players
score.
var hash=Md5.Md5Sum(name +""+ score + ""+ secretKey);

*var highscore_url = addScoreUrl + "name=" + WWW.EscapeURL(name) +
"=" + score + "=" + hash;

// Post the URL to the site and create a download object to get the
result.
hs_post = WWW(highscore_url);*
yield hs_post; // Wait until the download is done
if(hs_post.error) {
print("There was an error posting the high score: " +
hs_post.error);
}
}


http://www.perldoc.com/perl5.6/pod/func/die.html>('Could not
connect: '. mysql_error
());
mysql_select_db('my_database') or
die
('Could not select database');

// Strings must be escaped to prevent SQL injection attack.
$name = mysql_real_escape_string($_GET['name'], $db);
$score = mysql_real_escape_string($_GET['score'], $db);
$hash = $_GET['hash'];

$secretKey="mySecretKey"; # Change this value to match the value
stored in the client javascript below

$real_hash = md5($name . $score . $secretKey);
if($real_hash == $hash) {
// Send variables for the MySQL database class.
$query = "insert into scores values (NULL, '$name', '$score');";

$result = mysql_query($query) or
die
('Query failed: ' . mysql_error());
}
 ?>

This is the php side of things that I found online. Basically I am trying to
convert that to python code as you can see.

I wrote the getting part of the data and the rest is what I am working on
right now.

It would be nice,

if I could read values sent by unity(which is fine) and store them into
database rather than just displaying.

Thanks Karen.

Dhruv Adhia
http://thirdimension.com



On Thu, Oct 22, 2009 at 12:46 PM, Karen Tracey  wrote:

> On Thu, Oct 22, 2009 at 3:25 PM, Dhruv Adhia  wrote:
>
>> Yep and sorry I am bit new to this stuff, I mistook 69 for 200. This
>> explained it
>> http://cwiki.apache.org/GMOxSAMPLES/using-asynchronous-http-client.data/s200.log
>>
>> so for '?' then should my url pattern for add_Score look like this
>>   (r'^add_score/?', 'carbon_chaos.highscore.views.add_score'),
>>
>>
>>
> No, query strings don't play any part in the url matching.  You might want
> to add a $ to the end of your existing pattern, to indicate that the inbound
> URL path must end after the slash after add_score...as it is your requested
> URL is only matching because that $ is missing from your pattern, allowing
> any URL path that starts with add_score/ to get routed to your add_score
> view, even if there is more after the add_score/ element of the URL path.
>
> What you need to do to be able to access the query string values from the
> request.GET dictionary is change whatever is generating that URL to generate
> it properly, with the ? separating the URL path from the query string.  But
> near as I can tell you have not said anything about where that URL is coming
> from, so I don't know what to tell you tot fix.  You need the request coming
> in to the server to have the ? in its proper place, you do not need the ? in
> the pattern.
>
> Karen
>
> >
>

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



Re: displaying posted data

2009-10-22 Thread Karen Tracey
On Thu, Oct 22, 2009 at 3:25 PM, Dhruv Adhia  wrote:

> Yep and sorry I am bit new to this stuff, I mistook 69 for 200. This
> explained it
> http://cwiki.apache.org/GMOxSAMPLES/using-asynchronous-http-client.data/s200.log
>
> so for '?' then should my url pattern for add_Score look like this
>
>   (r'^add_score/?', 'carbon_chaos.highscore.views.add_score'),
>
>
>
No, query strings don't play any part in the url matching.  You might want
to add a $ to the end of your existing pattern, to indicate that the inbound
URL path must end after the slash after add_score...as it is your requested
URL is only matching because that $ is missing from your pattern, allowing
any URL path that starts with add_score/ to get routed to your add_score
view, even if there is more after the add_score/ element of the URL path.

What you need to do to be able to access the query string values from the
request.GET dictionary is change whatever is generating that URL to generate
it properly, with the ? separating the URL path from the query string.  But
near as I can tell you have not said anything about where that URL is coming
from, so I don't know what to tell you tot fix.  You need the request coming
in to the server to have the ? in its proper place, you do not need the ? in
the pattern.

Karen

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



Re: Preview model before saving it

2009-10-22 Thread Aaron

On Oct 22, 1:41 pm, Ethan Jucovy  wrote:
> Do you need one-time previews ("are you sure you want to save this?") or
> real drafts that can be viewed more than once?  If you just need an
> intermediate preview step for the user who's submitting the data, you can do
> it without saving any data on the backend --

The general behavior I want is to have a page with the model form and
a "preview" link.  The preview link would open a page (likely a new
tab) that would display the model as it would appear on my web site.
That is, I have a template for each of my models, and I would like to
reuse those for rendering my preview objects, though I may have to add
an extra parameter to them to disable features only available to live
objects.

> write a "preview" view that validates the POSTed data without committing
>  and then
> renders a template with a form that includes that data by default, and which
> will POST to the real save view.
>
> I like to put the data in hidden fields, and render a representation of the
> previewed data separately.  That way the "save for real" form can just look
> like a button to the user, and you can have a separate form for modifying
> the data and going through the preview cycle again.
>
> I haven't done anything custom in the django admin, but I assume this
> technique can work there too.

That was the idea I had. I'd have a view that gets the ModelForm and
sends the (unsaved) model to the template. The trick is figuring out
how to get access to the ModelForm inside the view, especially when I
want to use the admin change form.
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: displaying posted data

2009-10-22 Thread Dhruv Adhia
Yep and sorry I am bit new to this stuff, I mistook 69 for 200. This
explained it
http://cwiki.apache.org/GMOxSAMPLES/using-asynchronous-http-client.data/s200.log

so for '?' then should my url pattern for add_Score look like this
  (r'^add_score/?', 'carbon_chaos.highscore.views.add_score'),


Thanks Karen.
Dhruv Adhia
http://thirdimension.com



On Thu, Oct 22, 2009 at 12:17 PM, Karen Tracey  wrote:

> On Thu, Oct 22, 2009 at 2:35 PM, Dhruv Adhia  wrote:
>
>> Allright, I see some progress, so now my views looks like this with that
>> little modification
>>
>> def add_score(request):
>>response_dict ={}
>>if request.POST:
>>name = request.POST['name']
>>score = request.POST['score']
>>hash = request.POST['hash']
>>response_dict = {'name': name, 'score': score, 'hash': hash}
>>return render_to_response('add_score.html', response_dict)
>>
>>
>> From unity I am getting scores and names and I am also posting it onto the
>> webserver. The getting part is fine as I could read it from the database.
>> But when I post , the server is getting the posted values but it also gives
>> 200 69 which is internal server error
>>
>>
> 200 is not internal server error, it is HTTP OK.  (500 is internal server
> error.) 69 is the number of bytes returned in the response.
>
>
>> here is what I see in terminal
>>
>> [22/Oct/2009 13:30:36] "GET
>> /add_score/name=carbon_chaos=100=56ee224509ffd27920e64189cab9a06f
>> HTTP/1.1" 200 69
>> [22/Oct/2009 13:30:36] "GET /display_score/ HTTP/1.1" 200 187
>>
>
> This shows you are not posting the data, rather you are getting it.  The
> request says GET and the parameters you are looking for are almost encoded
> into a query string, except it's missing the leading ? which signals the end
> of the url path and the beginning of the query string.  How is that request
> being generated?  It should be:
>
> /add_score/?name=carbon_chaos=100=56ee224509ffd27920e64189cab9a06f
>
>
> Without the ? the values will not be available in the request.GET
> dictionary, as they appear to be part of the URL path.
>
> Karen
>
> >
>

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



Re: displaying posted data

2009-10-22 Thread Karen Tracey
On Thu, Oct 22, 2009 at 2:35 PM, Dhruv Adhia  wrote:

> Allright, I see some progress, so now my views looks like this with that
> little modification
>
>
> def add_score(request):
>response_dict ={}
>if request.POST:
>name = request.POST['name']
>score = request.POST['score']
>hash = request.POST['hash']
>
>response_dict = {'name': name, 'score': score, 'hash': hash}
>return render_to_response('add_score.html', response_dict)
>
>
> From unity I am getting scores and names and I am also posting it onto the
> webserver. The getting part is fine as I could read it from the database.
> But when I post , the server is getting the posted values but it also gives
> 200 69 which is internal server error
>
>
200 is not internal server error, it is HTTP OK.  (500 is internal server
error.) 69 is the number of bytes returned in the response.


> here is what I see in terminal
>
> [22/Oct/2009 13:30:36] "GET
> /add_score/name=carbon_chaos=100=56ee224509ffd27920e64189cab9a06f
> HTTP/1.1" 200 69
> [22/Oct/2009 13:30:36] "GET /display_score/ HTTP/1.1" 200 187
>

This shows you are not posting the data, rather you are getting it.  The
request says GET and the parameters you are looking for are almost encoded
into a query string, except it's missing the leading ? which signals the end
of the url path and the beginning of the query string.  How is that request
being generated?  It should be:

/add_score/?name=carbon_chaos=100=56ee224509ffd27920e64189cab9a06f


Without the ? the values will not be available in the request.GET
dictionary, as they appear to be part of the URL path.

Karen

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



Re: displaying posted data

2009-10-22 Thread Dhruv Adhia
ohk , corrected. But then why am I not getting to see the values on browser?
is it because the url pattern is not matching?

Thanks Daniel.
Dhruv Adhia
http://thirdimension.com



On Thu, Oct 22, 2009 at 12:05 PM, Daniel Roseman wrote:

>
> On Oct 22, 7:35 pm, Dhruv Adhia  wrote:
> > Allright, I see some progress, so now my views looks like this with that
> > little modification
> >
> > def add_score(request):
> >response_dict ={}
> >if request.POST:
> >name = request.POST['name']
> >score = request.POST['score']
> >hash = request.POST['hash']
> >response_dict = {'name': name, 'score': score, 'hash': hash}
> >return render_to_response('add_score.html', response_dict)
> >
> > From unity I am getting scores and names and I am also posting it onto
> the
> > webserver. The getting part is fine as I could read it from the database.
> > But when I post , the server is getting the posted values but it also
> gives
> > 200 69 which is internal server error
> >
> > here is what I see in terminal
> >
> > [22/Oct/2009 13:30:36] "GET
> >
> /add_score/name=carbon_chaos=100=56ee224509ffd27920e64189cab9a06
> f
> > HTTP/1.1" 200 69
> > [22/Oct/2009 13:30:36] "GET /display_score/ HTTP/1.1" 200 187
> >
> > as you will see name = carbon_chaos and score=100 and some hash value...
> I
> > am posting those data from unity and when I load the scene I see that
> > activity happening inside the terminal. But it does not display the
> values
> > inside in the browser.
> >
> > What is the mistake?
> >
> > Thanks
> > Dhruv Adhiahttp://thirdimension.com
>
> You are using GET after all! As you can see from the console, it is a
> GET request, not a POST. So you should have been using request.GET
> ['whatever'] all along.
>
> I've no idea why you think '200 69' is an internal server error. On
> the contrary. The 200 part of that is the code for 'OK'. The 69 is
> just the length of the content that was returned.
> --
> DR.
> >
>

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



Re: displaying posted data

2009-10-22 Thread Daniel Roseman

On Oct 22, 7:35 pm, Dhruv Adhia  wrote:
> Allright, I see some progress, so now my views looks like this with that
> little modification
>
> def add_score(request):
>    response_dict ={}
>    if request.POST:
>        name = request.POST['name']
>        score = request.POST['score']
>        hash = request.POST['hash']
>        response_dict = {'name': name, 'score': score, 'hash': hash}
>    return render_to_response('add_score.html', response_dict)
>
> From unity I am getting scores and names and I am also posting it onto the
> webserver. The getting part is fine as I could read it from the database.
> But when I post , the server is getting the posted values but it also gives
> 200 69 which is internal server error
>
> here is what I see in terminal
>
> [22/Oct/2009 13:30:36] "GET
> /add_score/name=carbon_chaos=100=56ee224509ffd27920e64189cab9a06 f
> HTTP/1.1" 200 69
> [22/Oct/2009 13:30:36] "GET /display_score/ HTTP/1.1" 200 187
>
> as you will see name = carbon_chaos and score=100 and some hash value... I
> am posting those data from unity and when I load the scene I see that
> activity happening inside the terminal. But it does not display the values
> inside in the browser.
>
> What is the mistake?
>
> Thanks
> Dhruv Adhiahttp://thirdimension.com

You are using GET after all! As you can see from the console, it is a
GET request, not a POST. So you should have been using request.GET
['whatever'] all along.

I've no idea why you think '200 69' is an internal server error. On
the contrary. The 200 part of that is the code for 'OK'. The 69 is
just the length of the content that was returned.
--
DR.
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: displaying posted data

2009-10-22 Thread Dhruv Adhia
Inside my urls,

I have the url pattern as

(r'^add_score/', 'carbon_chaos.highscore.views.add_score'), # for displaying
posted data from unity..

is the url pattern wrong?
Thanks
Dhruv Adhia
http://thirdimension.com



On Thu, Oct 22, 2009 at 11:35 AM, Dhruv Adhia  wrote:

> Allright, I see some progress, so now my views looks like this with that
> little modification
>
> def add_score(request):
>response_dict ={}
>if request.POST:
>name = request.POST['name']
>score = request.POST['score']
>hash = request.POST['hash']
>response_dict = {'name': name, 'score': score, 'hash': hash}
>return render_to_response('add_score.html', response_dict)
>
>
> From unity I am getting scores and names and I am also posting it onto the
> webserver. The getting part is fine as I could read it from the database.
> But when I post , the server is getting the posted values but it also gives
> 200 69 which is internal server error
>
> here is what I see in terminal
>
> [22/Oct/2009 13:30:36] "GET
> /add_score/name=carbon_chaos=100=56ee224509ffd27920e64189cab9a06f
> HTTP/1.1" 200 69
> [22/Oct/2009 13:30:36] "GET /display_score/ HTTP/1.1" 200 187
>
> as you will see name = carbon_chaos and score=100 and some hash value... I
> am posting those data from unity and when I load the scene I see that
> activity happening inside the terminal. But it does not display the values
> inside in the browser.
>
> What is the mistake?
>
> Thanks
> Dhruv Adhia
> http://thirdimension.com
>
>
>
> On Thu, Oct 22, 2009 at 11:30 AM, Daniel Roseman wrote:
>
>>
>> On Oct 22, 7:19 pm, Dhruv Adhia  wrote:
>> > oops that was a typo.. thanks for pointing that out... Yep I see atleast
>> the
>> > html elements getting displayed like those arrows...
>> >
>> > on the views side I didnt get what f4nt meant.. can you show me an
>> example?
>> >
>>
>> You had it right in your reply to him: request.POST['name']
>>
>> request.GET['whatever'] is for elements that are passed in as GET
>> parameters, eg /myurl/?param1=value1
>> --
>> DR.
>> >>
>>
>

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



Re: displaying posted data

2009-10-22 Thread Dhruv Adhia
Allright, I see some progress, so now my views looks like this with that
little modification

def add_score(request):
   response_dict ={}
   if request.POST:
   name = request.POST['name']
   score = request.POST['score']
   hash = request.POST['hash']
   response_dict = {'name': name, 'score': score, 'hash': hash}
   return render_to_response('add_score.html', response_dict)


>From unity I am getting scores and names and I am also posting it onto the
webserver. The getting part is fine as I could read it from the database.
But when I post , the server is getting the posted values but it also gives
200 69 which is internal server error

here is what I see in terminal

[22/Oct/2009 13:30:36] "GET
/add_score/name=carbon_chaos=100=56ee224509ffd27920e64189cab9a06f
HTTP/1.1" 200 69
[22/Oct/2009 13:30:36] "GET /display_score/ HTTP/1.1" 200 187

as you will see name = carbon_chaos and score=100 and some hash value... I
am posting those data from unity and when I load the scene I see that
activity happening inside the terminal. But it does not display the values
inside in the browser.

What is the mistake?

Thanks
Dhruv Adhia
http://thirdimension.com



On Thu, Oct 22, 2009 at 11:30 AM, Daniel Roseman wrote:

>
> On Oct 22, 7:19 pm, Dhruv Adhia  wrote:
> > oops that was a typo.. thanks for pointing that out... Yep I see atleast
> the
> > html elements getting displayed like those arrows...
> >
> > on the views side I didnt get what f4nt meant.. can you show me an
> example?
> >
>
> You had it right in your reply to him: request.POST['name']
>
> request.GET['whatever'] is for elements that are passed in as GET
> parameters, eg /myurl/?param1=value1
> --
> DR.
> >
>

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



Re: displaying posted data

2009-10-22 Thread Daniel Roseman

On Oct 22, 7:19 pm, Dhruv Adhia  wrote:
> oops that was a typo.. thanks for pointing that out... Yep I see atleast the
> html elements getting displayed like those arrows...
>
> on the views side I didnt get what f4nt meant.. can you show me an example?
>

You had it right in your reply to him: request.POST['name']

request.GET['whatever'] is for elements that are passed in as GET
parameters, eg /myurl/?param1=value1
--
DR.
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: displaying posted data

2009-10-22 Thread Dhruv Adhia
oops that was a typo.. thanks for pointing that out... Yep I see atleast the
html elements getting displayed like those arrows...

on the views side I didnt get what f4nt meant.. can you show me an example?

Thanks
Dhruv Adhia
http://thirdimension.com



On Thu, Oct 22, 2009 at 11:05 AM, Daniel Roseman wrote:

>
> On Oct 22, 6:20 pm, Dhruv Adhia  wrote:
> > Hello,
> >
> > Quite a basic question.. I am posting data from Unity, its like name
> > and score. I want to read the posted data and display it.
> >
> > Here is the code that I currently have inside views.py
> >
> > def add_score(request):
> >response_dict ={}
> >if request.POST:
> >name = request.GET['name']
> >score = request.GET['score']
> >hash = request.GET['hash']
> >response_dict = {'name': name, 'score': score, 'hash': hash}
> >return render_to_response('add_score.html', response_dict)
> >
> > and template part
> >
> > Carbon Chaos leader board
> >
> > 
> > {% for carbon_chaos in response_dict %}
> > {{carbon_chaos.name}} >>> {{carbon_chaos.score}} >>>
> > {{carbon_chaos.hash}}
> > {% endfor %}
> >
> > Can somebody point out what is the mistake?
> >
> > Thanks,
> > Dhruv
>
> As well as the view issue noted by f4nt, there are two further
> mistakes in the template:
> * response_dict is not an element in the context, it's what you have
> called the context within your view. In the template itself, the
> context elements are the keys/values in that dictionary.
> * There is no 'carbon_chaos' item in your context, so it doesn't make
> sense to iterate through it.
>
> So the template should look like this:
> 
> {{name}} >>> {{score}} >>> {{hash}}
> 
> --
> DR.
> >
>

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



Filtering my User list based on a UserProfile field?

2009-10-22 Thread Jean-Nicolas

Hi there...

I've extended my User model (with both UserProfile and
UserPaymentInformation) to hold additional information about a user.
I'm able to add both to my admin area using Inlines (and re-
registering my admin site)...

However, I'm facing a problem that I'm not sure how to resolve: A very
important part of user administration for me is an "Approval queue",
so, basically when a new user registers, he's put in a queue until an
administrator approves him...(the queue is just a boolean field of my
UserProfile named is_in_queue)

My problem is: I would like to be able to display a list of users that
are in the queue... I tried using list_filter, but I can't filter my
User list using a UserProfile field ... here is my UserAdmin so far:

class MyUserAdmin(UserAdmin):
inlines = [UserPaymentInfoInline, UserProfileInline]
list_display = UserAdmin.list_display + (user_in_queue,)

Since list_display can be a callable, I added a function
(user_in_queue) that returns whether or not the user is in the queue,
which is great, but I still can't filter (or order) my users based on
the fact that they are in a queue, which is what I need for the
approval process... Having to scroll through the whole user list to
find out which ones are in the queue makes no sense...

I thought about adding a custom admin view that would only list the
users that are in the queue... That worked out well.. however, that
custom view will not show up on the Admin Index site...

So basically to sum it up: Can I filter my User list based on a
UserProfile field? If not, can I add a custom view that's accessible
from the front page without having to create a completely new
AdminSite only for that?

Any help would be appreciated!
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: displaying posted data

2009-10-22 Thread Daniel Roseman

On Oct 22, 6:20 pm, Dhruv Adhia  wrote:
> Hello,
>
> Quite a basic question.. I am posting data from Unity, its like name
> and score. I want to read the posted data and display it.
>
> Here is the code that I currently have inside views.py
>
> def add_score(request):
>    response_dict ={}
>    if request.POST:
>        name = request.GET['name']
>        score = request.GET['score']
>        hash = request.GET['hash']
>        response_dict = {'name': name, 'score': score, 'hash': hash}
>    return render_to_response('add_score.html', response_dict)
>
> and template part
>
> Carbon Chaos leader board
>
> 
> {% for carbon_chaos in response_dict %}
> {{carbon_chaos.name}} >>> {{carbon_chaos.score}} >>>
> {{carbon_chaos.hash}}
> {% endfor %}
>
> Can somebody point out what is the mistake?
>
> Thanks,
> Dhruv

As well as the view issue noted by f4nt, there are two further
mistakes in the template:
* response_dict is not an element in the context, it's what you have
called the context within your view. In the template itself, the
context elements are the keys/values in that dictionary.
* There is no 'carbon_chaos' item in your context, so it doesn't make
sense to iterate through it.

So the template should look like this:

{{name}} >>> {{score}} >>> {{hash}}

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



Re: displaying posted data

2009-10-22 Thread Dhruv Adhia
do you mean name = request.POST['name'] ?

Thanks
Dhruv Adhia
http://thirdimension.com



On Thu, Oct 22, 2009 at 10:48 AM, f4nt  wrote:

>
> You're initting your variables from request.GET instead of
> request.POST.
>
> On Oct 22, 12:20 pm, Dhruv Adhia  wrote:
> > Hello,
> >
> > Quite a basic question.. I am posting data from Unity, its like name
> > and score. I want to read the posted data and display it.
> >
> > Here is the code that I currently have inside views.py
> >
> > def add_score(request):
> >response_dict ={}
> >if request.POST:
> >name = request.GET['name']
> >score = request.GET['score']
> >hash = request.GET['hash']
> >response_dict = {'name': name, 'score': score, 'hash': hash}
> >return render_to_response('add_score.html', response_dict)
> >
> > and template part
> >
> > Carbon Chaos leader board
> >
> > 
> > {% for carbon_chaos in response_dict %}
> > {{carbon_chaos.name}} >>> {{carbon_chaos.score}} >>>
> > {{carbon_chaos.hash}}
> > {% endfor %}
> >
> > Can somebody point out what is the mistake?
> >
> > Thanks,
> > Dhruv
>
> >
>

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



Re: displaying posted data

2009-10-22 Thread f4nt

You're initting your variables from request.GET instead of
request.POST.

On Oct 22, 12:20 pm, Dhruv Adhia  wrote:
> Hello,
>
> Quite a basic question.. I am posting data from Unity, its like name
> and score. I want to read the posted data and display it.
>
> Here is the code that I currently have inside views.py
>
> def add_score(request):
>    response_dict ={}
>    if request.POST:
>        name = request.GET['name']
>        score = request.GET['score']
>        hash = request.GET['hash']
>        response_dict = {'name': name, 'score': score, 'hash': hash}
>    return render_to_response('add_score.html', response_dict)
>
> and template part
>
> Carbon Chaos leader board
>
> 
> {% for carbon_chaos in response_dict %}
> {{carbon_chaos.name}} >>> {{carbon_chaos.score}} >>>
> {{carbon_chaos.hash}}
> {% endfor %}
>
> Can somebody point out what is the mistake?
>
> Thanks,
> Dhruv

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



displaying posted data

2009-10-22 Thread Dhruv Adhia

Hello,

Quite a basic question.. I am posting data from Unity, its like name
and score. I want to read the posted data and display it.

Here is the code that I currently have inside views.py


def add_score(request):
   response_dict ={}
   if request.POST:
   name = request.GET['name']
   score = request.GET['score']
   hash = request.GET['hash']
   response_dict = {'name': name, 'score': score, 'hash': hash}
   return render_to_response('add_score.html', response_dict)


and template part

Carbon Chaos leader board


{% for carbon_chaos in response_dict %}
{{carbon_chaos.name}} >>> {{carbon_chaos.score}} >>>
{{carbon_chaos.hash}}
{% endfor %}


Can somebody point out what is the mistake?

Thanks,
Dhruv
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: Preview model before saving it

2009-10-22 Thread Ethan Jucovy
Do you need one-time previews ("are you sure you want to save this?") or
real drafts that can be viewed more than once?  If you just need an
intermediate preview step for the user who's submitting the data, you can do
it without saving any data on the backend --

write a "preview" view that validates the POSTed data without committing
 and then
renders a template with a form that includes that data by default, and which
will POST to the real save view.

I like to put the data in hidden fields, and render a representation of the
previewed data separately.  That way the "save for real" form can just look
like a button to the user, and you can have a separate form for modifying
the data and going through the preview cycle again.

I haven't done anything custom in the django admin, but I assume this
technique can work there too.

Hope this helps,

egj

On Thu, Oct 22, 2009 at 8:12 AM, Aaron  wrote:

>
> I've thought about using a "published" boolean but I'm not sure how
> that would help.
>
> These models are displayed on a live site, and it will be existing
> models I'll be editing and previewing. While a model is in "draft
> mode" I still want the old unchanged version of the model displayed on
> the live site. I'm not sure how I'm going to store either the original
> or the draft versions of the model, or how I'm going to replace the
> original with the draft after I commit its changes.
>
> On Oct 21, 5:38 pm, akonsu  wrote:
> > hello,
> >
> > anything is possible. you just need to decide how you are going to
> > store your changes before the model gets "really" saved so that the
> > preview functionality works. where would preview get the values from?
> > i propose a "published" boolean field in the model.
> >
> > konstantin
> >
> > On Oct 21, 3:41 pm, Aaron  wrote:
> >
> > > I'm wanting to set up model previews in the admin. I've been following
> > > this guide:
> >
> > >http://latherrinserepeat.org/2008/7/28/stupid-simple-django-admin-pre.
> ..
> >
> > > However, that guide seems to only apply to models that have already
> > > been saved (how is it different from "View on site"?). I wish to be
> > > able to make changes to my model, click on "Preview", and see what my
> > > model page will look like *before* saving it in the admin. Is this
> > > possible?
> >
>

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



Re: Do I have to pass the httprequest object to render_to_response every time?

2009-10-22 Thread Bayuadji

IMHO Yes,
otherwise the context_processor variable won't be available in template

-djibon-

On Thu, Oct 22, 2009 at 11:43 AM, jul  wrote:
>
> But I still have to pass RequestContext(request) to render_to_response
> if I'm not using generic views, right?
>
> On Oct 21, 8:38 pm, Andrew Ingram  wrote:
>> jul wrote:
>> > hi,
>>
>> > in my base.html template I've got a header which needs httprequest
>> > (request.path, request.user.is_authenticated...).
>> > In all my views I'm passing the request object to render_to_response.
>> > Is there any better way to do that?
>>
>> > thanks
>> > jul
>>
>> Hi jul,
>>
>> There is a context processor that comes as part of django that gives you
>> access to the request object:
>>
>> http://docs.djangoproject.com/en/dev/ref/templates/api/#django-core-c...
>>
>> as long as you have it specified in your settings.py, it will
>> automatically become available if you use render_to_response
>>
>> Regards,
>> Andrew Ingram
> >
>



-- 
--
http://www.tumbletooth.org
my linkedin profile : http://www.linkedin.com/in/bayuadji
--

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



Re: Advantages of using ManyToManyField(Bar, through='Foo_Bar') syntax vs not declaring a ManyToManyField at all

2009-10-22 Thread Tom Evans

On Thu, 2009-10-22 at 07:57 -0700, Monika Sulik wrote:
> Hi,
> 
> I was wondering what exactly are the advantages of having code like
> this:
> 
> >>
> class Foo (models.Model):
> bar_m2m = models.ManyToManyField(Bar,through='Foo_Bar')
> 
> class Bar (models.Model):
> pass
> 
> class Foo_Bar (models.Model):
> foo = models.ForeignKey(Foo)
> bar = models.ForeignKey(Bar)
> x = models.IntegerField()
> >>
> 
> over having the same code, but having the Foo class like so:
> 
> >>
> class Foo (models.Model):
> pass
> >>>
> 
> In both cases I can use foo.foo_bar_set and bar.foo_bar_set (assuming
> foo is a Foo Object and bar is a Bar Object). Why would I need the
> bar_m2m variable?
> I'm probably missing something pretty obvious, but if someone could
> point out the answer to me that would be great :)
> 
> Monika
> 

With a many to many with a through table, you can either go directly to
the other end of the relationship, or look at the through table. Without
it, you cannot look directly at the relationship, only at the link.

Eg, Users can be in many UserGroups and UserGroups can have many Users.
If I use a m2m relationship with a through table, I can do both these
things:

class UserGroup(models.Model):
  users=ManyToManyField(User, through='UserUserGroupPreferences')

class UserUserGroupPreferences(models.Model):
  user=models.ForeignKey('User')
  usergroup=models.ForeignKey('UserGroup')
  is_group_super_user=models.BooleanField(default=False)

u=User.objects.get(...)
# I can see directly which groups a user is in
u.usergroup_set.all()
# I can also examine things about a particular user -> group association
u.userusergrouppreferences_set.filter(is_group_super_user=True)

Without the m2m field, I wouldn't be able to go directly to the
usergroup from the user, I would only be able to go via the through
table.

Cheers

Tom


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



Re: Do I have to pass the httprequest object to render_to_response every time?

2009-10-22 Thread jul

But I still have to pass RequestContext(request) to render_to_response
if I'm not using generic views, right?

On Oct 21, 8:38 pm, Andrew Ingram  wrote:
> jul wrote:
> > hi,
>
> > in my base.html template I've got a header which needs httprequest
> > (request.path, request.user.is_authenticated...).
> > In all my views I'm passing the request object to render_to_response.
> > Is there any better way to do that?
>
> > thanks
> > jul
>
> Hi jul,
>
> There is a context processor that comes as part of django that gives you
> access to the request object:
>
> http://docs.djangoproject.com/en/dev/ref/templates/api/#django-core-c...
>
> as long as you have it specified in your settings.py, it will
> automatically become available if you use render_to_response
>
> Regards,
> Andrew Ingram
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



authenticated CDN content

2009-10-22 Thread captainmish

Hello

We have been using a view that implements X-Sendfile (with apache's
mod_xsendfile) to serve content to authorised users, but now need to
switch to cloudfiles. Cloudfiles doesnt offer any kind of
authentication, so we'll need to implement it in django / apache
somehow.

What I have done is just change the view (decorated with
user_passes_test) to return an HttpResponseRedirect for the CDN
content, this works but I was hoping someone had come up with
something smarter than this. Once someone has the CDN url of a file,
they can pass it around etc. It seems we cant use X-Sendfile for non-
local files (please let me know if I'm wrong!), so not really sure
what else to try.

Any tips very welcome!

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



Advantages of using ManyToManyField(Bar, through='Foo_Bar') syntax vs not declaring a ManyToManyField at all

2009-10-22 Thread Monika Sulik

Hi,

I was wondering what exactly are the advantages of having code like
this:

>>
class Foo (models.Model):
bar_m2m = models.ManyToManyField(Bar,through='Foo_Bar')

class Bar (models.Model):
pass

class Foo_Bar (models.Model):
foo = models.ForeignKey(Foo)
bar = models.ForeignKey(Bar)
x = models.IntegerField()
>>

over having the same code, but having the Foo class like so:

>>
class Foo (models.Model):
pass
>>>

In both cases I can use foo.foo_bar_set and bar.foo_bar_set (assuming
foo is a Foo Object and bar is a Bar Object). Why would I need the
bar_m2m variable?
I'm probably missing something pretty obvious, but if someone could
point out the answer to me that would be great :)

Monika

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



Re: Problem about write data into the DB

2009-10-22 Thread 邓超
HI Bruno,
  Thank you for your answer. The reason I choose setup the whole environment
is I need setup them in a virtual machine and send this virtual machine to
my friends to test it, they are not familiar with django, they just want to
open the web browser and test the site. And I also want to get a try,
actually this is my first time to deploy a django project, I need chance to
exercise.
  The HTTP 500 error has solved just now. Yes, you are right. the apache
account hasn't the r/w access to the DB file, I modified the rights of the
DB file and my site works well now! Thank you very much!

2009/10/22 bruno desthuilliers 

>
> On 21 oct, 17:28, 邓超  wrote:
> > Hi all,
> >   I deployed a django app on my laptop, the whole environment is like
> this:
> > the OS is UBUNTU904, the web server is Apache,
>
> If it's only for personal use on a single laptop, setting up Apache is
> possibly overkill - you could as well use the builtin dev server.
>
> >  and the database is sqlite3.
> > The deployment is success, but  when I try to write some data into the
> > database, I get the HTTP 500 error. And I check the error log, it
> > shows "*OperationalError:
> > unable to open database file*". What does this error mean? If there are
> some
> > operation permission need configure?
>
> Does the Apache process have r/w access on the sqlite DB file ? (on
> ubuntu, the user account for Apache is "www-data").
>
>
> >
>


-- 
Deng Chao

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



Re: admin actions bar in django 1.1

2009-10-22 Thread kkerbel

I think I found the problem...I have some files missing in my media
folder...namely 'actions.js'...I'm assuming adding this back will fix
my problem...if I could just figure out how to get my site to read the
media directory to begin with.  ha.

On Oct 21, 4:53 pm, kkerbel  wrote:
> it doesn't appear to be working for any apps.  everything else on the
> admin page shows fine to my knowledge...just not the admin actions
> bar.
>
> On Oct 21, 4:47 pm, kkerbel  wrote:
>
>
>
> > within the templates folder for my app (events in this case)...I just
> > have a folder named events containing templates for the pages...I do
> > not have any admin template mods.
>
> > On Oct 21, 12:47 pm, Peter Bengtsson  wrote:
>
> > > What customizations have your done in the templates/admin/ folder of
> > > the app that isn't working?
>
> > > On 21 Oct, 17:22, kkerbel  wrote:
>
> > > > i upgraded django 1.0.2 to 1.1 stable and I cannot see the admin
> > > > actions bar in one of my apps...or any of them for that matter.  My
> > > > fresh install of 1.1 has the bar, however, I can't seem to find the
> > > > discrepancy between the two installs.  Have any of you experienced
> > > > this?  Thanks!
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: Which apps/solutions are most appropriate for model based search in Django?

2009-10-22 Thread David De La Harpe Golden

>>> That is, a search on students
>>> is essentially an answer to the question "Show students that belong to
>>> the following schools, and who belong to the following states, and who
>>> have the following degrees / diplomas".

N.B. That in particular does sound like what might sometimes be called
"filtering" or "narrowing" rather than "searching".  Of course, it's
still kind of "searching" (or "finding" ... whatever...)

I presently use some simple ad-hoc code to implement my desired filters
in my application, but I've recently been looking closely at
django-filter which might provide more structure to the implementation:
http://github.com/alex/django-filter

(The other thing I do is use the nice jquery datatables plugin which
provides further last-minute intra-results text search on the client
side - http://www.datatables.net/ )


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



Re: Redirects on HTTPS

2009-10-22 Thread Tom Evans

On Thu, 2009-10-22 at 12:45 +0100, Tim Sawyer wrote:
> Hi,
> 
> I have a django app that works fine using http.  We have a requirement to
> serve the entire site using https, which is being done at the proxy level
> - so the Apache that my django is running inside (mod_wsgi) doesn't know
> about the https.
> 
> I have a problem with using HttpResponseRedirect - the redirect is
> changing the URL to be http.  Everything else about the URL is right.
> 
> How do I fix this, and have the redirect go to https?
> 
> Thanks,
> 
> Tim.
> 

I use middleware to update the request to think it came in over https.
This is an extremely cut down version of what we use, but if _every_
request is SSL it should work fine (not all our requests are SSL, and
not every view requires SSL, so ours is a lot more complex in deciding
whether to monkey patch).

class SSLMiddleware(object):

  def process_request(self, request):
  # request.is_secure() looks in os.environ to see whether request is SSL
  # Unfortunately, once you look in os.environ, you can't change it...
  # Therefore, we have to monkey patch that function, we know this is SSL
  request.is_secure = lambda: True

Cheers

Tom



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



Re: 500.html does not load

2009-10-22 Thread NoviceSortOf

>> Traceback error :  TemplateDoesNotExist: 500.html

Thanks for the note Akonsu, I'm looking at my template settings in
settings.py
on my production server and don't see any anomalies. As well all my
other templates load -- so I'm not sure where else to go to trouble
shoot this.

TEMPLATE_LOADERS = (
'django.template.loaders.filesystem.load_template_source',
'django.template.loaders.app_directories.load_template_source',)

TEMPLATE_DIRS = ("/home/mysite/www/myproject/templates",
 "/usr/lib/python2.3/site-packages/django/contrib/
admin/templates",)

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



Re: Caching performance regression between django 1.0 and django 1.1.1

2009-10-22 Thread Russell Keith-Magee

On Thu, Oct 22, 2009 at 4:38 PM, mt  wrote:
>
>
>
> On Oct 19, 1:08 pm, Russell Keith-Magee 
> wrote:
>> On Mon, Oct 19, 2009 at 6:52 PM, mt  wrote:
>>
>> > Hi All,
>> > I recently upgraded a high traffic site from django 1.0 to django
>> > 1.1.1 and noticed that the load on the server went through the roof,
>> > so I had to revert to django 1.0.
>> > I've done some testing and noticed that the caching behaviour between
>> > 1. 0 and 1.1.1 has changed.
>> > Basically I was caching expensive database queries using memcached, in
>> > django 1.0 reading from the cache is a fast operation however in
>> > django 1.1.1 reading from cache causes all fields with a callable as
>> > default to be called.
>> > In the case where that callable is an expensive operation the
>> > performance is severely affected.
>> > I've created patches showing this regression for the branches
>> >http://code.djangoproject.com/svn/django/branches/releases/1.0.X
>> > and
>> >http://code.djangoproject.com/svn/django/branches/releases/1.1.X
>> > which shows the default callable being called on cache read.
>>
>> > My questions are:
>> > 1. Is it wrong to store querysets in the cache?
>>
>> Strictly, a queryset doesn't contain *any* data - it's just a
>> programatic representation of a SQL query. So, putting a queryset in
>> the cache doesn't inherently mean that anything is being stored.
>> However, if the queryset has been evaluated, there might be something
>> in the queryset's internal result cache, and *that* value will be
>> returned when the value is retrieved from the cache.
>>
>> > 2. Should I log a bug for this in the django tracker and upload my
>> > test case patches?
>>
>> Certainly.
> Hi Russell,
> I've found the cause of the performance regression and have suggested
> a patch on ticket 12057 (http://code.djangoproject.com/ticket/12057)
> The patch runs without causing any other tests to fail in the django
> tree.
> Do you think this patch could have other side effects or is it OK?

First off - the test case is awesome - that helps a lot.

As for the fix: there's a much easier solution - on line 356 of
django/db/models/base.py, replace the current implementation:

return (self.__class__, (), data)

with an implementation that essentially reverts to the underlying
implementation of __reduce__:

return super(Model, self).__reduce__()

You can see the underlying problem if you inspect super().__reduce__,
and compare it to the current return value.

As a result, I suspect that an analogous problem will exist for any
model with deferred fields. I'll need to confirm this before I commit
the fix. If you can spare any time to look into this, I'd be much
obliged.

Yours,
Russ Magee %-)

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



Re: Which apps/solutions are most appropriate for model based search in Django?

2009-10-22 Thread chefsmart

Yes, I am also not convinced that an engine focused on full-text
search is relevant in this case. But i am no expert on that.

I haven't actually benchmarked the performance of the current solution
I am using, I am just looking to get some opinions or solutions if
django users have encountered this scenario before.

I am so tied in to Django models and my searches also return Django
querysets. If I do need to change tracks, I would be looking for some
solution that returns Django models and querysets on search. I am
going through a lot of projects on github and Google code, just
reading through their docs and source.

On Oct 22, 3:17 pm, bruno desthuilliers
 wrote:
> On 22 oct, 07:54, chefsmart  wrote:
>
>
>
> > This is on stackoverflow.com also, but I guess not all Django users
> > visit that site so I am posting this here also: -
>
> > I have a Django app where most of the search is driven by foreign
> > keys. For example, assuming Student, School, State, and
> > EducationalQualification are Django models, the user would search for
> > Students by specifying search criteria by selecting from lists of
> > Schools, States, Degrees, Diplomas etc. That is, a search on students
> > is essentially an answer to the question "Show students that belong to
> > the following schools, and who belong to the following states, and who
> > have the following degrees / diplomas".
>
> > My Django app is purely database driven - there are no documents or
> > webpages to search.
>
> > In this case where searching for Django models are guided mostly by
> > the foreign keys that model has, what search apps/solutions are most
> > appropriate? The ones I have taken a look at all talk a lot about full
> > text search, I may be wrong but I don't think that is appropriate in
> > my case.
>
> Given your specs, I don't see the point of fulltext search here.
> Unless of course you want to add a more generic search feature (like
> typing any random name or word and finding out which students have any
> association with this name or word, directly or via related models).
>
> > I am currently searching using Peter Herndon's approach 
> > (http://www.slideshare.net/tpherndon/django-search-presentation).
>
> Seems ok to me.
>
> > But this is
> > expected to be a high-traffic site and I am worried about speed and
> > performance.
>
> Did you actually benched your current solution with representative
> data and load ?
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: Preview model before saving it

2009-10-22 Thread Aaron

I've thought about using a "published" boolean but I'm not sure how
that would help.

These models are displayed on a live site, and it will be existing
models I'll be editing and previewing. While a model is in "draft
mode" I still want the old unchanged version of the model displayed on
the live site. I'm not sure how I'm going to store either the original
or the draft versions of the model, or how I'm going to replace the
original with the draft after I commit its changes.

On Oct 21, 5:38 pm, akonsu  wrote:
> hello,
>
> anything is possible. you just need to decide how you are going to
> store your changes before the model gets "really" saved so that the
> preview functionality works. where would preview get the values from?
> i propose a "published" boolean field in the model.
>
> konstantin
>
> On Oct 21, 3:41 pm, Aaron  wrote:
>
> > I'm wanting to set up model previews in the admin. I've been following
> > this guide:
>
> >http://latherrinserepeat.org/2008/7/28/stupid-simple-django-admin-pre...
>
> > However, that guide seems to only apply to models that have already
> > been saved (how is it different from "View on site"?). I wish to be
> > able to make changes to my model, click on "Preview", and see what my
> > model page will look like *before* saving it in the admin. Is this
> > possible?
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Redirects on HTTPS

2009-10-22 Thread Tim Sawyer

Hi,

I have a django app that works fine using http.  We have a requirement to
serve the entire site using https, which is being done at the proxy level
- so the Apache that my django is running inside (mod_wsgi) doesn't know
about the https.

I have a problem with using HttpResponseRedirect - the redirect is
changing the URL to be http.  Everything else about the URL is right.

How do I fix this, and have the redirect go to https?

Thanks,

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



Re: "Unsupressing" errors when called from templates

2009-10-22 Thread Peter Bengtsson

2009/10/22 bruno desthuilliers :
>
>
>
> On 21 oct, 16:00, Peter Bengtsson  wrote:
>> On 21 Oct, 14:29, bruno desthuilliers 
>> wrote:> On 21 oct, 15:05, Peter Bengtsson  wrote:
>>
>> >  a NotImplementedError would be more appropriate !-) 
>>
>> I don't know what  means
>
> oops, sorry - it's french for "OT".
>
>>
>> > Did you actually tried with this exact code ? If yes, this contradicts
>> > the FineManual(tm)
>>
>>
>> That's true for other exceptions only. E.g. ValueError or
>> ZeroDivisionError
>
> Yeps - I've seen your other posts and the link to the ticket since I
> posted this. Sorry if the answer looked a bit patronizing, but more
> often than not, posters fail to read the FineManual(tm) - or to find
> the relevant section.
>
It did but I would have written the same in reply if I suspected
someone hadn't skimmed the manual.


>> There is.http://code.djangoproject.com/ticket/11421
>>
>> I've written a patch that solves it already. Now working on tests for
>> it.
>
> Well done.
>
> >
>



-- 
Peter Bengtsson,
work www.fry-it.com
home www.peterbe.com
hobby www.issuetrackerproduct.com
fun crosstips.org

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



Re: "Unsupressing" errors when called from templates

2009-10-22 Thread bruno desthuilliers



On 21 oct, 16:00, Peter Bengtsson  wrote:
> On 21 Oct, 14:29, bruno desthuilliers 
> wrote:> On 21 oct, 15:05, Peter Bengtsson  wrote:
>
> >  a NotImplementedError would be more appropriate !-) 
>
> I don't know what  means

oops, sorry - it's french for "OT".

>
> > Did you actually tried with this exact code ? If yes, this contradicts
> > the FineManual(tm)
>
>
> That's true for other exceptions only. E.g. ValueError or
> ZeroDivisionError

Yeps - I've seen your other posts and the link to the ticket since I
posted this. Sorry if the answer looked a bit patronizing, but more
often than not, posters fail to read the FineManual(tm) - or to find
the relevant section.

> There is.http://code.djangoproject.com/ticket/11421
>
> I've written a patch that solves it already. Now working on tests for
> it.

Well done.

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



Re: edit fieldset.html template

2009-10-22 Thread onoxo

is there some kind of manual/procedure to use objects in template
pages?

On Oct 21, 10:40 pm, onoxo  wrote:
> hi!
> i have a model and I'm using it as inline in admin site. here is the
> code:
>
> models.py
>
> class PhotoItem(models.Model):
>     order = models.IntegerField(blank = True, null = True)
>     itemset = models.ForeignKey('PhotoSet', related_name='photoset')
>     item = models.ForeignKey('Photo', related_name='photoitem')
>
> admin.py
>
> class PhotoItemInline(admin.StackedInline):
>     model = PhotoItem
>     ordering = ['order']
>     raw_id_fields = ['item']
>     extra = 5
>
> i want to use value (item.image) from PhotoItem object (witch is a
> string that represents s path to image) in "templates/admin/includes/
> fieldset.html" template. the problem is that i dont know how to refer
> to that attribute (item.image) when I'm in html.
> since i'm designer i'll show you what i need, this is the picture of
> field that i need to create in inlines (this is done in filebrowser
> app):http://vedran.webfactional.com/kontenjner/fb.png
>
>  i've try to put this on many places:
> item.image
> but it's not working.
>
> could someone please help me with this one?
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: Inner Join perhaps?

2009-10-22 Thread The Danny Bos


Actually, that's no good as it craps out if there's no matching
records in CollectionUser.
Back to the drawing board ... Any better ideas?



d

- - -


On Oct 22, 9:01 pm, The Danny Bos  wrote:
> Hey there, I want to loop through all items in CollectionItem
> (models.py below), build a list of the items, then get
> CollectionUser.grade if that exists where (user=request.user) and it's
> associated with the item in CollectionItem list.
>
> eg:
>
> "Item 1" - ""
> "Item 2" - "Grade = 89"
> "Item 3" - ""
> "Item 4" - "Grade = 5"
> "Item 5" - "Grade = 34"
> "Item 5" - ""
>
> Here's my models.py
>
> class Collection(models.Model):
>         title = models.CharField(max_length=50, unique=True)
>         description = models.TextField(blank=True)
>
> class CollectionItem(models.Model):
>         collection = models.ForeignKey(Collection)
>         image = models.ImageField(blank=True, upload_to='temp/')
>
> class CollectionUser(models.Model):
>         user = models.ForeignKey(User)
>         collection_item = models.ForeignKey(CollectionItem, blank=True)
>         grade = models.CharField(max_length=10)
>
> Know what I mean?
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: 500.html does not load

2009-10-22 Thread raj

Hi,

> On Oct 21, 2:50 pm, NoviceSortOf  wrote:
> > Although I have 500.html in my
> > site-packages/django/contrib/admin/templates folder 500.html does not
> > appear when it should, below see my errors (I've included the
> > traceback items below).
>
> > Is there something else I need to configure to get 500.html to load?
> > TemplateDoesNotExist: 500.html

Seems like server is expecting a non-admin template. Just copy that
500.html from contrib/admin/templates to your templates directory
where all other non-admin templates are kept. Let's hope it'll work,
given that you have pointed to that template location from within your
settings.


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



Re: Problem about write data into the DB

2009-10-22 Thread bruno desthuilliers

On 21 oct, 17:28, 邓超  wrote:
> Hi all,
>   I deployed a django app on my laptop, the whole environment is like this:
> the OS is UBUNTU904, the web server is Apache,

If it's only for personal use on a single laptop, setting up Apache is
possibly overkill - you could as well use the builtin dev server.

>  and the database is sqlite3.
> The deployment is success, but  when I try to write some data into the
> database, I get the HTTP 500 error. And I check the error log, it
> shows "*OperationalError:
> unable to open database file*". What does this error mean? If there are some
> operation permission need configure?

Does the Apache process have r/w access on the sqlite DB file ? (on
ubuntu, the user account for Apache is "www-data").


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



Re: Inner Join perhaps?

2009-10-22 Thread The Danny Bos


I think I've got it.
Does the below look right and would it run ok with 1000 Items on a
page?

test_sql = ((t, t.collectionuser_set.get(user=request.user)) for t in
CollectionItem.objects.filter(collection=collection))

for item, useritems in test_sql:
print 'Test: %s - %s' % (item.title, useritems.grade)





On Oct 22, 9:01 pm, The Danny Bos  wrote:
> Hey there, I want to loop through all items in CollectionItem
> (models.py below), build a list of the items, then get
> CollectionUser.grade if that exists where (user=request.user) and it's
> associated with the item in CollectionItem list.
>
> eg:
>
> "Item 1" - ""
> "Item 2" - "Grade = 89"
> "Item 3" - ""
> "Item 4" - "Grade = 5"
> "Item 5" - "Grade = 34"
> "Item 5" - ""
>
> Here's my models.py
>
> class Collection(models.Model):
>         title = models.CharField(max_length=50, unique=True)
>         description = models.TextField(blank=True)
>
> class CollectionItem(models.Model):
>         collection = models.ForeignKey(Collection)
>         image = models.ImageField(blank=True, upload_to='temp/')
>
> class CollectionUser(models.Model):
>         user = models.ForeignKey(User)
>         collection_item = models.ForeignKey(CollectionItem, blank=True)
>         grade = models.CharField(max_length=10)
>
> Know what I mean?
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: Which apps/solutions are most appropriate for model based search in Django?

2009-10-22 Thread bruno desthuilliers



On 22 oct, 07:54, chefsmart  wrote:
> This is on stackoverflow.com also, but I guess not all Django users
> visit that site so I am posting this here also: -
>
> I have a Django app where most of the search is driven by foreign
> keys. For example, assuming Student, School, State, and
> EducationalQualification are Django models, the user would search for
> Students by specifying search criteria by selecting from lists of
> Schools, States, Degrees, Diplomas etc. That is, a search on students
> is essentially an answer to the question "Show students that belong to
> the following schools, and who belong to the following states, and who
> have the following degrees / diplomas".
>
> My Django app is purely database driven - there are no documents or
> webpages to search.
>
> In this case where searching for Django models are guided mostly by
> the foreign keys that model has, what search apps/solutions are most
> appropriate? The ones I have taken a look at all talk a lot about full
> text search, I may be wrong but I don't think that is appropriate in
> my case.

Given your specs, I don't see the point of fulltext search here.
Unless of course you want to add a more generic search feature (like
typing any random name or word and finding out which students have any
association with this name or word, directly or via related models).

> I am currently searching using Peter Herndon's approach 
> (http://www.slideshare.net/tpherndon/django-search-presentation).

Seems ok to me.

> But this is
> expected to be a high-traffic site and I am worried about speed and
> performance.


Did you actually benched your current solution with representative
data and load ?
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: Dreamhost PS installation problems.

2009-10-22 Thread Daniel Roseman

On Oct 20, 2:04 pm, wonderfullyrich  wrote:
> I'm trying to use a mix between thehttp://wiki.dreamhost.com/Django#Setup
> andhttp://webhostingreal.com/content/view/18/1/(which looks slightly
> more recent then the wiki) to setup django on a PS server with
> Dreamhost.  I'm stuck at the easy_install portion.
>
> I realize dreamhost might not be the most django friendly provider,
> but I'd like to see if I can get it working as imagining the pain of
> forklifting to a new Private Server is hard to imagine right now.
>
> I've installed the virtualenv based on the info 
> fromhttp://wiki.dreamhost.com/Python#Virtualenv. For whatever reason,
> even after I "source .bash_profile" it's still not got the right path.
>
> Can anyone give me a hint as to what might be going on and how to fix
> it?
>
> I'm getting the following error message:
>
> [clarke]$ cd ~/django/
> [clarke]$ ~/local/bin/easy_install django_src

> error: Setup script exited with error: mkpath: 'name' must be a string
> (got u'/home/.roflmao/wonderfullyrich/django/django_src/egg-dist-tmp-
> yKloQV')
>
> Thanks,
> Rich

If you're using virtualenv, you should use 'source bin/activate' to
activate the virtual environment and use its path definitions.

Note that both of the guides you link to are written for the normal
Dreamhost shared hosting, rather than the private server. Since on PS
you have root access, you should just be able to follow the standard
Django installation instructions.
--
DR.
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: concurrency and threading question

2009-10-22 Thread Graham Dumpleton



On Oct 22, 3:44 am, Javier Guerra  wrote:
> On Wed, Oct 21, 2009 at 9:49 AM, Michael Thon  wrote:
> > Thanks for pointing me towards celery.  Its probably overkill for what
> > I want to do right now but I'm going to try to set it up anyway.
>
> the roll-your-own alternative is just setting a DB table with the
> queued tasks, and a cron job (or a long-running daemon) that fetches
> the next job from the table to work on it.  it's called 'Ghetto
> queues'.  it works and for small setups can be much ligther, but for
> complex, or high-speed, or critical availability, it can quickly
> become a nightmare to set up right.
>
> note that if you write the cron job in Python, you can easily import
> Django's ORM to make really easy to share data with the webapp
>
> AFAIK, the 'Queue' module you mention gets it mostly right; but works
> only on a single Python interpreter.  If i'm not wrong, it can't
> mediate between the webapp and the background job, unless you modify
> eithermod_wsgior flup to spawn a thread for background
> processing (Graham? what would it take to add that tomod_wsgi?)

Not sure why people think they can utter my name in some arbitrary
conversation and expect me to appear. :-)

Anyway, I am not sure I understand what you perceive as the problem.
There is no problem in spawning background threads in context of web
application running under mod_wsgi. This can easily be done as side
effect of import main WSGI script file, or if properly thread
protected to avoid duplicates being started, triggered by a request
handler.

The real problem is the lifetime of the process in the context of the
web server depending on your configuration. This is why the suggestion
is that a separate daemon process independent of the web server be
used and for data about pending jobs to be communicated by the
database. Alternatively, the separate daemon process could have an XML-
RPC interface and web application could communicate to it via that.

In both these cases, if using a daemon process separate to the web
server, you then need infrastructure such as supervisor to start it up
and keep it running. This is extra setup and configuration work.

Getting back to why you don't run it in the web server, for embedded
mode you obviously have multiple processes and so in which does it
run. If you run it in one for which request originally arrived and a
future response is dependent on results cached in memory only, problem
is that you can't guarantee that requests go back to same process.

You can alleviate this using daemon mode of mod_wsgi, but does
restrict you to single process for application. In both cases you are
at the mercy of the process being restarted. For embedded mode at the
whim of Apache and for daemon mode dependent on someone touching WSGI
script file or similar. In both cases, if maximum number of requests
defined then also when that is exceeded.

One middle ground, so long as you don't periodically restart Apache,
is to create a special  mod_wsgi daemon mode process group consisting
of a single process. This daemon process wouldn't exist for the
purpose of handling requests, but purely to run your background job.

Because normally web application code wouldn't be loaded until first
request arrives for it, you would need to use WSGIImportScript
directive to preload a script file at process startup to initiate the
background thread and starting getting database from database and
processing it.

Doing this means for that process you are using Apache as a supervisor
and so at least avoid needing to install that infrastructure
separately.

Now, because it is still a web server process, the script which is
preloaded could itself be a variant of the normal WSGI script file,
including definition of the application entry point. You could then
delegate part of the URL namespace of the overall application to this
single daemon mode process, thus allowing it to also handle HTTP
requests.

This restricted set of URLs could be those which would allow one to
monitor the results of queued jobs, potentially aborting in progress
jobs or changing their operation. The original URLs which triggered
the jobs could also have been delegated here in the first place.

It could also be a distinct WSGI application support XML-RPC interface
like described before for separate daemon process outside of web
server. In this case just running it as just another daemon mode
process on same web server. You might just want to block any requests
not coming from localhost so only accessible by main application
running in same web server.

Anyway, you could certainly do various odd things with mod_wsgi daemon
mode if you really wanted to.

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

Inner Join perhaps?

2009-10-22 Thread The Danny Bos

Hey there, I want to loop through all items in CollectionItem
(models.py below), build a list of the items, then get
CollectionUser.grade if that exists where (user=request.user) and it's
associated with the item in CollectionItem list.

eg:

"Item 1" - ""
"Item 2" - "Grade = 89"
"Item 3" - ""
"Item 4" - "Grade = 5"
"Item 5" - "Grade = 34"
"Item 5" - ""

Here's my models.py

class Collection(models.Model):
title = models.CharField(max_length=50, unique=True)
description = models.TextField(blank=True)

class CollectionItem(models.Model):
collection = models.ForeignKey(Collection)
image = models.ImageField(blank=True, upload_to='temp/')

class CollectionUser(models.Model):
user = models.ForeignKey(User)
collection_item = models.ForeignKey(CollectionItem, blank=True)
grade = models.CharField(max_length=10)


Know what I mean?

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



Re: installing Django on Mac OS 10.6

2009-10-22 Thread dk

Perhaps you could post about your results.  I tried this, in setting
up a deployment server, and ran into roadblocks (which I did not
document) so I switched to sqlite.  The latter comes with the python
on snow-leopard, and the only issues I had were with permissions; I
had to make the database AND the directory holding my source code
writable by _www.

On Oct 21, 11:49 am, robin  wrote:
> Thank you very very much. I am off install the module.
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



apache authentication with django+flip+fastcgi

2009-10-22 Thread Robin Becker

We currently have django(using flup) running as a fastcgi  external server (via 
a socket) and would like to use django to control access to static apache files 
(to avoid duplicate logins etc etc); I see that fastcgi can do Authentication 
(in the http sense) and access checking. Is there a way to get django to 
control 
static access in this manner.

I know that I can start up a secondary version of my project and use it as a 
standalone fastcgi script to do what I need, but that requires me to control 
two 
  servers when changes are made and seems a bit clunky.
-- 
Robin Becker

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



Re: Caching performance regression between django 1.0 and django 1.1.1

2009-10-22 Thread mt



On Oct 19, 1:08 pm, Russell Keith-Magee 
wrote:
> On Mon, Oct 19, 2009 at 6:52 PM, mt  wrote:
>
> > Hi All,
> > I recently upgraded a high traffic site from django 1.0 to django
> > 1.1.1 and noticed that the load on the server went through the roof,
> > so I had to revert to django 1.0.
> > I've done some testing and noticed that the caching behaviour between
> > 1. 0 and 1.1.1 has changed.
> > Basically I was caching expensive database queries using memcached, in
> > django 1.0 reading from the cache is a fast operation however in
> > django 1.1.1 reading from cache causes all fields with a callable as
> > default to be called.
> > In the case where that callable is an expensive operation the
> > performance is severely affected.
> > I've created patches showing this regression for the branches
> >http://code.djangoproject.com/svn/django/branches/releases/1.0.X
> > and
> >http://code.djangoproject.com/svn/django/branches/releases/1.1.X
> > which shows the default callable being called on cache read.
>
> > My questions are:
> > 1. Is it wrong to store querysets in the cache?
>
> Strictly, a queryset doesn't contain *any* data - it's just a
> programatic representation of a SQL query. So, putting a queryset in
> the cache doesn't inherently mean that anything is being stored.
> However, if the queryset has been evaluated, there might be something
> in the queryset's internal result cache, and *that* value will be
> returned when the value is retrieved from the cache.
>
> > 2. Should I log a bug for this in the django tracker and upload my
> > test case patches?
>
> Certainly.
Hi Russell,
I've found the cause of the performance regression and have suggested
a patch on ticket 12057 (http://code.djangoproject.com/ticket/12057)
The patch runs without causing any other tests to fail in the django
tree.
Do you think this patch could have other side effects or is it OK?
Thanks
Michael

>
> > 3. Was this change made on purpose to fulfill other features?
>
> I can't think of any obvious reason that you would see a regression of
> that sort - the core infrastructure for queries didn't change between
> v1.0 and v1.1. There were some features added (such as aggregates),
> and some cleanup of the internals of value_list() and values()
> querysets, but those changes shouldn't have affected caching
> behaviour.
>
> Yours,
> Russ Magee %-)
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: Dreamhost PS installation problems.

2009-10-22 Thread Richard Jeong
 As a follow up, does anyone know of a individual/group that I can pay to
help me resolve this error?  As this is work related I need to get it
resolve and I can't afford to leave dreamhost right now.  I'd like to see if
I can find someone who can spend an hour or two an help me find out if it's
problem that's resolveable or if I'm totally screwed until Dreamhost get's
it's act together.

Cheers,
Rich

rje...@spamcop.net
skype: rjeong
blog: blog.wonderfullyrich.net
http://imgs.xkcd.com/comics/beliefs.jpg


On Tue, Oct 20, 2009 at 16:04, wonderfullyrich wrote:

> I'm trying to use a mix between the http://wiki.dreamhost.com/Django#Setup
> and http://webhostingreal.com/content/view/18/1/ (which looks slightly
> more recent then the wiki) to setup django on a PS server with
> Dreamhost.  I'm stuck at the easy_install portion.
>
> I realize dreamhost might not be the most django friendly provider,
> but I'd like to see if I can get it working as imagining the pain of
> forklifting to a new Private Server is hard to imagine right now.
>
> I've installed the virtualenv based on the info from
> http://wiki.dreamhost.com/Python#Virtualenv . For whatever reason,
> even after I "source .bash_profile" it's still not got the right path.
>
> Can anyone give me a hint as to what might be going on and how to fix
> it?
>
> I'm getting the following error message:
>
> [clarke]$ cd ~/django/
> [clarke]$ ~/local/bin/easy_install django_src
> Processing django_src
> Running setup.py -q bdist_egg --dist-dir /home/.roflmao/
> wonderfullyrich/django/django_src/egg-dist-tmp-yKloQV
> zip_safe flag not set; analyzing archive contents...
> django.templatetags.__init__: module references __path__
> django.contrib.admindocs.views: module references __path__
> django.contrib.auth.tests.views: module references __file__
> django.contrib.admin.__init__: module references __path__
> django.contrib.gis.gdal.tests.test_ds: module references __file__
> django.contrib.gis.tests.layermap.tests: module references __file__
> django.contrib.gis.tests.geoapp.tests: module references __file__
> django.core.management.sql: module references __file__
> django.core.management.base: module references __path__
> django.core.management.__init__: module references __file__
> django.core.management.__init__: module references __path__
> django.core.management.commands.loaddata: module references __file__
> django.core.servers.basehttp: module references __path__
> django.template.loaders.app_directories: module references __file__
> django.db.__init__: module references __path__
> django.db.models.loading: module references __file__
> django.utils.autoreload: module references __file__
> django.utils.version: module references __path__
> django.utils.translation.trans_real: module references __file__
> django.views.i18n: module references __file__
> django.test._doctest: module references __file__
> django.test._doctest: module MAY be using inspect.getsourcefile
> django.test.simple: module references __file__
> django.conf.__init__: module references __file__
> django.conf.project_template.manage: module references __file__
> error: Setup script exited with error: mkpath: 'name' must be a string
> (got u'/home/.roflmao/wonderfullyrich/django/django_src/egg-dist-tmp-
> yKloQV')
>
>
> Thanks,
> Rich

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



multiple Sites, multiple Users, a User is restricted to one Site

2009-10-22 Thread ncherro

I'm working on a CMS project, and my idea is to have one Django
project serve multiple websites.  I want to set things up so that
user1, user2, user3, etc... can log into my CMS website (e.g. www.cms.com)
and update their respective websites (e.g. user1 updates www.user1.com,
user2 updates www.user2.com, etc).  Each user must be restricted to
his own website (i.e. user1 cannot access www.user2.com through the
admin section).

Is this kind of setup possible with Django?  If so, can someone point
me in the right direction?

Thanks,
Nick

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