Saturday, January 31, 2015

Re: Restrict downloading files in Django?


On Sun, Feb 1, 2015 at 1:33 AM, Javier Guerra Giraldez <javier@guerrag.com> wrote:
On Sat, Jan 31, 2015 at 11:52 AM, Robert Rössler <r.rossler96@gmail.com> wrote:
> what is the best way to restrict downloading files only to authorized users?

it's not hard to do if you manage the file downloading with a view.

of course, file serving within Django is very inefficient, your
webserver (Apache, nginx, etc.) is far more efficient at this.

so, the solution is to write a view that looks like it's serving the
file (after checking for authorization), but instead of actually
serving, delegates the job to the webserver.  check X-Accel-Redirect
(nginx) or X-Sendfile (apache)

The X-Sendfile (or analog) approach is the right way to go - there are even Django apps that can help manage this process. See:


For a recent blog talking walking through the process.

Yours,
Russ Magee %-)

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@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/CAJxq849OgE-y2UqHXFFs6XAKKHOxryJGKHgeWwhqniyF4WgEGg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Re: Initial stages of django

Did you take a look at the official tutorial?


On Sat, Jan 31, 2015 at 5:02 PM, Sreenivasarao Pallapu <sreenivas.engece@gmail.com> wrote:
Hi,
   I'm new to django. I know basic python. I heard that django is nothing but python. I've installed django and started as on video tutorials. But it is a bit confusing to me. I know nothing about the classes and functions they are using. Could you please suggest me better book or tutorial for easy start...

--
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+unsubscribe@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/48249b8a-3468-492f-a88f-854bc8f0ab44%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+unsubscribe@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/CALn3ei05ohK43tv3AGFwt-WwYzYVQTNk3rQjwnvbWp-UHp8kxw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Re: Is is possible to have a distributed database with Django?

Sure, it's possible. But this is a really hard problem. One way is to
let the database do all the heavy lifting. But you'll have to forget
about using simple databases like SQLite or MySQL. Oracle's advanced
replication documentation talks about exactly this type of situation
w/r/t materialized views:

https://docs.oracle.com/database/121/REPLN/repmview.htm#REPLN266

Another option is to do it all in the Django app. Your app would
probably always query and modify the local copy for end user requests.
Then there would be a separate portion of your app that runs in the
background on a schedule (management command? celery task?) that syncs
the local copy of the database with the master when it can.

But good luck getting all that logic correct. For simple projects you
might be able to, but add any sort of complexity and you're asking for
trouble. For instance: suppose your table has a unique constraint that
can be satisfied in the local DB but not the master DB. Are you ready
to throw away the local transactions that can't satisfy the
constraint?

But there are other types of constraints not included in the database
schema. For instance, let's say you have logic in your application so
that user Fred can destroy Widgets but only if he has the manager
permission. Fred gets demoted, but before the demotion is synced to
the local DB he goes through and destroys all the Widgets. How do you
keep that change from being propagated to the master DB when the next
sync happens?

The details of your particular app may make some of these questions
easier. Maybe not all of the DB needs to be read/write while in a
disconnected state. For example, consider a sales man going to a
remote location to talk to a client. He might be OK with readonly
copies of the master DB's Widget table, Contacts table, SLA table, etc
and only need an appendonly copy of the Orders table (that is, he can
read existing Orders, create/edit new Orders, but not edit existing
Orders). But you will still need reconciliation logic for when he gets
back in case the Widget or SLA he used in the Order no longer exists.


On Sat, Jan 31, 2015 at 10:04 AM, Itumeleng Mphoso <itumphoso@gmail.com> wrote:
> I'm new to Django and have just deployed my first Django application. My
> problem is, the application is used by people in different locations and
> networks, so when ever the network is down, those using a different network
> can't have access to the application. I need all the networks to have a
> local database that they use, but this database should also synchronize
> whenever they have internet. Is there anything I can do with Django to make
> this possible?
>
> --
> 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+unsubscribe@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/450edd30-433b-4d4f-8e70-21f11369b7c5%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+unsubscribe@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/CAD4ANxWDM3TQMSs4PNjMF22om9e5upo%3DBN5p6012GOB-KAm2YQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Initial stages of django

Hi,
   I'm new to django. I know basic python. I heard that django is nothing but python. I've installed django and started as on video tutorials. But it is a bit confusing to me. I know nothing about the classes and functions they are using. Could you please suggest me better book or tutorial for easy start...

--
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+unsubscribe@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/48249b8a-3468-492f-a88f-854bc8f0ab44%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Re: incorrect syntax of django core management __init.py file (reported on windows powershell)

Django 1.3 only works with python 2, not python 3

On Sat, Jan 31, 2015 at 2:31 PM, Akshit Arora <akshit.arora1995@gmail.com> wrote:
hey, I am working on this project that requires django with apache


it's installation guide is here :


Now, I have installed every dependency mentioned in step 2. 

versions installed are:
django 1.3
python 3.4
apache 2.4

I am using windows 8.1 (windows powershell 3)
The real problem is when I run command :

python manage.py runserver

powershell reports syntactical errors in django core management __init.py file line 302  <as shown in the following screenshot>

I checked up everything online, the file is in correct syntax.
please suggest what to do.

Following is a powershell screenshot of the problem i am facing
Inline image 1

-- 
With Regards,
Akshit Arora

--
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+unsubscribe@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/7131e9f7-4941-4f00-b909-cfc0d13a5bc0%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+unsubscribe@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/CALn3ei3QSeGpNsr42xu%2BYF7t0SP8e4zP9L7VMRpADdNhhrFejQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Re: Restrict downloading files in Django?

On Sat, Jan 31, 2015 at 11:52 AM, Robert Rössler <r.rossler96@gmail.com> wrote:
> what is the best way to restrict downloading files only to authorized users?

it's not hard to do if you manage the file downloading with a view.

of course, file serving within Django is very inefficient, your
webserver (Apache, nginx, etc.) is far more efficient at this.

so, the solution is to write a view that looks like it's serving the
file (after checking for authorization), but instead of actually
serving, delegates the job to the webserver. check X-Accel-Redirect
(nginx) or X-Sendfile (apache)

