Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
politicorific
Sep 15, 2007
just wanted to say thank you for this awesome tutorial. Just a minor nit-pick, the path structure used changes slightly and maybe combine some of the steps to see verifiable change.

I'm sure I will be posting here with all sorts of questions in the following weeks/months

Adbot
ADBOT LOVES YOU

politicorific
Sep 15, 2007
I'm trying to determine if Django is the right tool for my website:

http://politicorific.gotdns.com:8090/
try "work" "sweep"

It conjugates Hebrew verbs. There are 4800 entries, the example and many of the other sites in the examples are geared toward user created content.

Can it be done, should it be done?

politicorific
Sep 15, 2007
Are there any more tutorials on how to write views/urls? Or any really good examples available in the djangosites w/sources?

I've linked up a pre-existing database to my django code. The admin app has incredible power, which demonstrates most everything I want my users to be able to view (search, sort by category). I have about 5,000 records that I want to be able to cross-reference with links inside records. First I'm trying something easier - I want to create a url/view so that https://www.mysite.com/english/x/ where x is a letter a-z returns all entries starting with that letter. Writing 26 different urls sounds stupid, plus I two other similar patterns with another ~250 entries.

why doesn't this work?

views.py
code:
def englishdictionary(request):
    query = request.GET.get('q', '')
    if query:
        qset = (
            Q(english__startswith=englishdictionary)
            )
        results = Entry.objects.filter(qset).distinct()
    else:
        results = []
    return render_to_response("c:/django/words/templates/search.html", {
        "results": results,
        "query": query
    })
urls.py
code:
from django.conf.urls.defaults import *
from words.display.views import englishdictionary

urlpatterns = patterns('',
    (r'^admin/', include('django.contrib.admin.urls')),
    (r'^search/', 'words.display.views.search'),
(r'^english/[A-Za-z]/', englishdictionary))
I can define "englishdictionary" in views.py to be any letter I want, but how do I get django to determine the variable based on the url?

politicorific
Sep 15, 2007
awesome! That worked perfectly

politicorific
Sep 15, 2007
okay two questions and this is more just to show off...
urls.py
code:
(r'^\xD7\xA2\xD7\x91\xD7\xA8\xD7\x99\xD7\xAA',englishdictionary2))
I'm trying to make a unicode/foreignlanguage URL - I have an English dictionary, and this is for a foreign language. If you think you suck at regular expressions - I can't be that much better.
Basically I'd like to do the same thing as before
code:
(r'^tablenumber/(?P<digit>\d+\w)/', tablenumber)
yet, I believe I looked at the documentation, but I can't use a named group - basically another 22 letters to pass to an index


Next question regarding views/models.
__str__ in model constructs the output of the database search into a single string. I need to manipulate this data separately - each piece goes to a different place. I suppose I could use .split() and create another list, but that just doesn't seem elegant enough.

