Re: Using Sum() for a models method inside a Query

2014-11-24 Thread monoBOT
You can create a model method (with no parameter) that can solve that, so
you can call it from the templates.

something like:

class MyObject(models.Model):
a = models.IntegerField()
b = models.Integerfield()

def miOperation(self):
return self.a + self.b

def miOtherOpertion(self):
return self.a * self.b



2014-11-24 4:21 GMT+00:00 Ethan Blackburn :

> related: https://groups.google.com/forum/#!topic/django-users/s9qgXC4TNrA
>
> Short answer: you can't. A raw query would be your best bet(i.e. "SELECT
> SUM(a + b) AS sum FROM app_X")
>
>
> On Sunday, November 23, 2014 4:42:48 PM UTC-6, Jorge Andrés Vergara Ebratt
> wrote:
>>
>> Hello everyone,
>>
>> Well, the tittle says it all:
>>
>> I have a model X
>>
>> class X(models.Model)
>> a = models.IntegerField()
>> b = models.IntegerField()
>>
>> def getC(self):
>> return a + b
>>
>>
>> So, when I'm inside a template I can call {{x.getC}} and it gets the
>> method for the current instance it's in, but how can I get the Sum, or Avg
>> of that method? I tried doing Sum('getC') but I get the error because getC
>> isn't callable in the query...
>>
>> Thanks in advance for the help
>>
>> --
>> *Jorge Andres Vergara Ebratt*
>> *#SoftwareDeveloper (Or at least trying to be)*
>> *@javebratt*
>> *facebook.com/javebratt *
>>
>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/b5350447-264f-4145-be9d-8ea709673918%40googlegroups.com
> 
> .
>
> For more options, visit https://groups.google.com/d/optout.
>



-- 
*monoBOT*
Visite mi sitio(Visit my site): monobotsoft.es/blog/

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CA%2BxOsGBZFBmfcqJDMuRppms8CVp8yc0-nnWpymkomUUQ07_fbQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Obtaining content from Git

2014-11-24 Thread martin f krafft
also sprach Russell Keith-Magee  [2014-11-24 07:16 
+0100]:
> The right place is in the view.
[…]
> If you want to do "interesting" things like retrieve a specific
> file version, you're not going to be able to use the storage API,
> because most raw

Interesting perspective you have there, which I can follow very
well. Thanks!

But let me dig a bit further, nevertheless:

> The storage layer is an abstraction to enable reusable apps. If
> I write a "user profile" app that needs to store an avatar, then
> I don't care where that avatar comes from, as long as it's
> available. It could be on a local filesystem; it could be on
> a cloud file store (like S3). The storage API lets me do that.

It could come from Git! After all, Git is really a database by
itself, just like the filesystem could be viewed as a database. So
somewhere in my idealist brain there's this theory that I could just
add a Git-storage-plugin to the storage layer and that would cause
content to be fetched from Git auto-magically if the
request-for-data by the view (not the HTTP request) matches certain
criteria and those data are available in Git. If not, then the
lookup goes to the next storage plugin.

So my view might call some sort of lookup() function, e.g.

  lookup_description(event_id)

which just returns a string. Ordinarily, this string comes from
pgsql at the moment. What I'd like to see is a way to override this
function so that instead the data are fetched from
  git.example.org/myrepo.git, branch=live, file=events/$event_id

Obviously, I could just as well call the Git-specific stuff straight
from the view, but that would inevitably tie the view to Git. Maybe
this is what I want, I am just trying to explain how I approached
this and what led me to ask the question the way I did.

> If you're just looking to read the *current* value in a git
> repository, then just use normal filesystem storage over a normal
> git checkout.

Yeah, this might well be the best option, also in terms of
performance, unless I want to keep track of blob hashes to avoid
doing the whole branch→tree→blob lookup every time, which the
filesystem "caches" for me.

Do you know of a simple example that fetches data from the
filesystem? I am being lazy here as I am sure there's plenty, so
feel free to RTFM me! ;) However, maybe you know a very good example
that makes everything so clear and then I'd really appreciate this
over wading through the various means. I know Django has provisions
for serving static files, but somehow it seems like that's not what
I want… (since the files are not actually static and a given path
could return different data on subsequent calls)



Furthermore, I'd actually like to post-process the data. The Git
repo would contain reStructuredText files and I'd like to render
them before filling the result into template slots.

This makes me think that there ought to be a cache involved at this
level. Sure, I could make a simple expiration-based cache, but I'd
really rather make the cache depend on the mtime of the underlying
source file on the filesystem (but include the post-processing step
in between).

Have you seen something like this done? Is this also still best done
in a view?

Thanks a lot for your patience and helpful replies!

-- 
@martinkrafft | http://madduck.net/ | http://two.sentenc.es/
 
review of a chemistry paper:
  "paper should be greatly reduced or completely oxidized."
-- frank vastola
 
spamtraps: madduck.bo...@madduck.net

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/20141124090640.GA30500%40albatross.lehel.madduck.net.
For more options, visit https://groups.google.com/d/optout.


digital_signature_gpg.asc
Description: Digital signature (see http://martin-krafft.net/gpg/sig-policy/999bbcc4/current)


Re: Obtaining content from Git

2014-11-24 Thread Tim Chase
On 2014-11-24 10:06, martin f krafft wrote:
> It could come from Git! After all, Git is really a database by
> itself, just like the filesystem could be viewed as a database.
[snip]
> Furthermore, I'd actually like to post-process the data. The Git
> repo would contain reStructuredText files and I'd like to render
> them before filling the result into template slots.

You'd still have to sort out how to know which blob you want to
return/render.  If you have the hash-id of it, you can do a direct
lookup.  Throwing together some pseudo-code, your urls.py might look
something like

  urlpatterns = patterns('',
url(r'^blob/([0-9a-f]{40})/$', 'myapp.views.render_blob', ...),
)

and then in myapp/views.py you'd have something like

  from django.shortcuts import render
  import some_git_lib
  import your_markdown_lib

  def render_blob(request, sha):
try:
  blob = some_git_lib.fetch_blob(sha)
except some_git_lib.SomeException:
  raise # do some actual error handling/reporting here
else:
  rendered_markdown = your_markdown_lib.htmlize(blob)
  return render(request, "my_template.html", {"data": blob})

Only you know how the sha1 of the blob is determined, but the rest
should give you a pretty straight-forward implementation.  In theory,
you could also set the cache control headers in the response so that
they're ludicrously far in the future (assuming you don't plan to
change your my_template.html) because the blob shouldn't ever change
without having a different SHA1.

-tkc



-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/20141124041927.20723b62%40bigbox.christie.dr.
For more options, visit https://groups.google.com/d/optout.


Re: Obtaining content from Git

2014-11-24 Thread Russell Keith-Magee
On Mon, Nov 24, 2014 at 5:06 PM, martin f krafft 
wrote:

> also sprach Russell Keith-Magee  [2014-11-24
> 07:16 +0100]:
> > The right place is in the view.
> […]
> > If you want to do "interesting" things like retrieve a specific
> > file version, you're not going to be able to use the storage API,
> > because most raw
>
> Interesting perspective you have there, which I can follow very
> well. Thanks!
>
> But let me dig a bit further, nevertheless:
>
> > The storage layer is an abstraction to enable reusable apps. If
> > I write a "user profile" app that needs to store an avatar, then
> > I don't care where that avatar comes from, as long as it's
> > available. It could be on a local filesystem; it could be on
> > a cloud file store (like S3). The storage API lets me do that.
>
> It could come from Git! After all, Git is really a database by
> itself, just like the filesystem could be viewed as a database. So
> somewhere in my idealist brain there's this theory that I could just
> add a Git-storage-plugin to the storage layer and that would cause
> content to be fetched from Git auto-magically if the
> request-for-data by the view (not the HTTP request) matches certain
> criteria and those data are available in Git. If not, then the
> lookup goes to the next storage plugin.
>
> So my view might call some sort of lookup() function, e.g.
>
>   lookup_description(event_id)
>
> which just returns a string. Ordinarily, this string comes from
> pgsql at the moment. What I'd like to see is a way to override this
> function so that instead the data are fetched from
>   git.example.org/myrepo.git, branch=live, file=events/$event_id
>
> Obviously, I could just as well call the Git-specific stuff straight
> from the view, but that would inevitably tie the view to Git. Maybe
> this is what I want, I am just trying to explain how I approached
> this and what led me to ask the question the way I did.
>

Perhaps I wasn't clear. Of course an avatar could come from a git store. My
point is that it's not a natural mapping. A file system is a mapping
between a path name and a binary blob. Git has an additional layer - the
path name, *plus* a historical version (referenced either by a hash, or a
date). And you can't arbitrarily write to any point in a Git tree. Ok...
you can if you're willing to have orphan nodes, but if you're thinking
about version control in the traditional sense, a git repository can only
be written to the "end" of history, but read from any point in it's history.

