add send_confirmation and send_notificaiton methods to contact; add send_quotation method to booking; inject services in models and decoupled views

This commit is contained in:
Ruidy Nemausat 2020-04-08 10:48:52 +02:00
parent 835fd664bf
commit fed5732204
4 changed files with 30 additions and 23 deletions

View file

@ -3,6 +3,7 @@ from django.db import models
from rental.models.guest import Guest
from rental.models.place import Place
import rental.services.calendar as calendar
import rental.tasks.apiMailer as mailer # or gMailer
class BookingManager(models.Manager):
@ -45,3 +46,6 @@ class Booking(models.Model):
nights = (self.end - self.start).days
return self.place.price * nights
def send_quotation(self):
mailer.send_quotation.delay(self.guest.name, self.guest.email)

View file

@ -1,5 +1,5 @@
from django.db import models
import rental.tasks.apiMailer as mailer # or gMailer
class Contact(models.Model):
@ -12,3 +12,15 @@ class Contact(models.Model):
subject = models.EmailField(max_length=50)
message = models.TextField(max_length=50)
date = models.DateTimeField(auto_now_add=True)
def send_confirmation(self):
mailer.send_confirmation.delay(self.name, self.email)
def send_notification(self):
mailer.send_notification.delay(
self.name,
self.email,
self.subject,
self.message,
self.date
)

View file

@ -23,7 +23,7 @@
</script>
<script>
(function(c, a) {
(function (c, a) {
if (!a.__SV) {
var b = window;
try {
@ -32,7 +32,7 @@
j,
k = b.location,
f = k.hash;
d = function(a, b) {
d = function (a, b) {
return (m = a.match(RegExp(b + "=([^&]*)"))) ? m[1] : null;
};
f &&
@ -49,24 +49,24 @@
var l, h;
window.mixpanel = a;
a._i = [];
a.init = function(b, d, g) {
a.init = function (b, d, g) {
function c(b, i) {
var a = i.split(".");
2 == a.length && ((b = b[a[0]]), (i = a[1]));
b[i] = function() {
b[i] = function () {
b.push([i].concat(Array.prototype.slice.call(arguments, 0)));
};
}
var e = a;
"undefined" !== typeof g ? (e = a[g] = []) : (g = "mixpanel");
e.people = e.people || [];
e.toString = function(b) {
e.toString = function (b) {
var a = "mixpanel";
"mixpanel" !== g && (a += "." + g);
b || (a += " (stub)");
return a;
};
e.people.toString = function() {
e.people.toString = function () {
return e.toString(1) + ".people (stub)";
};
l = "disable time_event track track_pageview track_links track_forms track_with_groups add_group set_group remove_group register register_once alias unregister identify name_tag set_config reset opt_in_tracking opt_out_tracking has_opted_in_tracking has_opted_out_tracking clear_opt_in_out_tracking people.set people.set_once people.unset people.increment people.append people.union people.track_charge people.clear_charges people.delete_user people.remove".split(
@ -74,9 +74,9 @@
);
for (h = 0; h < l.length; h++) c(e, l[h]);
var f = "set set_once union unset remove delete".split(" ");
e.get_group = function() {
e.get_group = function () {
function a(c) {
b[c] = function() {
b[c] = function () {
call2_args = arguments;
call2 = [c].concat(Array.prototype.slice.call(call2_args, 0));
e.push([d, call2]);
@ -114,7 +114,7 @@
mixpanel.init("fd38f05cab7987b17dfa3aac4ff1a032");
</script>
<title>VillaFleurie</title>
<title>VillaFleurie Locations de vacances</title>
<meta content="width=device-width, initial-scale=1.0" name="viewport" />
<meta content="" name="keywords" />
<meta content="" name="description" />

View file

@ -7,11 +7,8 @@ from rental.forms import ReservationForm, ContactForm
from rental.models.booking import Booking
from rental.models.contact import Contact
from rental.models.guest import Guest
from rental.models.picture import Picture
from rental.models.place import Place
from rental.models.testimonial import Testimonial
from rental.services.calendar import check_availability, synchronize_calendars, update
from rental.tasks.apiMailer import * # or gMailer
def index(request):
@ -79,7 +76,6 @@ def handle_reservation_form(request, context={}, init_template='rental/reservati
guest = guest.first()
place = get_object_or_404(Place, name=place_name)
# available = check_availability(place, )
if place.is_available(start, end):
reservation = Booking.objects.create_booking(
@ -89,7 +85,8 @@ def handle_reservation_form(request, context={}, init_template='rental/reservati
start=start,
end=end
)
send_quotation.delay(name, email)
reservation.send_quotation()
context = {
'reservation': reservation
@ -144,14 +141,8 @@ def contact(request):
message=form.cleaned_data['message']
)
send_confirmation.delay(contact.name, contact.email)
send_notification.delay(
contact.name,
contact.email,
contact.subject,
contact.message,
contact.date
)
contact.send_confirmation()
contact.send_notification()
return render(request, 'rental/contact_merci.html', {})