--
Javier

--
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+unsubscribe@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/CAFkDaoRu08gBCwDcicr4g9iktDMqYtdkXZUNUVQMJOMZRPj73A%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

incorrect syntax of django core management __init.py file (reported on windows powershell)

hey, I am working on this project that requires django with apache

https://github.com/nbproject/nbproject

it's installation guide is here :

https://github.com/nbproject/nbproject/wiki/Install-guide

Now, I have installed every dependency mentioned in step 2. 

versions installed are:
django 1.3
python 3.4
apache 2.4

I am using windows 8.1 (windows powershell 3)
The real problem is when I run command :

python manage.py runserver

powershell reports syntactical errors in django core management __init.py file line 302  <as shown in the following screenshot>

I checked up everything online, the file is in correct syntax.
please suggest what to do.

Following is a powershell screenshot of the problem i am facing
Inline image 1

-- 
With Regards,
Akshit Arora

--
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+unsubscribe@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/7131e9f7-4941-4f00-b909-cfc0d13a5bc0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Re: Restrict downloading files in Django?

i don't know if this is the best way to do that. But you can create a view that response the file after verify the user credentials. 

The problem is:  once the user knows the urls from file, he can share the url with others.

Its not difficult create an "one time url" to the request to solve this problem.

On Sat, Jan 31, 2015 at 2:52 PM, Robert Rössler <r.rossler96@gmail.com> wrote:
Hello,
what is the best way to restrict downloading files only to authorized users?
I want to let users upload files and let them download them, but restrict downloading other users files.

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+unsubscribe@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/f67b7248-72e2-4ed9-95b6-66604598bc62%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+unsubscribe@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/CAGjPPHksBZ%3Df_wtyyX-NDM4n-XKWi_LsR3q6os1g17xv%3D%3DAbSw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Restrict downloading files in Django?

Hello,
what is the best way to restrict downloading files only to authorized users?
I want to let users upload files and let them download them, but restrict downloading other users files.

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+unsubscribe@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/f67b7248-72e2-4ed9-95b6-66604598bc62%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Is is possible to have a distributed database with Django?

I'm new to Django and have just deployed my first Django application. My problem is, the application is used by people in different locations and networks, so when ever the network is down, those using a different network can't have access to the application. I need all the networks to have a local database that they use, but this database should also synchronize whenever they have internet. Is there anything I can do with Django to make this possible?

--
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+unsubscribe@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/450edd30-433b-4d4f-8e70-21f11369b7c5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Re: How to get hold of a session after getting signaled?


On 31 Jan 2015 10:11, "Stephen J. Butler" <stephen.butler@gmail.com> wrote:
>
> You still could store the do_something_after_badge_awarded result in a
> database table, but cache the lookups from the view for something
> short, like 5 minutes. How quickly after a badge is awarded do people
> need to be notified?
>
> Also, you could use a memcached library to store/fetch the awards by
> user ID. Should be pretty quick. That assumes of course that it's OK
> to lose award notifications if memcached restarts. Would look
> something like:
>
> # store
> mc.append(key_for_user, "{0} ".format(award_obj.pk))
>
> # ...
>
> # get. use a lockless cas() algo
> award_objs = None
> while award_objs is None:
>     award_ids, cas_token = mc.gets(key_for_user)
>     if not award_ids:
>         # No awards waiting for us
>         award_objs = []
>     elif mc.cas(key_for_user, "", cas_token):
>         # Awards didn't change on us, continue
>         award_objs = Awards.objects.filter(pk__in=award_ids.split())
>
> Or you could do something with the Django cache framework. Or you
> could use local files and serialization.
>
> But I do think you should test your assumption that the DB check for
> awarded awards will be too expensive. Especially if cached. Most apps
> make a ton of DB calls anyway, and this one will mostly be empty.
>
+1. You need to measure rather than assume.
> On Sat, Jan 31, 2015 at 2:02 AM, Tobias Dacoir <falc410@gmail.com> wrote:
> > I can't just call badge.award_to(user) because I need to wait for the check
> > logic to verify if the user should receive a badge or not.
> > My workaround is that I created a new table that inserts badge and user
> > foreign keys and before the view is rendered I will check this table for any
> > entries for that user. If there are, I will copy the data to a message and
> > delete the object from the database again.
> >
> > It's rather ugly due to the many database hits which I would like to avoid
> > but I can't think of anything else at the moment. Apparently (using google)
> > there is no way to get hold of the request in a post_save() signal - which I
> > need to check all achievements.
> >
> > The only real solution would be to not use this post_save() signal but
> > manually do the checking for achievements before my view is rendered, which
> > would require some work on the original source code. I will look into it
> > though next week.
> >
> > --
> > 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+unsubscribe@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/ee9653c8-2c8e-479e-871b-34774862888b%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+unsubscribe@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/CAD4ANxWOT1Mg%3D47H89s0Xoi9m7kVA-y1Ag5qoh9vrdO9Nuc7tg%40mail.gmail.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+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CA%2BWjgXNxXw5PWgKY%3DgBeak%3DWMbSfn5a_zATLYAtvJGGr-pff0A%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Re: admin site questions

2015-01-31 7:14 GMT+01:00 Mike <mike.thon@gmail.com>:
I'm building a simple CRUD application to hold some data for our research group.  After 2 hours I have the basic functionality working using the admin site only and no custom views.  I just need to figure out if I can go ahead and deploy it using the admin site as the main user interface. So, my questions are:

1) Is it ok to use the admin site as the main interface to the project? It will not be public facing and will be used by 4-5 people.

2) On the admin page, 'Select [model] to change' can I have those links point to a read only view of the model data and then have that page link to an editable view? I'm thinking that having an extra step will help to prevent accidental updates.


Thanks
Mike

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@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/a83b7ad7-d353-4770-876b-18760ea3b6b2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Hi Mike,

1. Sure you can use the admin pages as the main interface for the project. They do work very well and you shouldn't have any issues with them. We are using the admin interface as a backend interface for one of the projects I am working on. The only issue is that sometimes the admin pages are a bit cumbersome to use, otherwise it all "just works".

