Re: Problem updating data

2011-08-25 Thread Karen McNeil
Thank you Malcolm, you were exactly right!

I would have never thought of that, but I have a custom save method
and when I commented it out and restarted the app, setting the active
property worked just as expected.  Now I just have to figure out what
the hell is wrong with my save method... :-)

Thank you!

~Karen


On Aug 24, 8:31 pm, Malcolm Box <malcolm@gmail.com> wrote:
> Instead of counting the inactive, try counting the active ones. If that
> count doesn't go up by one, I'd suspect something's dodgy in your Entry
> model's save() that means it doesn't write successfully to the db.
>
> You could debug by doing:
>
> from django.db import connection
> connection.queries
> e1.save()
> connection.queries
>
> to see what the SQL generated was.
>
> Then start looking at your database to see what it's doing.
>
> Malcolm
>
> On 23 August 2011 23:08, Karen McNeil <karenlmcn...@gmail.com> wrote:
>
>
>
>
>
>
>
>
>
> > No, that's not the problem. Even if I redo the query now, I still get
> > the same count (see below). And, like I said, the change does not show
> > up in the admin either -- THE VALUE HAS NOT BEEN CHANGED.
>
> > This behavior is so unexpected I'm not sure how to even begin trouble-
> > shooting it.
>
> > ~Karen
>
> > PS -- What's wrong with querying by "active=0"? I did it that way
> > because that's what the admin interface does for filters... is there
> > any difference?
>
> > NEW SHELL SESSION FROM TODAY, TESTING SAME THING:
>
> > >>> from dictionary.models import Entry
> > >>> entries = Entry.objects.filter(active=False)
> > >>> entries.count()
> > 3642
> > >>> e1 = entries[0]
> > >>> e1
> > 
> > >>> e1.active
> > False
>
> > --
> > 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.
>
> --
> Malcolm Box
> malcolm@gmail.com

-- 
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: Problem updating data

2011-08-23 Thread Karen McNeil
No, that's not the problem. Even if I redo the query now, I still get
the same count (see below). And, like I said, the change does not show
up in the admin either -- THE VALUE HAS NOT BEEN CHANGED.

This behavior is so unexpected I'm not sure how to even begin trouble-
shooting it.

~Karen

PS -- What's wrong with querying by "active=0"? I did it that way
because that's what the admin interface does for filters... is there
any difference?


NEW SHELL SESSION FROM TODAY, TESTING SAME THING:

>>> from dictionary.models import Entry
>>> entries = Entry.objects.filter(active=False)
>>> entries.count()
3642
>>> e1 = entries[0]
>>> e1

>>> e1.active
False

-- 
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.



Problem updating data

2011-08-22 Thread Karen McNeil
I have a model "Entry" with an "active" field, which is just a
boolean.  All of the current entries were false, and I was trying to
set them all as true, and I'm running into a strange problem.  Here's
an example, trying to set just one entry to inactive:

>>> from dictionary.models import Entry
>>> entries = Entry.objects.filter(active=0)
>>> entries.count()
3642
>>> e1 = entries[0]
>>> e1

>>> e1.active
False
>>> e1.active=True
>>> e1.save()
>>> e1.active
True
>>> Entry.objects.filter(active=0).count()
3642


Even though, when I checked e1.active, it showed it as being "True",
you can tell from the final count of inactive items that it hadn't
actually changed.  I see the same thing when I go into the admin
change page for that item -- "Active" is not checked.

What is going on here?

~Karen

-- 
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: Using request.GET and having issues

2011-04-16 Thread Karen McNeil
Yep, the encoding was the problem.  I just added a line
searchterm = searchterm.encode('utf-8')

and now it works!

Thank you!



On Apr 16, 9:19 am, Karen Tracey <kmtra...@gmail.com> wrote:
> 2011/4/16 Karen McNeil <karenlmcn...@gmail.com>
>
>
>
> > I have the following view set up:
>
> > def concord(request):
> >    searchterm = request.GET['q']
> >    ... more stuff ...
> >    return render_to_response('concord.html', locals())
>
> > With URL "http://mysite.com/concord/?q=برشه;, and template code
> >     Your search for {{ searchterm }} returned {{ results }}
> > results in {{ texts.count }} texts.
> > I get this result on the page:
> >    Your search for برشه returned 0 results in 8 texts.
>
> > The search term (برشه) is being passed successfully, but there should
> > be 13 results, not zero.  When I hard-code "searchterm = 'برشه' " into
> > the concord view, instead of "searchterm = request.GET['q']", the page
> > displays perfectly.
>
> With this line of code:
>
> "searchterm = 'برشه' "
>
> searchterm will be a bytestring, utf-8 encoded if that is the encoding of
> your file.
>
> With this:
>
> searchterm = request.GET['q']"
>
> it will be unicode. Django returns unicode from the DB and request
> dictionaries.
>
> I notice you are explicitly encoding to utf-8 the texts you are searching
> before passing them into the nltk code. However you never do this for the
> searchterm, and I'd guess that is why the difference in results when you
> hard code it vs. pulling it from request.GET.
>
> Can't you pass unicode to the nltk code? If you can, I'd get rid of the
> explicit encoding to utf-8 of the DB content you are searching. If you
> really must pass it bytestrings instead of of unicode, then explicitly
> encoding the search term to to utf-8 as well will probably fix the problem.
>
> 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.



