Re: Using a RadioSelect widget with ModelChoiceField

2021-02-06 Thread Matt Rowbottom
Hi wne

Thanks again for the suggestion, but those solutions are for how to make a 
`ChoiceField` behave like a `ModelChoiceField`. 

My `ModelChoiceField` works fine while the default `Select` widget is used. 
But when I use the `RadioSelect` widget the blank option disappears. This 
only occurs in Django from version 3.1 onwards.

I'm not looking for workarounds - I would like to know why the RadioSelect 
isn't showing a blank option. If it's a bug, I will file a bug report.

On Saturday, 6 February 2021 at 5:59:27 pm UTC+11 wne...@gmail.com wrote:

> https://stackoverflow.com/questions/14541074/empty-label-choicefield-django
>
> суббота, 6 февраля 2021 г. в 06:31:52 UTC+3, Matt Rowbottom: 
>
>> Hi wne 
>>
>> Using `to_field_name` changes the value of the options/inputs, but 
>> doesn't seem to have any effect on whether a blank option is available. 
>> Using `required=False` should provide a blank option.
>>
>> Below is a pic of how it's rendering. Animal Radio is missing a blank 
>> option. 
>>
>> [image: Screen Shot 2021-02-06 at 2.25.47 pm.png]
>>
>> On Saturday, 6 February 2021 at 1:35:02 am UTC+11 wne...@gmail.com wrote:
>>
>>> to_field_name="name",
>>>
>>> пятница, 5 февраля 2021 г. в 17:15:27 UTC+3, Matt Rowbottom: 
>>>
>>>> Hello. I think I've found a bug.
>>>>
>>>> Prior to Django v3.1, both of the fields in the following form would be 
>>>> rendered with an empty option, labelled as '-':
>>>>
>>>> ```
>>>> from django import forms
>>>> from .models import Animal
>>>>
>>>> class AnimalForm(forms.Form):
>>>> animal_select = forms.ModelChoiceField(
>>>> queryset=Animal.objects.all(),
>>>> required=False,
>>>> )
>>>> animal_radio = forms.ModelChoiceField(
>>>> queryset=Animal.objects.all(),
>>>> required=False,
>>>> widget=forms.RadioSelect()
>>>> )
>>>> ```
>>>>
>>>> Since Django v3.1, the field using the RadioSelect widget no longer 
>>>> displays the empty option. 
>>>>
>>>> I've tested it with the following versions:
>>>>
>>>> 3.0works
>>>> 3.0.12works
>>>> 3.1broken
>>>> 3.1.6 broken
>>>> 3.2a1broken
>>>>
>>>> I can't find anything in the docs or the v3.1 release notes (
>>>> https://docs.djangoproject.com/en/dev/releases/3.1/#forms) to explain 
>>>> the change.
>>>>
>>>> Does anyone know if this is intentional?
>>>
>>>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/c3e4cc73-99b5-4f46-9466-23afb38c5f21n%40googlegroups.com.


Re: Using a RadioSelect widget with ModelChoiceField

2021-02-05 Thread Matt Rowbottom
Hi wne 

Using `to_field_name` changes the value of the options/inputs, but doesn't 
seem to have any effect on whether a blank option is available. Using 
`required=False` should provide a blank option.

Below is a pic of how it's rendering. Animal Radio is missing a blank 
option. 

[image: Screen Shot 2021-02-06 at 2.25.47 pm.png]

On Saturday, 6 February 2021 at 1:35:02 am UTC+11 wne...@gmail.com wrote:

> to_field_name="name",
>
> пятница, 5 февраля 2021 г. в 17:15:27 UTC+3, Matt Rowbottom: 
>
>> Hello. I think I've found a bug.
>>
>> Prior to Django v3.1, both of the fields in the following form would be 
>> rendered with an empty option, labelled as '-':
>>
>> ```
>> from django import forms
>> from .models import Animal
>>
>> class AnimalForm(forms.Form):
>> animal_select = forms.ModelChoiceField(
>> queryset=Animal.objects.all(),
>> required=False,
>> )
>> animal_radio = forms.ModelChoiceField(
>> queryset=Animal.objects.all(),
>> required=False,
>> widget=forms.RadioSelect()
>> )
>> ```
>>
>> Since Django v3.1, the field using the RadioSelect widget no longer 
>> displays the empty option. 
>>
>> I've tested it with the following versions:
>>
>> 3.0works
>> 3.0.12works
>> 3.1broken
>> 3.1.6 broken
>> 3.2a1broken
>>
>> I can't find anything in the docs or the v3.1 release notes (
>> https://docs.djangoproject.com/en/dev/releases/3.1/#forms) to explain 
>> the change.
>>
>> Does anyone know if this is intentional?
>
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/c3d317c7-f3d3-4cf2-9535-9219d0ad9cfcn%40googlegroups.com.


Using a RadioSelect widget with ModelChoiceField

2021-02-05 Thread Matt Rowbottom
Hello. I think I've found a bug.

Prior to Django v3.1, both of the fields in the following form would be 
rendered with an empty option, labelled as '-':

```
from django import forms
from .models import Animal

class AnimalForm(forms.Form):
animal_select = forms.ModelChoiceField(
queryset=Animal.objects.all(),
required=False,
)
animal_radio = forms.ModelChoiceField(
queryset=Animal.objects.all(),
required=False,
widget=forms.RadioSelect()
)
```

Since Django v3.1, the field using the RadioSelect widget no longer 
displays the empty option. 

I've tested it with the following versions:

3.0works
3.0.12works
3.1broken
3.1.6 broken
3.2a1broken