2. I don't think you can do that easily in django. What you can do is rewrite the index page and use an intermediate page before you go to the change page. But django does not support this functionality without a lot of changes.

Regards,

Andréas

--
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+unsubscribe@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/CALXYUbk09fuvwne_8dt8ZC_BUZa%3DKFUjerooBs6rN7drW_XKXA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Re: How to get hold of a session after getting signaled?

You still could store the do_something_after_badge_awarded result in a
database table, but cache the lookups from the view for something
short, like 5 minutes. How quickly after a badge is awarded do people
need to be notified?

Also, you could use a memcached library to store/fetch the awards by
user ID. Should be pretty quick. That assumes of course that it's OK
to lose award notifications if memcached restarts. Would look
something like:

# store
mc.append(key_for_user, "{0} ".format(award_obj.pk))

# ...

# get. use a lockless cas() algo
award_objs = None
while award_objs is None:
award_ids, cas_token = mc.gets(key_for_user)
if not award_ids:
# No awards waiting for us
award_objs = []
elif mc.cas(key_for_user, "", cas_token):
# Awards didn't change on us, continue
award_objs = Awards.objects.filter(pk__in=award_ids.split())

Or you could do something with the Django cache framework. Or you
could use local files and serialization.

But I do think you should test your assumption that the DB check for
awarded awards will be too expensive. Especially if cached. Most apps
make a ton of DB calls anyway, and this one will mostly be empty.

On Sat, Jan 31, 2015 at 2:02 AM, Tobias Dacoir <falc410@gmail.com> wrote:
> I can't just call badge.award_to(user) because I need to wait for the check
> logic to verify if the user should receive a badge or not.
> My workaround is that I created a new table that inserts badge and user
> foreign keys and before the view is rendered I will check this table for any
> entries for that user. If there are, I will copy the data to a message and
> delete the object from the database again.
>
> It's rather ugly due to the many database hits which I would like to avoid
> but I can't think of anything else at the moment. Apparently (using google)
> there is no way to get hold of the request in a post_save() signal - which I
> need to check all achievements.
>
> The only real solution would be to not use this post_save() signal but
> manually do the checking for achievements before my view is rendered, which
> would require some work on the original source code. I will look into it
> though next week.
>
> --
> 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+unsubscribe@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/ee9653c8-2c8e-479e-871b-34774862888b%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+unsubscribe@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/CAD4ANxWOT1Mg%3D47H89s0Xoi9m7kVA-y1Ag5qoh9vrdO9Nuc7tg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Re: Do Signals block Django process?

Thanks for the info about django-debug-toolbar. I will certainly test it. I assume that I do a quite a lot of slow queries, but during development I run with a very reduced dataset, so my database (sqlite too instead of mysql) only contains a couple of hundred entries whereas in deployment it will be 10.000+.

Still hopefully I can get some estimates which queries take how long to finish right now and optimize those.

And in a 2nd stage I need some kind of tool to simulate multiple users login in and filling out forms on the site to see how it behaves. I found a couple of names using google, however I still have to settle for one tool that is still maintained and well documented. Any recommendations in that area are welcome.

On Saturday, January 31, 2015 at 1:57:55 AM UTC+1, Tundebabzy wrote:

The view will return after the receiver has finished its work. But are you doing any slow queries? I ask because you might be over engineering your work.

A good place to start is to benchmark your queries using a tool like django-debug-toolbar. With that you can know exactly how long it takes one user to query your database and then use that to estimate for more users.


--
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+unsubscribe@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/c85156f9-e36e-4a17-ad64-744802736fda%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Re: How to get hold of a session after getting signaled?

I can't just call badge.award_to(user) because I need to wait for the check logic to verify if the user should receive a badge or not.
My workaround is that I created a new table that inserts badge and user foreign keys and before the view is rendered I will check this table for any entries for that user. If there are, I will copy the data to a message and delete the object from the database again.

It's rather ugly due to the many database hits which I would like to avoid but I can't think of anything else at the moment. Apparently (using google) there is no way to get hold of the request in a post_save() signal - which I need to check all achievements.

The only real solution would be to not use this post_save() signal but manually do the checking for achievements before my view is rendered, which would require some work on the original source code. I will look into it though next week.

--
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+unsubscribe@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/ee9653c8-2c8e-479e-871b-34774862888b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Friday, January 30, 2015

using celery with django.

I am experimenting with celery with django and i am using windows 7 os on my machine.

Here is outcome... so far.

I added sample app to my project and added tasks.py to my app.
--------------------------------------------------------
tasks.py 
--------------------------------------------------------
from models import SampleCount
from celery import task

@task()
def add_to_count():
    try:
        sc=SampleCount.objects.get(pk=1)
    except:
        sc=SampleCount()
    sc.counter=sc.counter+1
    sc.save()

 ----------------------------------------------------------------------
 models.py 
------------------------------------------------------------------------
from django.db import models

# Create your models here.
class SampleCount(models.Model):
    counter = models.IntegerField(default=0)
    
    
    def __int__(self):
        return self.counter
-------------------------------------------------------------------------------
settings.py
------------------------------------------------------------------------------

INSTALLED_APPS = (
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'User_Registration',
    'Location_Management',
    'Drop_Slot_Management',
    'django_extensions',
    'djcelery',
    'kombu.transport.django',
    'sample',
)

BROKER_URL = "django://"

-------------------------------------------------------------------------
Here is what I am doing I am running manage.py shell
importing the model and running the add_to_count() which adds to counter field. 

I run the celeryd from manage.py celeryd. it runs without error

when i run add_to_count.delay().  I get following error in celeryd running prompt. 
  uuid, retval, SUCCESS, request=task_request,
File "C:\Python27\lib\site-packages\celery-3.1.17-py2.7.egg\celery\backends\ba
.py", line 256, in store_result
  request=request, **kwargs)
File "C:\Python27\lib\site-packages\django_celery-3.1.16-py2.7.egg\djcelery\ba
ends\database.py", line 29, in _store_result
  traceback=traceback, children=self.current_task_children(request),
File "C:\Python27\lib\site-packages\django_celery-3.1.16-py2.7.egg\djcelery\ma
gers.py", line 42, in _inner
  return fun(*args, **kwargs)