Re: Using request.GET and having issues

2011-04-16 Thread Karen McNeil
No, that's not the issue. In addition to displaying the count, the
page also shows the resulting sentences, and the count here is correct
because no results were returned.

I think Karen, below, might be right that it has something to do with
the encoding of the search string... I'll try working that angle and
see if I get anywhere with it.

Thank you all for your help...


On Apr 16, 5:41 am, Shawn Milochik  wrote:
> This doesn't appear to be a Django question. Your 'results' variable
> is being populated by checking the length of an
> nltk.text.ConcordanceIndex() instance. I'm not familiar with the nltk
> module, but I'm assuming you are at least a little, since you're using
> it. It appears that its length isn't useful in determining the count
> you want.
>
> Shawn

-- 
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.



Using request.GET and having issues

2011-04-15 Thread Karen McNeil
I have the following view set up:

def concord(request):
searchterm = request.GET['q']
... more stuff ...
return render_to_response('concord.html', locals())

With URL "http://mysite.com/concord/?q=برشه;, and template code
 Your search for {{ searchterm }} returned {{ results }}
results in {{ texts.count }} texts.
I get this result on the page:
Your search for برشه returned 0 results in 8 texts.

The search term (برشه) is being passed successfully, but there should
be 13 results, not zero.  When I hard-code "searchterm = 'برشه' " into
the concord view, instead of "searchterm = request.GET['q']", the page
displays perfectly.

The full code for the view is below... What am I missing here?

~Karen


def concord(request):
searchterm = request.GET['q']

#== Retrieving relevant corpus texts from database ===
texts = Text.objects.filter(content__contains=searchterm)
content = ""
for t in texts:
content += t.content + "\n"

#== Encoding ===
content_uni = content.encode('utf-8')
tokens = content_uni.split()


#== Concordancing with NLTK ===
text = nltk.Text(tokens)
ci = nltk.text.ConcordanceIndex(text.tokens)
offsets = ci.offsets(searchterm)
results = len(offsets)
tokens = ci.tokens()

#== Set variables to return to webpage ===
context =  []
for offset in offsets:
before = ' '.join(tokens[offset-10:offset])
word = tokens[offset]
after = ' '.join(tokens[offset+1:offset+10])
context.append([before, word, after])
return render_to_response('concord.html', locals())

-- 
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: Passing variables to the template... I've having logic problems

2011-04-15 Thread Karen McNeil
Yes, that worked.  Thank you!

Of course, now that I fixed that, I have to deal with the other
problem that I was avoiding... But I'll post that in a different
question.  :-)

Thanks again, Pedro.


On Apr 15, 9:35 pm, Pedro Kroger  wrote:
> You can try something like:
>
> def my_view(request):
>       ...
>
>     context = []
>     for offset in offsets:
>         before = ' '.join(tokens[offset-5:offset])
>         word = tokens[offset]
>         after = ' '.join(tokens[offset+1:offset+5])
>         context.append(before, word, after)
>
>     ...  ...
>
>     return render_to_response("template.html", {'context': context})
>
> Now your data will be available inside the 'context' variable and you
> can access the 'context' variable in your template like you want. I
> hope that helps.
>
> Pedro
>
> --http://pedrokroger.net

-- 
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.



Passing variables to the template... I've having logic problems

2011-04-15 Thread Karen McNeil
I'm trying to make a concordance (ie, a list of a certain searchterm,
including its surrounding context) and I can get it to work in the
interpreter, but I'm having problems figuring out how to make it a
list that I can pass it to the template.  This is what works in the
interpreter (tokens is a list of words which can be accessed by an
index number, and offset is the index number corresponding to the
searchterm):

>>> for offset in offsets:
... before = ' '.join(tokens[offset-5:offset])  #Takes the
five preceding words and joins them in a string
... word = tokens[offset] #The
searchterm occurance
... after = ' '.join(tokens[offset+1:offset+5])#The five
words after the searchterm
... print "%s %s %s" % (before, word, after)
...
حنانلافاقتزاهيةتبرلي برشه وسيلة في العادة بكوشة
فيهاشويةمشاكلوطلبةوشوية برشه حاجات يعني وكما تعرف
يلقىحلعلىالخاطرتوا برشه ناس كما نحنا هكه
بالكلّوالبلادقاعدةتخسرفي برشه م الشباب متاعها على
كانطحانغيرهاوينوفمّه برشه ممّن تسّوللهم انفسهم الرخيصه

