Created
March 6, 2014 03:03
-
-
Save shofetim/9381459 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# From line 37 beehive/apps/orders/views/__init__.py | |
@render_to("orders/_route_dates.html") | |
def route_dates(request, route_id): | |
route = Route.objects.get(pk=route_id) | |
route_trips = list(route.routetrip_set.all().select_related('route')) | |
route_trips.sort(key=lambda rt: (rt.pull.date() < date.today(), rt.pull)) | |
return locals() | |
# from line 26 of beehive/apps/website_registration/views.py | |
from django.db import connection | |
@render_to('website_registration/registration_form.html') | |
def do_register(request): | |
if request.method == "POST": | |
signup_form = NamedUserRegistrationFormUniqueEmail(request.POST) | |
if signup_form.is_valid(): | |
new_user, new_customer = Customer.create_user_and_customer( | |
password=signup_form.cleaned_data['password1'], | |
email=signup_form.cleaned_data['email'], | |
full_name=signup_form.cleaned_data['full_name'], | |
is_active=False, | |
) | |
# create registration profile | |
reg_profile = RegistrationProfile.objects.create_inactive_user(new_user) | |
bes.django.log_user(type='register', request=request, action='register') | |
# redirect to active page | |
return HttpResponseRedirect(reverse('registration_complete', args=(new_user.id,))) | |
else: | |
signup_form = NamedUserRegistrationFormUniqueEmail() | |
return { | |
'form':signup_form, | |
} | |
# From line 98 beehive/apps/orders/models.py | |
@classmethod | |
def new_on_the_fly_order(cls, customer, payment_term, drop_point_trip=None): | |
order = cls(order_status=ORDER_STATUS_PICKING, customer=customer, | |
checkout_payment_type=payment_term, | |
origin=ORDER_ORIGIN_INTERNAL, order_date=datetime.now()) | |
order.save() | |
drop_point = None | |
route_trip = None | |
if drop_point_trip: | |
drop_point = drop_point_trip.drop_point | |
route_trip = drop_point_trip.route_trip | |
OrderShipment.objects.create( | |
order=order, drop_point_trip=drop_point_trip, | |
drop_point=drop_point, requested_route_trip=route_trip) | |
if drop_point_trip: | |
if not drop_point_trip.will_definitely_pick: | |
drop_point_trip.will_definitely_pick = True | |
drop_point_trip.save() | |
order.get_or_create_order_pick(pick_climate=DRY_CHILLED_PICK_CLIMATE) | |
return order | |
def save(self, *args, **kwargs): | |
if self.order_status in (ORDER_STATUS_CART, ORDER_STATUS_RESUMED): | |
assert not (Order.objects | |
.filter(order_status__in=(ORDER_STATUS_CART, | |
ORDER_STATUS_RESUMED), | |
customer=self.customer) | |
.exclude(pk=self.pk).exists()), "Attempted to create a second cart." | |
if self.price_level is None: | |
self.price_level = self.calculate_price_level() | |
self.flag_is_paid_as_stale(and_recalculate=False) | |
if self.pk: | |
self.order_code = self.calculate_order_code() | |
if 'csw' in settings.ENV: | |
self.origin = ORDER_ORIGIN_INTERNAL | |
super(Order, self).save(*args, **kwargs) | |
self.trigger_cache_recalculation() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment