views:

54

answers:

1

I am torn between to DRY and loose coupling :(

I have two sites which you can link your account and then the sites can share data (via a RESTful api...)

one site is a media aggregation site and the other is a media store where people can buy digital media (music/photo/video).

My boss wants to emulate the itunes store and have a built-in store in the aggregation site where people can buy the stuff they like and have it added to their account automatically.

I have 99% of the templates and views (django) written for the store site, that I would need to display the content on the media site.

Should I just render the templates and deliver pre-rendered html (via api) to the media (aggregation) site, (and obey DRY) or should I deliver json to avoid tightly coupled custom templates on the store side?

Or maybe a hybrid design would work better? deliver pre-rendered chunks of html (like a top 10 products in a <ol>) and let the media site request the chunks it needs?

The hybrid design seems most promising to me (right now), but will probably result is a lot more api calls (and therefore more database queries)

What do you think?

edit - A new idea: (as seen in the comment) What do you think of having the store site loaded up with some custom css into an iframe?

I think that should eliminate confusion, reduce the amount of tightly coupled code to 2 of 3 dozen lines or so, and save me the massive headache of maintaining two sets of templates that are almost identical.

+1  A: 

The web designers are going to kill you when you spread the HTML over two sites, so one site should deliver (raw) data and the other site should decide how to render that data. Also, this is going to become a maintenance nightmare. Just imagine you have to fix a bug by staring at some HTML: How often are you going to ask yourself which of the two sites generated which part of the HTML?

So let the store render the data structures it gets from the media site. The media site should send whole data structures (i.e. a list of the top 10, only the description, maybe as JSON, without formatting). This avoids unnecessary round trips.

Aaron Digulla
I had a thought, what do you think of having the store site generate everything and putting it in an iframe on the media site? That way there will not be confusion, and I can keep also avoid having two sets of templates that are 95% the same?
Jiaaro