Re: Am I missing a design pattern? My views code somehow isn't as elegant as it should be...

2016-10-23 Thread Vinicius Assef
Inline answers follow... On 23 October 2016 at 10:01, Andrew wrote: > Tried to look up service layers, but couldn't find examples of how it was > supposed to look like - is it supposed to be like a class, and I toss the > lead into it and it handles business logic

Re: Am I missing a design pattern? My views code somehow isn't as elegant as it should be...

2016-10-23 Thread ludovic coues
Python doesn't have special structure to separate internal and interface. There is a convention of prefixing the internal with an underscore. That's all. So having IPInfo.request being part of your interface is totally fine. Or you could keep things as they are. Or rename IPInfo.request to

Re: Am I missing a design pattern? My views code somehow isn't as elegant as it should be...

2016-10-23 Thread Andrew
Tried to look up service layers, but couldn't find examples of how it was supposed to look like - is it supposed to be like a class, and I toss the lead into it and it handles business logic and saving? Normally I'd use ipinfo.result myself, but I read somewhere about separating the interface

Re: Am I missing a design pattern? My views code somehow isn't as elegant as it should be...

2016-10-22 Thread Vinicius Assef
I'd say you're missing a service layer. It's known as a good practice to not have "business rules" in your views. IP lookup should be done in your view anyway, because it's a "web related thing". The `save_the_lead()` and email sending should be in the service layer. Extending a little bit and

Re: Am I missing a design pattern? My views code somehow isn't as elegant as it should be...

2016-10-22 Thread ludovic coues
Class Based View really shine in form handling. You can find the documentation at [1]. All the boilerplate code will be 3 assignment like template_name = 'wizard/questionnaire.html' while the logic will go into form_valid function. I would also add a comment for the Matcher object and why the m

Re: Am I missing a design pattern? My views code somehow isn't as elegant as it should be...

2016-10-21 Thread Andrew Chiw
As someone POSTs a questionnaire, I lookup some additional info about the IP and save that into a model's JSONField. I'm sending the request into django-ipware's get_ip(), which will return the IP address as a string. Since this data is ephemeral, I put it directly in the constructor instead of

Re: Am I missing a design pattern? My views code somehow isn't as elegant as it should be...

2016-10-21 Thread Alex Heyden
Are you intentionally sending the whole request into that constructor and concatenating it to a URL string? I can't imagine any way this doesn't end in disaster. I'm sure the community would happily help, but it's not at all obvious from the supplied code what you're trying to do here. On Fri,

Am I missing a design pattern? My views code somehow isn't as elegant as it should be...

2016-10-21 Thread Andrew Chiw
In my views, I have this: def questionnaire(request): def save_the_lead(cleaned_data, ipinfo): email = cleaned_data.pop('email', None) lead, created = Lead.objects.update_or_create(email=email) lead.q = cleaned_data lead.ipinfo = ipinfo lead.save()