I can't find anything in the docs or the v3.1 release notes 
(https://docs.djangoproject.com/en/dev/releases/3.1/#forms) to explain the 
change.

Does anyone know if this is intentional?

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/bd2dcf85-c453-4b84-9b27-e41e5721a10dn%40googlegroups.com.


Intermittent Javascript Tests Headless Chrome Timeout

2020-06-16 Thread Matt Ferrante
After rebasing my PR (https://github.com/django/django/pull/12333), it 
failed the JS tests, but hasn't touched any JS files. I suspect this was an 
intermittent failure, unrelated to my PR and wanted to re-run the JS tests, 
but I don't think I have permission to do so. Is there a good way I should 
re-trigger this test suite?

Thanks!

https://djangoci.com/job/pull-requests-javascript/6624/console


Files: js_tests/tests.html -> all
Options: timeout=5000, 
inject="/home/jenkins/workspace/pull-requests-javascript/node_modules/grunt-contrib-qunit/chrome/bridge.js",
 urls=[], force=false, console, httpBase=false, summaryOnly=false

Testing js_tests/tests.html 
>> There was an error with headless chrome
Fatal error: Navigation Timeout Exceeded: 5000ms exceeded 
npm ERR! Test failed.  See above for more details.
Build step 'Execute shell' marked build as failure
Finished: FAILURE

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/0ee50aa0-6d16-4c67-99a0-9a1b16a7652ao%40googlegroups.com.


Re: A learner following a Mosh Tutorial on Django and having a problem saving a product to SQLite

2020-05-30 Thread Matt D

>
>
> ^ Is this where you deleted the migrations?

I keep receiving this error when I enter py manage.py migrate products:

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/a2ad2f14-0144-4ce8-9100-c107b8b36d22%40googlegroups.com.


Re: A learner following a Mosh Tutorial on Django and having a problem saving a product to SQLite

2020-05-29 Thread Matt D

>
> Hello Iain,
>
 I am also working on Mosh's python tutorial and I'm having the same 
problems that you expressed in this chat. Did you delete the migrations 
through pycharm or through your computer to make it work?
Thanks

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/5cf0bf92-5773-43a3-a273-4ccfdb61734c%40googlegroups.com.


Re: Query help

2019-09-12 Thread Matt
Tosin,
Please refer below. This should help.
https://docs.djangoproject.com/en/2.2/topics/db/queries/


best,
matt

On Thu, Sep 12, 2019 at 10:01 AM Tosin Ayoola 
wrote:

> Halo guyz I actually need a little help, I'm working on a airline tickets
> reservations project using postman Api that requires making query for
> available flight going to a particular destination,  from a particular
> city, arrival date & departure  date & I got no idea on how to write the
> query,  Pls can anyone help out thanks
>
> --
> 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 view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAHLKn70jgSAAHL9YtX5Y6-9BWNdx42i0-0LnVt%3DQCPB-Bgjwow%40mail.gmail.com
> <https://groups.google.com/d/msgid/django-users/CAHLKn70jgSAAHL9YtX5Y6-9BWNdx42i0-0LnVt%3DQCPB-Bgjwow%40mail.gmail.com?utm_medium=email_source=footer>
> .
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CACZnaa%3Dg3HuiOUFidFB%2BJL7GSWvTZ2%2Bg-Ow%3D2dtxECnN%3DirBMQ%40mail.gmail.com.


Re: New user question: Where to put non-form validation code?

2019-07-25 Thread Matt Zand
Hi everyone,
Does anyone know how to post blog at below page:
https://www.djangoproject.com/community/blogs/

I am really frustrated as I submitted last week but nothing is there. Who
is in charge of blog posts on Django site?

Thx,
Matt



On Thu, Jul 25, 2019 at 12:38 AM Mike Dewhirst 
wrote:

> On 25/07/2019 1:03 pm, Jim Illback wrote:
> > I had a slight variation on this thread - where to put some M2M field
> > validation/deletion logic.
> >
> > I have a purely model-based form where a checkbox’s value determines
> > whether another field (it’s a M2M field) in the form should be NULL or
> > keep its values to be saved in the database. So, following the
> > appropriate separation of concerns as advocated below, I added logic
> > in both the models' clean and save override methods. Neither approach
> > set the other field to NULL when it should have been. The reason is
> > the form still contained M2M values even though the model said to
> > delete them (delete the set, actually).
> >
> > After a lot of trial and error, it turns out that the model’s save
> > seems to be run BEFORE the form’s save. To me, that seems backwards.
> > Shouldn’t the model’s processes (which are directly relate to the
> > database, the ultimate data source) occur last and well before the
> > form’s (which are merely an interaction with the user)? What was
> > happening was my model’s delete actually did the deletions (those IDs
> > were gone), but then the form’s processing came along afterwards and
> > re-inserted them again (with brand new IDs).
>
> Don't know what's happening here but you can be sure Django is doing it
> the right way.
>
> Maybe you need to look at your on_delete constants. models.CASCADE
> versus models.SET_NULL or models.PROTECT
>
> >
> > Can someone help me understand why Django has chosen this seemingly
> > “inversion” of processing - first models’ processes, then forms’? And,
> > perhaps more importantly, where should this either/or logic should be
> > placed so it will take effect?
> >
> > Thanks very much,
> > Jim Illback
> >
> >> On Jul 13, 2019, at 11:48 PM, Mike Dewhirst  >> <mailto:mi...@dewhirst.com.au>> wrote:
> >>
> >> Well yes it could be called multifaceted.
> >>
> >> Usually but not always the interface with the user is the form. You
> >> can have non-database fields as well as model fields so either way
> >> there has to be a full suite of validation functionality available in
> >> both types of forms. Luckily, model forms automatically call
> >> model.clean() for you.
> >>
> >> Unit tests don't though. You have deliberately call obj.clean() if
> >> you want to test things. obj.save() doesn't call obj.clean().
> >>
> >> Actually, I also do a bit in view code too especially if there are
> >> non-database or hidden fields in the form. I know you are not
> >> supposed to validate data in a view for proper separation of concerns
> >> but it does keep my forms neater.
> >>
> >> The bottom line for me is that if I can imagine non-form access ...
> >> eg through an API ... then all validation possible has to be via
> >> model.clean() and the API has to remember to call clean() before
> >> saving every time there is a POST
> >>
> >> Hence I*always*put business rules validation in model.clean() and
> >> leave 'local' validation for the form.
> >>
> >> You are right. There are quite a few moving parts
> >>
> >> /Connected by Motorola/
> >>
> >>
> >> Dean Karres mailto:dean.kar...@gmail.com>>
> wrote:
> >>
> >> Thank you. There are way more parts to this than I would have imagined.
> >>
> >>
> >>
> >> On Sat, Jul 13, 2019, 8:01 PM Mike Dewhirst  >> <mailto:mi...@dewhirst.com.au>> wrote:
> >>
> >> On 14/07/2019 10:37 am, Dean Karres wrote:
> >>> Hi,
> >>>
> >>> I am learning Django.  I am using CBVs.  My default "index.py"
> >>> view is basically a dashboard for the app I am playing with.  As
> >>> my models and views become more complicated I want to be able to
> >>> ask, for any model instance, is this instance "valid" or
> >>> "complete".  Valid means that all Required elements are present
> >>> and have reasonable values.  "Complete" means that an instance
> >>> is "valid" but also some specific bits of additional info a

Blog or link sharing in the community page

2019-07-24 Thread Matt Zand
Hi, 

I shared one blog post last week in community section. It does not show up. 
https://www.djangoproject.com/community/

Can someone help me out. My article links was below:
https://myhsts.org/upload-and-process-website-cvs-file-using-python-django.html

and RSS link
https://myhsts.org/rss_feed.xml


-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/4316e3fd-9eb8-4a40-94a4-bff83376dac2%40googlegroups.com.


Re: Set user permission via python

2019-04-10 Thread Matt Collins
I've solved this. First of all, the codename for the permission should be 
called as a codename and second, I had to remove the app name 
(display_data) like this:

permission = Permission.objects.get(codename='settings')


On Tuesday, April 9, 2019 at 9:25:09 PM UTC-6, Matt Collins wrote:
>
> Hi,
>
> I'm trying to set a permission for a user that I'm creating with a python 
> script. I've tested and found that the codename for the permission is 
> "display_data.settings" using the following:
>
> python manage.py shell
> from django.contrib.auth.models import User
> user_name = User.objects.get(username="user_name")
> user_name.get_all_permissions()
> set([u'display_data.settings']) 
>
>
> I'm trying to set this permission for the user with the following:
>
> from django.contrib.auth import get_user_model
> from django.contrib.auth.models import User, Permission
>
> User = get_user_model()
>
> #check to see if user exists, create it if it doesn't
> User.objects.filter(username="user_name").exists() or\
> User.objects.create_user(username='user_name', email='
> usern...@example.com', password='blah')
>  
>
> #add permissions to user
> u = User.objects.get(username="user_name")
> permission = Permission.objects.get(name='display_data.settings')
> u.user_permissions.add(permission)
>
>  
> When I run this, I get the following error:
>
>
> django.contrib.auth.models.DoesNotExist: Permission matching query does 
> not exist.
>
>
> Can anybody tell me what I'm missing? 
>

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/e092d493-6dc5-4374-ad9e-e664e6b9d0b6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Set user permission via python

2019-04-09 Thread matt
Hi,

I'm trying to set a permission for a user that I'm creating with a python 
script. I've tested and found that the codename for the permission is 
"display_data.settings" using the following:

python manage.py shell
from django.contrib.auth.models import User
user_name = User.objects.get(username="user_name")
user_name.get_all_permissions()
set([u'display_data.settings']) 


I'm trying to set this permission for the user with the following:

from django.contrib.auth import get_user_model
from django.contrib.auth.models import User, Permission

User = get_user_model()

#check to see if user exists, create it if it doesn't
User.objects.filter(username="user_name").exists() or\
User.objects.create_user(username='user_name', 
email='usern...@example.com', password='blah')
 

#add permissions to user
u = User.objects.get(username="user_name")
permission = Permission.objects.get(name='display_data.settings')
u.user_permissions.add(permission)

 
When I run this, I get the following error:


django.contrib.auth.models.DoesNotExist: Permission matching query does not 
exist.


Can anybody tell me what I'm missing? 

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/c039cb7b-fd33-4b41-9e2a-b94e3f2d628f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Channels: rejecting web socket connections with a custom close code

2018-10-08 Thread Matt F
Hi Andrew,

Thanks for clarifying.  I didn't think to look at the ASGI spec but it is 
described quite well there under the WebSocket/Close section.  Thanks for 
your hard work on this project.

Regards,
Matt


On Saturday, 6 October 2018 10:47:46 UTC+1, Andrew Godwin wrote:
>
> Hi Matt,
>
> This is because the two ways of closing are different - closing before the 
> socket is open sends a HTTP error code (what browsers report for this is 
> different in terms of websocket errors), whereas closing once it is open 
> allows a websocket error to be used.
>
> This is referenced in the spec at 
> https://asgi.readthedocs.io/en/latest/specs/www.html#websocket but 
> somewhat obliquely; I’ll try to make it a bit clearer.
>
> Andrew
>
>>
>>
>>

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/12417d20-f76f-4d3b-ba04-2ed55b22757e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Channels: rejecting web socket connections with a custom close code

2018-10-03 Thread Matt F
Hello all,

I have a question about the process of accepting/rejecting web socket 
connections in Channels consumers (v2.1.3).  I have found that if I have 
code like this:

class MyConsumer(JsonWebsocketConsumer):
def connect(self):
if authenticated:
self.accept()
else:
self.close(4001)


then when rejecting a connection the close code always comes through on the 
client side as 1006 (abnormal closure) instead of 4001.  There is a stack 
overflow post about the same issue that led me to an answer that solves 
this: 
https://stackoverflow.com/questions/50009440/django-channels-2-0-websocketbridge-js-403-when-self-codecode-1007

And a code snippet that works correctly is as follows:

class MyConsumer(JsonWebsocketConsumer):
def connect(self):
self.accept()
if not authenticated:
self.close(4001)


The Channels documentation is ambiguous as to which of these is correct.  
Now I think I know the answer as the first way breaks and the second way 
works, but I wanted to check with someone more knowledgeable that this way 
of doing things is by design and not just working by accident.  It feels a 
bit wrong to accept a connection and then immediately close it, but I 
understand if you have to do it this way, to get the custom close code 
returned perhaps you have to have an open connection in the first place.  
Can someone please confirm?

Many thanks!
Matt

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/6a4a797c-e590-4f4d-a718-074a3cf704bc%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Creating models from json url feed

2018-05-12 Thread Matt Snelgar
All of the products will share the same fields.

I would filter on products, but my searches would only be restricted to one
market at a time.

On Sun, May 13, 2018 at 1:51 AM, Ryan Nowakowski <tuba...@fattuba.com>
wrote:

>
>
> On May 10, 2018 7:40:47 AM CDT, Matt Snelgar <snelg...@gmail.com> wrote:
> >
> >
> >I am making a django app to browse available products at different
> >markets.
> >I am getting data for my models from a JSON url feed,
> >
> >I am not sure on the best approach to turn this data into models as the
> >
> >feed for a single market can contain upwards of 50k items.
> >
> >
> >Models - feel free to suggest any improvements on these
> >
> ># Details of a sellable products
> >class Product(models.Model):
> >   item = models.IntegerField(primary_key=True, auto_created=False)
> >name = models.CharField(max_length=40)
> >
> ># Market where products can be bought, some markets will cater to
> >multiple suburbs.
> >class Market(models.Model):
> >id = models.IntegerField(primary_key=True, auto_created=True)
> >name = models.CharField(max_length=40)
> >
> ># Nearby suburbs can share the one market
> >class Suburb(models.Model):
> >name = models.CharField(max_length=30)
> >market = models.ForeignKey(Market, on_delete=models.SET_NULL,
> >null=True)
> >
> ># Actual product for sale
> >class ProductForSale(models.Model):
> >sale = models.IntegerField(primary_key=True)
> >product = models.ForeignKey(Product, on_delete=models.SET_NULL,
> >null=True)
> >cost = models.IntegerField(default=1)
> >owner = models.CharField(max_length=30)
> >quantity = models.IntegerField(default=1)
> >market = models.ForeignKey(Market,on_delete=models.SET_NULL, null=True
> >)
> >Feed of markets products example
> >
> >"market_products": [
> >{
> >"id":11654,
> >"item":123,
> >"owner":"Bob",
> >"suburb":"Springvale",
> >"cost":3,
> >"quantity":1,
> >
> >},
> >{
> >"id":11655,
> >"item":123,
> >"owner":"Sarah",
> >"suburb":"Sunnyville",
> >"cost":5,
> >"quantity":2,
> >
> >},
> >
> >This is how I am trying to populate my ProductForSale models - I don't
> >know
> >if this is the correct approach for the Product FK, or how to link the
> >suburb to its Market FK
> >
> >markets = Market.objects.all()
> >for market in markets:
> >url = "jsonurl"
> >response = urllib.request.urlopen(url)
> >data = json.loads(response.read())
> >for entry in data['market_products']:
> >new_product_sale = ProductForSale.objects.create(
> >product = Product.objects.get(item=entry['item']),
> >cost = entry['cost'],
> >owner = entry['owner'],
> >quantity = entry['quantity']
> >)
> >new_product_sale.save()
> >
> >Is there a point where I should create a separate model for each
> >markets
> >products, or is it fine to house them all in the one model?
>
> Do products from different markets have many different fields?  Or are
> most of the fields common?
>
> Do you need to be able to filter on products across markets? Or are most
> of your product queries specific to a particular market?
>

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAOaq%3D559npSb77r6VmaszpFx9GgZgANVQ7qZGsh5gRVrm_%3DZJQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Creating models from json url feed

2018-05-10 Thread Matt Snelgar


I am making a django app to browse available products at different markets. 
I am getting data for my models from a JSON url feed, 

I am not sure on the best approach to turn this data into models as the 
feed for a single market can contain upwards of 50k items.


Models - feel free to suggest any improvements on these

# Details of a sellable products
class Product(models.Model):
item = models.IntegerField(primary_key=True, auto_created=False)
name = models.CharField(max_length=40)

# Market where products can be bought, some markets will cater to multiple 
suburbs.
class Market(models.Model):
id = models.IntegerField(primary_key=True, auto_created=True)
name = models.CharField(max_length=40)

# Nearby suburbs can share the one market
class Suburb(models.Model):
name = models.CharField(max_length=30)
market = models.ForeignKey(Market, on_delete=models.SET_NULL, null=True)

# Actual product for sale
class ProductForSale(models.Model):
sale = models.IntegerField(primary_key=True)
product = models.ForeignKey(Product, on_delete=models.SET_NULL, 
null=True)
cost = models.IntegerField(default=1)
owner = models.CharField(max_length=30)
quantity = models.IntegerField(default=1)
market = models.ForeignKey(Market,on_delete=models.SET_NULL, null=True )
Feed of markets products example

"market_products": [
{
"id":11654,
"item":123,
"owner":"Bob",
"suburb":"Springvale",
"cost":3,
"quantity":1,

},
{
"id":11655,
"item":123,
"owner":"Sarah",
"suburb":"Sunnyville",
"cost":5,
"quantity":2,

},

This is how I am trying to populate my ProductForSale models - I don't know 
if this is the correct approach for the Product FK, or how to link the 
suburb to its Market FK

markets = Market.objects.all()
for market in markets:
url = "jsonurl"
response = urllib.request.urlopen(url)
data = json.loads(response.read())
for entry in data['market_products']:
new_product_sale = ProductForSale.objects.create(
product = Product.objects.get(item=entry['item']),
cost = entry['cost'],
owner = entry['owner'],
quantity = entry['quantity']
)
new_product_sale.save()

Is there a point where I should create a separate model for each markets 
products, or is it fine to house them all in the one model?

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/0a0f0614-dc75-4813-9542-f1d6de3134bf%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Django development -

2018-01-25 Thread Matt
Hi all,

First time poster  - so hi! & hope I'm asking things here in the right way. 
I've used django, on and off, for a while for personal little projects, and 
found it fun to use.  But I'm, no pro, and its not my day job.

Now I've started a project locally, which I'd like to flesh out, make it 
more robust and then go-live with the idea as an actual website.  I've 
tried to adhere to the structure of building the site up in the correct way 
to be like an app, but again I'm no pro.

So I'd love to hear some experience of people that have moved a prototype 
through dev, into prod.

As I see it, I'd need;
1) a dev to work with me to turn the prototype (amateur code) into 
something better -> where's the best place to look for them? 
2) a platform to deploy it on (AWS, heroku, or similar) - and potentially 
someone different to do that for me - again, where's the best place to look 
for them?

So if you've got some experience in taking a django site through this, I'd 
love to hear about how you did it.

Finally - I hope I've asked the right type of question here in the group - 
I know its not the classic feature / debug question - but I didn't knwo 
where else to ask.

Thanks!
-Matt

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/7cf7cc54-9f3d-4830-82eb-45e085c4c6e5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Database router with read replica

2017-08-30 Thread Matt Pegler
I'm hoping for some advice on how to utilize read replica databases with
Django.  I searched the django-users archive but didn't find much
discussion about this.  I also can't find many blog posts or discussion
elsewhere.  Do people have experience or general advice on using read
replicas with Django?

I am hoping to implement a database router that will intelligently use a
read replica while maintaining consistency despite replica lag.  I have a
couple things I'd like another opinion on:

First is handling replication lag.  Our read replica typically lags ~20ms
behind master, so we want to route all queries that occur after a write
within the same request to the master database.  I believe this can be
accomplished using a thread local in the database router that is reset
after each request using a middleware.  Does that seem like a reasonable
approach?

Second is handling atomic blocks.  As far as I can tell, Django will not
automatically route all queries within an atomic block to the same
database, so this needs to be handled within the router.  Is
connection.in_atomic_block
<https://github.com/django/django/blob/cd7afcdcac69cc4e6f762188262957bceb4760e0/django/db/transaction.py#L107>
a
public API, or is there a better way to tell if we're within an atomic
block?

Thanks,
Matt

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CA%2BSd1We3Yq37fYsZu1rVJcxizty6NNG4q-EeVp83wT7aeuh8pQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Encapsulating Complex Business Logic in a Migraiton

2017-08-29 Thread Matt S
Standard practice is that you do not refer to "current" models (i.e. from 
app.models import MyModel) in a migration as the migration will break when 
that models changes. This means copying any model-specific code into the 
migration. This becomes impractical when the code needed for the migration 
spans multiple files and models.

How can I encapsulate a complex chain of business logic involving multiple 
models in a migration? For example, if I have instance methods on ModelA 
which calls methods on ModelB, ModelB queries for ModelC and calls methods 
on it. If I use those methods as they exist on the models, the migration 
will eventually break when any of the involved Models' schema changes.

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/a60b8ed4-a5a6-40c8-b959-17e2a3ec3363%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Creation of default site not triggering post_save signal

2016-09-12 Thread Matt Thompson
Hi Simon,

Thank you very much for your prompt reply!  I've added the following to my 
app, which seems to work just fine:

@receiver(models.signals.post_migrate)
def gen_site_config_post_migrate(plan, **kwargs):
# A migration of the `django.contrib.sites` app was applied.
if plan and any(migration.app_label == 'sites' for migration, _ in 
plan):
try:
site = Site.objects.get(name='example.com')
except ObjectDoesNotExist:
pass
else:
SiteConfig.objects.get_or_create(
site=site,
admin_email='ad...@example.com',
remote=False
)

It seems the code inside the if statement is called several times (7, to be 
exact) when I run initial migrations, with the site finally getting created 
at the end.  This is why I've had to add some exception handling for when 
the site doesn't exist.

Simon, one last question for you -- where should this code live?  I 
currently have it shoved in my model file but that doesn't feel quite right.

Thank you again!

--Matt

On Saturday, September 10, 2016 at 10:42:16 PM UTC-4, Simon Charette wrote:
>
> Hi Matt,
>
> I worked on the changes that broke your code.
>
> Starting with 1.10 the migration signals are passed an `apps` kwarg 
> representing
> the state of models before and after the specified migrations are applied.
>
> This allows signal receivers to manipulate model definitions that are
> synchronized with their actual database representation just like a data
> migrations would (e.g. `RunPython` operations).
>
> Before this change was introduced the signal receivers were performing 
> queries
> using the globally available model definitions which could lead to failures
> when querying the underlying tables as their schema were not synchronized 
> with
> their global model definitions.
>
> In your case, the signals you attached to the global `Site` model are not 
> fired
> anymore as the queries are performed using the migration specific one which
> you cannot attach listeners to.
>
> It's hard for me to come up with a complete solution without the actual 
> code
> attached to `post_save(sender=Site)` but something along these lines 
> should do:
>
> @receiver(post_migrate)
> def sync_site(plan, **kwargs):
> # A migration of the `django.contrib.sites` app was applied.
> if plan and any(migration.app_label == 'sites' for migration, _ in 
> plan):
> # ... perform actions
>
> Let me know if you need more details,
> Simon
> Le samedi 10 septembre 2016 21:59:56 UTC-4, Matt Thompson a écrit :
>>
>> Hi All,
>>
>> I have a small Django app that uses the sites framework and has a 
>> post_save signal on Site that does some bits and bobs when a new site is 
>> created.  On 1.9.7, when you run migrations for the first time, it 
>> correctly triggers the post_save signal.  However, after upgrading to 
>> 1.10.1, dropping the database, and re-running migrations, the post_save 
>> signal I have setup on Site doesn't seem to be triggering.  I tried reading 
>> the 1.10 release notes and while there was mention of a pre_migrate() and 
>> post_migrate() signals, I couldn't make heads or tails on whether that is 
>> related.
>>
>> If this is a deliberate change, can someone please point me to the 
>> specifics?  If it's a bug, I'd be more than happy to file a bug.
>>
>> Thanks!
>>
>> --Matt
>>
>

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/dfc9ae9c-d7fb-4f2a-a857-bae133f92b03%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Creation of default site not triggering post_save signal

2016-09-10 Thread Matt Thompson
Hi All,

I have a small Django app that uses the sites framework and has a post_save 
signal on Site that does some bits and bobs when a new site is created.  On 
1.9.7, when you run migrations for the first time, it correctly triggers 
the post_save signal.  However, after upgrading to 1.10.1, dropping the 
database, and re-running migrations, the post_save signal I have setup on 
Site doesn't seem to be triggering.  I tried reading the 1.10 release notes 
and while there was mention of a pre_migrate() and post_migrate() signals, 
I couldn't make heads or tails on whether that is related.

If this is a deliberate change, can someone please point me to the 
specifics?  If it's a bug, I'd be more than happy to file a bug.

Thanks!

--Matt

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/c386413e-4b56-4673-bfb9-76e5ee851433%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Part 5 of creating firat django app

2016-08-29 Thread Matt Maloney
I am at - test a view, and I just instantiated a client. I try doing the 
command response = client.get(reverse('polls:index')) -- but with a long 
traceback, the console ultimately says that it can't find 
polls/question_list.html, which I see nothing instructing me to make in the 
tutorial.

Thanks in advance,
Matt

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/db242011-262e-4ed3-9b48-b39081cab91e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Unable to get tests to work

2016-08-19 Thread Matt
I purged all the '*.pyc' and the result remains the same. The missing pyc 
files could be explained by that I use Pycharm to dev in. It appears that 
this IDE cleans those up automatically. Also I have been dropping to a 
shell trying to test things to resolve the issue, which would explain why 
there are some pyc files but not all.

pytest was an attempt to resolve the issue outside of django's manage.py. 
It failed as well. Here is the pytest.ini:

[pytest]
DJANGO_SETTINGS_MODULE=refreshes.settings

Thanks,
Matt

On Friday, August 19, 2016 at 10:37:51 AM UTC-6, Fred Stluka wrote:
>
> Matt,
>
> At a glance, the directory structure looks OK.  Seems odd though
> that you have some *.pyc files with no corresponding *.py file.
> For example, frontend/tests.pyc and nas/tests.pyc.  Could such 
> a file be tripping up the test runner?  That might explain why it 
> fails when no arguments -- searching for all tests and getting 
> confused -- but succeeds when told to run only backups.tests.
>
> Same for all of the erp/*.pyc files.
>
> Perhaps try deleting all *.pyc file in the entire tree and then run
> the tests, letting them be recreated from the *.py files as needed.
>
> Also, I see a backup/tests.py with no *.pyc file.  Is there a syntax 
> error in that file that makes it not compile?  Or is it just not 
> getting that far?
>
> Also, what is in pytest.ini?  Is it perhaps directing the test runner 
> to look for tests that don't exist?
>
> --Fred 
> --
> Fred Stluka -- mailt...@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 8/18/16 3:49 PM, Matt wrote:
>
> Sorry replied to the wrong thread: https://dpaste.de/OF8j
>
> On Wednesday, August 17, 2016 at 11:16:27 PM UTC-6, Gergely Polonkai 
> wrote: 
>>
>> Hello,
>>
>> this “refreshes.backups.tests” thing bothers me a lot. Could you show us 
>> your directory structure, please?
>>
>> Best,
>> Gergely 
>>
>> On Wed, Aug 17, 2016, 23:03 Matt <kicke...@gmail.com> wrote:
>>
>>> Ok a step forward. When I spell out the tests it works:  
>>>
>>> https://dpaste.de/2MXf
>>>
>>> But when I run test without arguments, it fails out:
>>>
>>> https://dpaste.de/cgTH
>>>
>>> There is more than the backups app here, but I plan to replicate out the 
>>> fix when I get it.
>>>
>>> On Wednesday, August 17, 2016 at 2:34:45 PM UTC-6, Fred Stluka wrote:
>>>
>>>> Matt,
>>>>
>>>> Oops!  Right.  I just noticed that in the dpaste.
>>>>
>>>> My next guess is you may need to change the name "good_index_text"
>>>> to something that starts with "test_" to get it to be recognized as a 
>>>> test.
>>>>
>>>> Or maybe something to do with "refreshes"?  The test trace shows
>>>> it trying to run testcase "refreshes.backups.tests", but in the manual
>>>> import you did from the python shell, you only import "backups.tests"
>>>>
>>>> --Fred 
>>>> --
>>>>
>>> Fred Stluka -- mailt...@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 8/17/16 4:27 PM, Matt wrote:
>>>>
>>> Sorry for the typo, but I have already do that way. I have the output in 
>>>> the the first link.
>>>>
>>>> On Wednesday, August 17, 2016 at 2:24:19 PM UTC-6, Fred Stluka wrote: 
>>>>>
>>>>> Matt,
>>>>>
>>>>> Drop the "s" from "tests":
>>>>>
>>>>> ./manage.py test backups
>>>>>
>>>>> --Fred 
>>>>> --
>>>>> Fred Stluka -- mailt...@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 8/17/16 4:17 PM, Matt wrote:
>>>>>
>>>>> When I'm trying to get tests to work it simply states tha

Re: Unable to get tests to work

2016-08-18 Thread Matt
Sorry replied to the wrong thread: https://dpaste.de/OF8j

On Wednesday, August 17, 2016 at 11:16:27 PM UTC-6, Gergely Polonkai wrote:
>
> Hello,
>
> this “refreshes.backups.tests” thing bothers me a lot. Could you show us 
> your directory structure, please?
>
> Best,
> Gergely 
>
> On Wed, Aug 17, 2016, 23:03 Matt <kicke...@gmail.com > wrote:
>
>> Ok a step forward. When I spell out the tests it works: 
>>
>> https://dpaste.de/2MXf
>>
>> But when I run test without arguments, it fails out:
>>
>> https://dpaste.de/cgTH
>>
>> There is more than the backups app here, but I plan to replicate out the 
>> fix when I get it.
>>
>> On Wednesday, August 17, 2016 at 2:34:45 PM UTC-6, Fred Stluka wrote:
>>
>>> Matt,
>>>
>>> Oops!  Right.  I just noticed that in the dpaste.
>>>
>>> My next guess is you may need to change the name "good_index_text"
>>> to something that starts with "test_" to get it to be recognized as a 
>>> test.
>>>
>>> Or maybe something to do with "refreshes"?  The test trace shows
>>> it trying to run testcase "refreshes.backups.tests", but in the manual
>>> import you did from the python shell, you only import "backups.tests"
>>>
>>> --Fred 
>>> --
>>>
>> Fred Stluka -- mailt...@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 8/17/16 4:27 PM, Matt wrote:
>>>
>> Sorry for the typo, but I have already do that way. I have the output in 
>>> the the first link.
>>>
>>> On Wednesday, August 17, 2016 at 2:24:19 PM UTC-6, Fred Stluka wrote: 
>>>>
>>>> Matt,
>>>>
>>>> Drop the "s" from "tests":
>>>>
>>>> ./manage.py test backups
>>>>
>>>> --Fred 
>>>> --
>>>> Fred Stluka -- mailt...@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 8/17/16 4:17 PM, Matt wrote:
>>>>
>>>> When I'm trying to get tests to work it simply states that its unable 
>>>> to import .tests. I'm not sure what I'm missing here. Here is some 
>>>> output please let me know if you need more: 
>>>>
>>>> ./manage.py tests backups
>>>> https://dpaste.de/4U9C
>>>>
>>>> The test file:
>>>> https://dpaste.de/bBZt
>>>> -- 
>>>> 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...@googlegroups.com.
>>>> To post to this group, send email to django...@googlegroups.com.
>>>> Visit this group at https://groups.google.com/group/django-users.
>>>> To view this discussion on the web visit 
>>>> https://groups.google.com/d/msgid/django-users/89d6fac7-0848-4e35-8b4a-62d24178c3aa%40googlegroups.com
>>>>  
>>>> <https://groups.google.com/d/msgid/django-users/89d6fac7-0848-4e35-8b4a-62d24178c3aa%40googlegroups.com?utm_medium=email_source=footer>
>>>> .
>>>> 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...@googlegroups.com.
>>> To post to this group, send email to django...@googlegroups.com.
>>> Visit this group at https://groups.google.com/group/django-users.
>>>
>>> To view this discussion on the web visit 
>>> https://groups.google.com/d/msgid/django-users/04fcacea-15d0-42af-afe5-424c2d1df86f%40googlegroups.com
>>>  
>>> <https://groups.google.com/d/msgid/django-users/04fcacea-15d0-42af-afe5-424c2d1df86f%40googlegroups.com?utm_medium=email_source=footer>
>>> .
>>> For more options, visit ht

Re: Unable to get tests to work

2016-08-18 Thread Matt
Here you go:

https://dpaste.de/OF8j

On Wednesday, August 17, 2016 at 11:16:27 PM UTC-6, Gergely Polonkai wrote:
>
> Hello,
>
> this “refreshes.backups.tests” thing bothers me a lot. Could you show us 
> your directory structure, please?
>
> Best,
> Gergely 
>
> On Wed, Aug 17, 2016, 23:03 Matt <kicke...@gmail.com > wrote:
>
>> Ok a step forward. When I spell out the tests it works: 
>>
>> https://dpaste.de/2MXf
>>
>> But when I run test without arguments, it fails out:
>>
>> https://dpaste.de/cgTH
>>
>> There is more than the backups app here, but I plan to replicate out the 
>> fix when I get it.
>>
>> On Wednesday, August 17, 2016 at 2:34:45 PM UTC-6, Fred Stluka wrote:
>>
>>> Matt,
>>>
>>> Oops!  Right.  I just noticed that in the dpaste.
>>>
>>> My next guess is you may need to change the name "good_index_text"
>>> to something that starts with "test_" to get it to be recognized as a 
>>> test.
>>>
>>> Or maybe something to do with "refreshes"?  The test trace shows
>>> it trying to run testcase "refreshes.backups.tests", but in the manual
>>> import you did from the python shell, you only import "backups.tests"
>>>
>>> --Fred 
>>> --
>>>
>> Fred Stluka -- mailt...@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 8/17/16 4:27 PM, Matt wrote:
>>>
>> Sorry for the typo, but I have already do that way. I have the output in 
>>> the the first link.
>>>
>>> On Wednesday, August 17, 2016 at 2:24:19 PM UTC-6, Fred Stluka wrote: 
>>>>
>>>> Matt,
>>>>
>>>> Drop the "s" from "tests":
>>>>
>>>> ./manage.py test backups
>>>>
>>>> --Fred 
>>>> --
>>>> Fred Stluka -- mailt...@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 8/17/16 4:17 PM, Matt wrote:
>>>>
>>>> When I'm trying to get tests to work it simply states that its unable 
>>>> to import .tests. I'm not sure what I'm missing here. Here is some 
>>>> output please let me know if you need more: 
>>>>
>>>> ./manage.py tests backups
>>>> https://dpaste.de/4U9C
>>>>
>>>> The test file:
>>>> https://dpaste.de/bBZt
>>>> -- 
>>>> 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...@googlegroups.com.
>>>> To post to this group, send email to django...@googlegroups.com.
>>>> Visit this group at https://groups.google.com/group/django-users.
>>>> To view this discussion on the web visit 
>>>> https://groups.google.com/d/msgid/django-users/89d6fac7-0848-4e35-8b4a-62d24178c3aa%40googlegroups.com
>>>>  
>>>> <https://groups.google.com/d/msgid/django-users/89d6fac7-0848-4e35-8b4a-62d24178c3aa%40googlegroups.com?utm_medium=email_source=footer>
>>>> .
>>>> 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...@googlegroups.com.
>>> To post to this group, send email to django...@googlegroups.com.
>>> Visit this group at https://groups.google.com/group/django-users.
>>>
>>> To view this discussion on the web visit 
>>> https://groups.google.com/d/msgid/django-users/04fcacea-15d0-42af-afe5-424c2d1df86f%40googlegroups.com
>>>  
>>> <https://groups.google.com/d/msgid/django-users/04fcacea-15d0-42af-afe5-424c2d1df86f%40googlegroups.com?utm_medium=email_source=footer>
>>> .
>>> For more options, visit https://groups.google.com

Re: Unable to get tests to work

2016-08-17 Thread Matt
Ok a step forward. When I spell out the tests it works: 

https://dpaste.de/2MXf

But when I run test without arguments, it fails out:

https://dpaste.de/cgTH

There is more than the backups app here, but I plan to replicate out the 
fix when I get it.

On Wednesday, August 17, 2016 at 2:34:45 PM UTC-6, Fred Stluka wrote:
>
> Matt,
>
> Oops!  Right.  I just noticed that in the dpaste.
>
> My next guess is you may need to change the name "good_index_text"
> to something that starts with "test_" to get it to be recognized as a 
> test.
>
> Or maybe something to do with "refreshes"?  The test trace shows
> it trying to run testcase "refreshes.backups.tests", but in the manual
> import you did from the python shell, you only import "backups.tests"
>
> --Fred 
> --
> Fred Stluka -- mailt...@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 8/17/16 4:27 PM, Matt wrote:
>
> Sorry for the typo, but I have already do that way. I have the output in 
> the the first link.
>
> On Wednesday, August 17, 2016 at 2:24:19 PM UTC-6, Fred Stluka wrote: 
>>
>> Matt,
>>
>> Drop the "s" from "tests":
>>
>> ./manage.py test backups
>>
>> --Fred 
>> --
>> Fred Stluka -- mailt...@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 8/17/16 4:17 PM, Matt wrote:
>>
>> When I'm trying to get tests to work it simply states that its unable to 
>> import .tests. I'm not sure what I'm missing here. Here is some output 
>> please let me know if you need more: 
>>
>> ./manage.py tests backups
>> https://dpaste.de/4U9C
>>
>> The test file:
>> https://dpaste.de/bBZt
>> -- 
>> 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...@googlegroups.com.
>> To post to this group, send email to django...@googlegroups.com.
>> Visit this group at https://groups.google.com/group/django-users.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/89d6fac7-0848-4e35-8b4a-62d24178c3aa%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/django-users/89d6fac7-0848-4e35-8b4a-62d24178c3aa%40googlegroups.com?utm_medium=email_source=footer>
>> .
>> 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...@googlegroups.com .
> To post to this group, send email to django...@googlegroups.com 
> .
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/django-users/04fcacea-15d0-42af-afe5-424c2d1df86f%40googlegroups.com
>  
> <https://groups.google.com/d/msgid/django-users/04fcacea-15d0-42af-afe5-424c2d1df86f%40googlegroups.com?utm_medium=email_source=footer>
> .
> 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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/404f7e22-6f34-4c0d-bfdd-f277f6fb7543%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Unable to get tests to work

2016-08-17 Thread Matt
Sorry for the typo, but I have already do that way. I have the output in 
the the first link.

On Wednesday, August 17, 2016 at 2:24:19 PM UTC-6, Fred Stluka wrote:
>
> Matt,
>
> Drop the "s" from "tests":
>
> ./manage.py test backups
>
> --Fred 
> --
> Fred Stluka -- mailt...@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 8/17/16 4:17 PM, Matt wrote:
>
> When I'm trying to get tests to work it simply states that its unable to 
> import .tests. I'm not sure what I'm missing here. Here is some output 
> please let me know if you need more: 
>
> ./manage.py tests backups
> https://dpaste.de/4U9C
>
> The test file:
> https://dpaste.de/bBZt
> -- 
> 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...@googlegroups.com .
> To post to this group, send email to django...@googlegroups.com 
> .
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/django-users/89d6fac7-0848-4e35-8b4a-62d24178c3aa%40googlegroups.com
>  
> <https://groups.google.com/d/msgid/django-users/89d6fac7-0848-4e35-8b4a-62d24178c3aa%40googlegroups.com?utm_medium=email_source=footer>
> .
> 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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/04fcacea-15d0-42af-afe5-424c2d1df86f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Unable to get tests to work

2016-08-17 Thread Matt
When I'm trying to get tests to work it simply states that its unable to 
import .tests. I'm not sure what I'm missing here. Here is some output 
please let me know if you need more:

./manage.py tests backups
https://dpaste.de/4U9C

The test file:
https://dpaste.de/bBZt

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/89d6fac7-0848-4e35-8b4a-62d24178c3aa%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Turn off migrations completely in Django 1.7

2016-04-20 Thread Matt Schinckel


On Wednesday, December 2, 2015 at 6:31:31 PM UTC+10:30, john@gmail.com 
wrote:
>
> +1 for disabling migrations completely - for several reasons.
>
> 1. Right now, I'm trying to run tests against a production database with 
> runserver, in *read-only* mode - but it fails because it can't create the 
> django_migrations table.  (I'm in the process of upgrading from Django 1.4 
> to 1.8, so the table doesn't yet exist in production.) 
>

2. Our mysql database is 3TB, with some tables of up to 500GB - and I 
> assume that migrating them with Django - without taking the system down for 
> days - is not possible.  Instead, we use Percona's pt-online-schema-change, 
> which does an excellent job of migrating big tables, whilst keeping them 
> fully usable with no downtime.
>

When upgrading from 1.4 to 1.7+, you shouldn't be changing anything in the 
database. Sure, you'll want to build up the migrations, but you won't 
actually want to apply them, only fake them. If you are attempting to 
change your db structure at the same point in time as upgrading from 
pre-1.7 to post-1.7, you are making it much harder than it needs to be. 
(Yes, I'm going through the same process, with a database of similar size. 
Mine is postgres though).
 

> Point 2 is covered, I think, by setting all models to unmanged, as we do - 
> but that doesn't help me with the upgrade process in point 1 - unless I'm 
> missing something?
>
> (Yes, perhaps I could jump through hoops and make a second, writable 
> database, with appropriate routers etc, to enable creation of the 
> django_migrations table, to get past point 1 - but if django migrations are 
> useless to us anyway... disabling migrations entirely seems far more 
> logical.)
>
>
>

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/2b648b12-78ba-4323-9404-512aef5d0e77%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


pyodbc: Works in Plain Python, Django 1.8 Shell Throws Error

2015-04-27 Thread Matt Woodward
Running into a bit of an odd problem I hope someone can help with.

Envrionment:
* Ubuntu Server 14.04, 64-bit (Vagrant box)
* Python 3.4
* Django 1.8
* pyodbc 3.0.8

pyodbc installs fine. When I do python3 and then import pyodbc, that works 
fine.

When I do python3 manage.py shell and then import pyodbc, however, I get 
this:
http://pastebin.com/cNDrmvcb

Got a bit of help in IRC with someone suggested to turn on pdb trace on the 
run_shell command, which I did, but then I just get this:
*** SystemError: initialization of pyodbc raised unreported exception

I just can't figure out why it'd work in a plain python interpreter but not 
in the Django shell, and I'm not sure how to diagnose or troubleshoot 
further.

Appreciate any tips or suggestions anyone might have. Thanks!

-- 
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/949d8be7-8ca2-499d-90eb-aa621498b038%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: "The outermost 'atomic' block cannot use savepoint = False when autocommit is off." error after upgrading to Django 1.8

2015-04-03 Thread Matt Woodward
Thanks so much for the quick and thorough reply!

I think I'm set now with the "Right" example below -- I was getting errors 
(the most cryptic of which was just "__exit__") when I was trying various 
incarnations of atomic but it seems to be working now using the example you 
provided.

The last thing I need to verify is the behavior change around assigning 
unsaved objects to relations since in this particular case I'm creating a 
new object and then saving other objects that have the first one as a FK, 
but that's looking good thus far in testing.

Thanks again for your help -- much appreciated!

Matt

On Thursday, April 2, 2015 at 12:09:59 PM UTC-7, Simon Charette wrote:
>
> Hi Matt,
>
> I think it would be preferable to use atomic() here.
>
> From reading the documentation 
> <https://docs.djangoproject.com/en/1.8/topics/db/transactions/> it looks 
> like you might already be in a transaction when calling `set_autocommit` 
> but it's hard to tell without the full traceback.
>
> What kind of errors do you get from:
>
> def foo(request):
> with transaction.atomic():
> # ... do stuff involving multiple database actions ...
>
> Note that you should never catch `DatabaseError` within an `atomic()` 
> context. You should wrap the context managed block with a try/except 
> instead:
>
> *Wrong*
> with transaction.atomic():
> try:
> # Do database stuff possibly raising database errors
> except DatabaseError:
> pass
>
>
> *Right*
> try:
> with transaction.atomic():
> # Do database stuff possibly raising database errors
> except DatabaseError:
> pass
>
> Simon
>
> Le jeudi 2 avril 2015 14:42:26 UTC-4, Matt Woodward a écrit :
>>
>> Hi all -- I just upgraded one of my projects to Django 1.8 from 1.7.7 and 
>> in a view function where we're doing manual transaction management 
>> (Postgres) I'm now getting the error in the subject line.
>>
>> Basic gist of the code involved:
>>
>> def foo(request):
>>   try:
>> transaction.set_autocommit(False)
>>
>> ... do stuff involving multiple database actions ...
>>   except (DatabaseError, Exception) as e:
>> transaction.rollback()
>>
>> This worked fine in 1.7.7 so I'm not sure what I need to change to get it 
>> working with 1.8.
>>
>> I did read the docs on the atomic() functionality and took a few runs at 
>> that but just wound up with different errors, so I thought I'd start with 
>> what I originally had and see what I need to change to make Django 1.8 
>> happy. But if using the atomic() stuff is preferable any tips around that 
>> would also be appreciated; I can post the errors I'm getting when trying 
>> things that way as needed.
>>
>> Appreciate any ideas anyone has. Thanks.
>>
>

-- 
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/02966744-31f5-496b-8f44-fcb551b4184c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


"The outermost 'atomic' block cannot use savepoint = False when autocommit is off." error after upgrading to Django 1.8

2015-04-02 Thread Matt Woodward
Hi all -- I just upgraded one of my projects to Django 1.8 from 1.7.7 and 
in a view function where we're doing manual transaction management 
(Postgres) I'm now getting the error in the subject line.

Basic gist of the code involved:

def foo(request):
  try:
transaction.set_autocommit(False)

... do stuff involving multiple database actions ...
  except (DatabaseError, Exception) as e:
transaction.rollback()

This worked fine in 1.7.7 so I'm not sure what I need to change to get it 
working with 1.8.

I did read the docs on the atomic() functionality and took a few runs at 
that but just wound up with different errors, so I thought I'd start with 
what I originally had and see what I need to change to make Django 1.8 
happy. But if using the atomic() stuff is preferable any tips around that 
would also be appreciated; I can post the errors I'm getting when trying 
things that way as needed.

Appreciate any ideas anyone has. Thanks.

-- 
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/670a0358-3538-4a2f-b5e3-b1c2a33076ee%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


django custom timezone middleware causing django.contrib.humanize test to fail

2015-03-31 Thread Matt Ball
Hi -- I'm unable to get all tests to pass with Django 1.5.4 when I have 
custom timezone-activating middleware enabled.

I've posted code here: http://stackoverflow.com/questions/29376612

Is there a way to disable the middleware for that specific test?

-- 
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/8cdcad03-1bed-4ca0-ab13-10d93e0fa6c8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Authenticate users with both username and email

2015-01-15 Thread Matt Cooper
Your if block in views.py is not well-formed. I haven't tested this but I'd 
write it more like this:

# try username
user = auth.authenticate(username=username, password=password)
if user is not None:
auth.login(request, user)
return HttpResponseRedirect('/')
# fall-through to email
user = auth.authenticate(email=username, password=password)
if user is not None:
auth.login(request, user)
return HttpResponseRedirect('/')
# ok, neither one worked
return HttpResponseRedirect('/accounts/invalid_login')


On Wednesday, January 14, 2015 at 10:07:29 PM UTC-8, Kakar Nyori wrote:

> I have extendted the *UserCreationForm* with email and other fields, so 
> that I could authenticate a user with both its username and email.
>
> forms.py:
>
>> class UserCreationForm(UserCreationForm):
>> class Meta:
>> model = User
>> fields = ('first_name', 'last_name', 'username', 'email',)
>
>
>  
> views.py:
>
> def auth_view(request):
>> username = request.POST.get('username','')
>> password = request.POST.get('password','')
>> user = auth.authenticate(username=username, password=password)
>> if user is not None:
>> auth.login(request, user)
>> return HttpResponseRedirect('/')
>> elif:
>> user = auth.authenticate(email=username, password=password)
>> if user is not None:
>> auth.login(request, user)
>> return HttpResponseRedirect('/')
>> else:
>> return HttpResponseRedirect('/accounts/invalid_login')
>
>
> html:
>
> 
>> {%csrf_token%}
>> Email or Username:
>> 
>> Password:
>> 
>> 
>> 
>
>
>
> In the views I tried giving both the *username* and *email *as input from 
> the form as *name*, and check to see if username and password 
> authenticate. If not then check whether email and password authenticate. 
> But its not working. How do I solve this problem? Please kindly help me. 
> Thank you.
>

-- 
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/97740eb6-f826-4159-b770-20e66d917b20%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Desired: Field behavior like AutoField + unique_with

2015-01-14 Thread Matt Cooper
Got it - thank you! This community is great :)

On Tuesday, January 13, 2015 at 11:31:19 PM UTC-8, Jani Tiainen wrote:
>
> Because sequence number was running number per "tenant" (in my case it 
> was invoice type) that started from zero (0) at the beginning of the 
> every year. 
>
> You could use max+1 as well but you should be aware that there is a 
> slim chance that there is race condition and you may end up having two 
> entities with the same max number - that though would raise error when 
> trying to save into database. 
>
> By having explicitly pessimistic locking (select_for_update) for a row 
> with tenant + sequence value you can guarantee that no other request 
> can change the value while you're reading it. 
>
> To make that easier you can create custom manager that can retrieve 
> updated sequence values automagically, so your call would look like 
> something like: 
>
> Tenant.sequence.get_value(tenant, sequence) 
>
>
> On Tue, 13 Jan 2015 06:37:21 -0800 (PST) 
> Matt Cooper <vtbas...@gmail.com > wrote: 
>
> > Thanks Jani, good to hear someone has gone down this road before. 
> > Since you did it in code, is there a reason you kept a sequence value 
> > on Tenant rather than using 
> > Widget.objects.aggregate(Max(Widget.sequence_value)) ? I ask because 
> > for my app, Widget is actually just one of several cases where I need 
> > this pattern. If I could keep all the book-keeping on the model with 
> > the constraint, that seems cleaner to me. But, of course, I'm not 
> > willing to pay a huge performance or corruption penalty just for 
> > vague ideological purity :) 
> > 
> > Thanks again! 
> > ~matt 
> > 
> > On Tuesday, January 13, 2015 at 5:07:21 AM UTC-8, Jani Tiainen wrote: 
> > > 
> > > I've done something similiar. 
> > > 
> > > Only way to do that is that you need to upkeep that tenant 
> > > sequence_id manually, 
> > > 
> > > So doing something like: 
> > > 
> > > class Tenant(models.Model): 
> > > name = models.CharField(max_length=50) 
> > > sequence_value = models.IntegerField() 
> > > 
> > > and in a code: 
> > > 
> > > tenant = Tenant.object.get(id=tenant_id).select_for_update()  # 
> > > Pessimistic locking 
> > > tenant.sequence_value = tenant.sequence_value + 1 
> > > tenant.save() 
> > > 
> > > widget = Widget(owner=tenant,sequence_value=tenant.sequence_value) 
> > > widget.save() 
> > > 
> > > That should do the trick. Another option could be using table 
> > > triggers to automate 
> > > that within a database table trigger(s). 
> > > 
> > > On Mon, 12 Jan 2015 21:26:54 -0800 (PST) 
> > > Matt Cooper <vtbas...@gmail.com > wrote: 
> > > 
> > > > I'm building a multi-tenant application with a data model that 
> > > simplifies 
> > > > to: 
> > > > 
> > > > class Tenant(models.Model): 
> > > > name = models.CharField(max_length=50) 
> > > > 
> > > > class Widget(models.Model): 
> > > > owner = models.ForeignKey(Tenant) 
> > > > sequence_id =  
> > > > 
> > > > 
> > > > I want Widget.sequence_id to work like an AutoField (that is, 
> > > automatically 
> > > > give me something unique and generally incrementing by 1) but 
> > > > scoped to 
> > > a 
> > > > single Widget.owner. So for instance, when Tenant A creates 3 
> > > > widgets, 
> > > they 
> > > > would get sequence_ids 1, 2, and 3. Then Tenant B comes along and 
> > > creates 2 
> > > > widgets; those widgets get sequence_ids 1 and 2. The tenant/user 
> > > > gets no control over the number, but it's something she'll see in 
> > > > the UI. AutoNumber is out because from the perspective of a 
> > > > single tenant, they should have sequential widget IDs. 
> > > > GUIDs/UUIDs are out because it needs 
> > > to 
> > > > be human-readable. 
> > > > 
> > > > I looked through docs on AutoField and unique_together. I turned 
> > > > StackOverflow upside down and only found this 
> > > > <
> http://stackoverflow.com/questions/18072586/django-autofield-increment>, 
> > > 
> > > > which isn't quite what I want. I didn't see anything on 
> > > djangopackages.com 
> > > > that would solve my problem, though I could have missed it. 
> > >

Re: Desired: Field behavior like AutoField + unique_with

2015-01-13 Thread Matt Cooper
Thanks Jani, good to hear someone has gone down this road before. Since you 
did it in code, is there a reason you kept a sequence value on Tenant 
rather than using Widget.objects.aggregate(Max(Widget.sequence_value)) ? I 
ask because for my app, Widget is actually just one of several cases where 
I need this pattern. If I could keep all the book-keeping on the model with 
the constraint, that seems cleaner to me. But, of course, I'm not willing 
to pay a huge performance or corruption penalty just for vague ideological 
purity :)

Thanks again!
~matt

On Tuesday, January 13, 2015 at 5:07:21 AM UTC-8, Jani Tiainen wrote:
>
> I've done something similiar. 
>
> Only way to do that is that you need to upkeep that tenant sequence_id 
> manually, 
>
> So doing something like: 
>
> class Tenant(models.Model): 
> name = models.CharField(max_length=50) 
> sequence_value = models.IntegerField() 
>
> and in a code: 
>
> tenant = Tenant.object.get(id=tenant_id).select_for_update()  # 
> Pessimistic locking 
> tenant.sequence_value = tenant.sequence_value + 1 
> tenant.save() 
>
> widget = Widget(owner=tenant,sequence_value=tenant.sequence_value) 
> widget.save() 
>
> That should do the trick. Another option could be using table triggers to 
> automate 
> that within a database table trigger(s). 
>
> On Mon, 12 Jan 2015 21:26:54 -0800 (PST) 
> Matt Cooper <vtbas...@gmail.com > wrote: 
>
> > I'm building a multi-tenant application with a data model that 
> simplifies 
> > to: 
> > 
> > class Tenant(models.Model): 
> > name = models.CharField(max_length=50) 
> > 
> > class Widget(models.Model): 
> > owner = models.ForeignKey(Tenant) 
> > sequence_id =  
> > 
> > 
> > I want Widget.sequence_id to work like an AutoField (that is, 
> automatically 
> > give me something unique and generally incrementing by 1) but scoped to 
> a 
> > single Widget.owner. So for instance, when Tenant A creates 3 widgets, 
> they 
> > would get sequence_ids 1, 2, and 3. Then Tenant B comes along and 
> creates 2 
> > widgets; those widgets get sequence_ids 1 and 2. The tenant/user gets no 
> > control over the number, but it's something she'll see in the UI. 
> > AutoNumber is out because from the perspective of a single tenant, they 
> > should have sequential widget IDs. GUIDs/UUIDs are out because it needs 
> to 
> > be human-readable. 
> > 
> > I looked through docs on AutoField and unique_together. I turned 
> > StackOverflow upside down and only found this 
> > <http://stackoverflow.com/questions/18072586/django-autofield-increment>, 
>
> > which isn't quite what I want. I didn't see anything on 
> djangopackages.com 
> > that would solve my problem, though I could have missed it. 
> > 
> > Basically, has anyone done something like this before and have a 
> suggested 
> > pattern? 
> > 
> > Thanks! 
> > ~matt 
> > 
> > -- 
> > 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...@googlegroups.com . 
> > To post to this group, send email to django...@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/37fd32e7-28dd-4c10-8451-b0d705a3e52e%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/1ab4b16d-df97-4412-9622-22cf3b344f80%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Desired: Field behavior like AutoField + unique_with

2015-01-13 Thread Matt Cooper
I'm building a multi-tenant application with a data model that simplifies 
to:

class Tenant(models.Model):
name = models.CharField(max_length=50)

class Widget(models.Model):
owner = models.ForeignKey(Tenant)
sequence_id = 


I want Widget.sequence_id to work like an AutoField (that is, automatically 
give me something unique and generally incrementing by 1) but scoped to a 
single Widget.owner. So for instance, when Tenant A creates 3 widgets, they 
would get sequence_ids 1, 2, and 3. Then Tenant B comes along and creates 2 
widgets; those widgets get sequence_ids 1 and 2. The tenant/user gets no 
control over the number, but it's something she'll see in the UI. 
AutoNumber is out because from the perspective of a single tenant, they 
should have sequential widget IDs. GUIDs/UUIDs are out because it needs to 
be human-readable.

I looked through docs on AutoField and unique_together. I turned 
StackOverflow upside down and only found this 
<http://stackoverflow.com/questions/18072586/django-autofield-increment>, 
which isn't quite what I want. I didn't see anything on djangopackages.com 
that would solve my problem, though I could have missed it.

Basically, has anyone done something like this before and have a suggested 
pattern?

Thanks!
~matt

-- 
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/37fd32e7-28dd-4c10-8451-b0d705a3e52e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Alternative to fabric

2014-11-17 Thread Matt Gushee
Hi--

On Mon, Nov 17, 2014 at 12:27 PM, René Fleschenberg
<r...@fleschenberg.net> wrote:

> On Monday 17 November 2014 17:42:22 Brad Pitcher wrote:
>> I agree Ansible is a good fit for your situation. Since Ansible works from
>> yaml files, you don't have to write any Python 2.x compatible code as you
>> would with Fabric.

That's true.

> I agree that Ansible is a nice tool, but AFAIK, it is not Python 3 compatible.

That's also true.

In other words, you don't have to write Python 2 (or any Python) code
to use Ansible, but you do have to have Python 2 installed on your
target hosts, which I believe was the OP's objection.

The question of transitioning to Python 3 has been discussed in the
Ansible community; apparently the devs feel that moving to Python 3 at
this time would not deliver any great benefits, and would risk
alienating a large enterprise user base that is mostly using Python
2.x.

I was also looking at other alternatives, and it doesn't seem like
there are any good CM/deployment tools that currently support Python
3. It did look like Fabric is at least planning for a transition (I
think I saw something about it in the docs ... or maybe they had a
Python 3 development branch ... it was a few weeks ago, so I don't
remember exactly).

--
Matt Gushee

-- 
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/CABrD0edV8Ar6muh0eVP0UjjpYHf%3DbR%3DPHdE%2BpzSz_%3DRaa0bo6w%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Another Noob questions

2014-09-01 Thread Matt Gushee
Hello again--

Since I don't really understand what you are doing, I can't give you
any specific help. But since I have the impression you are new not
only to Django but to online technical forums, let me give you a
general recommendation:

You will get better answers if you ask better questions. That means
primarily that you should describe in some detail what steps you have
followed and what is not working - e.g. if you get an error message,
say exactly what the message is; or if you expected some result and
aren't getting it, describe exactly what you were expecting. And if
you are following some tutorial or how-to document, please say exactly
which one - preferably with a link. And so on. You have to exercise
some judgement about the level of detail - if your question includes
all the information that could possibly be relevant, that's probably
too much, so just take your best guess as to what the important points
are. In this case, you should at least tell us:

  1. how you installed Django (e.g. are you using virtualenv ?);
  2. what kind of hosting account you have; and
  3. what database you are using.

Best of luck with your project!


On Mon, Sep 1, 2014 at 6:58 PM, Michael Carey  wrote:
> No I didnt have a url(r'^$', views.home_page),
>
> I have pushed the site to git and am trying to view it on git for a start.
>
>
>
> On Tuesday, 2 September 2014 10:18:21 UTC+10, Michael Carey wrote:
>>
>> So I followed a tutorial on graphing a graph in Django.
>>
>> I have the urls page set up, do I need a index.html?
>>
>> Thank you,
>>
>> MC
>
> --
> 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/8d91a2a3-343f-4424-b9ad-4e0b6de0f509%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/CABrD0eeRVSj8efPax0qFx1PzNErf5cYzLWvM45oW98H6ET4whA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Another Noob questions

2014-09-01 Thread Matt Gushee
Hi, Michael--

On Mon, Sep 1, 2014 at 6:58 PM, Michael Carey <mpc.t...@gmail.com> wrote:
>
> I have pushed the site to git and am trying to view it on git for a start.

Seeing as I'm the one who recommended Git to you, I'd better say something ...

If you literally mean 'view it on git' - though I'm not even sure what
you mean by that - it probably is not going to work. Git, or any
version control system, is just for managing your code - it has
nothing to do with running your application.

You have to run Django (e.g. 'python manage.py runserver') just as you
would on your development machine. And there are almost certainly
other steps you need to do to set up the server, but without knowing
anything about your hosting environment or about the exact steps you
have followed already, it's not possible to say much more.

It seems like either you are glossing over a lot of detail in your
questions, or you are lacking some basic knowledge of how this stuff
works. Nothing you can't learn, but if your posts are accurately
describing what you are doing, I think you're in for a lot of
frustration.

I have to go make dinner, but I'll check back later. If you're stuck,
I'll see if I can point you to some helpful resources.

--
Matt Gushee

-- 
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/CABrD0ee8fp3RwLb9TMzuJq9imauF34RLu_VbdYJDAy%2BWHJwteQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: I have created an app (total noob question)

2014-08-31 Thread Matt Gushee
Hi, Michael--

On Sun, Aug 31, 2014 at 10:28 PM, Michael Carey <mpc.t...@gmail.com> wrote:
> That is assuming that you just upload the files?

Your doubt is justified. Just uploading the files is a bit of an
oversimplification. It would help if you gave some specifics about the
directory structure you're working with.

However, I can make a few general recommendations ...

1. Are you using version control? If not, you should - and it solves
part of your problem. I know it may seem like overkill to go through
all the steps of setting up a repo for just a little app, but if you
are at all serious about this Django development thing it will save
you a lot of work in the long run. I think these days Git is the most
popular version control system, but Mercurial (AKA hg) and Bazaar (AKA
bzr) are also very good (and both programmed in Python, yay!).

There is a good, concise tutorial online about setting up a Django
project to work with Git. I don't have a link for it, but I found it
very easily by Googling something like "Django version control."

So, assuming you have shell access (e.g., can log in via SSH) on your
web server, you would follow a procedure like this:

  git push
DEV MACHINE   -->   GIT REPOSITORY

  git pull
SERVER <--GIT REPOSITORY

That's *very* simplified. In reality, if you are trying to do
professional development, you need to at least have a test environment
online, so that you always test the code in conditions that are as
nearly identical as possible to your production server. But the above
will do if you're just experimenting. And if you don't have shell
access, someone else will have to help you with that.

Now, what files do you put under version control?

Let's say you follow the typical advice, and have a virtual
environment, with any Django projects/sites in separate directories.
For example, I'm using a setup like this (on Linux):

/srv/http/salixmedia.com/test/
pyenv/
 [virtual environment with Django and other
required libraries]
my_site/
 admin.py
 settings.py
 local_settings.py
 models.py
 wsgi.py
 
my_app/
 admin.py
 models.py
 views.py
 

In this setup, all of 'my_app' would go under version control.
Likewise, all of 'my_site' *except* for local_settings.py - or
whichever file contains your secret keys and database password. You
need to guard that information closely, so it should never go into
version control.

Some people think you should put the virtual env (my 'pyenv'
directory) under version control too; I say no. You do want to ensure
that you have all the same libraries installed everywhere, but there's
another way to do that:

  $ pip freeze  > requirements.txt  # on development box

  $ pip install -r requirements.txt   # on server

The requirements file lists all your installed packages, including
their versions. 'requirements.txt' should be under version control, so
you will have it on your server when you check out the code there. I'm
sure this approach is not totally foolproof, but I believe it is
fairly reliable, and will save you from cluttering your repo with a
great deal of third-party code that you will probably never modify.

Okay, so that takes care of all your python code and config files. You
also have to deal with your database. And honestly, I'm pretty new at
Django myself, and haven't completed figured out this aspect. When you
are setting up a site, you need to use commands such as

 python manage.py syncdb

and

 python manage.py migrate 

If you're not familiar with those, I'd suggest you go through the
online documentation. These commands take care of your schemas (to
oversimplify, those represent your models in the database), but they
don't, by default, handle any site content that you may have created.
That's the part I'm not too sure about, but I'm sure others on this
list will have good advice.

Hope that helps a bit.

--
Matt Gushee

-- 
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/CABrD0eeQoqMcMAiqmmyMgwxMbvZ01rj%2BC%2BkAzepjX%3D8EYDMZxg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: how to call django web page with ordinary html page

2014-08-29 Thread Matt Gushee
On Fri, Aug 29, 2014 at 6:16 AM, Shubham Pansari
<pansarishubham2...@gmail.com> wrote:
> You are missing csrf_token which is set by request for csrf verification.
> After the line
> http://127.0.0.1:8000/test/; method="post">
> in your code put {%csrf_token%} and it should work fine

I'm a Django newbie, so I could well be mistaken, but I don't think
that will work. The OP said it was plain HTML; that means Django
doesn't process it, so Django template tags won't work. But it looks
like Flatpages might help:
http://www.djangobook.com/en/2.0/chapter16.html.

--
Matt Gushee

-- 
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/CABrD0ed5HGNC%2BVbz3urmaJNEpYVWSdbjKmu86F4rkENL3DydDQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Widget for simple (not input) text

2014-08-28 Thread Matt Gushee
What do you want to do with this 'widget'? From your description, it
sounds like you could use a normal paragraph element -- which might
look something like this in a Django template:

   {{ some_text }}

Does that not meet your needs?

--
Matt Gushee

On Thu, Aug 28, 2014 at 5:51 PM, Yarick Antonov <exx...@gmail.com> wrote:
> Does Django (or HTML itself) contain any sort of TextField, what represent
> not the form for text input but simple, static not editable text?
> I mean something like this: http://i.imgur.com/Nv0XN0J.png
>
> Is it possible to have a widget for that data, or i can use simple string to
> do this?
>
> --
> 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/92f5c4d1-4d10-41cb-b34d-d9701a394493%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/CABrD0ee6imW-KAJ1kwQeKagSV_-MqPJJ4_ZoB48jF7BkK%2BbcAg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Looking for a pointer

2014-08-15 Thread Matt Lind
I think I found it.

It appears that the form has a name called "fileupload" and submits back to 
the orginal page.  From there the JS fires off.

I guess I'll have to see how to modify this.

Any other pointers would be appreciated!

On Friday, August 15, 2014 8:34:43 AM UTC-4, Collin Anderson wrote:
>
> It's happening somewhere in the javascript. 
> https://github.com/Alem/django-jfu/tree/master/jfu/static/js

-- 
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/ac4718a9-f166-4504-b47a-61385f485790%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Looking for a pointer

2014-08-15 Thread Matt Lind

What I am wondering is how the Button type "Submit" is calling that JS some 
where.

I don't see any specific script/method calls on the upload_form.html page, 
which specifically is where the bar "shows up".

Thanks

On Friday, August 15, 2014 8:34:43 AM UTC-4, Collin Anderson wrote:
>
> It's happening somewhere in the javascript. 
> https://github.com/Alem/django-jfu/tree/master/jfu/static/js

-- 
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/a7edbe7d-25ac-424f-9351-8f5288c7be0e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Looking for a pointer

2014-08-15 Thread Matt Lind
I am using this project here:

https://github.com/Alem/django-jfu

Everything is installed and working properly.

The project includes a progress bar logic that I'd like to re-use elsewhere 
on my site.

The progress bar filling appears to happen when the "Start Upload" buttons 
are clicked.

However I can't seem to find the logic as to where or why that bit of code 
kicks off.

Can anyone out here enlighten me as to where the "on-click" type action is 
taking place?

Thanks

-- 
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/052d78bb-e4f8-480f-be3b-fcb1cc86593a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Please help:ImportError: No module named django

2014-07-24 Thread Matt Gushee
Hi, Liu Xuan--

What result do you get when you do the following?

Python 2.7.6

>>> import sys
>>> sys.path

On Thu, Jul 24, 2014 at 1:23 PM, New Django User  wrote:
> Hi, I have problems with Django in windows 7.
>
> I installed Django using Windows Powershell:
>
> PS C:\Python27> pip install django
> Requirement already satisfied (use --upgrade to upgrade): django in
> c:\anaconda\lib\site-package.
>
> However, when I run "import django" in Python 2.7.6 shell, it showed the
> following error message:
>
> Traceback (most recent call last):
>   File "", line 1, in 
> import django
> ImportError: No module named django
>
> I searched over the internet and did not find useful information.
>
> Please help.
>
> Many thanks in 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/b30d3b18-c728-4bd5-8a72-874dd5a065b3%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/CABrD0efC05zFMNOgTKDX%3D0YcCV5tAnW6JDUbamOosRTRqGQLxg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Registration extend nightmare

2014-06-02 Thread Matt Guy
Thanks for your answer.

The prospect of dumping all of this and putting together a patchwork of my 
own code alongside registration is somewhat daunting at this stage. It also 
seems as though so many people use and recommend registration, including 
those successfully tackling this problem, that surely there must be a quick 
fix here!

I've sought postgres specific fixes to this problem, i've fiddled about in 
the sql console, i've tried a lot, but it's not seeming that simple. I 
think I just need a seasoned django warrior to wave a wand.

Any other thoughts?

Thanks,
Matt


On Saturday, May 31, 2014 12:22:50 AM UTC+2, WongoBongo wrote:
>
> This is not an answer to your question, but I have used 
> Django-registration before and ran into its limitations. Consider all the 
> time you spent trying to debug this then consider that you'd probably 
> already be done if you had just wrote a custom user and maybe salvaged some 
> of the nicer code from Django-registration.
>
> I've seen that error before. I seem to recall it comes from the way 
> postgres handles transactions when one part of the transaction craps out. 
> You might find some good info if you search for that specific message with 
> the term postgres. Maybe also review the docs on Django transactions.
>
> https://docs.djangoproject.com/en/1.6/topics/db/transactions/ 
> <https://www.google.com/url?q=https%3A%2F%2Fdocs.djangoproject.com%2Fen%2F1.6%2Ftopics%2Fdb%2Ftransactions%2F=D=1=AFQjCNG_icrJUvuVmnfeb_nLcMJIbDIm0g>
>
> K
>
>
> On Friday, May 30, 2014 7:26:04 AM UTC-7, Matt Guy wrote:
>>
>> I am trying to add an extra user profile registration field using 
>> registration. Should be so simple but this is bringing me to the edge.
>>
>

-- 
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/0576c58f-abdd-4bd2-8ebc-b8012cd48e40%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Registration extend nightmare

2014-05-30 Thread Matt Guy
able this, pass ``send_email=False``.

"""

new_user = User.objects.create_user(username, email, password)

new_user.is_active = False

new_user.save()

registration_profile = self.create_profile(new_user)

if send_email:

registration_profile.send_activation_email(site)

return new_user

create_inactive_user = transaction.commit_on_success(create_inactive_user)
__



Any thoughts would be much appreciated!

Matt


-- 
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/32e0edb8-5ff8-427f-bc69-6766b774011d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Casting a raw query set as a list for pagination

2014-04-26 Thread Matt Buck
I've created a paginator for RawQuerySets. 
 https://github.com/seamusmb/django-paginator-rawqueryset

On Tuesday, March 26, 2013 5:51:41 AM UTC-4, chambe...@gmail.com wrote:
>
> I'm trying to implement Django's built in pagination feature with a raw 
> query set. I've researched the issue and the answer is I need to cast my 
> set as a list. Something like this:
>
> paginator = Paginator(refg, 100) # Show 100 contacts per page
> paginator._count = len(list(refg))
>
> From my understanding, setting the count field for the paginator should 
> prevent Django from trying to get the size of my raw set, but this is not the 
> case.  I'm still getting the "RawQuerySet has no len() operation" error.  
> I've attched the relevant code from my views.py and my template.  
>
> Can I get some advice as to how I can fix this error?
>
>
> views.py
> refg = RefGene.objects.raw(qrefg) 
>
> paginator = Paginator(refg, 100) # Show 100 contacts per page 
> paginator._count = len(list(refg)) 
>
> # using django's generated forms 
> c = RequestContext(request, { 
> "refg": refg, ... }) 
>
> return HttpResponse(t.render(c)) 
>
>
> template
>
> {% autopaginate refg %}
> {% for r in refg %}
>
> 
> {{ r.data}}
> {{ r.loc}}
> 
>
> {% endfor %}
> {% paginate %}
>
>

-- 
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/86cd1c6d-5e2d-409c-8ce7-f911c61fe856%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Problems Sending Email From Django SIte

2014-02-01 Thread Matt Schinckel
Your ADMINS setting is incorrect.

In python, the value ((a,b)) is not a 1-tuple containing a 2-tuple, as you 
want, 
but a single 2-tuple, which django interprets as a tuple containing _just_ 
email
addresses.

Try:

ADMINS = (('Mark', 'x...@example.com'),)

Note the trailing comma after the inner tuple.

Matt.

On Saturday, February 1, 2014 3:21:32 PM UTC+10:30, mark wrote:
>
> Exim4 has two logs - main and reject.
>
> Message from python prompt and mutt - shows activity in main, but not 
> reject.
>
> Message from Server 500 error with django app - no activity in main, and a 
> message in reject - 
>
> 2014-01-31 21:30:55 unqualified recipient rejected:  H=localhost 
> [127.0.0.1]
>
> That is all I have. 
>
> My settings.py files...maybe you will see something missing or 
> mis-configured for email from a django site (I removed some sensitive 
> information).
>
> *The first file base.py:*
>
> import os
> BASE_DIR = os.path.dirname(os.path.dirname(__file__))
>
>
> # Application definition
>
> INSTALLED_APPS = (
> 'django.contrib.admin',
> 'django.contrib.auth',
> 'django.contrib.contenttypes',
> 'django.contrib.sessions',
> 'django.contrib.messages',
> 'django.contrib.staticfiles',
> 'django.contrib.humanize',
> 'south',
> 'inventory',
> )
>
> MIDDLEWARE_CLASSES = (
> 'django.contrib.sessions.middleware.SessionMiddleware',
> 'django.middleware.common.CommonMiddleware',
> 'django.middleware.csrf.CsrfViewMiddleware',
> 'django.contrib.auth.middleware.AuthenticationMiddleware',
> 'django.contrib.messages.middleware.MessageMiddleware',
> 'django.middleware.clickjacking.XFrameOptionsMiddleware',
> )
>
> DEBUG = False
>
> TEMPLATE_DEBUG = False
>
> ROOT_URLCONF = 'inventory_project.urls'
>
> LANGUAGE_CODE = 'en-us'
>
> TIME_ZONE = 'America/Phoenix'
>
> USE_I18N = True
>
> USE_L10N = True
>
> USE_TZ = True
>
> *The second file base_beagle.py:*
>
> # settings/base_beagle.py
> from base import *
>
> STATIC_ROOT = os.path.join(BASE_DIR, 'static')
> STATIC_URL = 'http://192.168.5.126:7000/static/'
>
> MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
> MEDIA_URL = 'http://192.168.5.126:7000/media/'
>
> *The third file prod_beagle.py*
>
> # settings/prod_beagle.py
> from base_beagle import *
>
> # SECURITY WARNING: keep the secret key used in production secret!
> SECRET_KEY = 'xx'
>
> # SECURITY WARNING: don't run with debug turned on in production!
> DEBUG = False
>
> TEMPLATE_DEBUG = False
>
> ALLOWED_HOSTS = ['192.168.5.126', 'localhost']
>
> EMAIL_HOST = "localhost"
> EMAIL_PORT = 25
> EMAIL_SUBJECT_PREFIX = "[Django-beagle] "
>
> DATABASES = {
> 'default': {
> 'ENGINE': 'django.db.backends.mysql',
> 'NAME': 'inventory_prod',
> 'USER': '',
> 'PASSWORD': '***',
> }
> }
>
> INTERNAL_IPS = ("127.0.0.1","192.168.5.126")
>
> ADMINS = (('mark', 'x...@xx.xxx'))
>
> LOGIN_URL = '/mom/inventory/login/'
>
> WSGI_APPLICATION = "inventory_project.wsgi.application"
>
>
> Thanks,
>
> Mark
>
>
> On Fri, Jan 31, 2014 at 8:49 PM, m1chael <myk...@gmail.com 
> >wrote:
>
>> can you tail a mail server log file, while trying to send a django
>> e-mail, and see what happens? also take a look at a log file for
>> command line and mutt do a comparison of all. maybe that will help
>>
>> On Fri, Jan 31, 2014 at 10:35 PM, Mark Phillips
>> <ma...@phillipsmarketing.biz > wrote:
>> > Thank-you for your response...However,
>> >
>> > 1. I can send email from the command line and from mutt.
>> >
>> > 2. I can send email from a python prompt using the settings.py in my 
>> app.
>> >
>> > These two facts tell me the mail server is configured properly.
>> >
>> > 3. Only my django app cannot send email.
>> >
>> > This fact leads me to believe my django app is mis-configured for 
>> sending
>> > email. In all other aspects, my app works as designed.
>> >
>> > Do you have any other helpful suggestions?
>> >
>> > Mark
>> >
>> >
>> > On Fri, Jan 31, 2014 at 7:26 PM, m1chael <myk...@gmail.com> 
>> wrote:
>> >>
>> >> Your mail server needs configuring.
>> >>
>> >> On Fri, Jan 31, 2014 at 8:15 PM, Mark Phillips
>> >> <ma...@phillipsmarketing.biz > wrote:
>> >

Re: Generate a random directory for files to be uploaded

2013-12-05 Thread Matt Lind
Disregard.  I found my error.  I was trying to pass something I shouldn't 
have.  This seems to be working now.

Thanks again!

On Thursday, December 5, 2013 9:10:13 AM UTC-5, Daniel Roseman wrote:
>
> On Thursday, 5 December 2013 12:23:52 UTC, Matt Lind wrote:
>>
>> Ok, I get what what you're saying, but I seem to be having a heck of a 
>> time getting the randDir passed into the instance to perform the upload.
>>
>> Here is the new code snippets:
>>
>> views.py
>> instance = Upfile( file = file)
>> instance.upload(randDir)
>>
>> models.py
>>
>> @staticmethod
>> def upload(randDir)
>>file = models.FileField( upload_to = MEDIA_ROOT+'/'+randDir)
>>
>> I am using @staticmethod as I found that otherwise I needed to pass 
>> "self" and kept getting a NameError "self" not defined.
>>
>> The error I currently get with the above code is:
>>
>> TypeError: 'file' is an invalid keyword argument for this function
>>
>> When clicking my "upload" button.
>>
>> Thanks
>>
>
>
> You can't do that: model fields need to be defined in the model itself, at 
> declaration time.
>
> But you seem to have missed the bit in the documentation[1] which 
> describes how upload_to can be a callable, which does exactly what you want.
>
> def my_upload_to(instance, filename)
> directory = "".join(random.choice(string.ascii_letters) for n in 
> xrange(12))
> return os.path.join(MEDIA_ROOT, directory, filename)
>
> class UpFile(models.Model):
> file = models.FileField(upload_to=my_upload_to)
>
>
> [1]: 
> https://docs.djangoproject.com/en/1.6/ref/models/fields/#django.db.models.FileField.upload_to
>
> --
> DR.
>

-- 
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/04ca88b0-4d89-481a-843b-90d252c21066%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Generate a random directory for files to be uploaded

2013-12-05 Thread Matt Lind
I did miss that thanks!

However, I now seem to have an issue with the def my_upload_to(instance, 
filename) line.

Apparently "self" nor "instance" works here, and so I am getting the error 
1 argument given when I need "two".

@staticmethod doesn't seem to want to work properly either.

Thanks again!

On Thursday, December 5, 2013 9:10:13 AM UTC-5, Daniel Roseman wrote:
>
> On Thursday, 5 December 2013 12:23:52 UTC, Matt Lind wrote:
>>
>> Ok, I get what what you're saying, but I seem to be having a heck of a 
>> time getting the randDir passed into the instance to perform the upload.
>>
>> Here is the new code snippets:
>>
>> views.py
>> instance = Upfile( file = file)
>> instance.upload(randDir)
>>
>> models.py
>>
>> @staticmethod
>> def upload(randDir)
>>file = models.FileField( upload_to = MEDIA_ROOT+'/'+randDir)
>>
>> I am using @staticmethod as I found that otherwise I needed to pass 
>> "self" and kept getting a NameError "self" not defined.
>>
>> The error I currently get with the above code is:
>>
>> TypeError: 'file' is an invalid keyword argument for this function
>>
>> When clicking my "upload" button.
>>
>> Thanks
>>
>
>
> You can't do that: model fields need to be defined in the model itself, at 
> declaration time.
>
> But you seem to have missed the bit in the documentation[1] which 
> describes how upload_to can be a callable, which does exactly what you want.
>
> def my_upload_to(instance, filename)
> directory = "".join(random.choice(string.ascii_letters) for n in 
> xrange(12))
> return os.path.join(MEDIA_ROOT, directory, filename)
>
> class UpFile(models.Model):
> file = models.FileField(upload_to=my_upload_to)
>
>
> [1]: 
> https://docs.djangoproject.com/en/1.6/ref/models/fields/#django.db.models.FileField.upload_to
>
> --
> DR.
>

-- 
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/879ed008-64fd-4901-8ffc-dfa167eaaf91%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Generate a random directory for files to be uploaded

2013-12-05 Thread Matt Lind
I should also state that further down in the code I make use of snippets 
like:

basename = os.path.basename( instance.file.file.name )

So by not passing and uploading the file right away it seems like those 
snippets don't work anymore

On Sunday, November 24, 2013 10:31:34 AM UTC-5, Michael Manfre wrote:
>
> There are two things that you'll need to do. Set the random directory name 
> on the UpFile instance in the view and define a function to use with 
> upload_to that uses the random directory name on the instance to define the 
> file's target path.
>
>
> https://docs.djangoproject.com/en/dev/ref/models/fields/#django.db.models.FileField.upload_to
>
> Regards,
> Michael Manfre
>
> On Saturday, November 23, 2013 10:33:59 AM UTC-5, Matt Lind wrote:
>>
>> So I am trying to modify django-jfu ( a multi uploader) to send files to 
>> a unique directory for every unique upload session performed.  This is just 
>> due to my application's requirements and to prevent file collisions during 
>> the operations later down the road in my app.
>>
>> Anyway, here is views.py (I think the most relevant portion anyway, I 
>> could be wrong)
>>
>> def upload( request ):
>>
>> # The assumption here is that jQuery File Upload
>> # has been configured to send files one at a time.
>> # If multiple files can be uploaded simulatenously,
>> # 'file' may be a list of files.
>> #Create the file object
>> file = upload_receive( request )
>>
>> #Create an instance of our Uploader Class and pass it the file object
>> instance = UpFile ( file = file )
>> #Save the file object
>> instance.save() 
>>
>> And the "UpFile" class in models.py:
>>
>> class UpFile(models.Model):
>> file = models.FileField( upload_to = 
>> MEDIA_ROOT+'/'+"".join([random.choice(string.ascii_letters) for n in 
>> xrange(12)]))
>>
>> The problem I am having is that it appears that the "random" section at 
>> the tail end of the "upload_to" option in models,py is processed only once 
>> when the server is started (or restarted).
>>
>> This won't work for my particular application, as I need the "top level" 
>> for any uploaded of a set of files to be unique.
>>
>> For example if I have the following "upload sessions"
>>
>> Session 1:  User only uploaded a single file.  A new random/unique 
>> directory should be generated under MEDIA_ROOT, and the file should be 
>> placed in that directory.
>> Session 2:  User uploaded 2 files.  A new random/unique directory should 
>> be generated under MEDIA_ROOT, and BOTH files should be uploaded to that 
>> directory (NOT a different directory per file)
>> Session 3:  User uploaded 100 files.  Like session 2 above, a new 
>> random/unique directory should be generated under MEDIA_ROOT and all 100 
>> files should be placed underneath.
>>
>> Later on I plan on cleaning house, but for now simply getting that logic 
>> down will get me moving again...
>>
>> Thanks for any help you can provide.
>>
>

-- 
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/8170d555-94a3-4695-bff3-ab070276213f%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Generate a random directory for files to be uploaded

2013-12-05 Thread Matt Lind
Ok, I get what what you're saying, but I seem to be having a heck of a time 
getting the randDir passed into the instance to perform the upload.

Here is the new code snippets:

views.py
instance = Upfile( file = file)
instance.upload(randDir)

models.py

@staticmethod
def upload(randDir)
   file = models.FileField( upload_to = MEDIA_ROOT+'/'+randDir)

I am using @staticmethod as I found that otherwise I needed to pass "self" 
and kept getting a NameError "self" not defined.

The error I currently get with the above code is:

TypeError: 'file' is an invalid keyword argument for this function

When clicking my "upload" button.

Thanks


On Sunday, November 24, 2013 10:31:34 AM UTC-5, Michael Manfre wrote:
>
> There are two things that you'll need to do. Set the random directory name 
> on the UpFile instance in the view and define a function to use with 
> upload_to that uses the random directory name on the instance to define the 
> file's target path.
>
>
> https://docs.djangoproject.com/en/dev/ref/models/fields/#django.db.models.FileField.upload_to
>
> Regards,
> Michael Manfre
>
> On Saturday, November 23, 2013 10:33:59 AM UTC-5, Matt Lind wrote:
>>
>> So I am trying to modify django-jfu ( a multi uploader) to send files to 
>> a unique directory for every unique upload session performed.  This is just 
>> due to my application's requirements and to prevent file collisions during 
>> the operations later down the road in my app.
>>
>> Anyway, here is views.py (I think the most relevant portion anyway, I 
>> could be wrong)
>>
>> def upload( request ):
>>
>> # The assumption here is that jQuery File Upload
>> # has been configured to send files one at a time.
>> # If multiple files can be uploaded simulatenously,
>> # 'file' may be a list of files.
>> #Create the file object
>> file = upload_receive( request )
>>
>> #Create an instance of our Uploader Class and pass it the file object
>> instance = UpFile ( file = file )
>> #Save the file object
>> instance.save() 
>>
>> And the "UpFile" class in models.py:
>>
>> class UpFile(models.Model):
>> file = models.FileField( upload_to = 
>> MEDIA_ROOT+'/'+"".join([random.choice(string.ascii_letters) for n in 
>> xrange(12)]))
>>
>> The problem I am having is that it appears that the "random" section at 
>> the tail end of the "upload_to" option in models,py is processed only once 
>> when the server is started (or restarted).
>>
>> This won't work for my particular application, as I need the "top level" 
>> for any uploaded of a set of files to be unique.
>>
>> For example if I have the following "upload sessions"
>>
>> Session 1:  User only uploaded a single file.  A new random/unique 
>> directory should be generated under MEDIA_ROOT, and the file should be 
>> placed in that directory.
>> Session 2:  User uploaded 2 files.  A new random/unique directory should 
>> be generated under MEDIA_ROOT, and BOTH files should be uploaded to that 
>> directory (NOT a different directory per file)
>> Session 3:  User uploaded 100 files.  Like session 2 above, a new 
>> random/unique directory should be generated under MEDIA_ROOT and all 100 
>> files should be placed underneath.
>>
>> Later on I plan on cleaning house, but for now simply getting that logic 
>> down will get me moving again...
>>
>> Thanks for any help you can provide.
>>
>

-- 
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/dfbe4f18-8195-4242-acc7-eb505798f82f%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Errors on Django Tests Tutorial 5, how to fix.

2013-12-04 Thread Matt Schloepp
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'django',
'USER': 'matt',
'PASSWORD':'***',
'HOST': '127.0.0.1',
'PORT': '5432',
},
'OPTIONS': {
'autocommit': True,
}

I forgot to post DB settings
On Wednesday, December 4, 2013 2:32:14 PM UTC-8, Matt Schloepp wrote:
>
> Django is 1.6 and Python is 2.7.5. On Windows 8.1, no virtual-env, but my 
> actual project will be on a *nix VM. I accidentally download and install a 
> development version, I think removed it before installing 1.6 but no 
> previous django versions were installed on this system. Maybe dropping my 
> db and starting over would fix the issue?
>

-- 
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/acdf1883-ce8e-49e5-b48c-94edf6117620%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Errors on Django Tests Tutorial 5, how to fix.

2013-12-04 Thread Matt Schloepp
Django is 1.6 and Python is 2.7.5. On Windows 8.1, no virtual-env, but my 
actual project will be on a *nix VM. I accidentally download and install a 
development version, I think removed it before installing 1.6 but no 
previous django versions were installed on this system. Maybe dropping my 
db and starting over would fix the issue?

-- 
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/2272299c-3432-495a-b31f-28b70613ee13%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Errors on Django Tests Tutorial 5, how to fix.

2013-12-04 Thread Matt Schloepp
Commenting out my Postgresql DB and putting back the default options for 
the sqlite DB fixed the issue. 

Is there a tests.py variable I could use to create an If..Else that would 
allow this to be automatic and not force me to edit my settings.py every 
time I wanted to run a test.

-- 
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/16971b55-ed41-4086-ba37-4248b13646b7%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Errors on Django Tests Tutorial 5, how to fix.

2013-12-04 Thread Matt Schloepp
I'm running Django on Windows with PostgreSQL database. I'm in tutorial 5 
and have copy/pasted the code after it's initial failure. I've been 
following the tutorials to this point, with only a little side 
experimentation, and everything has been working. It looks like it DB 
related since I'm not using SQLite. I'm lost. What do I need to add or 
modify to get the tests to work?

Output:

> ==
>
> ERROR: test_was_published_recently_with_future_poll 
>> (polls.tests.PollMethodTests)
>
> --
>
> Traceback (most recent call last):
>
>   File "C:\python27\lib\site-packages\django\test\testcases.py", line 178, 
>> in __call__
>
> self._pre_setup()
>
>   File "C:\python27\lib\site-packages\django\test\testcases.py", line 749, 
>> in _pre_setup
>
> self._fixture_setup()
>
>   File "C:\python27\lib\site-packages\django\test\testcases.py", line 861, 
>> in _fixture_setup
>
> if not connections_support_transactions():
>
>   File "C:\python27\lib\site-packages\django\test\testcases.py", line 848, 
>> in connections_support_transactions
>
> for conn in connections.all())
>
>   File "C:\python27\lib\site-packages\django\test\testcases.py", line 848, 
>> in 
>
> for conn in connections.all())
>
>   File "C:\python27\lib\site-packages\django\utils\functional.py", line 
>> 49, in __get__
>
> res = instance.__dict__[self.func.__name__] = self.func(instance)
>
>   File "C:\python27\lib\site-packages\django\db\backends\__init__.py", 
>> line 664, in supports_transactions
>
> self.connection.leave_transaction_management()
>
>   File "C:\python27\lib\site-packages\django\db\backends\__init__.py", 
>> line 317, in leave_transaction_management
>
> if managed == self.get_autocommit():
>
>   File "C:\python27\lib\site-packages\django\db\backends\__init__.py", 
>> line 324, in get_autocommit
>
> self.ensure_connection()
>
>   File "C:\python27\lib\site-packages\django\db\backends\__init__.py", 
>> line 124, in ensure_connection
>
> self.connect()
>
>   File "C:\python27\lib\site-packages\django\db\utils.py", line 86, in 
>> __exit__
>
> db_exc_type = getattr(self.wrapper.Database, dj_exc_type.__name__)
>
> AttributeError: 'DatabaseWrapper' object has no attribute 'Database'
>
>
>> --
>
> Ran 0 tests in 0.001s
>
>
>> FAILED (errors=1)
>
>
 

-- 
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/b0067a22-b212-4ffa-ad5d-7fab897f9ca7%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Generate a random directory for files to be uploaded

2013-11-23 Thread Matt Lind
So I am trying to modify django-jfu ( a multi uploader) to send files to a 
unique directory for every unique upload session performed.  This is just 
due to my application's requirements and to prevent file collisions during 
the operations later down the road in my app.

Anyway, here is views.py (I think the most relevant portion anyway, I could 
be wrong)

def upload( request ):

# The assumption here is that jQuery File Upload
# has been configured to send files one at a time.
# If multiple files can be uploaded simulatenously,
# 'file' may be a list of files.
#Create the file object
file = upload_receive( request )

#Create an instance of our Uploader Class and pass it the file object
instance = UpFile ( file = file )
#Save the file object
instance.save() 

And the "UpFile" class in models.py:

class UpFile(models.Model):
file = models.FileField( upload_to = 
MEDIA_ROOT+'/'+"".join([random.choice(string.ascii_letters) for n in 
xrange(12)]))

The problem I am having is that it appears that the "random" section at the 
tail end of the "upload_to" option in models,py is processed only once when 
the server is started (or restarted).

This won't work for my particular application, as I need the "top level" 
for any uploaded of a set of files to be unique.

For example if I have the following "upload sessions"

Session 1:  User only uploaded a single file.  A new random/unique 
directory should be generated under MEDIA_ROOT, and the file should be 
placed in that directory.
Session 2:  User uploaded 2 files.  A new random/unique directory should be 
generated under MEDIA_ROOT, and BOTH files should be uploaded to that 
directory (NOT a different directory per file)
Session 3:  User uploaded 100 files.  Like session 2 above, a new 
random/unique directory should be generated under MEDIA_ROOT and all 100 
files should be placed underneath.

Later on I plan on cleaning house, but for now simply getting that logic 
down will get me moving again...

Thanks for any help you can provide.

-- 
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/49b570f3-20d0-46f0-bffe-dff7ad14cdd4%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Apache won't allow upload but dev server will

2013-08-09 Thread Matt Lind
I am attempting to setup django-bft on my CentOS 6.4 server.

When running under the dev server I am able to upload the file and it shows 
up on my server.

However, when running through MOD_WSGI everything about the site works, 
except for the upload.  The file never lands on the server and the 
application throws an error:

Invalid JSON: Environment: Request Method: POST Request URL: 
http://172.23.77.10/uploader/process/?X-Progress-ID=69e91467a474e2ae156004bcae3d8c75
 
Django Version: 1.3.7 Python Version: 2.6.6 Installed Applications: 
['django.contrib.auth', 'django.contrib.contenttypes', 
'django.contrib.sessions', 'django.contrib.sites', 
'django.contrib.messages', 'django.contrib.staticfiles', 
'django.contrib.admin', 'bft'] Installed Middleware: 
('django.middleware.common.CommonMiddleware', 
'django.contrib.sessions.middleware.SessionMiddleware', 
'django.middleware.csrf.CsrfViewMiddleware', 
'django.contrib.auth.middleware.AuthenticationMiddleware', 
'django.contrib.messages.middleware.MessageMiddleware') Traceback: File 
"/usr/lib/python2.6/site-packages/django/core/handlers/base.py" in 
get_response 111. response = callback(request, *callback_args, 
**callback_kwargs) File 
"/usr/lib/python2.6/site-packages/django/db/transaction.py" in inner 217. 
res = func(*args, **kwargs) File "/bft/views.py" in 
process_submission 262. upload_html(request, form.instance) File "/bft/views.py" in upload_html 426. upload.save() File "/bft/models.py" in save 91. super(File, self).save(*args, 
**kwargs) File "/usr/lib/python2.6/site-packages/django/db/models/base.py" 
in save 460. self.save_base(using=using, force_insert=force_insert, 
force_update=force_update) File 
"/usr/lib/python2.6/site-packages/django/db/models/base.py" in save_base 
543. for f in meta.local_fields if not isinstance(f, AutoField)] File 
"/usr/lib/python2.6/site-packages/django/db/models/fields/files.py" in 
pre_save 255. file.save(file.name, file, save=False) File 
"/usr/lib/python2.6/site-packages/django/db/models/fields/files.py" in save 
92. self.name = self.storage.save(name, content) File 
"/usr/lib/python2.6/site-packages/django/core/files/storage.py" in save 48. 
name = self.get_available_name(name) File 
"/usr/lib/python2.6/site-packages/django/core/files/storage.py" in 
get_available_name 74. while self.exists(name): File 
"/usr/lib/python2.6/site-packages/django/core/files/storage.py" in exists 
218. return os.path.exists(self.path(name)) File 
"/usr/lib/python2.6/site-packages/django/core/files/storage.py" in path 
234. raise SuspiciousOperation("Attempted access to '%s' denied." % name) 
Exception Type: SuspiciousOperation at /uploader/process/ Exception Value: 
Attempted access to 'media/temp/09-08-2013/apache_test.txt' denied.

The permissions on the file system are 775.  User is my personal user, 
group is apache.

Directive in httpd.conf for the directory is:

Alias /media/ ""


">
Options Indexes
AllowOverride None
Order deny,allow
Allow from all
 

When I browse to http:///media  I am able to see the index of 
the directory.

I have attempted to set the sticky bit for the group.  I have attempted to 
set the user owner as apache.  I have attempted to set permissions on the 
whole Django site to 777.  I have temporarily disabled SELinux.  I even 
temporarily gave the apache user a login, Su'd to the apache user.  That 
user can read and write to the directory in question.

I have watched the video here:  
http://blip.tv/pycon-australia/getting-started-with-apache-mod_wsgi-3859481

Anywhere else I can check?

TIA

-- 
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.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Avoid unbounded memory consumption when running `manage.py test`

2013-07-26 Thread Matt McClure
On Thursday, July 18, 2013 7:30:55 PM UTC-7, Matt McClure wrote:

> 1.  TestSuite. Here's a minimal hack to release the reference that 
> TestSuite would otherwise hold after a TestCase runs until the remainder of 
> the suite had finished.
>
> +self._tests.remove(test)
>

That turns out to be a bad idea because it modifies a list inside a loop 
iterating over it, making the loop skip items it should visit. Here's an 
updated change that doesn't suffer from that problem:

diff --git a/django/utils/unittest/suite.py b/django/utils/unittest/suite.py
index f39569b..8530200 100644
--- a/django/utils/unittest/suite.py
+++ b/django/utils/unittest/suite.py
@@ -1,5 +1,6 @@
 """TestSuite"""
 
+import gc
 import sys
 import unittest
 from django.utils.unittest import case, util
@@ -96,7 +97,11 @@ class TestSuite(BaseTestSuite):
 
 # private methods
 def _wrapped_run(self, result, debug=False):
-for test in self:
+while True:
+try:
+test = self._tests.pop(0)
+except IndexError:
+break
 if result.shouldStop:
 break
 
@@ -116,6 +121,7 @@ class TestSuite(BaseTestSuite):
 test(result)
 else:
 test.debug()
+#gc.collect()
 
 def _handleClassSetUp(self, test, result):
 previousClass = getattr(result, '_previousTestClass', None)

-- 
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.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Avoid unbounded memory consumption when running `manage.py test`

2013-07-18 Thread Matt McClure
On Thursday, July 18, 2013 6:12:16 PM UTC-4, Matt McClure wrote:

> AFAICT, TestResult holds references to each TestCase instance.


I can start to answer my own question. But I'm interested to know if others 
run into similar problems and how you solve them.

It looks like there are at least two participants that hold TestCase 
references longer than desirable.

1.  TestSuite. Here's a minimal hack to release the reference that 
TestSuite would otherwise hold after a TestCase runs until the remainder of 
the suite had finished.

diff --git a/django/utils/unittest/suite.py b/django/utils/unittest/suite.py
index f39569b..109a476 100644
--- a/django/utils/unittest/suite.py
+++ b/django/utils/unittest/suite.py
@@ -1,5 +1,6 @@
 """TestSuite"""
 
+import gc
 import sys
 import unittest
 from django.utils.unittest import case, util
@@ -116,6 +117,8 @@ class TestSuite(BaseTestSuite):
 test(result)
 else:
 test.debug()
+self._tests.remove(test)
+#gc.collect()
 
 def _handleClassSetUp(self, test, result):
 previousClass = getattr(result, '_previousTestClass', None)

I believe gc.collect() in the above is unnecessary. Calling it explicitly 
accelerates the collection, but the automatic collector will free the 
TestCase from memory soon enough as long as we can manage its lifetime by 
eliminating all the references to it.

2. TestResult and subclasses may hold references to TestCase instances via 
addSuccess() and friends. For example, 
django.utils.unittest.result.TestResult.addError does:

self.errors.append((test, self._exc_info_to_string(err, test)))

In my current scenario, I'm using unittest-xml-reporting's TestResult 
subclass, and the following patch eliminates the references to TestCase 
instances that it would otherwise save.

--- __init__.py~ 2013-05-02 16:45:19.0 -0400
+++ __init__.py 2013-07-18 21:39:13.0 -0400
@@ -8,6 +8,9 @@
 import os
 import sys
 import time
+
+import psutil
+
 from unittest import TestResult, _TextTestResult, TextTestRunner
 
 try:
@@ -27,13 +30,24 @@
 self.delegate = delegate
 
 def write(self, text):
-self._captured.write(text)
+#self._captured.write(text)
 self.delegate.write(text)
 
 def __getattr__(self, attr):
 return getattr(self._captured, attr)
 
 
+def testcase_name(test_method):
+testcase = type(test_method)
+
+# Ignore module name if it is '__main__'
+module = testcase.__module__ + '.'
+if module == '__main__.':
+module = ''
+result = module + testcase.__name__
+return result
+
+
 class _TestInfo(object):
 """This class keeps useful information about the execution of a
 test method.
@@ -44,11 +58,21 @@
 
 def __init__(self, test_result, test_method, outcome=SUCCESS, 
err=None):
 self.test_result = test_result
-self.test_method = test_method
 self.outcome = outcome
 self.elapsed_time = 0
 self.err = err
 
+#self.test_method = test_method
+self.test_description = 
self.test_result.getDescription(test_method)
+self.test_exception_info = (
+'' if not self.err
+else self.test_result._exc_info_to_string(
+self.err, test_method)
+)
+
+self.test_name = testcase_name(test_method)
+self.test_id = test_method.id()
+
 def test_finished(self):
 """Save info that can only be calculated once a test has run.
 """
@@ -58,16 +82,18 @@
 def get_description(self):
 """Return a text representation of the test method.
 """
-return self.test_result.getDescription(self.test_method)
+#return self.test_result.getDescription(self.test_method)
+return self.test_description
 
 def get_error_info(self):
 """Return a text representation of an exception thrown by a test
 method.
 """
-if not self.err:
-return ''
-return self.test_result._exc_info_to_string(self.err, \
-self.test_method)
+#if not self.err:
+#return ''
+#return self.test_result._exc_info_to_string(self.err, \
+#self.test_method)
+return self.test_exception_info
 
 
 class _XMLTestResult(_TextTestResult):
@@ -81,6 +107,8 @@
 self.successes = []
 self.callback = None
 self.elapsed_times = elapsed_times
+self.start_meminfo = psutil.Process(os.getpid()).get_memory_info()
+self.stop_meminfo = psutil.Process(os.getpid()).get_memory_info()
 
 def _prepare_callback(self, test_info, target_list, verbose_str,
 short_str):
@@ -103,6 +131,10 @@
 if self.showAll:
 self.stream.writeln('%s (%.3fs)' % \
   

Avoid unbounded memory consumption when running `manage.py test`

2013-07-18 Thread Matt McClure
What's a good way to avoid unbounded memory consumption when running 
manage.py test?

AFAICT, TestResult holds references to each TestCase instance. So 
attributes of my TestCase subclasses don't get freed by the garbage 
collector until the last reference to TestResult disappears, which isn't 
until the entire test run ends. The most obvious solution to me is to put 
tearDown methods in all my TestCase subclasses that delete the references 
to their own attributes. But it seems like there has to be a more general, 
automatic solution.

-- 
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.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Having an issue with Minimal File Upload utility

2013-06-26 Thread Matt Lind
Just wanted to update everyone on the solve for this.

It turns out that I was overzealous in my pre-planning.

In my urls.py at the top of my project I had defined extra applications 
that I had not fleshed out yet.  So they didn't have any urls.py or 
views.py defined.  

Even though the error was pointing at my specific code, after commenting 
out the applications I hadn't fleshed out yet, everything is working great.

Thanks

-- 
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.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Having an issue with Minimal File Upload utility

2013-06-22 Thread Matt Lind
Updating with full error:

Request Method:GETRequest URL:http:///uploader/list/Django 
Version:1.3.7Exception Type:TemplateSyntaxErrorException Value:

Caught ImportError while rendering: No module named urls

Exception Location:/usr/lib/python2.6/site-packages/django/utils/importlib.py 
in import_module, line 35Python Executable:/usr/bin/pythonPython Version:
2.6.6Python Path:

['/home//myproject',
 '/usr/lib64/python26.zip',
 '/usr/lib64/python2.6',
 '/usr/lib64/python2.6/plat-linux2',
 '/usr/lib64/python2.6/lib-tk',
 '/usr/lib64/python2.6/lib-old',
 '/usr/lib64/python2.6/lib-dynload',
 '/usr/lib64/python2.6/site-packages',
 '/usr/lib/python2.6/site-packages']

Server time:Sat, 22 Jun 2013 09:06:18 -0500

-- 
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.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Having an issue with Minimal File Upload utility

2013-06-19 Thread Matt Lind
My Settings.py:

# Django settings for EqlAnalystToolSet project.


import os, ldap
from django_auth_ldap.config import LDAPSearch, ActiveDirectoryGroupType

DEBUG = True
TEMPLATE_DEBUG = DEBUG

ADMINS = (
# ('Your Name', 'your_em...@example.com'),
)

MANAGERS = ADMINS

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql', # Add 'postgresql_psycopg2', 
'postgresql', 'mysql', 'sqlite3' or 'oracle'.
'NAME': '',  # Or path to database 
file if using sqlite3.
'USER': '',  # Not used with sqlite3.
'PASSWORD': '',  # Not used with sqlite3.
'HOST': '',  # Set to empty string for 
localhost. Not used with sqlite3.
'PORT': '',  # Set to empty string for default. 
Not used with sqlite3.
}
}

# AUTH_LDAP settings added by MJL

AUTHENTICATION_BACKENDS = (
'django_auth_ldap.backend.LDAPBackend',
)

AUTH_LDAP_SERVER_URI = 'ldap://'

AUTH_LDAP_BIND_DN = 
"CN=,CN=Users,DC=,DC=,DC=com"
AUTH_LDAP_BIND_PASSWORD = ''
AUTH_LDAP_USER_SEARCH = LDAPSearch("dc=,dc=,dc=com", 
ldap.SCOPE_SUBTREE, "(sAMAccountName=%(user)s)",)
AUTH_LDAP_GROUP_SEARCH = LDAPSearch("dc=,dc=,dc=com", 
ldap.SCOPE_SUBTREE, '(objectClass=group)',)
AUTH_LDAP_GROUP_TYPE = ActiveDirectoryGroupType()
AUTH_LDAP_REQUIRE_GROUP = 
'CN=,CN=Users,DC=,DC=,DC=com'

AUTH_LDAP_USER_ATTR_MAP = {
 "first name": "givenName",
 "last name":  "sn",
 "email":  "mail",
}

# SITE Variables adding by MJL

LOGIN_URL = '/login/'
SITE_ROOT = os.path.realpath(os.path.dirname(__file__))

# Hosts/domain names that are valid for this site; required if DEBUG is 
False
# See https://docs.djangoproject.com/en/1.3/ref/settings/#allowed-hosts
ALLOWED_HOSTS = []

# Local time zone for this installation. Choices can be found here:
# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
# although not all choices may be available on all operating systems.
# On Unix systems, a value of None will cause Django to use the same
# timezone as the operating system.
# If running in a Windows environment this must be set to the same as your
# system time zone.
TIME_ZONE = 'America/Chicago'

# Language code for this installation. All choices can be found here:
# http://www.i18nguy.com/unicode/language-identifiers.html
LANGUAGE_CODE = 'en-us'

SITE_ID = 1

# If you set this to False, Django will make some optimizations so as not
# to load the internationalization machinery.
USE_I18N = True

# If you set this to False, Django will not format dates, numbers and
# calendars according to the current locale
USE_L10N = True

# Absolute filesystem path to the directory that will hold user-uploaded 
files.
# Example: "/home/media/media.lawrence.com/media/"
MEDIA_ROOT = os.path.join(SITE_ROOT, 'media')

# URL that handles the media served from MEDIA_ROOT. Make sure to use a
# trailing slash.
# Examples: "http://media.lawrence.com/media/;, "http://example.com/media/;
MEDIA_URL = '/media/'

# Absolute path to the directory static files should be collected to.
# Don't put anything in this directory yourself; store your static files
# in apps' "static/" subdirectories and in STATICFILES_DIRS.
# Example: "/home/media/media.lawrence.com/static/"
STATIC_ROOT = os.path.join(SITE_ROOT, 'static')

# URL prefix for static files.
# Example: "http://media.lawrence.com/static/;
STATIC_URL = '/static/'

# URL prefix for admin static files -- CSS, JavaScript and images.
# Make sure to use a trailing slash.
# Examples: "http://foo.com/static/admin/;, "/static/admin/".
ADMIN_MEDIA_PREFIX = '/static/admin/'

# Additional locations of static files
STATICFILES_DIRS = (
# Put strings here, like "/home/html/static" or "C:/www/django/static".
# Always use forward slashes, even on Windows.
# Don't forget to use absolute paths, not relative paths.
)

# List of finder classes that know how to find static files in
# various locations.
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
#'django.contrib.staticfiles.finders.DefaultStorageFinder',
)

# Make this unique, and don't share it with anybody.
SECRET_KEY = ')2)@8!m!6c3)a0u%%4($hj6srh^xio$e4dyr6+)'

# List of callables that know how to import templates from various sources.
TEMPLATE_LOADERS = (
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
# 'django.template.loaders.eggs.Loader',
)

MIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
)

ROOT_URLCONF = 'myproject.urls'

TEMPLATE_DIRS = (
# Put strings here, like "/home/html/django_templates" or 
"C:/www/django/templates".
# Always use 

Having an issue with Minimal File Upload utility

2013-06-19 Thread Matt Lind
I am trying to get this utility to work within my own Django site:

https://github.com/doph/minimal-django-file-upload-example/tree/master/src/for_django_1-3/myproject

I have copied all the appropriate files to where they need to be.  I am on 
django 1.3.7 on Centos 6.4 64Bit.

When I run the list page I get the error:

Caught ImportError while rendering: No module named urls


When I copy the actual project and run it, it works.  When I attempt to add the 
functionality to my site, I get the above error.


Just wondering why a file copy would produce these different results.


Thanks in 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.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Difficulties displaying correct value in select widget with ModelForm/formset_factory:

2013-05-10 Thread Matt Conrad
Answering my own question from a few days ago, this:

choice_vals = scene.begin_scene.all().values()
ChoiceFormFactory = formset_factory(ChoiceForm)
formset = ChoiceFormFactory(initial=choice_vals)

is all wrong. I needed to be using a modelformset_factory, not a
formset_factory, with a few extra params:

ChoiceFormSetFactory = modelformset_factory(Choice, form=ChoiceForm,
extra=0)
formset = ChoiceFormSetFactory(queryset=scene.begin_scene.all())

This assigns the value of the select widget correctly out of the box, and
also avoids some later issues I ran into with .values() and initial=.

Matt







On Mon, May 6, 2013 at 4:28 PM, Matt C <matt...@gmail.com> wrote:

> I'm resorting to code in __init__ to set my select dropdown properly when
> using a ModelForm with formset_factory, and wondering if there is a better
> way.
>
> I have a model that looks like this:
>
> class Choice(models.Model):
> desc = models.TextField()
> begin_scene = models.ForeignKey(Scene, related_name='begin_scene')
> end_scene = models.ForeignKey(Scene, related_name='end_scene')
>
> with a corresponding ModelForm.
>
> My view contains this:
>
> choice_vals = scene.begin_scene.all().values()
> ChoiceFormFactory = formset_factory(ChoiceForm)
> formset = ChoiceFormFactory(initial=choice_vals)
>
>
> When I render the form, I get a select dropdown which contains correct FK
> values from Scene. However, the correct option in the dropdown is not
> selected.
>
> I did a bunch of searching and playing around and ended up with this in my
> form class, which does work to set the selected option correctly.
>
> class ChoiceForm(ModelForm):
> def __init__(self, *args, **kwargs):
> if 'initial' in kwargs and 'end_scene_id' in kwargs['initial']:
> kwargs['initial']['end_scene'] =
> kwargs['initial']['end_scene_id']
> super(ChoiceForm, self).__init__(*args, **kwargs)
>
> But I'm wondering if I missed something simpler/cleaner/more idiomatic.
> Did I?
>
>
>  --
> 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?hl=en.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>

-- 
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Difficulties displaying correct value in select widget with ModelForm/formset_factory:

2013-05-06 Thread Matt C
I'm resorting to code in __init__ to set my select dropdown properly when 
using a ModelForm with formset_factory, and wondering if there is a better 
way.

I have a model that looks like this:

class Choice(models.Model):
desc = models.TextField()
begin_scene = models.ForeignKey(Scene, related_name='begin_scene')
end_scene = models.ForeignKey(Scene, related_name='end_scene')

with a corresponding ModelForm.

My view contains this:

choice_vals = scene.begin_scene.all().values()
ChoiceFormFactory = formset_factory(ChoiceForm)
formset = ChoiceFormFactory(initial=choice_vals)


When I render the form, I get a select dropdown which contains correct FK 
values from Scene. However, the correct option in the dropdown is not 
selected.

I did a bunch of searching and playing around and ended up with this in my 
form class, which does work to set the selected option correctly.

class ChoiceForm(ModelForm):
def __init__(self, *args, **kwargs):
if 'initial' in kwargs and 'end_scene_id' in kwargs['initial']:
kwargs['initial']['end_scene'] = 
kwargs['initial']['end_scene_id']
super(ChoiceForm, self).__init__(*args, **kwargs)

But I'm wondering if I missed something simpler/cleaner/more idiomatic. Did 
I?


-- 
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: performance of delete

2013-04-24 Thread Matt Long
I'm curious how long manually running a single delete query with the 
appropriate where clause would take. Surely there's a way to do that through 
the Django ORM without having to drop into raw SQL?

That being said, there are limits to how long a given query can be, so the ORM 
would have to do some intelligent batching of your IN clause, so maybe it does 
make sense to leave that hairy logic out of the ORM :-) 

-- 
Matt Long
Sent with Sparrow (http://www.sparrowmailapp.com/?sig)


On Wednesday, April 24, 2013 at 18:31, Larry Martell wrote:

> I changed it to delete one row at a time and it's taking 3 minutes.
> 
> On Wed, Apr 24, 2013 at 6:38 PM, Setiaman Lee <setiaman@gmail.com> wrote:
> > Larry,
> > 
> > 
> > Avoid to use IN clause. I'd say to insert the events you want to delete into
> > the temp table. You can put the session id or user id in temp table to
> > differentiate set of data from other users. Then do the delete by joining
> > the temp table to the Event_Message_ldx table. your sql might look like
> > this:
> > 
> > delete event_message_ldx
> > from temp
> > where event_message_ldx.event_id = temp.event_id
> > and temp.userid = %s
> > 
> > above SQL can be executed in Django using RAW SQL. See the link below.
> > https://docs.djangoproject.com/en/dev/topics/db/sql/
> > 
> > Test the SQL in the MySQL workspace when it works then move the code to the
> > Django.
> > 
> > Rgrds,
> > Setiaman Lee
> > 
> > 
> > 
> > 
> > 
> > On Thu, Apr 25, 2013 at 8:12 AM, Larry Martell <larry.mart...@gmail.com>
> > wrote:
> > > 
> > > I have a table that has 2.5 million rows and 9 columns that are all
> > > int except for 2 varchar(255) - i.e. not that big of a table. I am
> > > executing this statement:
> > > 
> > > Event_Message_Idx.objects.filter(event_id__in=event_ids).delete()
> > > 
> > > Where event_ids has around 1,500 items in it. There is an index on
> > > event_id. This statement is taking 1 hour and 5 minutes to run. There
> > > is nothing else hitting the database at that time, and the machine
> > > it's running on is 97% idle and has plenty of free memory. This seems
> > > extremely excessive to me. I would guess it's because of the in
> > > clause. Perhaps this is more of a MySQL question when a django one,
> > > but is there some better way to do a delete like this in django?
> > > 
> > > --
> > > 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?hl=en.
> > > For more options, visit https://groups.google.com/groups/opt_out.
> > > 
> > 
> > 
> > --
> > 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?hl=en.
> > For more options, visit https://groups.google.com/groups/opt_out.
> > 
> 
> 
> -- 
> 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?hl=en.
> For more options, visit https://groups.google.com/groups/opt_out.
> 
> 


-- 
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Help interpreting profiler results (or: why is my app so slow?)

2013-04-18 Thread Matt Andrews
I wouldn't say huge (see the page/view in question at 
http://www.scenepointblank.com) -- I grab a bunch of things and then 
display them, mostly truncated (with HTML stripped out, usually for the 
homepage). The custom template tags take a bunch of arguments (say for a 
news post, it takes arguments about where to show the photo, how large to 
make the headline, etc) so there's lots of loading of views inside loops 
for each news story etc.

I've tried experimenting before with the template fragment caching and saw 
little in the way of results.


On Thursday, 18 April 2013 13:40:10 UTC+1, Shawn Milochik wrote:
>
> Hit send too soon:
>
>
> https://docs.djangoproject.com/en/dev/topics/cache/#template-fragment-caching
>
>
> On Thu, Apr 18, 2013 at 8:39 AM, Shawn Milochik 
> <sh...@milochik.com
> > wrote:
>
>> Yes, it does look like template tags are taking some time. Is the page 
>> huge? Are you doing a ton of formatting? Is there something you could maybe 
>> move to server-side?
>>
>> Also, this might help with caching bits of your output: 
>>
>>
>> On Thu, Apr 18, 2013 at 6:17 AM, Matt Andrews 
>> <ma...@mattandrews.info
>> > wrote:
>>
>>>
>>> On Thursday, 18 April 2013 10:45:40 UTC+1, Tom Evans wrote:
>>>
>>> On Wed, Apr 17, 2013 at 11:18 PM, Matt Andrews <ma...@mattandrews.info> 
>>>> wrote: 
>>>> > Hi all. 
>>>> > 
>>>> > Having performance problems with my Django app. I've posted here 
>>>> before 
>>>> > talking about this: one theory for my slowness woes was that I'm 
>>>> using raw 
>>>> > SQL for everything after getting sick of Django doing things weirdly 
>>>> > (duplicating queries, adding bizarre things like "LIMIT 3453453" to 
>>>> queries, 
>>>> > not being able to JOIN things like I wanted etc). I'm not opposed to 
>>>> going 
>>>> > back to the ORM but need to know if this is where my bottleneck is. 
>>>> > 
>>>> > I've run a profiler against my code and the results are here: 
>>>> > http://pastebin.com/raw.php?i=**HQf9bqGp<http://pastebin.com/raw.php?i=HQf9bqGp>
>>>> >  
>>>> > 
>>>> > On my local machine (a not very powerful laptop) I see Django Debug 
>>>> Toolbar 
>>>> > load times of ~1900ms for my site homepage. This includes 168ms of db 
>>>> calls 
>>>> > (11 queries, which I think are fairly well-tuned, indexed, etc). I 
>>>> cache 
>>>> > pretty well on production but load times are still slow -- some of 
>>>> this may 
>>>> > be down to my cheap webhost, though. In my settings I enabled 
>>>> > django.template.loaders.**cached.Loader but this doesn't seem to 
>>>> make much 
>>>> > difference. 
>>>> > 
>>>> > I'm having trouble seeing what the profiler results above are telling 
>>>> me: 
>>>> > can anyone shed any light? 
>>>>
>>>> Most of your time is spent in pprint, which was called over 14,000 
>>>> times to generate your page. Over 2 seconds spent printing out debug. 
>>>> This should be telling you "don't use pprint when you want to see how 
>>>> fast your code is". 
>>>>
>>>> Cheers 
>>>>
>>>> Tom 
>>>>
>>>
>>> Good point Tom, apologies. Here's the profiler results with DebugToolbar 
>>> switched off (and ordered by cumulative time, thanks Shawn!): 
>>> http://pastebin.com/raw.php?i=y3iP0cLn
>>>
>>> The top one is obviously my "home" method inside my views, but I'm 
>>> struggling to get more from it than that. Lots of template rendering, but 
>>> caching not helping here...?
>>>  
>>> -- 
>>> 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...@googlegroups.com .
>>> To post to this group, send email to django...@googlegroups.com
>>> .
>>> Visit this group at http://groups.google.com/group/django-users?hl=en.
>>> For more options, visit https://groups.google.com/groups/opt_out.
>>>  
>>>  
>>>
>>
>>
>

-- 
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Help interpreting profiler results (or: why is my app so slow?)

2013-04-18 Thread Matt Andrews

On Thursday, 18 April 2013 10:45:40 UTC+1, Tom Evans wrote:

> On Wed, Apr 17, 2013 at 11:18 PM, Matt Andrews 
> <ma...@mattandrews.info> 
> wrote: 
> > Hi all. 
> > 
> > Having performance problems with my Django app. I've posted here before 
> > talking about this: one theory for my slowness woes was that I'm using 
> raw 
> > SQL for everything after getting sick of Django doing things weirdly 
> > (duplicating queries, adding bizarre things like "LIMIT 3453453" to 
> queries, 
> > not being able to JOIN things like I wanted etc). I'm not opposed to 
> going 
> > back to the ORM but need to know if this is where my bottleneck is. 
> > 
> > I've run a profiler against my code and the results are here: 
> > http://pastebin.com/raw.php?i=HQf9bqGp 
> > 
> > On my local machine (a not very powerful laptop) I see Django Debug 
> Toolbar 
> > load times of ~1900ms for my site homepage. This includes 168ms of db 
> calls 
> > (11 queries, which I think are fairly well-tuned, indexed, etc). I cache 
> > pretty well on production but load times are still slow -- some of this 
> may 
> > be down to my cheap webhost, though. In my settings I enabled 
> > django.template.loaders.cached.Loader but this doesn't seem to make much 
> > difference. 
> > 
> > I'm having trouble seeing what the profiler results above are telling 
> me: 
> > can anyone shed any light? 
>
> Most of your time is spent in pprint, which was called over 14,000 
> times to generate your page. Over 2 seconds spent printing out debug. 
> This should be telling you "don't use pprint when you want to see how 
> fast your code is". 
>
> Cheers 
>
> Tom 
>

Good point Tom, apologies. Here's the profiler results with DebugToolbar 
switched off (and ordered by cumulative time, thanks Shawn!): 
http://pastebin.com/raw.php?i=y3iP0cLn

The top one is obviously my "home" method inside my views, but I'm 
struggling to get more from it than that. Lots of template rendering, but 
caching not helping here...?

-- 
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Help interpreting profiler results (or: why is my app so slow?)

2013-04-17 Thread Matt Andrews
Hi all.

Having performance problems with my Django app. I've posted here before 
talking about this: one theory for my slowness woes was that I'm using raw 
SQL for everything after getting sick of Django doing things weirdly 
(duplicating queries, adding bizarre things like "LIMIT 3453453" to 
queries, not being able to JOIN things like I wanted etc). I'm not opposed 
to going back to the ORM but need to know if this is where my bottleneck is.

I've run a profiler against my code and the results are here: 
http://pastebin.com/raw.php?i=HQf9bqGp

On my local machine (a not very powerful laptop) I see Django Debug Toolbar 
load times of ~1900ms for my site homepage. This includes 168ms of db calls 
(11 queries, which I think are fairly well-tuned, indexed, etc). I cache 
pretty well on production but load times are still slow -- some of this may 
be down to my cheap webhost, though. In my settings I 
enabled django.template.loaders.cached.Loader but this doesn't seem to make 
much difference.

I'm having trouble seeing what the profiler results above are telling me: 
can anyone shed any light?

If it helps at all, this is the homepage of my app: 
http://www.scenepointblank.com -- there's lot of HTML processing (stripping 
tags or truncating strings and parsing HTML etc). I use a couple of 
template tags quite frequently to re-use partial views (a news post, for 
example) so I can just pass it an object to work with. I don't know if this 
means a huge template overhead. I've explored replacing Django's templates 
with Jinja2 but fell at the first hurdle when none of the aforementioned 
template tags worked and I couldn't figure out how to port them to Jinja.

Any tips would be hugely appreciated.

-- 
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: m2m symmetry confusion

2013-04-11 Thread Matt Schinckel


On Friday, April 12, 2013 9:52:10 AM UTC+9:30, Lachlan Musicman wrote:
>
> On 12 April 2013 08:43, Dennis Lee Bieber <wlf...@ix.netcom.com> 
> wrote: 
> > On Thu, 11 Apr 2013 16:41:37 +1000, Lachlan Musicman 
> > <dat...@gmail.com> 
>
> > declaimed the following in gmane.comp.python.django.user: 
> > 
> > An individual typically only has two parents (unless you are 
> > considering birth and adoption, which may be needed to handle some of 
> > the odd situations forming with the various "same sex marriage" models), 
> > so many-to-many isn't really appropriate. And an individual could have 
> > many children. 
> > 
> > So I'd have a pair of links for 
> > 
> > father 
> > mother 
> > 
> > and that is IT... Children and Siblings are all query results (children 
> > of X are those with the appropriate parent slot = X). 
>
>
> I like your reasoning, but I disagree on your result. First, it 
> doesn't relate partners, second, it presumes two parents (I am a step 
> father). 
>

But a partner relationship is not at all related to a parent-child 
relationship.

That is, you may have children with a person who is not your partner. And,
you may have a partner and not have children.

And, you may have more than one partner (depending upon where you are,
you may have more than one partner simultaneously).

If you will only store adoptive OR birth parents, then you can get away with
a single mother and father fields. But, even for adoptive relationships, you
probably need a start date (and possibly a finish date), so I think they 
should
be stored seperately.

Thus, you have:

Person
 - date-of-birth
 - date-of-death
 - mother (fk-> Person)
 - father (fk -> Person)
 - adoptive_parent (m2m -> Person, maybe use a through table
to get start and finish dates).

The issue you have then is that you have two fks to Parent,
which means you would have to query differently to get a father's
children to a mother's. Or you could wrap '.children()' to get the
value.

 

> So I think I'm going to go with a 
>
> parent m2m 
> partner m2m 
>
> and take your advise to trash sibling and children. 
>
> Back to the grindstone then. 
>
>
Or, you could use the parent m2m with a through table to add
the relevant data. birth/adoptive parent, etc.

And, the partner m2m could also use a through table to store
start and finish times of the relationship.

Family relationships are hard...

Matt.

-- 
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Django problem:AttributeError:Manage isn't accessible via Link instances

2013-03-21 Thread Matt Woodward
On Thursday, March 21, 2013 12:49:45 AM UTC-7, simon xue wrote:
>
> When I read to page 31,"To get an object by ID,type the following:
> >>>Link.object.get(id=1)


Unless this is just a typo that should be objects plural:
Link.objects.get(id=1)

-- 
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Test database not auto-flushing

2013-03-01 Thread Matt
 

I have a bunch of unit test files, all of which consist of 
django.test.TestCase classes.

Wrote myself a little shell script to uncomment/comment test file imports 
in my __init__.py file, so I can run tests from certain test files, based 
off the command line arguments I give it. I am also able to run all the 
tests of all the test files in one go (for regression testing purposes).

I have this one test file that has some JSON fixtures and the first test 
checks that a certain model/table has 3 records in it (defined by the JSON 
fixture).

So here is the problem: when I run this test file on its own its tests pass 
with flying colours, but when I run the test with all other tests, that 
particular test case I mentioned, fails.

When I run all the tests, the database says there are 6 records in the 
table/model, but there should only be 3 (from the fixture), like when the 
test file is run by itself.

I also tried running the that test file with a few other test files (not 
all) and it passes. So the only time it doesn't, is when all the test files 
are run.

To me this seems like a bug in Django or PostgreSQL (DB I am using), 
because aren't Django TestCases supposed to auto-flush/reset the database 
between each test method, let alone test class?

Posted on stackoverflow (
http://stackoverflow.com/questions/15124828/django-test-database-not-auto-flushing),
 
but haven't got a response yet.

-- 
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Using template fragment caching *inside* a sitewide cache: possible?

2013-02-15 Thread Matt Andrews
I tried using the approach above (template fragment cache everywhere 
instead of sitewide) and the same problem was there: the inner cache didn't 
reflect cachebusting changes.

I ended up rewriting the code to pull the view fragments via AJAX (which 
did respect the cachebusting). You can see the results 
here: http://www.scenepointblank.com/ (it's the "popular right now" tabbed 
widget near the bottom right.

On Thursday, 14 February 2013 17:19:28 UTC, Matt Andrews wrote:
>
> Hi Tom,
>
> Yep, you've got the problem right. Reading it back that way I see the 
> issue much more clearly...
>
> One approach I thought of: what if, instead of the sitewide caching, I 
> used template-fragment caching for *every* view (there aren't that many) 
> and invalidated the relevant ones along with the nested caches when needed 
> (there are probably only five or so views where this would need to happen)?
>
> I'm on shared hosting so I don't think Varnish is going to be a 
> possibility...
>
> thanks!
>
> On Thursday, 14 February 2013 16:02:53 UTC, Tom Evans wrote:
>>
>> On Mon, Feb 11, 2013 at 1:42 PM, Matt Andrews <ma...@mattandrews.info> 
>> wrote: 
>> > Hi all, 
>> > 
>> > I've been experimenting with an expensive query I need to call 
>> (essentially 
>> > grabbing data from some Google APIs). I tried this experiment: 
>> > 
>> > A sitewide cache with a long (days) expiry time 
>> > A template fragment with its own separate cache inside a view cached by 
>> the 
>> > sitewide cache -- this fragment simply displays the current time. 
>> > A view function which clears the named template fragment cache. 
>> > 
>> > The behaviour I expected was that on first pageload, the fragment would 
>> > display the time of page render, and all subsequent reloads would 
>> display 
>> > the same time. This was true. 
>> > 
>> > The second part, though, was that I expected to be able to call the 
>> view 
>> > function to clear the fragment cache and then reload the page to see 
>> the 
>> > time update. This didn't happen. 
>> > 
>> > Is it possible to achieve this behaviour? Essentially I want to run a 
>> > background cron task which just hits the Google API and updates my 
>> cached 
>> > fragments - the Google data changes every 15 minutes but the sitewide 
>> cache 
>> > has several hours timeout, normally. 
>> > 
>> > Hope this makes sense. 
>> > 
>> > Matt 
>> > 
>>
>> Hi Matt 
>>
>> Can I restate the problem to see if I am getting it right? 
>>
>> You have a page fragment, 'FRAG', stored in the cache. 
>> You have a page, 'PAGE', using that fragment stored in the cache. 
>> You update 'FRAG' in the cache. 
>> You reload 'PAGE', and it has the old contents of 'FRAG' instead of 
>> the updated one. 
>>
>> If so, this is to be expected. The site cache caches entire responses, 
>> with a key derived from that request. When a new request comes in, a 
>> key is generated from that request. If the key is found in the cache, 
>> the cached response is returned. 
>>
>> At no point does the cache know that one cache entry is built using 
>> another, or that invalidating the fragment should invalidate any page 
>> containing that fragment. 
>>
>> One potential solution is to use something like Varnish, an HTTP 
>> accelerator/cache that has support for ESI - Edge Side Includes - that 
>> allow you to build up responses from multiple components, and 
>> intelligently cache the components. Eg, an example of what you are 
>> trying to do in Varnish using ESI: 
>>
>> https://www.varnish-cache.org/trac/wiki/ESIfeatures#Anesi:includeexample 
>>
>> Alternatively, I may have completely misunderstood this :) 
>>
>> Cheers 
>>
>> Tom 
>>
>

-- 
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Using template fragment caching *inside* a sitewide cache: possible?

2013-02-14 Thread Matt Andrews
Hi Tom,

Yep, you've got the problem right. Reading it back that way I see the issue 
much more clearly...

One approach I thought of: what if, instead of the sitewide caching, I used 
template-fragment caching for *every* view (there aren't that many) and 
invalidated the relevant ones along with the nested caches when needed 
(there are probably only five or so views where this would need to happen)?

I'm on shared hosting so I don't think Varnish is going to be a 
possibility...

thanks!

On Thursday, 14 February 2013 16:02:53 UTC, Tom Evans wrote:
>
> On Mon, Feb 11, 2013 at 1:42 PM, Matt Andrews 
> <ma...@mattandrews.info> 
> wrote: 
> > Hi all, 
> > 
> > I've been experimenting with an expensive query I need to call 
> (essentially 
> > grabbing data from some Google APIs). I tried this experiment: 
> > 
> > A sitewide cache with a long (days) expiry time 
> > A template fragment with its own separate cache inside a view cached by 
> the 
> > sitewide cache -- this fragment simply displays the current time. 
> > A view function which clears the named template fragment cache. 
> > 
> > The behaviour I expected was that on first pageload, the fragment would 
> > display the time of page render, and all subsequent reloads would 
> display 
> > the same time. This was true. 
> > 
> > The second part, though, was that I expected to be able to call the view 
> > function to clear the fragment cache and then reload the page to see the 
> > time update. This didn't happen. 
> > 
> > Is it possible to achieve this behaviour? Essentially I want to run a 
> > background cron task which just hits the Google API and updates my 
> cached 
> > fragments - the Google data changes every 15 minutes but the sitewide 
> cache 
> > has several hours timeout, normally. 
> > 
> > Hope this makes sense. 
> > 
> > Matt 
> > 
>
> Hi Matt 
>
> Can I restate the problem to see if I am getting it right? 
>
> You have a page fragment, 'FRAG', stored in the cache. 
> You have a page, 'PAGE', using that fragment stored in the cache. 
> You update 'FRAG' in the cache. 
> You reload 'PAGE', and it has the old contents of 'FRAG' instead of 
> the updated one. 
>
> If so, this is to be expected. The site cache caches entire responses, 
> with a key derived from that request. When a new request comes in, a 
> key is generated from that request. If the key is found in the cache, 
> the cached response is returned. 
>
> At no point does the cache know that one cache entry is built using 
> another, or that invalidating the fragment should invalidate any page 
> containing that fragment. 
>
> One potential solution is to use something like Varnish, an HTTP 
> accelerator/cache that has support for ESI - Edge Side Includes - that 
> allow you to build up responses from multiple components, and 
> intelligently cache the components. Eg, an example of what you are 
> trying to do in Varnish using ESI: 
>
> https://www.varnish-cache.org/trac/wiki/ESIfeatures#Anesi:includeexample 
>
> Alternatively, I may have completely misunderstood this :) 
>
> Cheers 
>
> Tom 
>

-- 
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Using template fragment caching *inside* a sitewide cache: possible?

2013-02-14 Thread Matt Andrews
Apologies for bumping this thread, but is there anybody with any insight on 
this? Really driving me crazy!

On Monday, 11 February 2013 13:42:05 UTC, Matt Andrews wrote:
>
> Hi all,
>
> I've been experimenting with an expensive query I need to call 
> (essentially grabbing data from some Google APIs). I tried this experiment:
>
>- A sitewide cache with a long (days) expiry time
>- A template fragment with its own separate cache *inside* a view 
>cached by the sitewide cache -- this fragment simply displays the current 
>time.
>- A view function which clears the named template fragment cache.
>
> The behaviour I expected was that on first pageload, the fragment would 
> display the time of page render, and all subsequent reloads would display 
> the same time. This was true.
>
> The second part, though, was that I expected to be able to call the view 
> function to clear the fragment cache and then reload the page to see the 
> time update. This didn't happen.
>
> Is it possible to achieve this behaviour? Essentially I want to run a 
> background cron task which just hits the Google API and updates my cached 
> fragments - the Google data changes every 15 minutes but the sitewide cache 
> has several hours timeout, normally.
>
> Hope this makes sense.
>
> Matt
>

-- 
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Using template fragment caching *inside* a sitewide cache: possible?

2013-02-11 Thread Matt Andrews
Hi all,

I've been experimenting with an expensive query I need to call (essentially 
grabbing data from some Google APIs). I tried this experiment:

   - A sitewide cache with a long (days) expiry time
   - A template fragment with its own separate cache *inside* a view cached 
   by the sitewide cache -- this fragment simply displays the current time.
   - A view function which clears the named template fragment cache.

The behaviour I expected was that on first pageload, the fragment would 
display the time of page render, and all subsequent reloads would display 
the same time. This was true.

The second part, though, was that I expected to be able to call the view 
function to clear the fragment cache and then reload the page to see the 
time update. This didn't happen.

Is it possible to achieve this behaviour? Essentially I want to run a 
background cron task which just hits the Google API and updates my cached 
fragments - the Google data changes every 15 minutes but the sitewide cache 
has several hours timeout, normally.

Hope this makes sense.

Matt

-- 
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Busting template fragment caches inside a sitewide cache: possible?

2013-02-10 Thread Matt Andrews
Hi all.

I have a site which makes use of Google's Analytics API which allows me to 
grab the most-viewed content on my site and then show it in various ways 
around the site ("most popular articles" etc). The query against this API 
is slow (takes a couple of seconds) so I've been caching it as described in 
my StackOverflow question about the technique 
here<http://stackoverflow.com/questions/13323150/advice-needed-on-django-caching-strategy>
,

The basic process is this:

   - A cron job hits a URL endpoint every 15 minutes
   - This URL makes the API request and caches the results (for 1 hour, in 
   case the cron ever fails)
   - Meanwhile, my app's views request this data and get served the cached 
   data.
   - In my views, I wrap all usage of this data in named template fragment 
   caches
   - The cron endpoint clears both the high-level cache (which the views 
   call) and the template fragment caches
   - I use a site-wide cache for the entire app.

This kind of works, but occasionally results in blank spaces where the data 
should be -- running the cron job manually has no effect on this. 
Occasionally, experimenting with restarting the server, clearing the app's 
cache and immediately calling the cron endpoints can fix things. After an 
hour or so things tend to work themselves out but it seems that the 15 
minute updates don't actually reflect in the templates.

The StackOverflow advice I got seemed to suggest that using template 
fragment caching *inside* a sitewide cached view should respect the inner 
cache setting, but it doesn't seem to.

Can anyone suggest a strategy for making this work reliably? Every time I 
deploy a new build of the app (and restart the server) it wipes the cache 
and pinging the update URL does nothing. I'm sure my logic is just a little 
wrong.

thanks
Matt

-- 
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Struggling with slow startup / SQL in new app (using raw SQL)

2013-01-22 Thread Matt Andrews
Yes, local app, local DB (which is an exact copy of the production DB). 
Interestingly, I just tried pointing the local app at the remote database 
and total query time (for 10 queries) went from 115ms to 3477ms! Really odd.

On Tuesday, January 22, 2013 7:54:53 PM UTC, Nikolas Stevenson-Molnar wrote:
>
>  When running locally, are you also using a local database instance? IIRC 
> the time that phpMyAdmin reports is the time taken for the database to 
> execute the query, whereas the time reported by the debug toolbar (I *
> think*) is complete round-trip (send query, execute, return results). So 
> if there is latency between your application and your database, that could 
> account for the discrepancy.
>
> The debug toolbar *does* add overhead to your request (about doubles the 
> page load time), but the numbers it reports should be more or less accurate 
> (iow a page might take 1s to load with the toolbar, but the toolbar will 
> report 500ms, which is accurate for load-time *without* the toolbar).
>
> _Nik
>
> On 1/22/2013 9:26 AM, Matt Andrews wrote:
>  
> Hi Nik, 
>
>  I see the discrepancy both locally and when deployed, too -- that's 
> what's so puzzling. If it helps, I'm using MySQL and running it on Windows 
> locally and under Passenger on my remote Linux server (also on MySQL).
>
>  Only other thing I can think of is that this "overhead" might literally 
> be the extra work Django Debug Toolbar does to show queries etc. Obviously 
> when I turn the toolbar off then I can't see (directly) the SQL times 
> Django is getting, but could be a factor? Either way, with the toolbar off 
> on production, there's definitely a slight "lag" before page requests start 
> to kick in -- maybe this is unrelated to the SQL, though.
>
>
> On Tuesday, 22 January 2013 16:42:19 UTC, Nikolas Stevenson-Molnar wrote: 
>>
>> Hi Matt, 
>>
>>  It's unlikely the problem lies with dictfetchall. The "small 
>> performance hit" mentioned by the docs probably refers to the fact that the 
>> function has a time complexity of (number of colulmns) * (number of rows). 
>> Since you're only getting 10 rows back, I can't see that having an 
>> appreciable impact.
>>
>>  I haven't seen this kind of variation between performing a direct 
>> query, and executing the query as part of a Django request… especially with 
>> such a basic query. Do you see the same difference in timing locally or is 
>> it only when deployed?
>>
>>  _Nik
>>
>>  On Jan 22, 2013, at 4:47 AM, Matt Andrews <ma...@mattandrews.info> 
>> wrote:
>>
>> That looks really useful - for future reference, great! Sadly my webhost 
>> is still bundling Django 1.2.3 :( 
>>
>>  In general, though, these issues still come down to the fact that a SQL 
>> query as executed by Django takes several times longer than going directly 
>> to the DB. Is this down to my use of dictfetchall() or something more low 
>> level?
>>
>>
>> On Tuesday, January 22, 2013 12:09:50 PM UTC, Jani Tiainen wrote: 
>>>
>>> Hi, 
>>>
>>> I see that you had quite a bunch of m2m keys. 
>>>
>>> Have you tried recent version of Django (1.4+) with prefetch_related() 
>>> [1] ? 
>>>
>>>
>>> [1] 
>>> <
>>> https://docs.djangoproject.com/en/1.4/ref/models/querysets/#prefetch-related>
>>>  
>>>
>>>
>>>
>>> 22.1.2013 13:57, Matt Andrews kirjoitti: 
>>> > Hi Jani, 
>>> > 
>>> > I made a StackOverflow post last year with an example of the ORM stuff 
>>> I 
>>> > tried and the poor queries it produced: 
>>> > 
>>> http://stackoverflow.com/questions/5843457/django-objects-all-making-360-queries-how-can-i-optimise-this-manytomany
>>>  
>>> > 
>>> > There's also this discussion about how using the same queryset in two 
>>> > places in the template caused Django to request its data twice: 
>>> > 
>>> http://stackoverflow.com/questions/9447053/best-way-to-slice-a-django-queryset-without-hitting-the-database-more-than-once(this
>>>  
>>> > was easily fixed, but again, not very intuitive and frustrated me) 
>>> > 
>>> > I don't have the data to hand currently but I also remember seeing 
>>> weird 
>>> > things happen where queries would end with stuff like "... LIMIT 
>>> > 234423445" (or some crazy number which I'd never entered and was 
>>> orders 
>>> > of magnitude bigger than the number of rows in the table). 

Re: Struggling with slow startup / SQL in new app (using raw SQL)

2013-01-22 Thread Matt Andrews
Hi Nik,

I see the discrepancy both locally and when deployed, too -- that's what's 
so puzzling. If it helps, I'm using MySQL and running it on Windows locally 
and under Passenger on my remote Linux server (also on MySQL).

Only other thing I can think of is that this "overhead" might literally be 
the extra work Django Debug Toolbar does to show queries etc. Obviously 
when I turn the toolbar off then I can't see (directly) the SQL times 
Django is getting, but could be a factor? Either way, with the toolbar off 
on production, there's definitely a slight "lag" before page requests start 
to kick in -- maybe this is unrelated to the SQL, though.


On Tuesday, 22 January 2013 16:42:19 UTC, Nikolas Stevenson-Molnar wrote:
>
> Hi Matt,
>
> It's unlikely the problem lies with dictfetchall. The "small performance 
> hit" mentioned by the docs probably refers to the fact that the function 
> has a time complexity of (number of colulmns) * (number of rows). Since 
> you're only getting 10 rows back, I can't see that having an appreciable 
> impact.
>
> I haven't seen this kind of variation between performing a direct query, 
> and executing the query as part of a Django request… especially with such a 
> basic query. Do you see the same difference in timing locally or is it only 
> when deployed?
>
> _Nik
>
> On Jan 22, 2013, at 4:47 AM, Matt Andrews 
> <ma...@mattandrews.info> 
> wrote:
>
> That looks really useful - for future reference, great! Sadly my webhost 
> is still bundling Django 1.2.3 :(
>
> In general, though, these issues still come down to the fact that a SQL 
> query as executed by Django takes several times longer than going directly 
> to the DB. Is this down to my use of dictfetchall() or something more low 
> level?
>
>
> On Tuesday, January 22, 2013 12:09:50 PM UTC, Jani Tiainen wrote:
>>
>> Hi, 
>>
>> I see that you had quite a bunch of m2m keys. 
>>
>> Have you tried recent version of Django (1.4+) with prefetch_related() 
>> [1] ? 
>>
>>
>> [1] 
>> <
>> https://docs.djangoproject.com/en/1.4/ref/models/querysets/#prefetch-related>
>>  
>>
>>
>>
>> 22.1.2013 13:57, Matt Andrews kirjoitti: 
>> > Hi Jani, 
>> > 
>> > I made a StackOverflow post last year with an example of the ORM stuff 
>> I 
>> > tried and the poor queries it produced: 
>> > 
>> http://stackoverflow.com/questions/5843457/django-objects-all-making-360-queries-how-can-i-optimise-this-manytomany
>>  
>> > 
>> > There's also this discussion about how using the same queryset in two 
>> > places in the template caused Django to request its data twice: 
>> > 
>> http://stackoverflow.com/questions/9447053/best-way-to-slice-a-django-queryset-without-hitting-the-database-more-than-once(this
>>  
>> > was easily fixed, but again, not very intuitive and frustrated me) 
>> > 
>> > I don't have the data to hand currently but I also remember seeing 
>> weird 
>> > things happen where queries would end with stuff like "... LIMIT 
>> > 234423445" (or some crazy number which I'd never entered and was orders 
>> > of magnitude bigger than the number of rows in the table). 
>> > 
>> > I'm aware these are probably edge cases that are down to my own novice 
>> > status, but even using things like select_related(), it wasn't doing 
>> > what I wanted. I just felt it easier to use my existing SQL (I'm 
>> > converting a PHP app over to Django) and I'm not concerned about 
>> > database portability (switching to postgres or whatever). 
>> > 
>> > Nik: just realised I missed your final question. For the SQL posted 
>> > above, the numbers are approximately: 12,000 rows in the `news` table, 
>> > maybe 10 `news_category` rows, about 100 `writers` and around 3000 
>> > `images`. All properly indexed and with sensible column types. 
>> > 
>> > On Tuesday, January 22, 2013 10:53:40 AM UTC, Jani Tiainen wrote: 
>> > 
>> > Hi, 
>> > 
>> >   From your raw SQL I saw you're doing few joins. So I suppose you 
>> do 
>> > quite a few foreign key fetches. 
>> > 
>> > You didn't mention anything how you originally tried to solve case 
>> with 
>> > ORM. Could you please publish what you had when things were slow? 
>> > 
>> > 22.1.2013 12:26, Matt Andrews kirjoitti: 
>> >  > Hi Nik, 
>> >  > 
>> >  > Thanks - I do feel like by circumventing the ORM I've just 
>>

Re: Struggling with slow startup / SQL in new app (using raw SQL)

2013-01-22 Thread Matt Andrews
That looks really useful - for future reference, great! Sadly my webhost is 
still bundling Django 1.2.3 :(

In general, though, these issues still come down to the fact that a SQL 
query as executed by Django takes several times longer than going directly 
to the DB. Is this down to my use of dictfetchall() or something more low 
level?


On Tuesday, January 22, 2013 12:09:50 PM UTC, Jani Tiainen wrote:
>
> Hi, 
>
> I see that you had quite a bunch of m2m keys. 
>
> Have you tried recent version of Django (1.4+) with prefetch_related() [1] 
> ? 
>
>
> [1] 
> <
> https://docs.djangoproject.com/en/1.4/ref/models/querysets/#prefetch-related> 
>
>
>
> 22.1.2013 13:57, Matt Andrews kirjoitti: 
> > Hi Jani, 
> > 
> > I made a StackOverflow post last year with an example of the ORM stuff I 
> > tried and the poor queries it produced: 
> > 
> http://stackoverflow.com/questions/5843457/django-objects-all-making-360-queries-how-can-i-optimise-this-manytomany
>  
> > 
> > There's also this discussion about how using the same queryset in two 
> > places in the template caused Django to request its data twice: 
> > 
> http://stackoverflow.com/questions/9447053/best-way-to-slice-a-django-queryset-without-hitting-the-database-more-than-once(this
>  
> > was easily fixed, but again, not very intuitive and frustrated me) 
> > 
> > I don't have the data to hand currently but I also remember seeing weird 
> > things happen where queries would end with stuff like "... LIMIT 
> > 234423445" (or some crazy number which I'd never entered and was orders 
> > of magnitude bigger than the number of rows in the table). 
> > 
> > I'm aware these are probably edge cases that are down to my own novice 
> > status, but even using things like select_related(), it wasn't doing 
> > what I wanted. I just felt it easier to use my existing SQL (I'm 
> > converting a PHP app over to Django) and I'm not concerned about 
> > database portability (switching to postgres or whatever). 
> > 
> > Nik: just realised I missed your final question. For the SQL posted 
> > above, the numbers are approximately: 12,000 rows in the `news` table, 
> > maybe 10 `news_category` rows, about 100 `writers` and around 3000 
> > `images`. All properly indexed and with sensible column types. 
> > 
> > On Tuesday, January 22, 2013 10:53:40 AM UTC, Jani Tiainen wrote: 
> > 
> > Hi, 
> > 
> >   From your raw SQL I saw you're doing few joins. So I suppose you 
> do 
> > quite a few foreign key fetches. 
> > 
> > You didn't mention anything how you originally tried to solve case 
> with 
> > ORM. Could you please publish what you had when things were slow? 
> > 
> > 22.1.2013 12:26, Matt Andrews kirjoitti: 
> >  > Hi Nik, 
> >  > 
> >  > Thanks - I do feel like by circumventing the ORM I've just "given 
> > up" 
> >  > and perhaps I'll reconsider -- none of my queries are 
> particularly 
> >  > "specialist" (as the sample above indicates) - I just found 
> Django 
> >  > generating odd things. 
> >  > 
> >  > To answer your questions: 
> >  > 
> >  > 1. Yes, reloading the page sees the same time for the queries (it 
> > just 
> >  > feels as though the entire process takes a second or two to 
> > start, which 
> >  > is perhaps not related to SQL itself). 
> >  > 
> >  > 2. I believe so, yes (it's shared hosting...). 
> >  > 
> >  > If you're curious, you can see a sample of the app at 
> >  > http://beta.scenepointblank.com <http://beta.scenepointblank.com> 
>
> > (obviously you won't see the SQL, but 
> >  > the "delay" between pages, even though these pages are all cached 
> > for 
> >  > 2hrs+, is partly my concern here). 
> >  > 
> >  > On Tuesday, January 22, 2013 4:24:09 AM UTC, Nikolas 
> > Stevenson-Molnar wrote: 
> >  > 
> >  > Hi Matt, 
> >  > 
> >  > Firstly, I encourage you to have another crack a the ORM. It 
> can 
> >  > certainly seem a bit aggravating at times if you're coming 
> > from a 
> >  > SQL mindset, but really pays off down the road in terms of 
> >  > maintainability and readability. Typically you should only 
> > need raw 
> >  > queries in Django in cases where you have super-specialized 

Re: Struggling with slow startup / SQL in new app (using raw SQL)

2013-01-22 Thread Matt Andrews
Hi Jani,

I made a StackOverflow post last year with an example of the ORM stuff I 
tried and the poor queries it produced: 
http://stackoverflow.com/questions/5843457/django-objects-all-making-360-queries-how-can-i-optimise-this-manytomany

There's also this discussion about how using the same queryset in two 
places in the template caused Django to request its data twice: 
http://stackoverflow.com/questions/9447053/best-way-to-slice-a-django-queryset-without-hitting-the-database-more-than-once
 (this 
was easily fixed, but again, not very intuitive and frustrated me)

I don't have the data to hand currently but I also remember seeing weird 
things happen where queries would end with stuff like "... LIMIT 234423445" 
(or some crazy number which I'd never entered and was orders of magnitude 
bigger than the number of rows in the table).

I'm aware these are probably edge cases that are down to my own novice 
status, but even using things like select_related(), it wasn't doing what I 
wanted. I just felt it easier to use my existing SQL (I'm converting a PHP 
app over to Django) and I'm not concerned about database portability 
(switching to postgres or whatever). 

Nik: just realised I missed your final question. For the SQL posted above, 
the numbers are approximately: 12,000 rows in the `news` table, maybe 10 
`news_category` rows, about 100 `writers` and around 3000 `images`. All 
properly indexed and with sensible column types. 

On Tuesday, January 22, 2013 10:53:40 AM UTC, Jani Tiainen wrote:
>
> Hi, 
>
>  From your raw SQL I saw you're doing few joins. So I suppose you do 
> quite a few foreign key fetches. 
>
> You didn't mention anything how you originally tried to solve case with 
> ORM. Could you please publish what you had when things were slow? 
>
> 22.1.2013 12:26, Matt Andrews kirjoitti: 
> > Hi Nik, 
> > 
> > Thanks - I do feel like by circumventing the ORM I've just "given up" 
> > and perhaps I'll reconsider -- none of my queries are particularly 
> > "specialist" (as the sample above indicates) - I just found Django 
> > generating odd things. 
> > 
> > To answer your questions: 
> > 
> > 1. Yes, reloading the page sees the same time for the queries (it just 
> > feels as though the entire process takes a second or two to start, which 
> > is perhaps not related to SQL itself). 
> > 
> > 2. I believe so, yes (it's shared hosting...). 
> > 
> > If you're curious, you can see a sample of the app at 
> > http://beta.scenepointblank.com (obviously you won't see the SQL, but 
> > the "delay" between pages, even though these pages are all cached for 
> > 2hrs+, is partly my concern here). 
> > 
> > On Tuesday, January 22, 2013 4:24:09 AM UTC, Nikolas Stevenson-Molnar 
> wrote: 
> > 
> > Hi Matt, 
> > 
> > Firstly, I encourage you to have another crack a the ORM. It can 
> > certainly seem a bit aggravating at times if you're coming from a 
> > SQL mindset, but really pays off down the road in terms of 
> > maintainability and readability. Typically you should only need raw 
> > queries in Django in cases where you have super-specialized (that 
> > uses views or non-standard functions) queries or need some specific 
> > optimization. If there's really no way to perform many of your 
> > "day-to-day" queries with the ORM then that's an indication that a 
> > different database design may fit your data model better. I 
> > understand that you may have a unique situation, but I just wanted 
> > to throw that out there as I personally find the ORM to be a huge 
> > time saver. 
> > 
> > Now, with that out of the way... a couple of considerations: 1) you 
> > say it's a slow "startup"; if you refresh the page do the queries 
> > run just as slow the second time around? and 2) are your Django app 
> > and phpMyAdmin running on the same machine? If not, could transit 
> > time be an issue? 
> > 
> > Finally, can you give an idea about the size of the tables in 
> > question? How many rows in each? 
> > 
> > _Nik 
> > 
> > On 1/21/2013 3:25 PM, Matt Andrews wrote: 
> >> Hi all, 
> >> 
> >> Fairly new to Django. I ended up pulling out all of the 
> >> ORM-generated queries and writing my own SQL directly (I got fed 
> >> up trying to work out how to achieve the kind of things I needed 
> >> without Django adding in extra joins or unintended WHERE clauses 
> >> etc). All my app's SQL uses cursor.execute() and the 
> >> dictfetchall(

Re: Struggling with slow startup / SQL in new app (using raw SQL)

2013-01-22 Thread Matt Andrews
Hi Nik,

Thanks - I do feel like by circumventing the ORM I've just "given up" and 
perhaps I'll reconsider -- none of my queries are particularly "specialist" 
(as the sample above indicates) - I just found Django generating odd things.

To answer your questions:

1. Yes, reloading the page sees the same time for the queries (it just 
feels as though the entire process takes a second or two to start, which is 
perhaps not related to SQL itself).

2. I believe so, yes (it's shared hosting...).

If you're curious, you can see a sample of the app at 
http://beta.scenepointblank.com (obviously you won't see the SQL, but the 
"delay" between pages, even though these pages are all cached for 2hrs+, is 
partly my concern here).

On Tuesday, January 22, 2013 4:24:09 AM UTC, Nikolas Stevenson-Molnar wrote:
>
>  Hi Matt,
>
> Firstly, I encourage you to have another crack a the ORM. It can certainly 
> seem a bit aggravating at times if you're coming from a SQL mindset, but 
> really pays off down the road in terms of maintainability and readability. 
> Typically you should only need raw queries in Django in cases where you 
> have super-specialized (that uses views or non-standard functions) queries 
> or need some specific optimization. If there's really no way to perform 
> many of your "day-to-day" queries with the ORM then that's an indication 
> that a different database design may fit your data model better. I 
> understand that you may have a unique situation, but I just wanted to throw 
> that out there as I personally find the ORM to be a huge time saver.
>
> Now, with that out of the way... a couple of considerations: 1) you say 
> it's a slow "startup"; if you refresh the page do the queries run just as 
> slow the second time around? and 2) are your Django app and phpMyAdmin 
> running on the same machine? If not, could transit time be an issue?
>
> Finally, can you give an idea about the size of the tables in question? 
> How many rows in each?
>
> _Nik
>
> On 1/21/2013 3:25 PM, Matt Andrews wrote:
>  
> Hi all, 
>
>  Fairly new to Django. I ended up pulling out all of the ORM-generated 
> queries and writing my own SQL directly (I got fed up trying to work out 
> how to achieve the kind of things I needed without Django adding in extra 
> joins or unintended WHERE clauses etc). All my app's SQL uses 
> cursor.execute() and the dictfetchall() method as referenced 
> here<https://docs.djangoproject.com/en/dev/topics/db/sql/#django.db.models.Manager.raw>
> . 
>
>  I've found that my app incurs a couple of seconds load time in 
> production, with CPU time at 2532ms and overall time 4684ms (according to 
> the debug toolbar). I'm seeing 8 SQL queries take 380ms, and each one seems 
> to be several times slower when made by Django versus hitting the database 
> through phpMyAdmin or something: eg, this query:
>
>  SELECT * FROM news 
> JOIN news_categories ON news.news_category_id = news_categories.id 
> LEFT JOIN writers ON news.writer_id = writers.id 
> LEFT JOIN images ON news.image_id = images.id 
> ORDER BY news.is_sticky DESC, news.date_posted DESC 
> LIMIT 10
>
>
>  This takes 14.8ms when run in phpMyAdmin (against the production 
> database) but Django reports it as 85.2ms. The same ratios are true for all 
> my other queries.
>
>  All I can think of is the note on the dictfetchall() method in the 
> Django docs which describes a "small performance hit". Is this it?!
>
>  I've profiled the app too, although I'm a bit hazy about what it all 
> means. Here's a dump of the result: 
> http://pastebin.com/raw.php?i=UHE9edVC(this is from running on my local 
> server rather than production but 
> performance is broadly similar).
>
>  Can anyone help me? I realise I've perhaps gone off-piste by writing raw 
> SQL but I feel it was justified.
>
>  thanks,
> Matt
>
>  
>  -- 
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To view this discussion on the web visit 
> https://groups.google.com/d/msg/django-users/-/Qiley9RqfngJ.
> To post to this group, send email to django...@googlegroups.com
> .
> To unsubscribe from this group, send email to 
> django-users...@googlegroups.com .
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
>
>
>  

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



Struggling with slow startup / SQL in new app (using raw SQL)

2013-01-21 Thread Matt Andrews
Hi all,

Fairly new to Django. I ended up pulling out all of the ORM-generated 
queries and writing my own SQL directly (I got fed up trying to work out 
how to achieve the kind of things I needed without Django adding in extra 
joins or unintended WHERE clauses etc). All my app's SQL uses 
cursor.execute() and the dictfetchall() method as referenced 
here<https://docs.djangoproject.com/en/dev/topics/db/sql/#django.db.models.Manager.raw>
. 

I've found that my app incurs a couple of seconds load time in production, 
with CPU time at 2532ms and overall time 4684ms (according to the debug 
toolbar). I'm seeing 8 SQL queries take 380ms, and each one seems to be 
several times slower when made by Django versus hitting the database 
through phpMyAdmin or something: eg, this query:

SELECT * FROM news 
JOIN news_categories ON news.news_category_id = news_categories.id 
LEFT JOIN writers ON news.writer_id = writers.id 
LEFT JOIN images ON news.image_id = images.id 
ORDER BY news.is_sticky DESC, news.date_posted DESC 
LIMIT 10


This takes 14.8ms when run in phpMyAdmin (against the production database) 
but Django reports it as 85.2ms. The same ratios are true for all my other 
queries.

All I can think of is the note on the dictfetchall() method in the Django 
docs which describes a "small performance hit". Is this it?!

I've profiled the app too, although I'm a bit hazy about what it all means. 
Here's a dump of the result: http://pastebin.com/raw.php?i=UHE9edVC (this 
is from running on my local server rather than production but performance 
is broadly similar).

Can anyone help me? I realise I've perhaps gone off-piste by writing raw 
SQL but I feel it was justified.

thanks,
Matt


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



Field pre-load hook?

2013-01-13 Thread Matt Barry
Hi,

I'm creating a model from an external database that has some encrypted 
columns.  Initially I was thinking of creating a custom field type:

class EncryptedField(models.Field):
  def db_type(self, connection): 
return 'TEXT'
  def pre_save(self, model, add):
return encrypt(getattr(model, self.attname))

..but it doesn't seem there are any hooks to decrypt the data on the 
loading side.  Am I missing anything, or is there a better way to do this 
sort of thing?

Thanks,
Matt

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



Re: Question on Multiple Database Connections

2012-12-14 Thread Matt Woodward
On Thursday, December 13, 2012 8:01:13 AM UTC-8, ke1g wrote:
>
>
> Just a shot in the dark: Maybe if, since you're not using the ORM on the 
> 'other' database, you shouldn't use django-pyodbc, but rather just pyobdc.
>

I should have said this earlier but I had the same thought and tried doing 
it directly with pyodbc, opening and closing the connection myself, and 
oddly enough the behavior is the same.

Thanks for the idea though! I'll keep digging and report back if I figure 
anything out. I have some alternative ways to handle this situation anyway 
but I'm curious to get to the bottom of the behavior for my own knowledge 
if nothing else.

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



Re: Queries to multiple tables

2012-11-11 Thread Matt Schinckel
Following up: if it affects a single instance of an object, then it belongs 
as a model method.

If it affects any number of them, then it should perhaps go on the manager 
(or even the queryset: I use django-model-utils PassThroughManager for this 
a lot).

Matt.

On Sunday, November 11, 2012 3:53:26 AM UTC+10:30, Javier Guerra wrote:
>
> On Sat, Nov 10, 2012 at 6:15 AM, Tomas Ehrlich 
> <tomas@gmail.com> 
> wrote: 
> > I usualy put methods like this one into Model, although Manager is also 
> > possible. Definitely not View or sth else. 
>
> definitely in the model. 
>
> you'd use it like this: 
>
> accnt = get_object_or_404 (Account, pk=account_id) 
> payee = get_object_or_404 (...) 
> accnt.make_payment (payee, amount) 
>
> it would be as easy as adding a method to your Account class, for example: 
>
> class Account (models.Model): 
> .. 
> .. 
>
> def make_payment(self, payee, amount, save=True): 
> if amount > self.balance: 
> throw NotEnoughFunds 
> self.balance -= amount 
> payee.balance += amount 
> if save: 
> self.save() 
> payee.save() 
>
> (of course, a serious accounting app don't modify balances but 
> registers debit/credit entries) 
>
> -- 
> Javier 
>

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



Re: Easy way to make all form fields read only?

2012-11-01 Thread Matt Woodward
On Thursday, November 1, 2012 4:33:47 AM UTC-7, Amyth wrote:

> I would suggest you adding Boolean field to your UserProfile model like 
> is_authorized = models.BooleanField(default=False)


Cool -- thanks for the suggestion. As I've said I'm new to the Django world 
but this community rocks! :-) Really appreciate all the suggestions and 
tips I'm getting so far.

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



Re: Easy way to make all form fields read only?

2012-11-01 Thread Matt Woodward
On Wednesday, October 31, 2012 8:40:10 PM UTC-7, elena wrote:

> I was also going to suggest using crispy forms -- having used it on a 
> recent project I'd strongly recommend it (it's great when it's plugged in 
> to  existing stylings such as: uni-form or bootstrap).
>
> I've used it with ModelForm using Layout() and Field() and it works a 
> treat.
>

Awesome -- thanks for the recommendation. I'll check it out.

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



Re: Easy way to make all form fields read only?

2012-10-30 Thread Matt Woodward
On Tuesday, October 30, 2012 5:20:44 AM UTC-7, ke1g wrote:

> Another protective hack would be to omit the 
> CSRF token when the form is read only. 
>

Thanks -- interesting idea! Ultimate goal is for the user to be able to 
tell they can't edit the form via the fields being read only (which applies 
a different style via the CSS) but that's a really interesting additional 
piece to potentially throw into the mix.

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



Re: Easy way to make all form fields read only?

2012-10-30 Thread Matt Woodward
On Tuesday, October 30, 2012 7:09:05 AM UTC-7, JirkaV wrote:

> On the UI side, you can set the "readonly" property on form fields. 
> This will prevent the field from being edited in a browser (I think so 
> - done that only once on a small internal project). 
>

Thanks -- I probably should have elaborated a bit more to say what I'm 
looking for (that may not exist) is a way of not having to do a user check 
on every single field and set the readonly flag individually, particularly 
since (at least based on my knowledge thus far) that gets messy given that 
we're using ModelForm and trying to render the fields with a simple 
template tag as much as possible. I haven't looked into whether or not that 
could be conditionally added as an attribute in the ModelForm, but that was 
another thought that crossed my mind.
 

>
> However, we warned - if *some* of your users can edit and submit the 
> form, you should also introduce server-side check testing if user is 
> allowed to edit fields. Making form fields read only won't prevent 
> anyone from actually submitting changed data (as it's just a 
> client-side control which can be easily worked around) 
>

Right, definitely will be doing this as well. Mostly the readonly state on 
the form is a visual/styling thing and also simply so there's no perception 
that people can edit things when they can't. Very good point to bring up 
though, and we'll definitely be checking again on the server side since as 
others have pointed out people can manipulate the DOM if they really want 
to wreak havoc. Thankfully this is an internal app which mitigates some of 
the danger, and certainly if this was a public app I would have fought a 
lot harder to not have a non-editable form be the way people view records.

Thanks!

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



Re: Easy way to make all form fields read only?

2012-10-30 Thread Matt Woodward
On Tuesday, October 30, 2012 1:36:19 AM UTC-7, elena wrote:

> How are you rendering the form? Are you using `forms.Form`?
>

We're using a ModelForm specifically.
 

>
> Do you mean "user's credentials" from `django.contrib.auth`?
>

Actually this is a custom user object -- users authenticate against Active 
Directory and we didn't yet look into tying that contrib.auth.user. 
Probably will do that on another phase of this app on Django 1.5 since 
that'll be a bit more flexible for our needs.

Thanks.

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



Re: Django HTTP Basic Auth

2012-10-18 Thread Matt Schinckel
You may want to look into requests, which wraps http request-response 
handling in a nicer wrapper.

http://pypi.python.org/pypi/requests/

Matt.

On Friday, October 19, 2012 1:15:06 PM UTC+10:30, Aaron C. de Bruyn wrote:
>
> On Thu, Oct 18, 2012 at 6:55 PM, django <mait...@gmail.com 
> >wrote:
>
>> I am trying to create a Django app, one of the thing I do in that is 
>> write a connection.py which connects to  a remote server. In that 
>> connection string I need to send one of the parameter as "http_auth = 
>> http_auth.HTTPBasicAuth(user, password)". I am not sure how to do that in 
>> Django. I searched the web a lot and nothing I got which is very relevant 
>> to what I am doing. Can anyone please help me. 
>
>
> If I understand you correctly, you want to connect to a service that uses 
> HTTP Basic Auth in connection.py and do something with the data.
>
> You might look into python's urllib2 library.
>
> I found this snippet:
>
> import urllib2, base64
>
>
> request = urllib2.Request("http://api.foursquare.com/v1/user;)
>
>
> base64string = base64.encodestring('%s:%s' % (username, 
> password)).replace('\n', '')
>
>
> request.add_header("Authorization", "Basic %s" % base64string)   
>
>
> result = urllib2.urlopen(request)
>
> Here:
>
> http://stackoverflow.com/questions/635113/python-urllib2-basic-http-authentication-and-tr-im
>
>
> -A
>
>

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



Re: loop user.get_profile displays none in a template

2012-10-18 Thread Matt Schinckel
user.get_profile() returns a model instance, not a dict. Model instances 
have no .items() method.

Matt.

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



Re: Missing manage.py

2012-10-04 Thread Matt Schinckel
An even better solution is to always work in a virtualenv: that way you can 
easily try out new packages, and not worry about conflicts.

Matt.

On Thursday, October 4, 2012 10:30:06 PM UTC+9:30, Ramiro Morales wrote:
>
> I think so. The usual reason for the problem you are experiencing is a 
> previous installation of Django on top of which the one you are trying 
> to use was installed without unintalling the older one first *. 
>
> So, the recommended action in such cases is to ensure you start with a 
> clean slate buy removing any and all traces of the old files causing 
> trouble. 
>
> 2012/10/4, Django_Newbie <anu...@gmail.com >: 
> > Hi.. 
> > I am using Django 1.4.1 on Windows 7 and face similar problem. I dont 
> see 
> > manage.py 
> > 
> > All I have is: 
> > __init__.py 
> > settings.py 
> > urls.py 
> > wsgi.py 
> > 
> > 
> > Is reinstalling Django only option? 
> > 
> > 
> > On Monday, 16 April 2012 16:56:32 UTC+5:30, Faeez wrote: 
> >> 
> >> Hi, 
> >> 
> >> I have a problem whenever I create a new project using the start 
> project 
> >> command, no manage.py file is created. 
> >> 
> >> I'm using Mac OS X. Thank you in advance 
> >> 
> > 
> > -- 
> > You received this message because you are subscribed to the Google 
> Groups 
> > "Django users" group. 
> > To view this discussion on the web visit 
> > https://groups.google.com/d/msg/django-users/-/_GE2ct9_qi0J. 
> > To post to this group, send email to 
> > django...@googlegroups.com. 
>
> > To unsubscribe from this group, send email to 
> > django-users...@googlegroups.com . 
> > For more options, visit this group at 
> > http://groups.google.com/group/django-users?hl=en. 
> > 
> > 
>
> -- 
> Enviado desde mi dispositivo móvil 
>
> Ramiro Morales 
>

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



Re: Newbie Project Setup and Terminology Questions

2012-09-16 Thread Matt Woodward
Thanks to all for the examples and insight! Very helpful.

Matt

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



Re: Alternatives to CBVs (class based views)

2012-09-12 Thread Matt Schinckel
One really small nitpick: when returning a 405, it is a requirement that 
you return a header with the acceptable methods:
>
>
> 10.4.6 405 Method Not Allowed

> The method specified in the Request-Line is not allowed for the resource 
identified by the Request-URI. The response MUST include an Allow header 
containing a list of valid methods for the requested resource.

(From http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html).


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



  1   2   3   4   5   >