code:
def __str__(self):
                return ("""%s,%s,%s,%s,%s,%s,%s,%s,...

really this goes on forever, there are 49 instances of %s and 49 different variables it's combining. There must be a better way!

politicorific
Sep 15, 2007
okay here I'll be explicit:

Here's the assumption that I want blown apart, that an application of a project can only receive a single output from models.py.

code:
from django.db import models

class Entry(models.Model):
        id = models.IntegerField(primary_key=True)
        uniqnumber = models.CharField(blank=True, maxlength=765)
        combined = models.CharField(blank=True, maxlength=765)
        english = models.CharField(blank=True, maxlength=765)
for a total of ~49 entries
then:
code:
          def __str__(self):
                return ("""%s,%s,%s,%s,%s,%s,%s,%s,
                        %s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s
                        %s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s
                        %s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s""")\
                        % (self.id,self.uniqnumber,self.combined,self.root1,\
                           self.root2,self.root3,self.root4,self.root5,self.root6,\
                           self.participle,self.tablenumber,self.intrans,\
                           self.english,self.sroot1,self.sroot2,self.sroot3,\
                           self.sroot4,self.sroot5,self.sroot6,self.broot1,\
                           self.nroot2,self.tabletype,self.pm1s,self.pf1s,\
                           self.pm1p,self.pf1p,self.hn1s,self.hm2s,self.hf2s,\
                           self.hm3s,self.hf3s,self.hn1p,self.hm2p,self.hm3p,\
                           self.fn1s,self.fm2s,self.ff2s,self.fm3s,self.fn1p,\
                           self.fm2p,self.ff2p,self.fm3p,self.ims,self.ifs,\
                           self.imp,self.ifp,self.inf)
The issue is that I want all those different variables to be separate, not combined.

Can I use a similar admin setup like this for my applications? If so how do I address them in other modules?

code:
class Admin:
                list_display = ('id','english','tablenumber','uniqnumber',\
'combined','root1','root2','root3','root4','root5','root6','participle','intrans',)
                #list_filter = ('english','tablenumber') #2 entries
                ordering = ('id',)
                search_fields = ('english',)
here is the view I'm trying to build:
code:
def formulate(request):
    query = request.GET.get('q', '')
    if query:
        qset = (Q(english__icontains=query))
        results = Entry.objects.filter(qset).distinct()
        resultnumber=len(results)
    return render_to_response("c:/django/words/templates/search.html", {
        "results": results,
        "query": query,
        "resultnumber": resultnumber})
I want to be able to pass individual Models, such as "english", "combined", "uniqnumber", and others onto this view to use in my template

politicorific
Sep 15, 2007
okay I've crawled out of my hole - the tutorial was a bit confusing with the str methods- time to see if I'm doing things correctly. A few posts to make sure I'm on track

First) performing a len on database results - either djangobook or the documentation says not to do this:

code:
results = ConjewgateEntry.objects.filter(qset).distinct()
    resultnumber=0
    if results:
            resultnumber=len(results)
    letter=letter.upper()
    return render_to_response("c:/django/words/templates/english_index.html", {
            "letter":letter,
            "results":results,
            "resultnumber":resultnumber,
    })
this is so that I can display "x results for ..."

Second random result generator:
code:
def randomly(request):
    import random
    digit = random.randint(1,5000)
    results = ConjewgateEntry.objects.filter(id=digit)#.distinct()
    resultnumber=0
    return render_to_response("c:/django/words/templates/select.html", {
            "digit":digit,
            "results":results,
            "resultnumber":resultnumber,
    })
Then I have my urls.py set up for "(r'^random/', randomly),"

Third: Static pages
code:
def english(request):
    return render_to_response("c:/django/words/templates/englishindex.html", {
    })
Is there a better way?

Finally I would like to make sure that my grammar is correct on this site I'm building. So I get something like "0 results" verses "1 result" - models.py has the meta tag.
code:
def tablenumber(request, digit):
    results = ConjewgateEntry.objects.filter(tablenumber=digit)#.distinct()
    resultnumber=0
    verbstatus= "verbs follow"
    if results:
            resultnumber=len(results)
            print resultnumber
            if resultnumber ==1:
                verbstatus = "verb follows"
    return render_to_response("c:/django/words/templates/tablenumber.html", {
            "digit":digit,
            "results":results,
            "resultnumber":resultnumber,
            "verbstatus":verbstatus
    }) 
Something tells me the "verbstatus" belongs in the template file, not in my views file.

one more thing:
code:
(r'^english/(?P<letter>\w)/', english_index),
this only works with numbers above 10, how do I make it work with numbers equal to or greater than 1?

So, does this all look okay?

politicorific
Sep 15, 2007
Thank you Wulfeh - you understood perfectly what I was going for in every instance.
The next step is deploying it to my hosting provider

politicorific
Sep 15, 2007
okay, I admit defeat again.

I'm going to try an abstract explanation of my database search problem.

my database is full of entries like this: a1b2c3d4e5

code:
def search(request):
    query = request.GET.get('q', '')
    qset = (
        Q(english__icontains=query)
        )
my query=abcde

Is it possible to instruct django's database api to be greedy and return (a1b2c3d4e5) from my query(abcde)?

Now let me complicate things - my search query is unicode, my data is unicode. I have 12 unicode characters I want the search to ignore. Is it possible to .split() "query" and use wildcards to make the match? Or should I consider .strip()-ing all 12 characters and maintain another database?

politicorific
Sep 15, 2007
I'm getting "reduce() of empty sequence with no initial value"

also, preferably it'll be doing this across 27 fields from 5000 rows...

what about this from djangobook appendix C:
http://www.djangobook.com/en/1.0/appendixC/

quote:

search

A Boolean full-text search that takes advantage of full-text indexing. This is like contains but is significantly faster due to full-text indexing.

Note this is available only in MySQL and requires direct manipulation of the database to add the full-text index.
Is this relevant? Although I read MySQL only indexes fields with 3 or more characters, my unicode strings should be longer than that(6 at least)

politicorific
Sep 15, 2007
Has anyone taken another look at Google's appengine? The thread is gone, but they've opened up to anyone (I never got a NOTIFY ME email). Their count is 80,000 people signed up.

Faced with the predicament of spending more to upgrade my host to deploy my django app ($10/month for ssh), I decided to start porting my project over to appengine. It's been sort of a pain, a lot of modules use functionality which isn't supported by appengine, but the biggest headache has been this:

Using GQL - google's proprietary database. Upgrading from an existing database is a huge pain in the rear end/or I'm just stupid.

I emailed a guy with some decent tutorials about django and appengine after running into some trouble, he wrote this:
http://thomas.broxrost.com/2008/06/15/porting-legacy-databases-to-google-app-engine/
http://code.google.com/appengine/articles/bulkload.html
So after exporting to a csv file you upload the data to google. One problem: it doesn't natively support unicode in the uploading tool
http://code.google.com/p/googleappengine/issues/detail?id=157

So I'm getting this error:
code:
['Traceback (most recent call last):\n', '  File "C:\\PROGRA~1\\Google\\google_a
ppengine\\google\\appengine\\ext\\bulkload\\__init__.py", line 377, in Load\n
 new_entities = loader.CreateEntity(columns)\n', '  File "C:\\PROGRA~1\\Google\\
google_appengine\\google\\appengine\\ext\\bulkload\\__init__.py", line 228, in C
reateEntity\n    entity[name] = converter(val)\n', "UnicodeEncodeError: 'ascii'
codec can't encode characters in position 0-7: ordinal not in range(128)\n"]
ERROR    2008-06-19 01:48:54,828 bulkload_client.py] Import failed
this is from a single 19 byte entry and it's driving me insane

Adbot
ADBOT LOVES YOU

politicorific
Sep 15, 2007
I'm planning on creating a new google appengine project soon that will create web pages with artwork determined by user input (basically bezier curves showing relationships). The best method I've come up with is to use SVGs since I want them to scale correctly. I would use in-line SVG code in xhtml, but in-line svg isn't fully supported by all browsers (safari seems to put 100pixel margins at the bottom of any inline svg code). So instead I'm planning on using object= and embed= code, however this means I must create the files before sending. If I can't access the file system on app engine, how can I do this?

I'm just doing theory right now, so the short version is, how do I dynamically create files to send to users without doing anything to the file system?

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply