Skip to main content

Home/ interesting_sites/ Group items tagged generic

Rss Feed Group items tagged

pagetribe .

Chapter 11: Generic Views - 0 views

  • from django.conf.urls.defaults import * from django.views.generic import list_detail from mysite.books.models import Publisher publisher_info = { 'queryset': Publisher.objects.all(), 'template_name': 'publisher_list_page.html', } urlpatterns = patterns('', (r'^publishers/$', list_detail.object_list, publisher_info) )
  • That’s really all there is to it. All the cool features of generic views come from changing the “info” dictionary passed to the generic view.
  • You might have noticed that sample publisher list template stores all the books in a variable named object_list.
  • ...10 more annotations...
  • it isn’t all that “friendly” to template authors: they have to “just know” that they’re dealing with books here.
  • better name
  • publisher_list;
  • 'template_object_name': 'publisher',
  • If you want to present a list of books by a particular publisher, you can use the same technique:
  • Another common need is to filter the objects given in a list page by some key in the URL. Earlier we hard-coded the publisher’s name in the URLconf, but what if we wanted to write a view that displayed all the books by some arbitrary publisher?
  • “wrap” the object_list generic view
  • # Look up the publisher (and raise a 404 if it can't be found). publisher = get_object_or_404(Publisher, name__iexact=name)
  • Notice that in the preceding example we passed the current publisher being displayed in the extra_context. This is usually a good idea in wrappers of this nature; it lets the template know which “parent” object is currently being browsed.
  • Or, you could use a less obvious but shorter version that relies on the fact that Book.objects.all is itself a callable:
pagetribe .

Kevin Kelly - 0 views

  •  
    Interesting site about technology in general.
pagetribe .

iiNews May - 0 views

  •  
    Job hunting online with Sandy Lim This month, we cover job hunting online, with a look at pay scales in the current job market; advice on preparing a quality resume; and a neat community forum for small business owners and freelancers. [Paycheck] The Great Australian Pay Check The Great Australian Pay Check susses out pay scales, perks, work-life balance and job satisfaction across the Aussie job market - letting you find out where you fit in without having to ask. Great for planning your next career move. [careerone] Career One Resume Advice Get good recommendations for the Australian style of resume writing, common Gen Y and migrant job search issues, and writing for specific recruitment audiences. When you're done, there's also cover letter & interview advice and a redundancy survival guide. [flying solo] Flying Solo If being your own boss is more your style, check out the Flying Solo community for articles on growing and promoting your business, how to work and & network smarter, and keeping your work-life balance in check. They've also got a discussion forum for specific advice and general banter. Still confused? All you internet first-timers can cut your teeth on our Broadband for Beginners workshops, where we also cover employment & social networking.
cafe software

My Profitable Business Career - 1 views

Managing a cafe is a tedious task because I need to have a close supervision with my business sales and transactions. So I decided to purchase a cafe POS software that will help me have an easier m...

Online system

started by cafe software on 23 Jan 12 no follow-up yet
pagetribe .

A tour of git: the basics - 0 views

shared by pagetribe . on 19 Feb 09 - Cached
  • ~ suffix
  • HEAD~
  • HEAD~2" refers to two commits back
  • ...19 more annotations...
  • refers to the previous commit
  • $ git log HEAD~3..
  • git show 13ed136b
  • git status" tells us that the current branch is "master"
  • It’s a little bit helpful to know that we’ve modified hello.c, but we might prefer to know exactly what changes we’ve made to it.
  • git diff
  • To set your name and email address, just use the following commands:
  • git config --global user.name "Your Name" git config --global user.email "you@example.com"
  • --author option to the “git commit”
  • a blank line, and then one or more paragraphs with supporting detail. Since many tools only print the first line of a commit message by default, it’s important that the first line stands alone.
  • git commit --amend
  • misspelling in it
  • It's worth emphasizing the value of minimal, independent commits. The smaller the changes are the more useful the history will be when actually using the history, not just viewing it.
  • Just run "git pull" everytime you want to pull in new changes that have landed in the upstream repository.
  • Again, you'll see that this precisely matches the final portion of the output from "git pull". Using "git fetch" and "git merge" let us achieve exactly what "git pull" did, but we were able to stop in the middle to examine the situation, (and we could have decided to reject the changes and not merge them---leaving our master branch unchanged).
  • For now, let's return back to the tip of the master branch by just checking it out again: $ git checkout master
  • $ git --bare init --shared The --shared option sets up the necessary group file permissions so that other users in my group will be able to push into this repository as well.
  • Now, generally the purpose of pushing to a repository is to have some "collaboration point" where potentially multiple people might be pushing or pulling.
  • git clone
