Opinion on static files and approaching hardcoding in a Django-like manner

2011-06-03 Thread xiao_haozi
Sorry if this might have been addressed before in a similar manner,
but I was curious as to what some others' thoughts were or what their
practices might be in this situation.

I have some bookmarklets and other javascript files in a /static/
directory. This are then linked in a view so that a user could drag
and drop into their toolbar.

Now, in other scenarios where I might be generating links, I simply
pipe in the domain (if needed) via Sites. However, in a static JS file
I obviously do not use a templating setup and thus cannot pipe in a
domain.

For now, in testing and personal use, I've just hardcoded in my domain
for these types of scenarios. However, what are some options for doing
this when I am pushing this code out for others to use.

[Example: bookmarklet use for a Django URL shortener - 
https://github.com/mutaku/Stumpy
]

Thanks in advance for any comments/suggestions.  I had some ideas in
mind, but thought it might be interesting to see what other people
were doing for these types of situations.

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



Re: django and fastcgi losing some info in request data

2011-04-26 Thread xiao_haozi
FOUND:
http://groups.google.com/group/django-users/msg/76718270ffed9696?pli=1
link for future reference.

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



Re: django and fastcgi losing some info in request data

2011-04-26 Thread xiao_haozi
sorry... was doing some more digging.

Seems the problem is exclusive to // scenarios.
doing somethign like this:
http://mydomain/url/http%3A%21%21wikipedia.com/
gives me the proper :
http:!!wikipedia.com
etc etc

so any clue why it would be exclusively stripping out one / from // ?

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



Re: django and fastcgi losing some info in request data

2011-04-25 Thread xiao_haozi
I could just manually check and add it before working with the model
like:
stump_split = list(this_stump.partition(":"))
if stump_split[1] and not stump_split[2].startswith("//"):
stump_split[2] = "/"+stump_split[2]
this_stump = ''.join(stump_split)

but that's kinda meh and still doesn't get to why it's happening.

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



django and fastcgi losing some info in request data

2011-04-25 Thread xiao_haozi
Hi all-

I have a problem that is driving me to the brink of insanity.

I'll preface this with the fact that running the built-in server
everything works fine. I encounter this issue running it via fastcgi
and lighttpd.
I will paste in all relevant info at the bottom.

In short, the workflow scheme is like this:

-take a url and encode it say like this: http%3A%2F%2Fgoogle.com/
-send it to django via url/http%3A%2F%2Fgoogle.com/
-urls.py reads in that and sends anything after url/ to a view
-this view handles the url and does some things with it for the
database model

running with the built-in server i can return and httpresponse with my
request data and get the proper:
http://google.com
but running with fastcgi i get:
http:/google.com

this breaks lots of code for me.

I can't figure out what is going on that it's getting stripped of one
of the / (or %2F).

Here is all the relevant information I could think of.

=
=> the attempted url:
http://__myDOMAIN/url/http%3A%2F%2Fgoogle.com/

=
=> expect (and receive when running built-in)
http://google.com

=
=> get when running via fastcgi
http:/google.com

=
=> urls.py part:
url(r'^url/(?P\S+)/$', 'shortener.views.submit'),

=
=> lighttpd accesslog info:
"GET /url/http%3A%2F%2F%2Fgoogle.com/ HTTP/1.1" 200 120 "-"

=
=> view part:
def submit(request,stump):
stump_clean = bleach.clean(stump)
this_stump = smart_str(stump_clean)
return HttpResponse("%s %s %s " % (stump,stump_clean,this_stump))

=
=> view httpresponse:
 http:/google.com http:/google.com http:/google.com

=
=> lighty stanza:
$HTTP["host"] =~ "__myDOMAIN__" {
  server.document-root = "/home/blahblah/Stumpy/"
  fastcgi.server = ( ".fcgi" =>
 ( "localhost" => (
 "socket" => "/var/lib/lighttpd/stumpy-fastcgi.socket",
 "bin-path" => "/home/blahblah/Stumpy/
stumpy.fcgi",
 "check-local" => "disable",
 "min-procs" => 2,
 "max-procs" => 4,
   )
 ),
   )
  alias.url = ( "/static/admin"  => "/home/blahblah/django/contrib/
admin/media/" )
  url.rewrite-once = ( "^(/static/.*)$" => "$1",
   "^/favicon\.ico$" => "/static/favicon.ico",
   "^(/.*)$" => "/stumpy.fcgi$1" )
}

=
=> fcgi script:
#!/usr/bin/env python
import sys, os

sys.path.insert(0, "..")

os.environ['PYTHON_EGG_CACHE'] = "/tmp/"

os.environ['DJANGO_SETTINGS_MODULE'] = "settings"

from django.core.servers.fastcgi import runfastcgi
runfastcgi(["method=threaded", "daemonize=false"])



Again, I don't have any problems if i run via "python manage.py
runserver" and use the built-in.
I only have this stripping problem via the fastcgi method.

Any help would be miraculous. I've been yanking hair out over this for
a while!
Thanks so much in advance for any input!

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



Re: admin interface and urls.py regex issue

2011-04-03 Thread xiao_haozi


On Apr 3, 11:58 pm, Karen Tracey <kmtra...@gmail.com> wrote:
> On Sun, Apr 3, 2011 at 11:35 PM, xiao_haozi <matthew.ma...@gmail.com> wrote:
> > I'm running into some perplexing regex issues in urls.py and getting
> > to my admin section.
> > It worked before but now that I have another view added in, anything
> > beyond the index regex is getting fed into the "url/" section rather
> > than admin:
>
> > I've included my urls.py section and the 500 error.
>
> > from django.conf.urls.defaults import patterns, include, url
>
> > # Uncomment the next two lines to enable the admin:
> > from django.contrib import admin
> > admin.autodiscover()
>
> > urlpatterns = patterns('',
> >    # Examples:
> >    # url(r'^
> > , 'Stumpy.views.home', name='home'),
> >    # url(r'^Stumpy/', include('Stumpy.foo.urls')),
>
> >    # show the index from /
> >    url(r'^, 'shortener.views.index'),
> >    # get a url for redirection /shorty
> >    url(r'^(?P\w+)/, 'shortener.views.detail'),
> >    # send a url to be shortened from /url/someencodedurl
> >    url(r'^url/(?P\S+)/, 'shortener.views.submit'),
>
> >    # Uncomment the admin/doc line below to enable admin
> > documentation:
> >    url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
> >    # Uncomment the next line to enable the admin:
> >    url(r'^admin/', include(admin.site.urls)),
> > )
>
> > judging by the 500 error it seems to be sending it to the submit view
>
> No, the traceback below shows that the code is in the detail view.
>
>
>
> > Environment:
>
> > Request Method: GET
> > Request URL:http://192.168.11.4:8001/admin/
>
> > [snip]
> > Traceback:
> > File "/home/mugen/programming/django/django/core/handlers/base.py" in
> > get_response
> > 111. response = callback(request, callback_args, **callback_kwargs)
> > File "/home/mugen/programming/Stumpy/shortener/views.py" in detail
> > 11. thisurl = url.objects.get(shorturl=short) File "/home/mugen/
>
> line 111 in views.py i(n detail).
>
> Your urlpattern for this view is:
>
>    url(r'^(?P\w+)/, 'shortener.views.detail'),
>
> url patterns are scanned in order, and the first one that matches is used.
> /admin/ matches that regex.so detail is called.
>
> Either move the entry for admin above this one (in which case you can never
> have a short value of "admin"), leave it where it is and give it a different
> prefix than /admin/ -- one that will not match this detail pattern, or
> change this detail pattern so that /admin/ does not match it.
>
> (You should also fix your detail view so it does not generate a server error
> when called with a short value that does not exist...a 404 would be a more
> typical response to that situation.)
>
> Karen
> --http://tracey.org/kmt/

Another save.
Thanks again.

I should probably give it a rest for tonight at this rate.

I moved admin above and that now works as you suggested.
I will keep it like this for now and then work on creating a better
 regex (even though admin will never be used in this context).

As for the error return. That is next on my list. This is all just
coming together now and so errors are not being caught gracefully yet,
but rather spitting back a 500 error so I can see what's what. I'll
have this spit back a 404 next.

Thanks again for all your help. Much appreciated!

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



Re: unicode and database oddity

2011-04-03 Thread xiao_haozi
Yeesh.
Good call.

Talk about embarrassed. I totally missed that.
Thanks for the editing eye!


On Apr 3, 11:46 pm, Karen Tracey <kmtra...@gmail.com> wrote:
> On Sun, Apr 3, 2011 at 11:33 PM, xiao_haozi <matthew.ma...@gmail.com> wrote:
> > from shortener.models import url
> > url = u'http://t04u.be/'
>
> In the 1st line you are importing a model (?) named url.
>
> In the 2nd you are discarding that url you just imported and rebinding the
> name url to a unicode string. You no longer have any reference to what you
> imported from shortener.models.
>
> Any attempt to use the name url as though it were the thing you imported is
> now going to give odd results (like the TypeError you reported).
>
> Don't name your variables the same as your models/classes. If you followed
> the CapWords convention for Python class names (and lowercase convention for
> variables) this would be less likely to happen.
>
> Karen
> --http://tracey.org/kmt/

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



unicode and database oddity --updated

2011-04-03 Thread xiao_haozi
Hi, sorry for the long message to follow, but I have an odd issue
with
inserting a value into my database (MySQL).
In short, I am grabbing in a url as a variable fed in via urls.py and
am getting that value as a unicode.
Even if I convert this with smart_str and it's type is then string, I
still raise a unicode error when trying to input this into my
database.
I have attached some error output from the 500 error being raised, as
well as some code from a shell session that I think more clearly
shows
my issue.
Any assistance would be greatly appreciated. Thanks in advance!
Environment:
Request Method: GET
Request URL:
http://192.168.11.4:8001/url/http://forecast.weather.gov/MapClick.php...
Django Version: 1.3 SVN-16009
Python Version: 2.6.5
Installed Applications:
['django.contrib.auth', 'django.contrib.contenttypes',
'django.contrib.sessions', 'django.contrib.sites',
'django.contrib.messages', 'django.contrib.staticfiles',
'django.contrib.admin', 'django.contrib.admindocs', 'shortener']
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 "/home/mugen/programming/django/django/core/handlers/base.py" in
get_response
111. response = callback(request, *callback_args, **callback_kwargs)
File "/home/mugen/programming/Stumpy/shortener/views.py" in submit
19. thisurl = url(longurl=theurl)
Exception Type: TypeError at /url/http://forecast.weather.gov/
MapClick.php?
CityName=Philadelphia=PA=PHI=39.9525=-75.1657/
Exception Value: 'unicode' object is not callable
from shortener.models import url
url = u'http://google.com/'
type(url)
b = url(longurl=url)
Traceback (most recent call last):
File "", line 1, in
TypeError: 'unicode' object is not callable
from django.utils.encoding import smart_str
b = url(longurl=smart_str(url))
Traceback (most recent call last):
File "", line 1, in
TypeError: 'unicode' object is not callable
smart_str(url)
'http://google.com/'
type(smart_str(url))
a = smart_str(url)
type(a)
b = url(longurl=a)
Traceback (most recent call last):
File "", line 1, in
TypeError: 'unicode' object is not callable

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



admin interface and urls.py regex issue

2011-04-03 Thread xiao_haozi
I'm running into some perplexing regex issues in urls.py and getting
to my admin section.
It worked before but now that I have another view added in, anything
beyond the index regex is getting fed into the "url/" section rather
than admin:

I've included my urls.py section and the 500 error.

from django.conf.urls.defaults import patterns, include, url

# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()

urlpatterns = patterns('',
# Examples:
# url(r'^$', 'Stumpy.views.home', name='home'),
# url(r'^Stumpy/', include('Stumpy.foo.urls')),

# show the index from /
url(r'^$', 'shortener.views.index'),
# get a url for redirection /shorty
url(r'^(?P\w+)/$', 'shortener.views.detail'),
# send a url to be shortened from /url/someencodedurl
url(r'^url/(?P\S+)/$', 'shortener.views.submit'),

# Uncomment the admin/doc line below to enable admin
documentation:
url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
# Uncomment the next line to enable the admin:
url(r'^admin/', include(admin.site.urls)),
)


judging by the 500 error it seems to be sending it to the submit view

Environment:

Request Method: GET
Request URL: http://192.168.11.4:8001/admin/

Django Version: 1.3 SVN-16009
Python Version: 2.6.5
Installed Applications:
['django.contrib.auth', 'django.contrib.contenttypes',
'django.contrib.sessions', 'django.contrib.sites',
'django.contrib.messages', 'django.contrib.staticfiles',
'django.contrib.admin', 'django.contrib.admindocs', 'shortener']
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 "/home/mugen/programming/django/django/core/handlers/base.py" in
get_response
111. response = callback(request, callback_args, **callback_kwargs)
File "/home/mugen/programming/Stumpy/shortener/views.py" in detail
11. thisurl = url.objects.get(shorturl=short) File "/home/mugen/
programming/django/django/db/models/manager.py" in get
132. return self.get_query_set().get(args, **kwargs) File "/home/mugen/
programming/django/django/db/models/query.py" in get
349. % self.model._meta.object_name)

Exception Type: DoesNotExist at /admin/
Exception Value: url matching query does not exist.

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



unicode and database oddity

2011-04-03 Thread xiao_haozi
Hi, sorry for the long message to follow, but I have an odd issue with
inserting a value into my database (MySQL).
In short, I am grabbing in a url as a variable fed in via urls.py and
am getting that value as a unicode.
Even if I convert this with smart_str and it's type is then string, I
still raise a unicode error when trying to input this into my
database.

I have attached some error output from the 500 error being raised, as
well as some code from a shell session that I think more clearly shows
my issue.

Any assistance would be greatly appreciated. Thanks in advance!

Environment:

Request Method: GET
Request URL:
http://192.168.11.4:8001/url/http://forecast.weather.gov/MapClick.php?CityName=Philadelphia=PA=PHI=39.9525=-75.1657/

Django Version: 1.3 SVN-16009
Python Version: 2.6.5
Installed Applications:
['django.contrib.auth', 'django.contrib.contenttypes',
'django.contrib.sessions', 'django.contrib.sites',
'django.contrib.messages', 'django.contrib.staticfiles',
'django.contrib.admin', 'django.contrib.admindocs', 'shortener']
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 "/home/mugen/programming/django/django/core/handlers/base.py" in
get_response
111. response = callback(request, *callback_args, **callback_kwargs)
File "/home/mugen/programming/Stumpy/shortener/views.py" in submit
19. thisurl = url(longurl=theurl)

Exception Type: TypeError at /url/http://forecast.weather.gov/
MapClick.php?
CityName=Philadelphia=PA=PHI=39.9525=-75.1657/
Exception Value: 'unicode' object is not callable

from shortener.models import url
url = u'http://t04u.be/'
type(url)

b = url(longurl=url)
Traceback (most recent call last):
File "", line 1, in
TypeError: 'unicode' object is not callable
from django.utils.encoding import smart_str
b = url(longurl=smart_str(url))
Traceback (most recent call last):
File "", line 1, in
TypeError: 'unicode' object is not callable
smart_str(url)
'http://t04u.be/'
type(smart_str(url))

a = smart_str(url)
type(a)

b = url(longurl=a)
Traceback (most recent call last):
File "", line 1, in
TypeError: 'unicode' object is not callable

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