You might be able to write a mapping to Storage that did some sort of
naming trick (e.g., split off a colon at the end of a filename for read, so
you could request "/my/file.txt:deadbeef" to request the "deadbeaf" hash of
/my/file.txt") - but my point is that the storage API doesn't contain a
*natural* endpoint for version information.

And, even if you did this, what you're going to get is a view of your Git
repository that tries *really* hard to make it look like just a normal file
system. All the interesting features will, by necessity of the interface,
be buried. If you actually want to do anything interesting based on the
fact that you're using a git store under the hood, you're better served
working closer to the metal.

> If you're just looking to read the *current* value in a git
> > repository, then just use normal filesystem storage over a normal
> > git checkout.
>
> Yeah, this might well be the best option, also in terms of
> performance, unless I want to keep track of blob hashes to avoid
> doing the whole branch→tree→blob lookup every time, which the
> filesystem "caches" for me.
>
> Do you know of a simple example that fetches data from the
> filesystem? I am being lazy here as I am sure there's plenty, so
> feel free to RTFM me! ;) However, maybe you know a very good example
> that makes everything so clear and then I'd really appreciate this
> over wading through the various means. I know Django has provisions
> for serving static files, but somehow it seems like that's not what
> I want… (since the files are not actually static and a given path
> could return different data on subsequent calls)
>
> A simple example that fetches data from the filesystem? Sure:

def myview(request):
with open('filename.txt') as datafile:
data = datafile.read()
return render(request, 'my template.html', {'data': data})

You're possibly getting lost by thinking that this is a "Django" thing - it
isn't. Basic Python is always an option.

Furthermore, I'd actually like to post-process the data. The Git
> repo would contain reStructuredText files and I'd like to render
> them before filling the result into template slots.
>
> This makes me think that there ought to be a cache involved at this
> level. Sure, I could make a simple expiration-based cache, but I'd
> really rather make the cache depend on the mtime of the underlying
> source file on the filesystem (but include the post-processing step
> in between)


Sure - so you can cac

Re: Obtaining content from Git

2014-11-24 Thread martin f krafft
also sprach Tim Chase  [2014-11-24 11:19 +0100]:
>   urlpatterns = patterns('',
> url(r'^blob/([0-9a-f]{40})/$', 'myapp.views.render_blob', ...),
> )

… this is straight-forward, thanks. I'd probably try not to expose
the SHAs to the user but request from the Git library a blob
identified by a path such as /path/to/file which the Git
library should then map to the blob, given a treeish to use as
a base (e.g. 'master', this could come from config).

> In theory, you could also set the cache control headers in the
> response so that they're ludicrously far in the future (assuming
> you don't plan to change your my_template.html) because the blob
> shouldn't ever change without having a different SHA1.

Two problems I see with this:

  1. If the SHA is not exposed, then a request path (see above) may
 well return different content on subsequent calls, so
 expiration-based caching isn't ideal;

  2. aren't the cache-control headers for the caches downstream?
 Wouldn't this mean that if 1,000 clients requested a page, the
 reStructuredText processor would have to do the same work 1,000
 times? I'd love to cache the result and serve that while the
 source file's pre-processing mtime hasn't changed.

-- 
@martinkrafft | http://madduck.net/ | http://two.sentenc.es/
 
"i like wagner's music better than anybody's. it is so loud that one
 can talk the whole time without other people hearing what one says."
-- oscar wilde
 
spamtraps: madduck.bo...@madduck.net

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/20141124104910.GA11742%40albatross.lehel.madduck.net.
For more options, visit https://groups.google.com/d/optout.


digital_signature_gpg.asc
Description: Digital signature (see http://martin-krafft.net/gpg/sig-policy/999bbcc4/current)


Re: models.py question for setting up multiple sql entries for 1 master sql entry

2014-11-24 Thread François Schiettecatte
Hi

You should consider having a single Barcodeid table and have a one-to-many 
relationship between the Hardwareid and Barcodeid.

François
 
> On Nov 24, 2014, at 1:43 AM, Bovine Devine  wrote:
> 
> Hello,
> 
> I am creating hardware database webapp in django and I have a question for 
> how to setup my models.py to ensure I get the data entered into the mysql db 
> that I have setup.
> 
> I have my models.py setup this way:
> 
> from django.db import models
> from django.utils import timezone
> # Create your models here.
> 
> 
> class Hardwareid(models.Model):
>   hardwareid_text = models.CharField(max_length=200)
>   pub_date = models.DateField(default=timezone.now)
>   def __unicode__(self): 
>   return self.hardwareid_text
>   
>   
> class Barcodeid1(models.Model):
>   barcode1 = models.ForeignKey(Hardwareid)
>   Barcodeid1_text = models.CharField(max_length=50)
>   def __unicode__(self): 
>   return self.Barcodeid1_text
>   
> class Barcodeid2(models.Model):
>   barcode2 = models.ForeignKey(Hardwareid)
>   Barcodeid2_text = models.CharField(max_length=50)
>   def __unicode__(self): 
>   return self.Barcodeid2_text
> 
> 
> My question is do I have this setup properly? The end result I would like to 
> have is to have a "master" Hardwareid name of an item in my sql db that has 
> multiple barcodeids associated with each master hardwareid.
> 
> Is this the correct way to do it?
>   
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/django-users/47abd291-f46c-4d9b-b535-bd1ed0a7c6da%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/19DACD41-B8C6-4499-B5E4-A214709A573A%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Obtaining content from Git

2014-11-24 Thread martin f krafft
also sprach Russell Keith-Magee  [2014-11-24 11:38 
+0100]:
> Perhaps I wasn't clear.

No, you were. I am just pushing back a little bit because I come
from another angle and I greatly appreciate your explanations in
helping me understand the Django way of thinking. So in the hope
that you now don't feel exploited… ;)

> You might be able to write a mapping to Storage that did some sort
> of naming trick (e.g., split off a colon at the end of a filename
> for read, so you could request "/my/file.txt:deadbeef" to request
> the "deadbeaf" hash of /my/file.txt") - but my point is that the
> storage API doesn't contain a *natural* endpoint for version
> information.

Arguably, the ref/hash/date could come from the config, not from the
file, and suddenly there'd be a 1:1 mapping between a filesystem
store and a storage that uses Git directly.

> And, even if you did this, what you're going to get is a view of
> your Git repository that tries *really* hard to make it look like
> just a normal file system.

Yeah, this is an excellent point, especially since I'd probably not
allow pushes to that Git repository but instead set up some sort of
polling or regular interval pulling. Then I might just as well use
a filesystem.

> def myview(request):
> with open('filename.txt') as datafile:
> data = datafile.read()
> return render(request, 'my template.html', {'data': data})
> 
> You're possibly getting lost by thinking that this is a "Django" thing - it
> isn't. Basic Python is always an option.

Yeah, but I would like to assume that this has been wrapped for
Django at least one "canonical" time, with all error handling done
and proper cache integration taken care of.

Because to just start off with a myview() view like you suggest
above is quickly going to become a full-time project, if you know
what I mean. ;)

> > Have you seen something like this done? Is this also still best
> > done in a view?
> 
> Well... yes, I've seen this done before. It's called GitHub :-)

Hehe, that was funny.

But seriously: forget about all of the Git stuff, let's just look at
the filesystem… at least in my universe, I'd like to assume that the
idea of reading marked-up data from disk, processing it, caching it
and then making the data available to templates is such an intuitive
and standard thing to do that it could even be in Django core — if
not there, then there ought to be an existing plugin for this.

Thanks for your help thus far!

-- 
@martinkrafft | http://madduck.net/ | http://two.sentenc.es/
 
don't hate yourself in the morning -- sleep till noon.
 
spamtraps: madduck.bo...@madduck.net

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/20141124114316.GA19818%40albatross.lehel.madduck.net.
For more options, visit https://groups.google.com/d/optout.


digital_signature_gpg.asc
Description: Digital signature (see http://martin-krafft.net/gpg/sig-policy/999bbcc4/current)


Re: Using Sum() for a models method inside a Query

2014-11-24 Thread Jorge Andrés Vergara Ebratt
Thanks, the best bet is the raw query, because I actually need the Sum of
the method result for all the instances in the query...

2014-11-24 3:52 GMT-05:00 monoBOT :

> You can create a model method (with no parameter) that can solve that, so
> you can call it from the templates.
>
> something like:
>
> class MyObject(models.Model):
> a = models.IntegerField()
> b = models.Integerfield()
>
> def miOperation(self):
> return self.a + self.b
>
> def miOtherOpertion(self):
> return self.a * self.b
>
>
>
> 2014-11-24 4:21 GMT+00:00 Ethan Blackburn :
>
>> related: https://groups.google.com/forum/#!topic/django-users/s9qgXC4TNrA
>>
>> Short answer: you can't. A raw query would be your best bet(i.e. "SELECT
>> SUM(a + b) AS sum FROM app_X")
>>
>>
>> On Sunday, November 23, 2014 4:42:48 PM UTC-6, Jorge Andrés Vergara
>> Ebratt wrote:
>>>
>>> Hello everyone,
>>>
>>> Well, the tittle says it all:
>>>
>>> I have a model X
>>>
>>> class X(models.Model)
>>> a = models.IntegerField()
>>> b = models.IntegerField()
>>>
>>> def getC(self):
>>> return a + b
>>>
>>>
>>> So, when I'm inside a template I can call {{x.getC}} and it gets the
>>> method for the current instance it's in, but how can I get the Sum, or Avg
>>> of that method? I tried doing Sum('getC') but I get the error because getC
>>> isn't callable in the query...
>>>
>>> Thanks in advance for the help
>>>
>>> --
>>> *Jorge Andres Vergara Ebratt*
>>> *#SoftwareDeveloper (Or at least trying to be)*
>>> *@javebratt*
>>> *facebook.com/javebratt *
>>>
>>  --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to django-users+unsubscr...@googlegroups.com.
>> To post to this group, send email to django-users@googlegroups.com.
>> Visit this group at http://groups.google.com/group/django-users.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/b5350447-264f-4145-be9d-8ea709673918%40googlegroups.com
>> 
>> .
>>
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
>
> --
> *monoBOT*
> Visite mi sitio(Visit my site): monobotsoft.es/blog/
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CA%2BxOsGBZFBmfcqJDMuRppms8CVp8yc0-nnWpymkomUUQ07_fbQ%40mail.gmail.com
> 
> .
>
> For more options, visit https://groups.google.com/d/optout.
>



-- 
*Jorge Andres Vergara Ebratt*
*#SoftwareDeveloper (Or at least trying to be)*
*@javebratt*
*facebook.com/javebratt *

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAAeX05Fj7zX%2B_4fyW9d8c20rg6ggRxvm1PavmRA4ymrNTSDkbQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Using Sum() for a models method inside a Query

2014-11-24 Thread monoBOT
You can also do that using the ORM instead of SQL, just instead of doing
the calls on the instanced model use a manager and do the calls on all the
objects in the database, something like this:

class Objectmanager(models.Manager):
def SumAB(self):
return sum([(obj.a + obj.b) for obj in MyObject.objects.all()])

class MyObject(models.Model):
a = models.IntegerField()
b = models.Integerfield()

objects = ObjectManager()


2014-11-24 11:53 GMT+00:00 Jorge Andrés Vergara Ebratt 
:

> Thanks, the best bet is the raw query, because I actually need the Sum of
> the method result for all the instances in the query...
>
> 2014-11-24 3:52 GMT-05:00 monoBOT :
>
>> You can create a model method (with no parameter) that can solve that, so
>> you can call it from the templates.
>>
>> something like:
>>
>> class MyObject(models.Model):
>> a = models.IntegerField()
>> b = models.Integerfield()
>>
>> def miOperation(self):
>> return self.a + self.b
>>
>> def miOtherOpertion(self):
>> return self.a * self.b
>>
>>
>>
>> 2014-11-24 4:21 GMT+00:00 Ethan Blackburn :
>>
>>> related:
>>> https://groups.google.com/forum/#!topic/django-users/s9qgXC4TNrA
>>>
>>> Short answer: you can't. A raw query would be your best bet(i.e. "SELECT
>>> SUM(a + b) AS sum FROM app_X")
>>>
>>>
>>> On Sunday, November 23, 2014 4:42:48 PM UTC-6, Jorge Andrés Vergara
>>> Ebratt wrote:

 Hello everyone,

 Well, the tittle says it all:

 I have a model X

 class X(models.Model)
 a = models.IntegerField()
 b = models.IntegerField()

 def getC(self):
 return a + b


 So, when I'm inside a template I can call {{x.getC}} and it gets the
 method for the current instance it's in, but how can I get the Sum, or Avg
 of that method? I tried doing Sum('getC') but I get the error because getC
 isn't callable in the query...

 Thanks in advance for the help

 --
 *Jorge Andres Vergara Ebratt*
 *#SoftwareDeveloper (Or at least trying to be)*
 *@javebratt*
 *facebook.com/javebratt *

>>>  --
>>> You received this message because you are subscribed to the Google
>>> Groups "Django users" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to django-users+unsubscr...@googlegroups.com.
>>> To post to this group, send email to django-users@googlegroups.com.
>>> Visit this group at http://groups.google.com/group/django-users.
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/django-users/b5350447-264f-4145-be9d-8ea709673918%40googlegroups.com
>>> 
>>> .
>>>
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>>
>>
>> --
>> *monoBOT*
>> Visite mi sitio(Visit my site): monobotsoft.es/blog/
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to django-users+unsubscr...@googlegroups.com.
>> To post to this group, send email to django-users@googlegroups.com.
>> Visit this group at http://groups.google.com/group/django-users.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/CA%2BxOsGBZFBmfcqJDMuRppms8CVp8yc0-nnWpymkomUUQ07_fbQ%40mail.gmail.com
>> 
>> .
>>
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
>
> --
> *Jorge Andres Vergara Ebratt*
> *#SoftwareDeveloper (Or at least trying to be)*
> *@javebratt*
> *facebook.com/javebratt *
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAAeX05Fj7zX%2B_4fyW9d8c20rg6ggRxvm1PavmRA4ymrNTSDkbQ%40mail.gmail.com
> 
> .
>
> For more options, visit https://groups.google.com/d/optout.
>



-- 
*monoBOT*
Visite mi sitio(Visit my site): monobotsoft.es/blog/

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr

Unable to open URL in new tab from ajax hit

2014-11-24 Thread swapnil srivastava
Ext.Ajax.request({
url: 'generate_birt/',
});

in view.py 


def generate_birt(request):
url = 
'http://10.2.114.2:8080/birt/frameset?__report=report/test.rptdesign&sample=my+parameter&__format=pdf'
return  HttpResponseRedirect(url,mimetype='pdf')

following error throws  


XMLHttpRequest cannot load 
http://10.2.114.2:8080/birt/frameset?__report=report/test.rptdesign&sample=my+parameter&__format=pdf.
 
No 'Access-Control-Allow-Origin' header is present on the requested 
resource. Origin 'http://10.2.114.2:8000' is therefor

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/967fea96-34c0-4c93-a13f-887b0e11e7ed%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Meta inheritance across abstract base class

2014-11-24 Thread Torsten Bronger
Hallöchen!

I have the following model structure:

class A(models.Model):
...
class Meta:
ordering = ["timestamp"]
get_latest_by = "timestamp"

class B(A):
class Meta(A.Meta):
abstract = True

class C(B):
...

Then, class C doesn't haven ordering or get_latest_by set.  Is this
expected behaviour?  Then, I would simply re-define them in B.

Tschö,
Torsten.

-- 
Torsten BrongerJabber ID: torsten.bron...@jabber.rwth-aachen.de
  or http://bronger-jmp.appspot.com

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/87h9xospms.fsf%40physik.rwth-aachen.de.
For more options, visit https://groups.google.com/d/optout.


Re: Web and mobile app with Django? Kivy? sth else?

2014-11-24 Thread Collin Anderson
Hi,

Django can do all of those things except the native android/ios apps. 
Django specializes in websites and especially helpful for handling things 
like logging in, querying a database, processing form input, and generating 
html.

Here are some ways Django can help with your situation:
You could build native android/ios apps and use Django for the server side 
of your app, like how Instagram does it. You could handle the desktop side 
as a website made with Django. If you really wanted low-cost-maintenance, 
you could have your android and ios apps just be simple wrappers around a 
webview that's loading content from Django.

Collin


On Friday, November 21, 2014 9:56:38 AM UTC-5, Mariusz Wilk wrote:
>
> I'm new to programming. Eventually, I'd like to make a website and an 
> android/ios app that would work together and display pretty much the same 
> content on a mobile as on the the web. Each client would log in (via mobile 
> or desktop) and continue solving some exercises from the place he 
> previously finished at. I have a potential client for this app, I don't 
> have any deadline and if it works fine I shouldn't have any problems 
> selling it to him and getting some commercial experience! So my question 
> is: *what should I be learning to eventually reach this goal?* I've done 
> a few Python tutorials/courses online, I played around with HTML, CSS and 
> JS, right now I'm learning Kivy. Django scared me a lot, but maybe I should 
> give it another try.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/e4e4ed98-407b-41c1-841c-0d91eb70de7c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Form doesn't show in HTML template

2014-11-24 Thread Collin Anderson
Hi,

Are the form fields in the html source (view source) and then getting 
hidden using CSS or removed using JavaScript?

What does this output? {% if form %}Yes, there's a form{% else %}No form{% 
endif %}

Collin


On Friday, November 21, 2014 11:33:16 AM UTC-5, Some Developer wrote:
>
> On 21/11/14 15:31, Vijay Khemlani wrote: 
> > If you manually call the form "as_p" method in the view (not the 
> > template), does it print the form? 
> > 
>
> OK. Sorted that out. 
>
> Running my program through the debugger shows that the form object 
> exists and has the correct fields associated with it. 
>
> I don't understand this. Everything I look at says that the form should 
> display correctly and it just isn't. The form_class has been 
> instantiated correctly, there are no errors or warnings when I run my 
> code. The template gets the form object passed to it as a context 
> object. The only thing that doesn't happen is the form being displayed. 
>
> Very strange indeed. 
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/a3f47557-0bb9-4406-8546-e8b262821bc8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Has anyone successfully used django-concurrency?

2014-11-24 Thread Collin Anderson
Hi Ian,

You may want to try opening an issue on django-consurrency showing the 
error you're getting.

https://github.com/saxix/django-concurrency/issues

Thanks,
Collin


On Friday, November 21, 2014 6:16:14 PM UTC-5, ia...@me.com wrote:
>
> Hey everyone,
>
> One last try. I've given up on django-locking, and am now trying 
> django-concurrency because it's more modern and more likely to work on 
> Django 1.6.8's admin interface.
>
> The documentation is very basic and doesn't actually give any examples, so 
> I'm not sure if I've missed something, but I'm getting this exception when 
> I modify my ConfigurationAdmin class to inherit from ConcurrentModelAdmin as 
> the documentation discusses. 
> 
>
> class ConfigurationAdmin(ConcurrentModelAdmin):
>
> form = forms.ConfigurationForm
> change_list_template = 'admin/configuration/change_list.html'
>
> ...
>
>
>
> Internal Server Error: /test/common/configuration/
> Traceback (most recent call last):
>   File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py", 
> line 137, in get_response
> response = response.render()
>   File "/usr/local/lib/python2.7/dist-packages/django/template/response.py", 
> line 105, in render
> self.content = self.rendered_content
>   File "/usr/local/lib/python2.7/dist-packages/django/template/response.py", 
> line 82, in rendered_content
> content = template.render(context)
>   File "/usr/local/lib/python2.7/dist-packages/django/template/base.py", line 
> 140, in render
> return self._render(context)
>   File "/usr/local/lib/python2.7/dist-packages/django/test/utils.py", line 
> 85, in instrumented_test_render
> return self.nodelist.render(context)
>   File "/usr/local/lib/python2.7/dist-packages/django/template/base.py", line 
> 840, in render
> bit = self.render_node(node, context)
>   File "/usr/local/lib/python2.7/dist-packages/django/template/debug.py", 
> line 78, in render_node
> return node.render(context)
>   File 
> "/usr/local/lib/python2.7/dist-packages/django/template/loader_tags.py", line 
> 123, in render
> return compiled_parent._render(context)
>   File "/usr/local/lib/python2.7/dist-packages/django/test/utils.py", line 
> 85, in instrumented_test_render
> return self.nodelist.render(context)
>   File "/usr/local/lib/python2.7/dist-packages/django/template/base.py", line 
> 840, in render
> bit = self.render_node(node, context)
>   File "/usr/local/lib/python2.7/dist-packages/django/template/debug.py", 
> line 78, in render_node
> return node.render(context)
>   File 
> "/usr/local/lib/python2.7/dist-packages/django/template/loader_tags.py", line 
> 123, in render
> return compiled_parent._render(context)
>   File "/usr/local/lib/python2.7/dist-packages/django/test/utils.py", line 
> 85, in instrumented_test_render
> return self.nodelist.render(context)
>   File "/usr/local/lib/python2.7/dist-packages/django/template/base.py", line 
> 840, in render
> bit = self.render_node(node, context)
>   File "/usr/local/lib/python2.7/dist-packages/django/template/debug.py", 
> line 78, in render_node
> return node.render(context)
>   File 
> "/usr/local/lib/python2.7/dist-packages/django/template/loader_tags.py", line 
> 123, in render
> return compiled_parent._render(context)
>   File "/usr/local/lib/python2.7/dist-packages/django/test/utils.py", line 
> 85, in instrumented_test_render
> return self.nodelist.render(context)
>   File "/usr/local/lib/python2.7/dist-packages/django/template/base.py", line 
> 840, in render
> bit = self.render_node(node, context)
>   File "/usr/local/lib/python2.7/dist-packages/django/template/debug.py", 
> line 78, in render_node
> return node.render(context)
>   File 
> "/usr/local/lib/python2.7/dist-packages/django/template/loader_tags.py", line 
> 62, in render
> result = block.nodelist.render(context)
>   File "/usr/local/lib/python2.7/dist-packages/django/template/base.py", line 
> 840, in render
> bit = self.render_node(node, context)
>   File "/usr/local/lib/python2.7/dist-packages/django/template/debug.py", 
> line 78, in render_node
> return node.render(context)
>   File 
> "/usr/local/lib/python2.7/dist-packages/django/template/loader_tags.py", line 
> 62, in render
> result = block.nodelist.render(context)
>   File "/usr/local/lib/python2.7/dist-packages/django/template/base.py", line 
> 840, in render
> bit = self.render_node(node, context)
>   File "/usr/local/lib/python2.7/dist-packages/django/template/debug.py", 
> line 78, in render_node
> return node.render(context)
>   File "/usr/local/lib/python2.7/dist-packages/django/template/base.py", line 
> 1196, in render
> _dict = func(*resolved_args, **resolved_kwargs)
>   File 
> "/usr/local/lib/python2.7/dist-packages/django/contrib/admin/templatetags/admin_list.py",
>  line 288, in result_list
> 'results': list(results(cl))}
>  

Re: Obtaining content from Git

2014-11-24 Thread Tim Chase
On 2014-11-24 11:49, martin f krafft wrote:
> also sprach Tim Chase  [2014-11-24
> 11:19 +0100]:
> >   urlpatterns = patterns('',
> > url(r'^blob/([0-9a-f]{40})/$',
> > 'myapp.views.render_blob', ...), )
> 
> … this is straight-forward, thanks. I'd probably try not to expose
> the SHAs to the user but request from the Git library a blob
> identified by a path such as /path/to/file which the Git
> library should then map to the blob, given a treeish to use as
> a base (e.g. 'master', this could come from config).

Django certainly gives you the flexibility to do both/either.  You
can even do things like

  url(r'branch/(?P[^/]*)(?P.*)', 
'myapp.views.render_branch_file', ...)

and then in your views.py

  def render_branch_file(request, branch, file_name):
data = some_git_lib.get_file_from_branch(branch, file_name)
...

You might need to tighten up those regular expressions in the urls.py
a bit, or sanitize them in the view to ensure that they don't allow
access to files outside the git tree (you might also want to prevent
access to the .git subdirectory)

> > In theory, you could also set the cache control headers in the
> > response so that they're ludicrously far in the future (assuming
> > you don't plan to change your my_template.html) because the blob
> > shouldn't ever change without having a different SHA1.
> 
> Two problems I see with this:
> 
>   1. If the SHA is not exposed, then a request path (see above) may
>  well return different content on subsequent calls, so
>  expiration-based caching isn't ideal;

You can use the resulting internal sha1 as the "etag" header which
would cache at the object level rather than at the URL level.

>   2. aren't the cache-control headers for the caches downstream?
>  Wouldn't this mean that if 1,000 clients requested a page, the
>  reStructuredText processor would have to do the same work 1,000
>  times? I'd love to cache the result and serve that while the
>  source file's pre-processing mtime hasn't changed.

yes-ish.  If you have a caching proxy such as Varnish in front of your
Django server, it can cache the pages coming out and then serve them
to all requesting clients.  I haven't dug into how that interacts
with "etag" vs. other cache-control headers, but that's where I'd
start researching.  Or just set the other cache-control headers.

-tkc








-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/20141124101138.1a76647e%40bigbox.christie.dr.
For more options, visit https://groups.google.com/d/optout.


Re: Web and mobile app with Django? Kivy? sth else?

2014-11-24 Thread Fred Stluka

+1 for writing a single RWD (Responsive Web Design) web app
using Django, instead of writing separate web, Android and iOS
apps.

If necessary, wrap the result in PhoneGap to mobile-specific
features, uploading images from the camera, capturing the
GPS location, showing maps, accessing the local file system
and contacts, etc.  But only if you need those features.

My current project uses RWD techniques to look good on
phones, tablets, and full screens.  Lots of jQuery, Ajax, HTML5
and CSS3 for a rich user experience.  Drag any of the pages
wider or narrower to see what I mean:
- http://helphopelive.org

--Fred

Fred Stluka -- mailto:f...@bristle.com -- http://bristle.com/~fred/
Bristle Software, Inc -- http://bristle.com -- Glad to be of service!
Open Source: Without walls and fences, we need no Windows or Gates.

On 11/24/14 8:37 AM, Collin Anderson wrote:

Hi,

Django can do all of those things except the native android/ios apps. 
Django specializes in websites and especially helpful for handling 
things like logging in, querying a database, processing form input, 
and generating html.


Here are some ways Django can help with your situation:
You could build native android/ios apps and use Django for the server 
side of your app, like how Instagram does it. You could handle the 
desktop side as a website made with Django. If you really wanted 
low-cost-maintenance, you could have your android and ios apps just be 
simple wrappers around a webview that's loading content from Django.


Collin


On Friday, November 21, 2014 9:56:38 AM UTC-5, Mariusz Wilk wrote:

I'm new to programming. Eventually, I'd like to make a website and
an android/ios app that would work together and display pretty
much the same content on a mobile as on the the web. Each client
would log in (via mobile or desktop) and continue solving some
exercises from the place he previously finished at. I have a
potential client for this app, I don't have any deadline and if it
works fine I shouldn't have any problems selling it to him and
getting some commercial experience! So my question is: *what
should I be learning to eventually reach this goal?* I've done a
few Python tutorials/courses online, I played around with HTML,
CSS and JS, right now I'm learning Kivy. Django scared me a lot,
but maybe I should give it another try.

--
You received this message because you are subscribed to the Google 
Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send 
an email to django-users+unsubscr...@googlegroups.com 
.
To post to this group, send email to django-users@googlegroups.com 
.

Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/e4e4ed98-407b-41c1-841c-0d91eb70de7c%40googlegroups.com 
.

For more options, visit https://groups.google.com/d/optout.


--
You received this message because you are subscribed to the Google Groups "Django 
users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/54737893.3080604%40bristle.com.
For more options, visit https://groups.google.com/d/optout.


Obtaining content from Git

2014-11-24 Thread reduxionist
>Hence I was thinking: how much trouble would it be to have Django 
>reach into Git rather than its database and obtain data there to be 
>filled into template slots? Ideally, there'd be the possibility of 
>running a filter (e.g. reStructuredText) between Git and the 
>template rendering. 

>What I envision is a storage layer (with optional caching) that 
>either fetches from the filesystem (with a Git checkout, using mtime 
>for cache expiration), or directly from a local Git repo (using 
>either commit or blob hash for cache expiration). 

>Does anyone know of such a module? 

Yes:

>Would it be hard to write? Where would one start? 

For examples of projects that do similar things:

A git-backed wiki:

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/7de0a097-ac9b-4231-86c0-e242c36a88cc%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Obtaining content from Git

2014-11-24 Thread reduxionist
Arg, Google Groups' mobile interface sucks for posting rather than reading. 
As I was trying to say:

On Tuesday, November 25, 2014 2:43:55 AM UTC+7, reduxionist wrote:
>
> >Hence I was thinking: how much trouble would it be to have Django 
> >reach into Git rather than its database and obtain data there to be 
> >filled into template slots? Ideally, there'd be the possibility of 
> >running a filter (e.g. reStructuredText) between Git and the 
> >template rendering. 
>
> >What I envision is a storage layer (with optional caching) that 
> >either fetches from the filesystem (with a Git checkout, using mtime 
> >for cache expiration), or directly from a local Git repo (using 
> >either commit or blob hash for cache expiration). 
>
> >Does anyone know of such a module? 

 
Yes:
https://bitbucket.org/bors_ltd/django-gitstorage
(before you fork to github anew, consider updating this existing, but out 
of date, github mirror: https://github.com/9h37/django-gitstorage)
 

> >Would it be hard to write? Where would one start? 
>

Here's a couple of example projects that do similar things.

A git-backed wiki: 
https://github.com/mgaitan/waliki

A mercurial based latex hosting site:
https://bitbucket.org/Svedrin/webtex
("This is a Django Project providing a WebTeX service. The way this works 
is totally ripped from BitBucket: Users have HG Repos, push their Documents 
into it, and can get a compiled version and other cool stuff over the net.")

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/13c2e5eb-0f34-41c8-a77d-6c8b799f1a96%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


How to deal with CSRF middleware from a crawler

2014-11-24 Thread Torsten Bronger
Hallöchen!

We use crawlers, which in our case a Python scripts that read data
from disk and send a lot of HTTP POST requests to the Django
deployment.  The POST requests hit the same URLs/Views that are also
used by the browser to edit something with a web .

If I activate the CSRF middleware, does this mean that our crawlers
have to make GET requests before every POST in order to get the CSRF
token?  This would slow down them significantly ...  Can one exclude
certain usernames from the CSRF checks?  Or do you see another way
of keeping the number of HTTP requests small in the crawlers?

Tschö,
Torsten.

-- 
Torsten BrongerJabber ID: torsten.bron...@jabber.rwth-aachen.de
  or http://bronger-jmp.appspot.com

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/87mw7gqshq.fsf%40physik.rwth-aachen.de.
For more options, visit https://groups.google.com/d/optout.


Re: How to deal with CSRF middleware from a crawler

2014-11-24 Thread Carl Meyer
Hi Torsten,

On 11/24/2014 01:00 PM, Torsten Bronger wrote:
> We use crawlers, which in our case a Python scripts that read data
> from disk and send a lot of HTTP POST requests to the Django
> deployment.  The POST requests hit the same URLs/Views that are also
> used by the browser to edit something with a web .
> 
> If I activate the CSRF middleware, does this mean that our crawlers
> have to make GET requests before every POST in order to get the CSRF
> token?  This would slow down them significantly ...  Can one exclude
> certain usernames from the CSRF checks?  Or do you see another way
> of keeping the number of HTTP requests small in the crawlers?

Unless you've modified the CSRF implementation locally, all it does is
check that the CSRF token provided in a cookie matches the one provided
in the POST data. This is effective because browser same-origin policy
prevents malicious JS from reading the cookie value that the user's
browser will send, or from controlling the sent cookie value.

But this means that the CSRF protection is simple to bypass in a case
like yours: you can just set the CSRF cookie and the POST var to the
same value in all your crawler's requests. It doesn't matter what that
value is.

Carl

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/547399E3.30009%40oddbird.net.
For more options, visit https://groups.google.com/d/optout.


signature.asc
Description: OpenPGP digital signature


How do I supply an appropriate application.wsgi to Gunicorn?

2014-11-24 Thread Christos Jonathan Seth Hayward
From
http://stackoverflow.com/questions/27113466/how-can-i-deploy-django-gunicorn-under-apache-proxy
:

've run through the documentation and am hitting the same pages over and
over again. At present I've found documentation to run off an existing
myapp.wsgi file, but documentation for how to make an appropriate wsgi file
is a little harder to find.

If I want to make, proxied by Apache, the equivalent of, on an older
version of Gunicorn etc.:

python manage.py run_gunicorn 0.0.0.0:

what should I be doing to supply a WSGI file for:

gunicorn project.wsgi:application

Thanks,
-- 
[image: Christos Jonathan Seth Hayward] 
Christos Jonathan Seth Hayward, an Orthodox Christian author.

Amazon / Kindle  • *Author
* • Author Bio 
 • *The Classic Orthodox Bible * • *Email
* • Facebook
 • Fan Page
• Github
 • Google Plus
 • LinkedIn
 • *Main Website
* • *Professional
* • Twitter
 • What's New?


If you read just *one* of my books, you'll want *The Best of Jonathan's
Corner * (Kindle
).

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAE6_B5SUNHzCEjoC%3D7y9tqWq-m%3DSWkYayqaQ6PNqy9BdXVqOAQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: How do I supply an appropriate application.wsgi to Gunicorn?

2014-11-24 Thread Carl Meyer
Hi,

On 11/24/2014 02:19 PM, Christos Jonathan Seth Hayward wrote:
> From
> http://stackoverflow.com/questions/27113466/how-can-i-deploy-django-gunicorn-under-apache-proxy
> :
> 
> 've run through the documentation and am hitting the same pages over and
> over again. At present I've found documentation to run off an existing
> myapp.wsgi file, but documentation for how to make an appropriate wsgi file
> is a little harder to find.
> 
> If I want to make, proxied by Apache, the equivalent of, on an older
> version of Gunicorn etc.:
> 
> python manage.py run_gunicorn 0.0.0.0:
> 
> what should I be doing to supply a WSGI file for:
> 
> gunicorn project.wsgi:application

That depends a bit on your version of Django. For any Django version
since 1.4, 'django-admin.py startproject' should generate a wsgi.py file
in your project. If your project doesn't have one, you can run
'startproject' to quickly see what one should look like and copy it into
your project.

Carl

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/5473A21F.8050801%40oddbird.net.
For more options, visit https://groups.google.com/d/optout.


signature.asc
Description: OpenPGP digital signature


Re: How do I supply an appropriate application.wsgi to Gunicorn?

2014-11-24 Thread Christos Jonathan Seth Hayward
Ok; wonder if I should upgrade Django.

I just ran a startproject earlier today (I can re-create it; I was just
trying to get it running and see the start page in my browser before going
further).

cjsh@ps306627:~/cynthia$ find . -name \*.wsgi

cjsh@ps306627:~/cynthia$ python manage.py shell

Python 2.6.6 (r266:84292, Aug 12 2014, 07:57:07)

[GCC 4.4.5] on linux2

Type "help", "copyright", "credits" or "license" for more information.

(InteractiveConsole)

>>> import django

>>> dir(django)

['VERSION', '__builtins__', '__doc__', '__file__', '__name__',
'__package__', '__path__', 'conf', 'contrib', 'core', 'db', 'dispatch',
'forms', 'get_version', 'http', 'middleware', 'shortcuts', 'template',
'templatetags', 'test', 'utils', 'views']

>>> django.VERSION

(1, 6, 5, 'final', 0)

>>>

​Further suggestions?


Thanks,

On Mon, Nov 24, 2014 at 3:24 PM, Carl Meyer  wrote:

> Hi,
>
> On 11/24/2014 02:19 PM, Christos Jonathan Seth Hayward wrote:
> > From
> >
> http://stackoverflow.com/questions/27113466/how-can-i-deploy-django-gunicorn-under-apache-proxy
> > :
> >
> > 've run through the documentation and am hitting the same pages over and
> > over again. At present I've found documentation to run off an existing
> > myapp.wsgi file, but documentation for how to make an appropriate wsgi
> file
> > is a little harder to find.
> >
> > If I want to make, proxied by Apache, the equivalent of, on an older
> > version of Gunicorn etc.:
> >
> > python manage.py run_gunicorn 0.0.0.0:
> >
> > what should I be doing to supply a WSGI file for:
> >
> > gunicorn project.wsgi:application
>
> That depends a bit on your version of Django. For any Django version
> since 1.4, 'django-admin.py startproject' should generate a wsgi.py file
> in your project. If your project doesn't have one, you can run
> 'startproject' to quickly see what one should look like and copy it into
> your project.
>
> Carl
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/5473A21F.8050801%40oddbird.net
> .
> For more options, visit https://groups.google.com/d/optout.
>



-- 
[image: Christos Jonathan Seth Hayward] 
Christos Jonathan Seth Hayward, an Orthodox Christian author.

Amazon / Kindle  • *Author
* • Author Bio 
 • *The Classic Orthodox Bible * • *Email
* • Facebook
 • Fan Page
• Github
 • Google Plus
 • LinkedIn
 • *Main Website
* • *Professional
* • Twitter
 • What's New?


If you read just *one* of my books, you'll want *The Best of Jonathan's
Corner * (Kindle
).

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAE6_B5RwmAdAmotBkmmARKZAED%3DKZyjeUk4a_Xz%3Dux%3DbA0d%2BiQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: How do I supply an appropriate application.wsgi to Gunicorn?

2014-11-24 Thread Carl Meyer


On 11/24/2014 02:38 PM, Christos Jonathan Seth Hayward wrote:
> Ok; wonder if I should upgrade Django.
> 
> I just ran a startproject earlier today (I can re-create it; I was just
> trying to get it running and see the start page in my browser before going
> further).
> 
> cjsh@ps306627:~/cynthia$ find . -name \*.wsgi

Your Django version is fine. The problem is that you're expecting to
find a file with the `.wsgi` extension. The file Django generates is
called `myproject/wsgi.py`, thus its dotted Python import path (which is
what you pass to gunicorn) is `myproject.wsgi`.

Carl

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/5473A6EF.4090107%40oddbird.net.
For more options, visit https://groups.google.com/d/optout.


signature.asc
Description: OpenPGP digital signature


Re: How do I supply an appropriate application.wsgi to Gunicorn?

2014-11-24 Thread Christos Jonathan Seth Hayward
Thanks so much!

Could you confirm the invocation?

cjsh@ps306627:~/cynthia$ gunicorn cynthia.wsgi 0.0.0.0:

usage: gunicorn [OPTIONS] [APP_MODULE]

gunicorn: error: No application module specified.

cjsh@ps306627:~/cynthia$ gunicorn cynthia.wsgi:application 0.0.0.0:

usage: gunicorn [OPTIONS] [APP_MODULE]

gunicorn: error: No application module specified.

cjsh@ps306627:~/cynthia$ gunicorn cynthia.wsgi:cynthia 0.0.0.0:

usage: gunicorn [OPTIONS] [APP_MODULE]

gunicorn: error: No application module specified.


On Mon, Nov 24, 2014 at 3:45 PM, Carl Meyer  wrote:

>
>
> On 11/24/2014 02:38 PM, Christos Jonathan Seth Hayward wrote:
> > Ok; wonder if I should upgrade Django.
> >
> > I just ran a startproject earlier today (I can re-create it; I was just
> > trying to get it running and see the start page in my browser before
> going
> > further).
> >
> > cjsh@ps306627:~/cynthia$ find . -name \*.wsgi
>
> Your Django version is fine. The problem is that you're expecting to
> find a file with the `.wsgi` extension. The file Django generates is
> called `myproject/wsgi.py`, thus its dotted Python import path (which is
> what you pass to gunicorn) is `myproject.wsgi`.
>
> Carl
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/5473A6EF.4090107%40oddbird.net
> .
> For more options, visit https://groups.google.com/d/optout.
>



-- 
[image: Christos Jonathan Seth Hayward] 
Christos Jonathan Seth Hayward, an Orthodox Christian author.

Amazon / Kindle  • *Author
* • Author Bio 
 • *The Classic Orthodox Bible * • *Email
* • Facebook
 • Fan Page
• Github
 • Google Plus
 • LinkedIn
 • *Main Website
* • *Professional
* • Twitter
 • What's New?


If you read just *one* of my books, you'll want *The Best of Jonathan's
Corner * (Kindle
).

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAE6_B5RrTBV5NB8cROvV%3D%2B_owyVDtfZrTAwvmSLrXd3hCXfMkw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: How do I supply an appropriate application.wsgi to Gunicorn?

2014-11-24 Thread Carl Meyer
On 11/24/2014 02:56 PM, Christos Jonathan Seth Hayward wrote:
> Thanks so much!
> 
> Could you confirm the invocation?
> 
> cjsh@ps306627:~/cynthia$ gunicorn cynthia.wsgi 0.0.0.0:
> 
> usage: gunicorn [OPTIONS] [APP_MODULE]
> 
> gunicorn: error: No application module specified.

That's the right invocation, but you need your python path set up to
include the directory that has `manage.py` in it (when you actually run
a `manage.py` command, this happens automatically, but not when you run
gunicorn).

There are a variety of ways that can be done, the simplest is to run
your gunicorn command from the same directory that contains `manage.py`
and set the PYTHONPATH env var:

PYTHONPATH=`pwd` gunicorn cynthia.wsgi 0.0.0.0:

Carl

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/5473AA8A.308%40oddbird.net.
For more options, visit https://groups.google.com/d/optout.


signature.asc
Description: OpenPGP digital signature


Re: How do I supply an appropriate application.wsgi to Gunicorn?

2014-11-24 Thread Carl Meyer
On 11/24/2014 03:00 PM, Carl Meyer wrote:
> On 11/24/2014 02:56 PM, Christos Jonathan Seth Hayward wrote:
>> Thanks so much!
>>
>> Could you confirm the invocation?
>>
>> cjsh@ps306627:~/cynthia$ gunicorn cynthia.wsgi 0.0.0.0:
>>
>> usage: gunicorn [OPTIONS] [APP_MODULE]
>>
>> gunicorn: error: No application module specified.
> 
> That's the right invocation, but you need your python path set up to
> include the directory that has `manage.py` in it (when you actually run
> a `manage.py` command, this happens automatically, but not when you run
> gunicorn).
> 
> There are a variety of ways that can be done, the simplest is to run
> your gunicorn command from the same directory that contains `manage.py`
> and set the PYTHONPATH env var:
> 
> PYTHONPATH=`pwd` gunicorn cynthia.wsgi 0.0.0.0:

Sorry, I was focused on the Python issues, didn't notice that you're
trying to pass a bind address without using the `-b` option. This is
what you want:

PYTHONPATH=`pwd` gunicorn -b 0.0.0.0: cynthia.wsgi

Carl

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/5473AB99.8040101%40oddbird.net.
For more options, visit https://groups.google.com/d/optout.


signature.asc
Description: OpenPGP digital signature


Re: How do I supply an appropriate application.wsgi to Gunicorn?

2014-11-24 Thread Christos Jonathan Seth Hayward
And with that, I'm off and running!

Thank you for your help.

On Mon, Nov 24, 2014 at 4:05 PM, Carl Meyer  wrote:

> On 11/24/2014 03:00 PM, Carl Meyer wrote:
> > On 11/24/2014 02:56 PM, Christos Jonathan Seth Hayward wrote:
> >> Thanks so much!
> >>
> >> Could you confirm the invocation?
> >>
> >> cjsh@ps306627:~/cynthia$ gunicorn cynthia.wsgi 0.0.0.0:
> >>
> >> usage: gunicorn [OPTIONS] [APP_MODULE]
> >>
> >> gunicorn: error: No application module specified.
> >
> > That's the right invocation, but you need your python path set up to
> > include the directory that has `manage.py` in it (when you actually run
> > a `manage.py` command, this happens automatically, but not when you run
> > gunicorn).
> >
> > There are a variety of ways that can be done, the simplest is to run
> > your gunicorn command from the same directory that contains `manage.py`
> > and set the PYTHONPATH env var:
> >
> > PYTHONPATH=`pwd` gunicorn cynthia.wsgi 0.0.0.0:
>
> Sorry, I was focused on the Python issues, didn't notice that you're
> trying to pass a bind address without using the `-b` option. This is
> what you want:
>
> PYTHONPATH=`pwd` gunicorn -b 0.0.0.0: cynthia.wsgi
>
> Carl
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/5473AB99.8040101%40oddbird.net
> .
> For more options, visit https://groups.google.com/d/optout.
>



-- 
[image: Christos Jonathan Seth Hayward] 
Christos Jonathan Seth Hayward, an Orthodox Christian author.

Amazon / Kindle  • *Author
* • Author Bio 
 • *The Classic Orthodox Bible * • *Email
* • Facebook
 • Fan Page
• Github
 • Google Plus
 • LinkedIn
 • *Main Website
* • *Professional
* • Twitter
 • What's New?


If you read just *one* of my books, you'll want *The Best of Jonathan's
Corner * (Kindle
).

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAE6_B5QMBGstoZJeVaEKN0ZuXevVS8t4Mdwk_1cbK%2B%2BTTr%2BvgA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Little baffled: object has no attribute 'save' only when running tests.

2014-11-24 Thread Detectedstealth
When writing a test to just try and create an object from my model I get 
the following error:

line 10, in test_saving_and_retrieving_fishtypes

test2.save()

AttributeError: 'FishType' object has no attribute 'save'


tests.py

from django.test import TestCase


from trip.models import FishType


class FishType(TestCase):



def test_saving_and_retrieving_fishtypes(self):

test2 = FishType()

test2.name = "Testing"

test2.save()



saved_fish_type = FishType.objects.all()

self.assertEqual(saved_fish_type.count(), 1)


models.py

from django.db import models


class FishType(models.Model):

name = models.CharField(max_length=50)



def __str__(self):

return self.name


Now when using django shell everything works as expected, but for some 
reason the tests won't work.

>>> from trip.models import *

>>> test_ = FishType()

>>> test_.save()

>>> test_



>>> test2 = FishType()

>>> test2.name = "Testing"

>>> test2.save()

>>> FishType.objects.all()

[, ]


Am I missing something? 


-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/340f84c4-47b8-4804-8daf-3e65b6f3ed3e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Little baffled: object has no attribute 'save' only when running tests.

2014-11-24 Thread Detectedstealth
Never mind I need some sleep I named my TestCase with the same name as my 
model... I can't believe I didn't see that.

class FishType(TestCase):

On Monday, November 24, 2014 2:31:33 PM UTC-8, Detectedstealth wrote:
>
> When writing a test to just try and create an object from my model I get 
> the following error:
>
> line 10, in test_saving_and_retrieving_fishtypes
>
> test2.save()
>
> AttributeError: 'FishType' object has no attribute 'save'
>
>
> tests.py
>
> from django.test import TestCase
>
>
> from trip.models import FishType
>
>
> class FishType(TestCase):
>
> 
>
> def test_saving_and_retrieving_fishtypes(self):
>
> test2 = FishType()
>
> test2.name = "Testing"
>
> test2.save()
>
> 
>
> saved_fish_type = FishType.objects.all()
>
> self.assertEqual(saved_fish_type.count(), 1)
>
>
> models.py
>
> from django.db import models
>
>
> class FishType(models.Model):
>
> name = models.CharField(max_length=50)
>
> 
>
> def __str__(self):
>
> return self.name
>
>
> Now when using django shell everything works as expected, but for some 
> reason the tests won't work.
>
> >>> from trip.models import *
>
> >>> test_ = FishType()
>
> >>> test_.save()
>
> >>> test_
>
> 
>
> >>> test2 = FishType()
>
> >>> test2.name = "Testing"
>
> >>> test2.save()
>
> >>> FishType.objects.all()
>
> [, ]
>
>
> Am I missing something? 
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/ca2243f8-a612-48a0-b95b-aeafa40b5200%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: not thread-safe function can break a django application?

2014-11-24 Thread Collin Anderson


On Saturday, November 22, 2014 4:46:56 AM UTC-5, Fabio Caritas Barrionuevo 
da Luz wrote:
>
> I was trying to answer a question in a Brazilian forum about django.
>
> one of the proposed solutions utilized the function locale.setlocale() 
> from locale module.
>
> according to the documentation[1] locale.setlocale() function is not 
> thread-safe
>
> the question is: 
>
> not thread-safe function can break a django application?
>
 Yes

If so, how? 
>
You can have "race conditions" where _sometimes_ you get unpredictable 
results.

Which scenario I would have problems? 
>
One request in one thread could set locale to English and then use the 
locale, meanwhile, another thread could set it to Spanish and then use the 
locale. If they did that at the same time, the English request might get 
the Spanish locale, or the Spanish request might get the English locale.

some easily reproducible example of problems using not thread-safe function?
>
import threading
state = {}

def english():
state['locale'] = 'english'
assert state['locale'] == 'english'

def spanish():
state['locale'] = 'spanish'
assert state['locale'] == 'spanish'

while 1:
threading.Thread(target=english).start()
threading.Thread(target=spanish).start()
 
(press ctrl+c to stop)

Also, note that it says "If the locale is not changed thereafter, using 
multithreading should not cause problems." So, if you only set it once and 
never change it, you should be fine.

Collin

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/4d3b1576-7942-418b-abe8-5f2c6cfb38ec%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Logging \u2083 as cp1252 UnicodeEncodeError in Python 3.4

2014-11-24 Thread Mike Dewhirst
Somehow recently the character causing the logging problem is one of 
many which are working well in the browser. They are unicode subscripted 
numbers for example, \u2083 is subscripted "3".


But in logging under Python 3.4 it causes

--- Logging error ---
Traceback (most recent call last):
  File "C:\Python34\Lib\logging\__init__.py", line 980, in emit 
stream.write(msg)
  File "C:\Users\mike\env\xxdx3\lib\encodings\cp1252.py", line 19, in 
encode

return codecs.charmap_encode(input,self.errors,encoding_table)[0]
UnicodeEncodeError: 'charmap' codec can't encode characters in position 
287-288: character maps to 




I assume this is because I'm running the Django dev server on Windows 8.1

I have reviewed the Python logging docs and seen no reference to code 
pages or even unicode.


There is no logging error when switching to Python 2.7

Is there anything I can do to rein this in?

Thanks

Mike

--
You received this message because you are subscribed to the Google Groups "Django 
users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/5473BBD3.8080905%40dewhirst.com.au.
For more options, visit https://groups.google.com/d/optout.


Re: Obtaining content from Git

2014-11-24 Thread Russell Keith-Magee
On Mon, Nov 24, 2014 at 7:43 PM, martin f krafft 
wrote:

> also sprach Russell Keith-Magee  [2014-11-24
> 11:38 +0100]:
> > Perhaps I wasn't clear.
>
> No, you were. I am just pushing back a little bit because I come
> from another angle and I greatly appreciate your explanations in
> helping me understand the Django way of thinking. So in the hope
> that you now don't feel exploited… ;)
>
> > You might be able to write a mapping to Storage that did some sort
> > of naming trick (e.g., split off a colon at the end of a filename
> > for read, so you could request "/my/file.txt:deadbeef" to request
> > the "deadbeaf" hash of /my/file.txt") - but my point is that the
> > storage API doesn't contain a *natural* endpoint for version
> > information.
>
> Arguably, the ref/hash/date could come from the config, not from the
> file, and suddenly there'd be a 1:1 mapping between a filesystem
> store and a storage that uses Git directly.
>
>
Sure - that could work too. Although I'd question why you'd do this, rather
than just checking out the relevant hash onto the filesystem, and doing a
direct filesystem read.

> And, even if you did this, what you're going to get is a view of
> > your Git repository that tries *really* hard to make it look like
> > just a normal file system.
>
> Yeah, this is an excellent point, especially since I'd probably not
> allow pushes to that Git repository but instead set up some sort of
> polling or regular interval pulling. Then I might just as well use
> a filesystem.
>
> > def myview(request):
> > with open('filename.txt') as datafile:
> > data = datafile.read()
> > return render(request, 'my template.html', {'data': data})
> >
> > You're possibly getting lost by thinking that this is a "Django" thing -
> it
> > isn't. Basic Python is always an option.
>
> Yeah, but I would like to assume that this has been wrapped for
> Django at least one "canonical" time, with all error handling done
> and proper cache integration taken care of.
>
> Because to just start off with a myview() view like you suggest
> above is quickly going to become a full-time project, if you know
> what I mean. ;)
>

Unless I'm missing some important detail, I don't see why. It's a fairly
simple caching layer, and a fairly simple rendering layer. The only
complexities that I can see are the ones related to accessing the Git
repository - and that's the bit that isn't part of a "common" use case.


> > > Have you seen something like this done? Is this also still best
> > > done in a view?
> >
> > Well... yes, I've seen this done before. It's called GitHub :-)
>
> Hehe, that was funny.
>
> But seriously: forget about all of the Git stuff, let's just look at
> the filesystem… at least in my universe, I'd like to assume that the
> idea of reading marked-up data from disk, processing it, caching it
> and then making the data available to templates is such an intuitive
> and standard thing to do that it could even be in Django core — if
> not there, then there ought to be an existing plugin for this.
>

Again - the reason that this isn't in Django is because it's not really
Django's bailiwick. Response-level caching is something that should be
handled at the web server level, and web servers have various ways to
handle this. And if you're going to be even more ruthless about it, I'd be
questioning why you've got a live Django server in the loop at all - if
it's static files, "post processed", then why not pre-render the Github
files to a "rendered" form (possibly in response to a commit trigger), and
simply serve the pre-rendered files as static content.

Yours,
Russ Magee %-)

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAJxq84-HogDjdv_w03qVCnv-KnNd3_9_VEce-ogCbQje8BOXMg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: DecimalField returns 'This value must be a decimal number' when blank