I know you can't read the Arabic output that's written there, but it's
exactly as it should be. Any way I've tried to get the before, word,
after returned as variables (or lists of variables) so I can pass them
to the template, it doesn't work.

What I want to be able to do is something like this:
{% for before, word, after in context %}
{{ before }} {{ word }} {{ after }}
{% endfor %}

I just can't figure out how to do it... Can anyone point me in the
right direction?

Thanks,
Karne

-- 
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: Looking for IDE + FTP

2011-03-28 Thread Karen McNeil
Just wanted to give you all an update:  I started using Aptana Studio
with the PyDev plug-in and I'm really liking it; I think it was just
what I needed.

Thanks for all the suggestions!

~Karen

-- 
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: Blog Listing on Home Page

2011-02-22 Thread Karen McNeil
This is definitely doable.  And easy -- you can use django's generic
views for it.

I recommend you pick up / download "Practical Django Projects," by
James Bennett.  He'll walk you through every step for creating a blog,
using generic views, etc.

~Karen McNeil


On Feb 21, 4:33 pm, delegb...@dudupay.com wrote:
> Hello People,
>
> I have a blog I'm currently designing and I have a little challenge.
>
> I can from the view get a template to render all the blogs in the database by 
> fetching
> articles = Article.objects.all()
> from the view and then loop over it in my template like so:
> {% for article in articles %}
> article.author
> article.date
> article.content
> {% endfor %}
> This renders all the articles in my blog.
> I however want it to show an article per page.
> How can I achieve that.
> Alternatively, I am thinking I could do a filter of articles on my home page 
> and the do a drill down from years, to months and then days. With title of 
> each article rendered such that a visitor can click on a title and then 
> directed to a page rendering the particular article.
> Is it doable? If yes, kindly give me a lead. And if no, kindly suggest a way 
> out.
> Thanks.
> Sent from my BlackBerry wireless device from MTN

-- 
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: Looking for IDE + FTP

2011-02-08 Thread Karen McNeil
So... that's a no, then?

I mean, about the question I asked.  You know, the "is there an IDE +
FTP program" question?

Although, to assuage everyone's concerns:

-- I do have a development site that I use to test any significant
changes before I put them on the live site. The point that I was
trying to make was that I *like* being about to upload the changes
(which I've already tested on the development site) as I'm going
along, from within the same program that I'm coding in.  Also, in DW
I'm able to have several files all open at once, each in a separate
tab.  And, if I want to look at a different file (either on the local
site or the remote site), the folder tree is right there so I can open
up whatever I want without having to switch programs.
-- The "live" site is pretty much my personal playground, so if I
accidentally break something for a few minutes it doesn't really
matter.
-- I *do* do a very simple kind of version control, where I save a
numbered copy of the major site files whenever I've made changes and
I've got a stable, working site. I've looked into Subversion and Git
and, believe me, they would be way overkill for my little projects.
-- I exercise regularly and eat all my vegetables.
-- I would rather poke my eyes out than use vim.

:-)  Karen

-- 
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: Looking for IDE + FTP

2011-02-08 Thread Karen McNeil
So... that's a no, then?

I mean, about the question I asked.  You know, the "is there an IDE +
FTP program" question?

Although, to assuage everyone's concerns:
- I do have a development site that I use to test any significant
changes before I put them on the live site.
  The point that I was trying to make was that I *like* being
about to upload the changes (which I've already
  tested on the development site) as I'm going along, from within
the same program that I'm coding in.  Also,
  I like having several files all open at once in Dreamweaver,
each in a separate tab.  And, if I want to check
  out a different file, the folder tree is right there so I can
open up whatever I want without having to switch
  programs.
- The "live" site is pretty much my personal playground, so if I
accidentally break something for a few minutes
  it doesn't really matter.
- I *do* do a very simple kind of version control, where I save a
numbered copy of the major site files
  whenever I've made changes and I've got a stable, working site.
I've looked into Subversion and Git and,
  believe me, they would be way overkill for my little projects.
- I exercise regularly and eat all my vegetables.
- I would rather poke my eyes out than use vim.

:-) Karen

-- 
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.



Looking for IDE + FTP

2011-02-08 Thread Karen McNeil
I have three Django sites that I've been working on recently and I've
been doing most of the development work in Dreamweaver.  I don't use
any of the wysiwyg features (or, pretty much, any of the Dreamweaver
program features), but I like it because I can do all the the code
edits and the FTP transfers all in one program.  I like being able to
grab a remote file, make some code changes, save and upload all at
once, and view a nice graphical display of the file structure for the
local and remote sites.

