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
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
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
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
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
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
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,
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()
8 matches
Mail list logo