2014-11-24 Thread Collin Anderson
Hi,

Use form.cleaned_data instead of request.POST, because form.cleaned_data 
will property convert strings into decimals or None.

codpozo = form.cleaned_data['codpozo']

But again, use a ModelForm. it's super easy:

class PozoForm(forms.ModelForm):
class Meta:
model = Pozo
fields = '__all__'

def EdicionCuenca(request):
if 'pozoform' in request.POST:
pozoform = PozoForm(request.POST)
if pozoform.is_valid():
pozo = PosoForm.save()
return redirect('/edicioncuenca/')
else:
pozoform = PozoForm()
   # etc

Collin

On Saturday, November 22, 2014 12:57:13 PM UTC-5, elcaiaimar wrote:
>
> Hi Collin
>
> I'm using postgresql db, I' ve attached my views, forms and models. I' ve 
> thought to do the ModelForm when I solve this problem, thanks for your 
> advice!
>
> Thank you very much!
>
>
> El domingo, 16 de noviembre de 2014 18:51:43 UTC+1, elcaiaimar escribió:
>>
>> Hello everybody, I've a problem with DecimalField at Forms. I've a long 
>> form in my template and I want to left some fields in blank. I've declared 
>> these fields with 
>> *required=False*, but when I submit the form I receive this error: '*This 
>> value must be a decimal number*'.
>>
>> I've tried to declare *blank=True, null=True* in respective fields in 
>> models.py and make a syncdb but it continues without works
>>
>> Does somebody know how could I solve this problem?
>>
>> Thank you very much!
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/35c538f7-c3a2-424c-bb0a-1fed7921abb3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Image input missing from POST request

