On Mar 19, 3:35 pm, 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.

Malcolm hinted at what needs to be done, but he assumed you'd already
done it - that is, take that 87 lines of duplicate code into a
separate function, and call it from both views.

def get_data(request):
    ... your 87 lines of code ...
    data.append(publications)
    return data

def by_pub(request):
    data = get_data(request)
    ... proceed with view ...

def text_file(request):
    data = get_data(request)
    ... proceed with view ...

(note I've renamed your views - Python convention is to use
lower_with_underscores for function names, and reserve StudlyCaps for
names of classes. Also, don't use 'list' as the name of a variable in
your get_data code, as that will hide the built-in list() type).
--
DR.

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

Reply via email to