Pass something in the request, like ?output=csv Then look for it in the view and feed the appopriate version.
On Mar 19, 10:35 am, Jesse <[email protected]> wrote: > My concern is that each view has 87 lines of duplicate code from the > "GET" data to get the appended list (shown here as: data retrieved to > create a list .....list.append(publications)). Anytime I make a > change in one view I have to remember to make the change in the other > view. Since I'm fairly new at Django, I'm thinking there must be a > more efficient way to write the views? I'm very pleased with how > everything is working, so now I am going back to try to clean up the > code. > > Thanks. > > On Mar 18, 6:43 pm, Malcolm Tredinnick <[email protected]> > wrote: > > > On Wed, 2009-03-18 at 11:24 -0700, Jesse wrote: > > > In the view.py I have (def Bypub) that sends data to a template and > > > paginates it. I have a second (def TextFile) that uses the same data > > > to send to a CSV file. I would like to combine the two (def Bypub and > > > def TextFile) together into def Bypub, but I'm not sure how to write > > > the statements to combine two responses. > > > What problem are you trying to solve here? You already have two views > > where the common stuff is in a separate function (the bit you've marked > > as retrieving the data in a list) and the distinct stuff is in the > > separate views. That ideal. > > > If the problem is that you want one URL to be able to access both > > formats, then simplest is to create a third view that works out which of > > the current two views to call and then passes onto them: > > > def dispatch_view(request,...): > > # ... work out which to call somehow... > > > if output_format == 'csv': > > return TextFile(request) > > else: > > return Bypub(request) > > > Is that what you're trying to do? > > > Regards, > > Malcolm --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---