File "C:\Python27\lib\site-packages\django_celery-3.1.16-py2.7.egg\djcelery\ma
gers.py", line 181, in store_result
  'meta': {'children': children}})
File "C:\Python27\lib\site-packages\django_celery-3.1.16-py2.7.egg\djcelery\ma
gers.py", line 87, in update_or_create
  return get_queryset(self).update_or_create(**kwargs)
File "C:\Python27\lib\site-packages\django_celery-3.1.16-py2.7.egg\djcelery\ma
gers.py", line 70, in update_or_create
  obj, created = self.get_or_create(**kwargs)
File "C:\Python27\lib\site-packages\django-1.7.2-py2.7.egg\django\db\models\qu
y.py", line 422, in get_or_create
  return self.get(**lookup), False
File "C:\Python27\lib\site-packages\django-1.7.2-py2.7.egg\django\db\models\qu
y.py", line 345, in get
  clone = self.filter(*args, **kwargs)
File "C:\Python27\lib\site-packages\django-1.7.2-py2.7.egg\django\db\models\qu
y.py", line 691, in filter
  return self._filter_or_exclude(False, *args, **kwargs)
File "C:\Python27\lib\site-packages\django-1.7.2-py2.7.egg\django\db\models\qu
y.py", line 709, in _filter_or_exclude
  clone.query.add_q(Q(*args, **kwargs))
File "C:\Python27\lib\site-packages\django-1.7.2-py2.7.egg\django\db\models\sq
query.py", line 1331, in add_q
  clause, require_inner = self._add_q(where_part, self.used_aliases)
File "C:\Python27\lib\site-packages\django-1.7.2-py2.7.egg\django\db\models\sq
query.py", line 1358, in _add_q
  current_negated=current_negated, connector=connector)
File "C:\Python27\lib\site-packages\django-1.7.2-py2.7.egg\django\db\models\sq
query.py", line 1182, in build_filter
  lookups, parts, reffed_aggregate = self.solve_lookup_type(arg)
File "C:\Python27\lib\site-packages\django-1.7.2-py2.7.egg\django\db\models\sq
query.py", line 1120, in solve_lookup_type
  _, field, _, lookup_parts = self.names_to_path(lookup_splitted, self.get_met
))
File "C:\Python27\lib\site-packages\django-1.7.2-py2.7.egg\django\db\models\sq
query.py", line 1383, in names_to_path
  field, model, direct, m2m = opts.get_field_by_name(name)
File "C:\Python27\lib\site-packages\django-1.7.2-py2.7.egg\django\db\models\op
ons.py", line 416, in get_field_by_name
  cache = self.init_name_map()
File "C:\Python27\lib\site-packages\django-1.7.2-py2.7.egg\django\db\models\op
ons.py", line 445, in init_name_map
  for f, model in self.get_all_related_m2m_objects_with_model():
File "C:\Python27\lib\site-packages\django-1.7.2-py2.7.egg\django\db\models\op
ons.py", line 563, in get_all_related_m2m_objects_with_model
  cache = self._fill_related_many_to_many_cache()
File "C:\Python27\lib\site-packages\django-1.7.2-py2.7.egg\django\db\models\op
ons.py", line 577, in _fill_related_many_to_many_cache
  for klass in self.apps.get_models():
File "C:\Python27\lib\site-packages\django-1.7.2-py2.7.egg\django\utils\lru_ca
e.py", line 101, in wrapper
  result = user_function(*args, **kwds)
File "C:\Python27\lib\site-packages\django-1.7.2-py2.7.egg\django\apps\registr
py", line 168, in get_models
  self.check_models_ready()
File "C:\Python27\lib\site-packages\django-1.7.2-py2.7.egg\django\apps\registr
py", line 131, in check_models_ready
  raise AppRegistryNotReady("Models aren't loaded yet.")
pRegistryNotReady: Models aren't loaded yet.

exc, exc_info.traceback)))
015-01-31 09:28:01,621: CRITICAL/MainProcess] Task sample.tasks.add_to_count[f
293be-aaeb-4e32-bbdb-b4a7ba042731] INTERNAL ERROR: AppRegistryNotReady("Models
ren't loaded yet.",)
aceback (most recent call last):
File "C:\Python27\lib\site-packages\celery-3.1.17-py2.7.egg\celery\app\trace.p
, line 283, in trace_task
  uuid, retval, SUCCESS, request=task_request,
File "C:\Python27\lib\site-packages\celery-3.1.17-py2.7.egg\celery\backends\ba
.py", line 256, in store_result
  request=request, **kwargs)
File "C:\Python27\lib\site-packages\django_celery-3.1.16-py2.7.egg\djcelery\ba
ends\database.py", line 29, in _store_result
  traceback=traceback, children=self.current_task_children(request),
File "C:\Python27\lib\site-packages\django_celery-3.1.16-py2.7.egg\djcelery\ma
gers.py", line 42, in _inner
  return fun(*args, **kwargs)
File "C:\Python27\lib\site-packages\django_celery-3.1.16-py2.7.egg\djcelery\ma
gers.py", line 181, in store_result
  'meta': {'children': children}})
File "C:\Python27\lib\site-packages\django_celery-3.1.16-py2.7.egg\djcelery\ma
gers.py", line 87, in update_or_create
  return get_queryset(self).update_or_create(**kwargs)
File "C:\Python27\lib\site-packages\django_celery-3.1.16-py2.7.egg\djcelery\ma
gers.py", line 70, in update_or_create
  obj, created = self.get_or_create(**kwargs)
File "C:\Python27\lib\site-packages\django-1.7.2-py2.7.egg\django\db\models\qu
y.py", line 422, in get_or_create
  return self.get(**lookup), False
File "C:\Python27\lib\site-packages\django-1.7.2-py2.7.egg\django\db\models\qu
y.py", line 345, in get
  clone = self.filter(*args, **kwargs)
File "C:\Python27\lib\site-packages\django-1.7.2-py2.7.egg\django\db\models\qu
y.py", line 691, in filter
  return self._filter_or_exclude(False, *args, **kwargs)
File "C:\Python27\lib\site-packages\django-1.7.2-py2.7.egg\django\db\models\qu
y.py", line 709, in _filter_or_exclude
  clone.query.add_q(Q(*args, **kwargs))
File "C:\Python27\lib\site-packages\django-1.7.2-py2.7.egg\django\db\models\sq
query.py", line 1331, in add_q
  clause, require_inner = self._add_q(where_part, self.used_aliases)
File "C:\Python27\lib\site-packages\django-1.7.2-py2.7.egg\django\db\models\sq
query.py", line 1358, in _add_q
  current_negated=current_negated, connector=connector)
File "C:\Python27\lib\site-packages\django-1.7.2-py2.7.egg\django\db\models\sq
query.py", line 1182, in build_filter
  lookups, parts, reffed_aggregate = self.solve_lookup_type(arg)
File "C:\Python27\lib\site-packages\django-1.7.2-py2.7.egg\django\db\models\sq
query.py", line 1120, in solve_lookup_type
  _, field, _, lookup_parts = self.names_to_path(lookup_splitted, self.get_met
))
File "C:\Python27\lib\site-packages\django-1.7.2-py2.7.egg\django\db\models\sq
query.py", line 1383, in names_to_path
  field, model, direct, m2m = opts.get_field_by_name(name)
File "C:\Python27\lib\site-packages\django-1.7.2-py2.7.egg\django\db\models\op
ons.py", line 416, in get_field_by_name
  cache = self.init_name_map()
File "C:\Python27\lib\site-packages\django-1.7.2-py2.7.egg\django\db\models\op
ons.py", line 445, in init_name_map
  for f, model in self.get_all_related_m2m_objects_with_model():
File "C:\Python27\lib\site-packages\django-1.7.2-py2.7.egg\django\db\models\op
ons.py", line 563, in get_all_related_m2m_objects_with_model
  cache = self._fill_related_many_to_many_cache()
File "C:\Python27\lib\site-packages\django-1.7.2-py2.7.egg\django\db\models\op
ons.py", line 577, in _fill_related_many_to_many_cache
  for klass in self.apps.get_models():
File "C:\Python27\lib\site-packages\django-1.7.2-py2.7.egg\django\utils\lru_ca
e.py", line 101, in wrapper
  result = user_function(*args, **kwds)
File "C:\Python27\lib\site-packages\django-1.7.2-py2.7.egg\django\apps\registr
py", line 168, in get_models
  self.check_models_ready()
File "C:\Python27\lib\site-packages\django-1.7.2-py2.7.egg\django\apps\registr
py", line 131, in check_models_ready
  raise AppRegistryNotReady("Models aren't loaded yet.")
pRegistryNotReady: Models aren't loaded yet.
015-01-31 09:29:01,681: WARNING/Worker-1] C:\Python27\lib\site-packages\celery
.1.17-py2.7.egg\celery\app\trace.py:365: RuntimeWarning: Exception raised outs
e body: AppRegistryNotReady("Models aren't loaded yet.",):
aceback (most recent call last):
File "C:\Python27\lib\site-packages\celery-3.1.17-py2.7.egg\celery\app\trace.p
, line 283, in trace_task
  uuid, retval, SUCCESS, request=task_request,
File "C:\Python27\lib\site-packages\celery-3.1.17-py2.7.egg\celery\backends\ba
.py", line 256, in store_result
  request=request, **kwargs)
File "C:\Python27\lib\site-packages\django_celery-3.1.16-py2.7.egg\djcelery\ba
ends\database.py", line 29, in _store_result
  traceback=traceback, children=self.current_task_children(request),
File "C:\Python27\lib\site-packages\django_celery-3.1.16-py2.7.egg\djcelery\ma
gers.py", line 42, in _inner
  return fun(*args, **kwargs)
File "C:\Python27\lib\site-packages\django_celery-3.1.16-py2.7.egg\djcelery\ma
gers.py", line 181, in store_result
  'meta': {'children': children}})
File "C:\Python27\lib\site-packages\django_celery-3.1.16-py2.7.egg\djcelery\ma
gers.py", line 87, in update_or_create
  return get_queryset(self).update_or_create(**kwargs)
File "C:\Python27\lib\site-packages\django_celery-3.1.16-py2.7.egg\djcelery\ma
gers.py", line 70, in update_or_create
  obj, created = self.get_or_create(**kwargs)
File "C:\Python27\lib\site-packages\django-1.7.2-py2.7.egg\django\db\models\qu
y.py", line 422, in get_or_create
  return self.get(**lookup), False
File "C:\Python27\lib\site-packages\django-1.7.2-py2.7.egg\django\db\models\qu
y.py", line 345, in get
  clone = self.filter(*args, **kwargs)
File "C:\Python27\lib\site-packages\django-1.7.2-py2.7.egg\django\db\models\qu
y.py", line 691, in filter
  return self._filter_or_exclude(False, *args, **kwargs)
File "C:\Python27\lib\site-packages\django-1.7.2-py2.7.egg\django\db\models\qu
y.py", line 709, in _filter_or_exclude
  clone.query.add_q(Q(*args, **kwargs))
File "C:\Python27\lib\site-packages\django-1.7.2-py2.7.egg\django\db\models\sq
query.py", line 1331, in add_q
  clause, require_inner = self._add_q(where_part, self.used_aliases)
File "C:\Python27\lib\site-packages\django-1.7.2-py2.7.egg\django\db\models\sq
query.py", line 1358, in _add_q
  current_negated=current_negated, connector=connector)
File "C:\Python27\lib\site-packages\django-1.7.2-py2.7.egg\django\db\models\sq
query.py", line 1182, in build_filter
  lookups, parts, reffed_aggregate = self.solve_lookup_type(arg)
File "C:\Python27\lib\site-packages\django-1.7.2-py2.7.egg\django\db\models\sq
query.py", line 1120, in solve_lookup_type
  _, field, _, lookup_parts = self.names_to_path(lookup_splitted, self.get_met
))
File "C:\Python27\lib\site-packages\django-1.7.2-py2.7.egg\django\db\models\sq
query.py", line 1383, in names_to_path
  field, model, direct, m2m = opts.get_field_by_name(name)
File "C:\Python27\lib\site-packages\django-1.7.2-py2.7.egg\django\db\models\op
ons.py", line 416, in get_field_by_name
  cache = self.init_name_map()
File "C:\Python27\lib\site-packages\django-1.7.2-py2.7.egg\django\db\models\op
ons.py", line 445, in init_name_map
  for f, model in self.get_all_related_m2m_objects_with_model():
File "C:\Python27\lib\site-packages\django-1.7.2-py2.7.egg\django\db\models\op
ons.py", line 563, in get_all_related_m2m_objects_with_model
  cache = self._fill_related_many_to_many_cache()
File "C:\Python27\lib\site-packages\django-1.7.2-py2.7.egg\django\db\models\op
ons.py", line 577, in _fill_related_many_to_many_cache
  for klass in self.apps.get_models():
File "C:\Python27\lib\site-packages\django-1.7.2-py2.7.egg\django\utils\lru_ca
e.py", line 101, in wrapper
  result = user_function(*args, **kwds)
File "C:\Python27\lib\site-packages\django-1.7.2-py2.7.egg\django\apps\registr
py", line 168, in get_models
  self.check_models_ready()
File "C:\Python27\lib\site-packages\django-1.7.2-py2.7.egg\django\apps\registr
py", line 131, in check_models_ready
  raise AppRegistryNotReady("Models aren't loaded yet.")
pRegistryNotReady: Models aren't loaded yet.

exc, exc_info.traceback)))
015-01-31 09:29:01,691: CRITICAL/MainProcess] Task sample.tasks.add_to_count[b
fb466-7e18-4aeb-a69d-791222e1aa8e] INTERNAL ERROR: AppRegistryNotReady("Models
ren't loaded yet.",)
aceback (most recent call last):
File "C:\Python27\lib\site-packages\celery-3.1.17-py2.7.egg\celery\app\trace.p
, line 283, in trace_task
  uuid, retval, SUCCESS, request=task_request,
File "C:\Python27\lib\site-packages\celery-3.1.17-py2.7.egg\celery\backends\ba
.py", line 256, in store_result
  request=request, **kwargs)
File "C:\Python27\lib\site-packages\django_celery-3.1.16-py2.7.egg\djcelery\ba
ends\database.py", line 29, in _store_result
  traceback=traceback, children=self.current_task_children(request),
File "C:\Python27\lib\site-packages\django_celery-3.1.16-py2.7.egg\djcelery\ma
gers.py", line 42, in _inner
  return fun(*args, **kwargs)
File "C:\Python27\lib\site-packages\django_celery-3.1.16-py2.7.egg\djcelery\ma
gers.py", line 181, in store_result
  'meta': {'children': children}})
File "C:\Python27\lib\site-packages\django_celery-3.1.16-py2.7.egg\djcelery\ma
gers.py", line 87, in update_or_create
  return get_queryset(self).update_or_create(**kwargs)
File "C:\Python27\lib\site-packages\django_celery-3.1.16-py2.7.egg\djcelery\ma
gers.py", line 70, in update_or_create
  obj, created = self.get_or_create(**kwargs)
File "C:\Python27\lib\site-packages\django-1.7.2-py2.7.egg\django\db\models\qu
y.py", line 422, in get_or_create
  return self.get(**lookup), False
File "C:\Python27\lib\site-packages\django-1.7.2-py2.7.egg\django\db\models\qu
y.py", line 345, in get
  clone = self.filter(*args, **kwargs)
File "C:\Python27\lib\site-packages\django-1.7.2-py2.7.egg\django\db\models\qu
y.py", line 691, in filter
  return self._filter_or_exclude(False, *args, **kwargs)
File "C:\Python27\lib\site-packages\django-1.7.2-py2.7.egg\django\db\models\qu
y.py", line 709, in _filter_or_exclude
  clone.query.add_q(Q(*args, **kwargs))
File "C:\Python27\lib\site-packages\django-1.7.2-py2.7.egg\django\db\models\sq
query.py", line 1331, in add_q
  clause, require_inner = self._add_q(where_part, self.used_aliases)
File "C:\Python27\lib\site-packages\django-1.7.2-py2.7.egg\django\db\models\sq
query.py", line 1358, in _add_q
  current_negated=current_negated, connector=connector)
File "C:\Python27\lib\site-packages\django-1.7.2-py2.7.egg\django\db\models\sq
query.py", line 1182, in build_filter
  lookups, parts, reffed_aggregate = self.solve_lookup_type(arg)
File "C:\Python27\lib\site-packages\django-1.7.2-py2.7.egg\django\db\models\sq
query.py", line 1120, in solve_lookup_type
  _, field, _, lookup_parts = self.names_to_path(lookup_splitted, self.get_met
))
File "C:\Python27\lib\site-packages\django-1.7.2-py2.7.egg\django\db\models\sq
query.py", line 1383, in names_to_path
  field, model, direct, m2m = opts.get_field_by_name(name)
File "C:\Python27\lib\site-packages\django-1.7.2-py2.7.egg\django\db\models\op
ons.py", line 416, in get_field_by_name
  cache = self.init_name_map()
File "C:\Python27\lib\site-packages\django-1.7.2-py2.7.egg\django\db\models\op
ons.py", line 445, in init_name_map
  for f, model in self.get_all_related_m2m_objects_with_model():
File "C:\Python27\lib\site-packages\django-1.7.2-py2.7.egg\django\db\models\op
ons.py", line 563, in get_all_related_m2m_objects_with_model
  cache = self._fill_related_many_to_many_cache()
File "C:\Python27\lib\site-packages\django-1.7.2-py2.7.egg\django\db\models\op
ons.py", line 577, in _fill_related_many_to_many_cache
  for klass in self.apps.get_models():
File "C:\Python27\lib\site-packages\django-1.7.2-py2.7.egg\django\utils\lru_ca
e.py", line 101, in wrapper
  result = user_function(*args, **kwds)
File "C:\Python27\lib\site-packages\django-1.7.2-py2.7.egg\django\apps\registr
py", line 168, in get_models
  self.check_models_ready()
File "C:\Python27\lib\site-packages\django-1.7.2-py2.7.egg\django\apps\registr
py", line 131, in check_models_ready
  raise AppRegistryNotReady("Models aren't loaded yet.")
pRegistryNotReady: Models aren't loaded yet.

Am I doing something wrong? 

Regards,
Sarfaraz Ahmed

--
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+unsubscribe@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/b2bec2f1-b849-4247-aca4-aee91be03687%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

admin site questions

I'm building a simple CRUD application to hold some data for our research group.  After 2 hours I have the basic functionality working using the admin site only and no custom views.  I just need to figure out if I can go ahead and deploy it using the admin site as the main user interface. So, my questions are:

1) Is it ok to use the admin site as the main interface to the project? It will not be public facing and will be used by 4-5 people.

2) On the admin page, 'Select [model] to change' can I have those links point to a read only view of the model data and then have that page link to an editable view? I'm thinking that having an extra step will help to prevent accidental updates.


Thanks
Mike

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@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/a83b7ad7-d353-4770-876b-18760ea3b6b2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Re: How to get hold of a session after getting signaled?

As far as I can tell on the project source, the only place the "badge_awarded" signal is triggered is in the "award_to" method in the Badge class, which does not handle a request object.

If you are calling something like "badge.award_to(user)" in one of your views, then you can modify the request response immediately after, without using the signal.

On Fri, Jan 30, 2015 at 1:19 PM, Tobias Dacoir <falc410@gmail.com> wrote:
I'm using django-badges in my project which can emit a signal when a user is awarded a badge. I was able to implemented a receiver function, however the output is the following:

signals.py (from badges):
import django.dispatch

badge_awarded
= django.dispatch.Signal(providing_args=['user', 'badge'])



my receiver function test:

from badges.signals import badge_awarded
@receiver(badge_awarded)
def do_something_after_badge_awarded(sender, user, badge, **kwargs):
   
print "Badge Signal received"
   
print sender # <play.meta_badges.neueBadge object at 0x109733d90>
   
print user # user object
   
print badge # badge object
   
print kwargs



and the output was:
Badge Signal received
<play.meta_badges.neueBadge object at 0x109733d90>
player1
Test Badge 2
{'signal': <django.dispatch.dispatcher.Signal object at 0x1096da4d0>}


I want to add a message to the request, to notify or show the user that he earned a badge. Is it possible someone get hold of the request? I can freely modify the original source code from django-badges. Currently it's invoked by post_save() on a model instance. So I doubt I can get the request from there.

I found a solution to add another 3rd party app which is called django-notification, but I don't want to add too many apps to my project. Another solution might be to just set some variable in the database and in my view to query this variable - however that will also cost performance and two database hits.

--
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+unsubscribe@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/5e8f655c-8385-46aa-94ae-2c5baef2034a%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+unsubscribe@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/CALn3ei1Q8cCtBgmsAQV%2BN_o3-5i-%2BrACxMXJXX3Gc%2BQhbtqkQw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Re: Best Practices Django Questions


On 30 Jan 2015 21:03, "G Z" <zukeru@gmail.com> wrote:
>
> Hello, I'm in the design stages of a site that I'm building. It is going to be a basic social media site for a game I'm designing in unity. I'm not entirely sure how to do some of the things I want to in Django. Thus, my first question is generally best practices question as well as a how do I do this question.
>
> Qustion #1: How do I set up my models field so that when a user uploads an image to a filefield it attaches the users name to the file that is being uploaded? Should I do this in the view or in the database?
>

Database. You can adjust the name after validation and just before it is saved to the database so you can just override the save method.

> Question #2: Examine my model design and tell me what I can do better, if I'm missing anything etc. I'm new to django so go easy. I didn't do the def and functions and class stuff just the over all structure. If it would be better if I posted that let me know and I will.
>
> Question#3 How do I make the page when a user logs in resolve to his username, and how do I use the username as the url so when you click on a list of friends it uses that friends username as the url for their profile and resolves to thier page, a quick overview on the best way to do this would be just fine. Just point me and kinda explain the theory and I'm sure I can figure out the rest. 
>
> Please just help me think of things I need to worry about design with django im just starting and I dont have a good base to go on.
>
>
> User
>
> id = models.AutoField(primary_key=True)
>
> username = models.CharField(max_length=4000)
>
> password = models.CharField(max_length=4000)
>
> email = models.CharField(max_length=4000)
>
> phone = models.CharField(max_length=4000)
>
> profile_image = models.FileField()
>
> about = models.CharField(max_length=4000)
>
> hometown = models.CharField(max_length=4000)
>
> job = models.CharField(max_length=4000)
>
> score = models.CharField(max_length=4000)
>
> hobbies = models.CharField(max_length=4000)
>
> datetime = models.DateField()
>
>
> Album
>
> id = models.AutoField(primary_key=True)
>
> userid = models.ForeignKey(User)
>
> name = models.CharField(max_length=4000)
>
> imageid = models.ForeignKey(Image)
>
> datetime = models.DateField()
>
>
> Image
>
> id = models.AutoField(primary_key=True)
>
> userid = models.ForeignKey(User)
>
> image = models.FileField()
>
> imgdesc = models.CharField(max_length=4000)
>
> datetime = models.DateField()
>
> Image_Comment
>
> id = models.AutoField(primary_key=True)
>
> userid = models.ForeignKey(User)
>
> imageid = models.ForeignKey(Image)
>
> comment = models.CharField(max_length=4000)
>
> datetime = models.DateField()
>
>
> Image_Likes
>
> id = models.AutoField(primary_key=True)
>
> imageid = models.ForeignKey(Image)
>
> userid = models.ForeignKey(User)
>
> datetime = models.DateField()
>
>
> Post
>
> id = models.AutoField(primary_key=True)
>
> userid = models.ForeignKey(User)
>
> message = models.CharField(max_length=4000)
>
> image = models.FileField()
>
> embed_link = models.CharField(max_length=4000)
>
> liked_count = models.CharField(max_length=4000)
>
> datetime = models.DateField()
>
>
> Post_Comment
>
> id = models.AutoField(primary_key=True)
>
> userid = models.ForeignKey(User)
>
> postid = models.ForeignKey(Post)
>
> comment = models.CharField(max_length=4000)
>
> datetime = models.DateField()
>
>
> Post_User_Likes
>
> id = models.AutoField(primary_key=True)
>
> postid = models.ForeignKey(Post)
>
> userid = models.ForeignKey(User)
>
> datetime = models.DateField()
>
>
> User_Friends
>
> id = models.AutoField(primary_key=True)
>
> userid = models.ForeignKey(User)
>
> friendid = models.ForeignKey(User)
>
> blocked = models.CharField(max_length=4000)
>
> datetime = models.DateField()
>
>
> Reported
>
> id = models.AutoField(primary_key=True)
>
> userid = models.ForeignKey(User)
>
> friendid = models.ForeignKey(User)
>
> comment = models.CharField(max_length=4000)
>
> datetime = models.DateField()
>
>
> --
> 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+unsubscribe@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/71830c67-c98c-4e38-95f8-235f7c1b9d81%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+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CA%2BWjgXP%2BJe9%2Bpv-N6bskn0UH9MjPyoO-S58_X3hPJbmJ6yF%3DQw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Re: Do Signals block Django process?


