Re: Error message on 'django.urls.exceptions.NoReverseMatch'

2017-07-30 Thread James Schneider
On Jul 30, 2017 12:06 AM, "ron_w_add via Django users" <
django-users@googlegroups.com> wrote:

I have started writing a page to to display a photo. This page correctly
display the photo data (nb. no photo added yet) as well as the ‘Invalid
item ID’ message if an invalid value has been requested. The HTML code is
in ‘photos.html’ is as follows:




I am now trying to start testing the above function by using the following
test function in tests_views.py:


class PhotosByLocationIndexViewTests(TestCase):

 """

 testing 'def photo(requeset)'

 """

 def test_for_no_photos_in_photos(self):

   # 'photourl' is in 'wlp_app/urls.py'

   response = self.client.get(reverse('photourl'))




The above line is your issue. See below.


The ‘photourl’ name that is called by the ‘reverse’ function above is in
the urls.py:


urlpatterns = [

 url(r'^$', views.index, name='indexurl'),

 url(r'^photo/(?P[0-9]+)/$', views.photo, name='photourl')

]


Per the urls.py above, you need to provide a value for the photo_id to
reverse() as an arg or kwarg, otherwise Django has no way to know which
photo you are referring to, and therefore can't generate the URL.

See the following for proper usage of reverse() with examples.

https://docs.djangoproject.com/en/1.11/ref/urlresolvers/#reverse

-James

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


Re: Django form needs pagination and saved data - how????

2017-07-30 Thread James Schneider
On Jul 28, 2017 5:56 PM, "Jim Illback"  wrote:

I use the latest versions of Django, python, bootstrap3, and crispy forms
for this project.

I am trying to present a list of flashcards to a user, sorted by category
(e.g., Math, Vocabulary, etc.). Then, I want the user to check either the
full category or individual flashcards to be added to their practice
account.

To maintain user inputted checkboxes on multiple pages, I must use POST.
But, pagination only uses GET. So, a hack on pagination is to wrap the
Next/Previous buttons in a sub-form and POST using the buttons. This works
for pagination, but then my normal “I’m done, submit this session and
process the updates” button - my submit button - does nothing: no GET, no
POST, nothing.

*How can I enable pagination, multiple screen data accumulation across
pages, and final submission of the session when complete? *


I can't speak to your submit button issue, other than either a piece of
JavaScript is getting in the way, or the button is located outside of a
 tag.

As for the rest of your troubles, it really sounds like you need a form
wizard framework, which is what I think you mean by "pagination". Django
used to ship one as part of the contrib package, but has since moved it out
to it's own separately maintained app.

https://django-formtools.readthedocs.io/en/latest/wizard.html

It handles keeping data state across multiple form submissions, along with
dynamic form additions/omissions based on previous steps.

Another option you may consider is developing this process like a
single-page-application, where all of the data and forms are managed via
JS, and the final collection of data is submitted as a single blob to the
server for permanent storage. That's obviously over simplified, but I hope
you catch my meaning.

-James

-- 
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%2Be%2BciVCh5oEr3rHLEUB4L%3Dpus_bL8H%2BxpmCev5syjes_XOBDg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


failed of installing MySLQ

2017-07-30 Thread ahagbes89
I have not much experiences in Python. I have installed Django  but the 
installation of the data base (MySQL) fails
It is displayed that windows visual c++ is required. I don't know how to do.
Thank

-- 
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/0e53b86b-9a3a-4c76-82b9-6410472c00e8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


GeoDjango distance lookup on Subquery: AttributeError: 'tuple' object has no attribute 'extend'

2017-07-30 Thread Oliver Eidel
Good evening,

I'm having a problem doing a distance lookup on a Subquery. I always get an 
AttributeError (see above).

Put simply, I have a table of Locations where a User may have many 
Locations (one-to-many). Now, I want to look up which users were close to a 
Point at a specific time, i.e., get the newest Location which is equal or 
older than my lookup time T for each user and do a distance query to only 
include users close by. I chose to do this with a Subquery, but correct me 
if my approach is not optimal.

This error is triggered in django/contrib/gis/db/models/lookups.py", line 
143.
Interestingly, sql_params is a Tuple in this case, which of course doesn't 
allow .extend() to be called. However, I am not proficient enough to fully 
understand the stacktrace, especially at which point sql_params suddenly 
becomes a Tuple instead of a List, which it should be.

Full stacktrace at the bottom of this post.

Simplified reproduction:

models.py
from django.contrib.auth.models import User
from django.contrib.gis.db import models

class Location(models.Model):
user = models.ForeignKey(User, on_delete=models.CASCADE,
 related_name='locations')
location = models.PointField()
created_at = models.DateTimeField(auto_now=True)




views.py or in shell
from datetime import timedelta
from django.contrib.auth.models import User
from django.contrib.gis.geos import Point
from django.contrib.gis.measure import D
from django.db.models import OuterRef, Subquery
from django.utils import timezone

from .models import Location

some_time = timezone.now() - timedelta(days=1)
some_location = Point(49.1, 110.2)
radius = D(m=1000)

# get the a location for each user which is less than or equal
# to our lookup time some_time
locations = Location.objects \
.filter(user=OuterRef('pk'),
created_at__lte=some_time) \
.order_by('-created_at')

# select the users which were close by at our lookup time some_time
# this yields the attribute error.
users = User.objects \
.annotate(location_at_time=Subquery(
 locations.values('location')[:1])
 ) \
.filter(location_at_time__distance_lte=(some_location, radius))

# interestingly, this similar query without a subquery works
users = User.objects \
.filter(location__location__distance_lte=(some_location, radius
))


when running pdb in django/contrib/gis/db/models/lookups.py in 
GISLookup.as_sql(),  the values of some variables are these:

(Pdb) sql_params
(datetime.datetime(2017, 7, 30, 22, 5, 44, 866379, tzinfo=),)   # <-- 
Tuple!
(Pdb) lhs_sql
'(SELECT U0."location" FROM "api_location" U0 WHERE (U0."user_id" = 
(V0."id") AND U0."created_at" <= %s) ORDER BY U0."created_at" DESC LIMIT 1)'
(Pdb) rhs_sql
'%s'
(Pdb) rhs_params
[, 1000.0]

the next command sql_params.extend(rhs_params) then fails, obviously.

So I suppose there's something fishy going on due to the Subquery.

Would love some help, as I'm pretty much just starting out with Django (and 
Python) and my source code reading skills are very limited.

Thanks! :)


Full stacktrace:

Traceback (most recent call last):
  File "myproject/philter/tests/test_api.py", line 284, in test_play
response = self.create_game(self.users[0])
  File "myproject/philter/tests/test_api.py", line 248, in create_game
response = self.game_view(request)
  File 
"myproject/venv/lib/python3.6/site-packages/django/views/decorators/csrf.py", 
line 58, in wrapped_view
return view_func(*args, **kwargs)
  File 
"myproject/venv/lib/python3.6/site-packages/django/views/generic/base.py", 
line 68, in view
return self.dispatch(request, *args, **kwargs)
  File 
"myproject/venv/lib/python3.6/site-packages/rest_framework/views.py", line 
489, in dispatch
response = self.handle_exception(exc)
  File 
"myproject/venv/lib/python3.6/site-packages/rest_framework/views.py", line 
449, in handle_exception
self.raise_uncaught_exception(exc)
  File 
"myproject/venv/lib/python3.6/site-packages/rest_framework/views.py", line 
486, in dispatch
response = handler(request, *args, **kwargs)
  File "myproject/philter/api/views.py", line 149, in post
possible_question_count = questions.count()
  File 
"myproject/venv/lib/python3.6/site-packages/django/db/models/query.py", 
line 364, in count
return self.query.get_count(using=self.db)
  File 
"myproject/venv/lib/python3.6/site-packages/django/db/models/sql/query.py", 
line 499, in get_count
number = obj.get_aggregation(using, ['__count'])['__count']
  File 
"myproject/venv/lib/python3.6/site-packages/django/db/models/sql/query.py", 
line 463, in get_aggregation
outer_query.add_subquery(inner_query, using)
  File 
"myproject/venv/lib/python3.6/site-packages/django/db/models/sql/subqueries.py",
 
line 209, in add_subquery
self.subquery, self.sub_params = 
query.get_compiler(using).as_sql(wi

Re: Django form needs pagination and saved data - how????

2017-07-30 Thread Jim Illback
Thanks for your reply, James. Appreciate it. BTW, if you check my template, the 
button is within the form tags, but you probably are right on the JS - I don’t 
know JS much at all so just copied other people’s code.

I may be mistaken, but I think the wizard link below requires a “static” or 
semi-static forms flow path (form1, form2, …, formlast). Generally, when you do 
pagination, there is no preset number of pages - it depends upon the data being 
requested or available. So, I think that option would not work. But, if I’m 
wrong, I’d love to know. Thanks.

And, as for using Java just so you can use Django, doesn’t that raise the 
obvious question - so why use Django?

To try to illustrate that my issue is a common business issue, here’s a 
scenario that is exactly the same situation and one used by almost everyone:

A new car purchase site needs the user to pick the car and model. Then, that 
data stays static throughout the transaction. However, the user might want 
different options (tires, engines, transmission types, etc.). And, those 
options are always too many for one page, so they must be done using 
pagination. When all the options are reviewed - or maybe just one page of 
options or two or… - then the final idea is to show the user the car’s price, 
have all the selections chosen listed out for the user to review, and ask for 
further actions like "do you want to purchase this car?”.

Are these types of business scenarios just not in Django’s wheelhouse?


On Jul 30, 2017, at 4:51 AM, James Schneider 
mailto:jrschneide...@gmail.com>> wrote:



On Jul 28, 2017 5:56 PM, "Jim Illback" 
mailto:subaru...@hotmail.com>> wrote:
I use the latest versions of Django, python, bootstrap3, and crispy forms for 
this project.

I am trying to present a list of flashcards to a user, sorted by category 
(e.g., Math, Vocabulary, etc.). Then, I want the user to check either the full 
category or individual flashcards to be added to their practice account.

To maintain user inputted checkboxes on multiple pages, I must use POST. But, 
pagination only uses GET. So, a hack on pagination is to wrap the Next/Previous 
buttons in a sub-form and POST using the buttons. This works for pagination, 
but then my normal “I’m done, submit this session and process the updates” 
button - my submit button - does nothing: no GET, no POST, nothing.

How can I enable pagination, multiple screen data accumulation across pages, 
and final submission of the session when complete?

I can't speak to your submit button issue, other than either a piece of 
JavaScript is getting in the way, or the button is located outside of a  
tag.

As for the rest of your troubles, it really sounds like you need a form wizard 
framework, which is what I think you mean by "pagination". Django used to ship 
one as part of the contrib package, but has since moved it out to it's own 
separately maintained app.

https://django-formtools.readthedocs.io/en/latest/wizard.html

It handles keeping data state across multiple form submissions, along with 
dynamic form additions/omissions based on previous steps.

Another option you may consider is developing this process like a 
single-page-application, where all of the data and forms are managed via JS, 
and the final collection of data is submitted as a single blob to the server 
for permanent storage. That's obviously over simplified, but I hope you catch 
my meaning.

-James

--
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%2Be%2BciVCh5oEr3rHLEUB4L%3Dpus_bL8H%2BxpmCev5syjes_XOBDg%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+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/46BD3ACD-5040-4ABE-9AA0-8BA201E1BDF5%40hotmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django form needs pagination and saved data - how????

2017-07-30 Thread James Schneider
On Jul 30, 2017 4:50 PM, "Jim Illback"  wrote:

Thanks for your reply, James. Appreciate it. BTW, if you check my template,
the button is within the form tags, but you probably are right on the JS -
I don’t know JS much at all so just copied other people’s code.


I thought that's how you're supposed to program in JS? Been doing it that
way for years. ;-)


I may be mistaken, but I think the wizard link below requires a “static” or
semi-static forms flow path (form1, form2, …, formlast). Generally, when
you do pagination, there is no preset number of pages - it depends upon the
data being requested or available. So, I think that option would not work.
But, if I’m wrong, I’d love to know. Thanks.


By default, yes, it is expecting a known number of steps for more simple
processes. However, it has all of the hooks necessary to create a fully
dynamic flow. I did a dynamic flow back when this package was still in
Django core, but I doubt the process has changed much.


And, as for using Java just so you can use Django, doesn’t that raise the
obvious question - so why use Django?


I'm not sure what you're referring to here. I don't think that I mentioned
Java specifically, nor would I have reason to.

Perhaps a mistaken interpretation of my reference to an SPA? This is what I
meant:

https://en.m.wikipedia.org/wiki/Single-page_application


To try to illustrate that my issue is a common business issue, here’s a
scenario that is exactly the same situation and one used by almost everyone:

A new car purchase site needs the user to pick the car and model. Then,
that data stays static throughout the transaction. However, the user might
want different options (tires, engines, transmission types, etc.). And,
those options are always too many for one page, so they must be done using
pagination. When all the options are reviewed - or maybe just one page of
options or two or… - then the final idea is to show the user the car’s
price, have all the selections chosen listed out for the user to review,
and ask for further actions like "do you want to purchase this car?”.

Are these types of business scenarios just not in Django’s wheelhouse?


The level of dynamic content generation required for all of those steps
will likely be complex, possibly even complicated, for any generic
framework to handle. The Django formtools can handle the scenario you've
listed, but your code organization and naming standard will need to be
strongly enforced to keep the various steps separate.

The workflow you've mentioned isn't necessarily complicated at a high
level, the step decisions are rather binary. Either a person wants to
select different tires, or doesn't and accepts the default selection. The
code in formtools for step selection is usually that simple "if they wanted
different tires in a previous step, now show them this form for tires",
almost a one-liner (for each step).

Honestly, the biggest issue will be displaying the multiple pages of
options, which is somewhat a separate issue.

There are several strategies. You can display multiple form pages across
multiple requests, keeping the results of each along the way, which
complicates your back end code. Before the influx of JS and HTML5, this was
rather common.

The newer approach is to use JS to pull all of the possible options, and
handle the UI and pagination within JS, perhaps in a pop up modal window.
The data is retrieved via an API call, and once a selection is made by the
user, either a form is executed containing all of the possible options that
the user selected.

Datatables.js might be a good option for this, as it can also handle the
dynamic pagination of options surprisingly well, and plays excellent with
Bootstrap. Heck, you can probably use DT with either strategy. It would
definitely ease the logic for the server based form wizard, and likely save
you a ton of JS scripting for an SPA-like display.

If it were me, I'd investigate Datatables.js with the Bootstrap integration
and pagination. It's relatively easy to implement (I, like yourself, am
averse to JS), and provides killer functionality with minimal custom JS
(mostly single minimal function calls to control ordering of table
columns). Once you have that working, try integrating the table with a form
combined with pagination, I think that will be the silver bullet you're
looking for.

https://datatables.net

-James

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