Problem is, Dreamweaver's code view is definitely not built for
Python, and it doesn't look like they have any plans to support it any
time in the foreseeable future.  Which means that I get no color-
coding of the code, and I'm constantly getting indentation errors.

I've always had Dreamweaver on my computer (a Mac) and so have never
used a separate FTP program, and the only IDE I've ever used is IDLE.
I used IDLE when I was first learning Python, but now that I'm working
with the websites, I find it much more convenient to just open the
files from within DW.  Does anyone know of another, Python-friendly,
program that I could use for both code-editing and ftp?

Thanks,
Karen

-- 
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: Storing *big* texts in db fields

2011-02-01 Thread Karen McNeil
Thank you for your responses.

I think you're right that calculating the wordcount could be the
problem. I also have another method that displays the authors, so that
I can see the author(s) in the admin list, even though it's a
ManyToMany relationship. I would imagine that that's part of the
problem too, since it has to make a separate db query for each item it
displays -- can I fix that using post_save as well?

~Karen

On Feb 1, 3:55 am, Mike Ryan <m...@fadedink.co.uk> wrote:
> (I tried to post this once before, but the browser crashed so I am not
> sure if it got posted. Apologies for dupe content if so)
>
> Is it possible the wordcount function is slowing everything down? Does
> it run each time you view the admin page?
> If so, I would try adding it as an attribute to the model and counting
> the words when the model is saved (using the
> post_save signal), instead of counting the words each time the admin
> page is displayed (if that's what you are doing).
>
> On Feb 1, 2:22 am, Karen McNeil <karenlmcn...@gmail.com> wrote:
>
> > I've created an application to manage texts, storing the content in a
> > TextField, along with metadata in other fields. Now that I've
> > completed the model and started actually adding the texts, the admin
> > is getting vey slow. The app is just for the use of me and my
> > team, so the slowness is not a deal-breaker, but it's annoying to work
> > with and I still have a lot of texts to add to the corpus.
>
> > Although I may be adding a large amount of smaller texts in the
> > future, the texts that I have now are large, mostly in the tens of
> > thousands of words, with the largest currently at 101,399 words.
> > (Which I know because I added a method to the model to calculate the
> > wordcount, and have it displayed in the admin list. Which gives me no
> > end of pleasure.)
>
> > So, is it a bad idea to be storing texts this large in a database
> > field? I really hope not, because when I first started this project
> > (granted, before I started using Django), I was reading the data from
> > files and running into constant encoding/decoding problems. (These
> > texts I'm collecting are in Arabic.)
>
> > If it's not a totally horrible idea to do this like I'm doing, is
> > there anything I can do to improve performance?  I tried implementing
> > caching and it didn't make any difference.
>
> > Thanks,
> > Karen

-- 
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.



Storing *big* texts in db fields

2011-01-31 Thread Karen McNeil
I've created an application to manage texts, storing the content in a
TextField, along with metadata in other fields. Now that I've
completed the model and started actually adding the texts, the admin
is getting vey slow. The app is just for the use of me and my
team, so the slowness is not a deal-breaker, but it's annoying to work
with and I still have a lot of texts to add to the corpus.

Although I may be adding a large amount of smaller texts in the
future, the texts that I have now are large, mostly in the tens of
thousands of words, with the largest currently at 101,399 words.
(Which I know because I added a method to the model to calculate the
wordcount, and have it displayed in the admin list. Which gives me no
end of pleasure.)

So, is it a bad idea to be storing texts this large in a database
field? I really hope not, because when I first started this project
(granted, before I started using Django), I was reading the data from
files and running into constant encoding/decoding problems. (These
texts I'm collecting are in Arabic.)

If it's not a totally horrible idea to do this like I'm doing, is
there anything I can do to improve performance?  I tried implementing
caching and it didn't make any difference.

Thanks,
Karen

-- 
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.



Can I store full dates (mmddyyyy) and year-only dates (yyyy) in the same field?

2011-01-25 Thread Karen McNeil
Hello,

I'm designing a model which is a collection of texts.  Some of the
texts will be things like books, with a  date of publication, and
some of them will be articles or transcripts with a mmddyyy date of
publication/broadcast.

I'd like to structure it somehow so that when I view the list of texts
in the admin site, I see something like this:


TitleDate  ...other
fields
--
Sample Book   1984 ...
Sample Blog Post 1/14/2010 ...


Can I (should I?) store these two kinds of dates in one field?  If I
can't (or shouldn't), is there some other way to accomplish this
(that's not too complicated)?

Thanks,
Karen

-- 
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.