On 30 Jan 2015 17:13, "Tobias Dacoir" <falc410@gmail.com> wrote:
>
> I just added django-badges to my project. Basically it can award Badges if Users fullfill certain requirements. For this, everytime I call user.save() django-badges receives the post_save() signal and starts checking.
>
> Now my project is similar to an online quiz, where users submit forms to answer questions. Right now I only have tested it locally and I'm not sure how to simulate multiple users accessing the page at the same time.
>
> When later run on production in combination with a webserver, will Django spawn a new thread for each connection / user? Or will there be only one thread, so if two users are accessing the website, the 2nd has to wait until the request from the first user is processed?
>

Django is single threaded but the web server can create multiple instances of your application.

> Also what about my signal to process the badges. If I have a function that calls user.save(), which then signals to the badges module, will the execution of the original function stop until the signal has been processed or not?
>
> def myView(request):
>    do_something()
>    request.user.save()
>    # signal emitted
>    # ...
>    render(view)
>
> So in this case, will the view be rendered immediately or only after the receiver for the signal has finished doing it's work? In my case I don't really need it to be asynchronous as long as the badge checking is fast enough and doesn't block the website for other users.
>

The view will return after the receiver has finished its work. But are you doing any slow queries? I ask because you might be over engineering your work.

A good place to start is to benchmark your queries using a tool like django-debug-toolbar. With that you can know exactly how long it takes one user to query your database and then use that to estimate for more users.

> --
> 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+unsubscribe@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/f3b2f9dd-4681-48a1-8d49-79f73d45d0eb%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+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CA%2BWjgXPiaV7iFGnFZRiQCNBv_hNypGO%2BewyOxHkLcfOfQ-Vjtw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Re: CSRF verification failed when I use smart phone

Here's an example of the csrf cookie value obtained by typing document.cookie in the javascript console.


--
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+unsubscribe@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/3879ce91-fa33-4e6f-a57b-d51abf6052e7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Re: CSRF verification failed when I use smart phone

What you want to compare is the expected token value and the token value the view received (via POST, PUT, DELETE, etc.). These values need to match. Printing out the token via {{ csrf_token }} in the template will show you the token that the view will receive when the form is submitted. This submitted value needs to match the value in the cookie named csrftoken.


On Friday, January 30, 2015 at 1:59:45 PM UTC-8, Pouria M wrote:
Thanks Zach. 
What are your thoughts after this test? if they match or if they don't match

On Wednesday, January 28, 2015 at 9:46:23 PM UTC-8, Zach Borboa wrote:
For anyone trying to debug this issue, you may want to print out the variable using {{ csrf_token }} as well as using {% csrf_token %} on the form to verify the token is correct.

--
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+unsubscribe@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/e7d8ec73-4fc1-44bf-9424-77edb20d4bb0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Re: using Django on an existing mysql schema


On Fri, Jan 30, 2015 at 10:47 PM, William Muriithi <william.muriithi@gmail.com> wrote:
‎Hello,

I am new to Django and planning to use it for a project I have in mind. I am strong in mysql, but not too good in developing. In fact, the secondary purpose of this project is to improve my python development skills.

With such a background, I went about doing my data modeling and then set up views on top to de normalize the underlying schema and pushing most of the business logic in mysql. I want to use Django mainly to insert and display, which increases the chance of success with few bugs.

Problem is, with Django, it seems things are done the other way around. After playing with it, I noticed it changes the keys from unsigned to signed, something I feal is bad from database point of view. It converted enum to char, which to me is less appealing. In short, I don't like the change its introducing. ‎

My question is, can one use Django with an existing database without getting in trouble with the framework? I believe this has to be possible somehow as most companies work from data backwards. Would appreciate a good advice on how you guys and girls went‎ about using Django from existing schema. Or a Django book that take that perspective. The once I have read advice me to leave database work to orm.

Yes, you can. Django's ORM is there to make your life easier, but there's no requirement that you use it to create your tables, or even to execute queries. There's an inspectdb management command to help build wrapper models for your database; but if you want, you can avoid the ORM entirely, and use raw database cursors to talk directly to the database. 

Of course, if you do this, you're going to miss out on at least some of the power of Django. 

For example, Django has a forms library, which is quite powerful. You can use it without using Django's ORM. However, if you *are* using Django's ORM, you can use ModelForms, which is a way to automatically generate a form for a model.
 
You're also going to miss out on the community of apps that are out there to help you get functionality running easily. For example, if you don't have Django ORM models, then Django's admin interface wont work. A lot of the power of Django is that it has a good "meta" understanding of the data in the database; if you take that away, then the functionality that relies on it obviously wont work.

There's nothing inherently wrong with this - you can code everything yourself if you want and treat Django as little more than a request routing library. The only problems you're going to experience are related to the fact that documentation out there will generally assume that you're using Django models, not rolling your own. My only concern is that this might leave you with an odd perception of the capabilities of Django.

Yours,
Russ Magee %-)


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