2014-11-24 Thread Collin Anderson
Hi,

I certainly am learning something new about . 
However, it may be that that trick simply doesn't work correctly for file 
fields. My question is: _does_ it work correctly when the  is a 
child of the ?

Collin

On Saturday, November 22, 2014 1:21:32 PM UTC-5, Abhishek Batra wrote:
>
> Hey Donarb,
>
> Input fields are not required to be inside form elements, so long as they 
> specify the form attribute as I have done. Check the form attribute here 
>  
> for reference.
> Moreover, I have other input fields as well which are outside the form 
> element, but they get successfully submitted.
>
> Any other suggestions anyone?
>
> Thanks,
> Abhishek
>
> On Saturday, November 22, 2014 11:03:39 PM UTC+5:30, donarb wrote:
>>
>> On Friday, November 21, 2014 7:56:54 PM UTC-8, Abhishek Batra wrote:
>>>
>>> Hi,
>>>
>>> This is probably not a Django issue, but just trying my luck.
>>>
>>> I have an input field corresponding to a Django ImageField in a Django 
>>> template. Rendered, the HTML looks like:
>>>
>>> >>   method="post" 
>>>   id="profile_form"
>>>   enctype="multipart/form-data">
>>> ... (other input fields and elements)>> id="id_profile_pic" name="profile_pic" type="file" />
>>>
>>> The corresponding View is an UpdateView. I found request.FILES to be 
>>> empty and request.cleaned_data to contain 'profile_pic': None.
>>>
>>> I used firebug to track the POST data. It contained other fields but not 
>>> profile_pic.
>>>
>>> Can anyone say why the file does not get uploaded? I've posted this 
>>> question to StakOverflow 
>>> 
>>>  as 
>>> well, in case someone wants reputation points.
>>>
>>> Thanks,
>>> Abhishek Batra
>>>
>>
>>
>> The input field is outside the closing  tag so would not be 
>> uploaded as part of the form. 
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/5370361b-d0af-401b-9579-ddf2483d9ebc%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: django on ubuntu

2014-11-24 Thread Collin Anderson
Also, in case you haven't seen it, the official django tutorial is amazing.
https://docs.djangoproject.com/en/dev/intro/

On Saturday, November 22, 2014 10:42:13 AM UTC-5, Mosharof sabu wrote:
>
>  hi 
>   i a going to start django on ubuntu . can any one please give me 
> some link of good tutorial of django on ubuntu (from installation to 
> advance ).
>   
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/b21dc46b-7cec-4c9a-b655-d258c8267e12%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Obtaining content from Git

2014-11-24 Thread martin f krafft
also sprach Russell Keith-Magee  [2014-11-25 01:16 
+0100]:
> Sure - that could work too. Although I'd question why you'd do
> this, rather than just checking out the relevant hash onto the
> filesystem, and doing a direct filesystem read.

Yeah, and I think you have me 99.5% convinced that I want
a filesystem backend.

> And if you're going to be even more ruthless about it, I'd be
> questioning why you've got a live Django server in the loop at all
> - if it's static files, "post processed", then why not pre-render
> the Github files to a "rendered" form (possibly in response to
> a commit trigger), and simply serve the pre-rendered files as
> static content.

Because the static content is used inside dynamic apps, and certain
parts of the website would be offered instead by apps and not static
files at all. As I said in my initial e-mail, we currently have
a Django app with Apache-level overrides of certain static pages
that are trying hard to look just like and integrate well with the
output Django renders and this is ugly.

-- 
@martinkrafft | http://madduck.net/ | http://two.sentenc.es/
 
normaliser unix c'est comme pasteuriser le camembert.
 
spamtraps: madduck.bo...@madduck.net

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/20141125054104.GA5859%40fishbowl.rw.madduck.net.
For more options, visit https://groups.google.com/d/optout.


digital_signature_gpg.asc
Description: Digital signature (see http://martin-krafft.net/gpg/sig-policy/999bbcc4/current)


How to do DB memcaching in Django with derived data?

2014-11-24 Thread Saqib Ali

My question is explained in detail here:
http://stackoverflow.com/questions/27114947/how-to-do-db-memcaching-in-django-with-derived-data

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/8cbb595d-0da1-42a5-93c5-ca6ffaf94743%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django install packages using pip

2014-11-24 Thread Hossein Rashnoo
the problem was i use python2.6 with django 1.7 and when install django 1.6 
problem solved

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/02806b34-e930-492a-9a20-77d3ce96b8a2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


defining an app stub using AppConfig?

2014-11-24 Thread Eric Abrahamsen
I'm messing around with testing many Github forks of the emencia
newsletter app, looking for one I like. In the meantime (and as I'm
likely to continue switching around for a while), I'd like not to have
to commit code that points at the different names of the different apps:
they all have the same models and database structure, the only thing
that changes is the top-level name of the module.

I looked at the code for contrib/comments, and have some questions about
using AppConfig.

What I'd like to do is have a setting in settings.py that reads:

NEWSLETTER_APP='maja_newsletter'

Or what have you. This would change semi-regularly as I test.

Then I'd have a top-level file called newslettermodule.py, with
something like this in it:

from django.conf import settings
from django.apps import apps

module = apps.get_app_config(settings.NEWSLETTER_APP.rpartition(".")[2]).module


Here's where I'm having trouble. Is there any way that I can basically
dump all the models from what would be module.models into this file?
Playing with this in the shell, when I try to import actual models from
module.models I get an "No module named module.models", even though
eval'ing "module.models" directly gives me:



Clearly this is just a misunderstanding on my part about how Python
modules work.

Is there anything I can do? Looking at the code in contrib/comments I
suspect not -- if there were, it would have been done there.

Anyway, thanks for any light shed on how AppConfig can be used in this
situation...

Eric

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/87vbm3ixb5.fsf%40ericabrahamsen.net.
For more options, visit https://groups.google.com/d/optout.