pagetribe .

http://nltk.googlecode.com/svn/trunk/doc/book/ch01.html - 0 views

  • We can count how often a word occurs in a tex
  • Adding two lists creates a new list
  • count the occurrences of a particular word using text1.count('heaven')
  • ...18 more annotations...
  • By convention, m:n means elements m…n-1
  • A consequence of this last change is that the list only has four elements, and accessing a later value generates an error
  • We can join the words of a list to make a single string, or split a string into a list, as follows:
  • 'Monty Python'.split()
  • frequency distribution
  • frequency of each vocabulary item
  • find the 50 most frequent words
  • hese very long words are often hapaxes (i.e. unique) and perhaps it would be better to find frequently occurring long words.
  • Here are all words from the chat corpus that are longer than 7 characters, that occur more than 7 times:   >>> fdist5 = FreqDist(text5) >>> sorted([w for w in set(text5) if len(w) > 7 and fdist5[w] > 7]) ['#14-19teens', '#talkcity_adults', '((((((((((', '........', 'Question', 'actually', 'anything', 'computer', 'cute.-ass', 'everyone', 'football', 'innocent', 'listening', 'remember', 'seriously', 'something', 'together', 'tomorrow', 'watching'] >>>
  • The collocations() function does this for us
  • find bigrams that occur more often than we would expect based on the frequency of individual words.
  • fdist = FreqDist(samples) create a frequency distribution containing the given samples fdist.inc(sample) increment the count for this sample fdist['monstrous'] count of the number of times a given sample occurred fdist.freq('monstrous') frequency of a given sample fdist.N() total number of samples fdist.keys() the samples sorted in order of decreasing frequency for sample in fdist: iterate over the samples, in order of decreasing frequency fdist.max() sample with the greatest count fdist.tabulate() tabulate the frequency distribution fdist.plot() graphical plot of the frequency distribution fdist.plot(cumulative=True) cumulative plot of the frequency distribution fdist1 < fdist2 test if samples in fdist1 occur less frequently than in fdist2
  • it goes through each word in text1, assigning each one in turn to the variable w and performing the specified operation on the variable.
  • The above notation is called a "list comprehension"
  • [f(w) for ...] or [w.f() for ...],
  • Now that we are not double-counting words like This and this
  • by filtering out any non-alphabetic items:   >>> len(set([word.lower() for word in text1 if word.isalpha()]))
  • A collocation is a sequence of words which occur together unusually often. Thus red wine is a collocation, while the wine is not. A characteristic of collocations is that they are resistant to substitution with words that have similar senses — maroon wine sounds definitely odd.
pagetribe .

Chapter 8: Advanced Views and URLconfs - 0 views

  • Here, each view starts by checking that request.user is authenticated — that is, the current user has successfully logged into the site — and redirects to /accounts/login/ if not.
  • It would be nice if we could remove that bit of repetitive code from each of these views and just mark them as requiring authentication.
  • Now, we can remove the if not request.user.is_authenticated() checks from our views and simply wrap them with requires_login in our URLconf:
  • ...3 more annotations...
  • This has the same effect as before, but with less code redundancy. Now we’ve created a nice, generic function — requires_login() that we can wrap around any view in order to make it require login.
  • making a view wrapper.
  • There’s an important gotcha here: the regular expressions in this example that point to an include() do not have a $ (end-of-string match character) but do include a trailing slash.
  •  
    Here, each view starts by checking that request.user is authenticated - that is, the current user has successfully logged into the site - and redirects to /accounts/login/ if not.
pagetribe .

Debugging Django - 0 views

  • assert False
  • import pdb; pdb.set_trace()
  • The pdb prompt doubles up as a full Python interactive shell, so you can not only access variables but you can modify them, call functions and generally mess around with the internals of your application as much as you like, while it’s running
1 - 8 of 8
Showing 20 items per page