-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ENH: Add private Workshops and Special Rates #66
Conversation
b0d9133
to
ada3823
Compare
fd14f40
to
0b446ad
Compare
0b446ad
to
2643b69
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great @jakereps! 👍
Just a few minor questions/comments here. Let me know if you want to discuss further. Thanks!!
'a customer receiving a discount in the ' | ||
'form of https://workshops.qiime.org/wor' | ||
'kshop_slug/rate=discount_code', | ||
default=uuid.uuid4) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That seems to be a Django issue. Probably something weird to do with the inline admin. I'll do some digging to see if there is any way to fix it.
var publicWorkshop = $('#id_public'); | ||
var privateCodeRow = $('.field-private_code'); | ||
var privateCodeInput = $('#id_private_code'); | ||
var privateCodeUrlSpan = $('#pcode'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would require quite a bit of hacking with JS. I tried to go the same route as the private code with the discount code but the help text just goes up to the question mark alt text next to the column header so I put a generic help text. I could try to get it to happen, but it will need a lot more lines than the private code.
@@ -105,7 +124,12 @@ class Rate(models.Model): | |||
price = models.DecimalField(max_digits=6, decimal_places=2, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
<input type="submit" class="btn btn-primary pull-right" value="Continue" /> | ||
<div class="col-md-3 col-md-offset-9"> | ||
{% if workshop.public %} | ||
{{ form.special_code }} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this leftover from the earlier version where the discount code was manually entered? If so, can you remove this?
|
||
|
||
class WorkshopDetail(FormMixin, DetailView): | ||
model = Workshop | ||
form_class = OrderForm | ||
context_object_name = 'workshop' | ||
discount_code = None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can drop this, see below.
|
||
# dicount_code must be grabbed before anything begins as putting it | ||
# in the get() was somehow being beaten by the get_form_kwargs() | ||
def dispatch(self, request, *args, **kwargs): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can drop this, see below.
return HttpResponseRedirect(reverse('payments:index')) | ||
return response | ||
|
||
def get_form_kwargs(self): | ||
kwargs = super().get_form_kwargs() | ||
kwargs['workshop'] = self.object | ||
kwargs['discount_code'] = self.discount_code | ||
return kwargs | ||
|
||
def get_context_data(self, **kwargs): | ||
context = super().get_context_data(**kwargs) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Before calling super()
just do self.discount_code = self.request.GET.get('rate')
, then you should have the discount code everywhere you need it.
|
||
# Since there are possible GET parameters we need to conditionally | ||
# determine the queryset for the ListView | ||
def get_queryset(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice use of the get_queryset
hook!
@@ -74,6 +83,16 @@ def get_absolute_url(self): | |||
return reverse('payments:details', kwargs={'slug': self.slug}, | |||
subdomain='workshops') | |||
|
|||
def filter_rates(self, rate_code): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like this convenience method!
@@ -57,7 +66,7 @@ def sold_out_rates(self): | |||
return self.rate_set.filter(sold_out=True) | |||
|
|||
class Meta: | |||
unique_together = (('title', 'slug'), ) | |||
unique_together = (('title', 'slug'), ('private_code', 'public')) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good call.
Thanks @thermokarst! Looking into the rate uuid bug, and a way to handle the dynamic url helpers like the secret code does, everything else was addressed! |
a16b45f
to
e18a3dd
Compare
So everything should be good, @thermokarst. Got rid of the UUID bug by changing the behavior of the form entirely, and added dynamic URL's. In order to do the dynamic URLs the JS had to get a little bit ugly, but hey, it works? ¯_(ツ)_/¯ |
906e034
to
3036213
Compare
85b4b05
to
03164ca
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great @jakereps! One minor change inline.
Also, I think we need to include a check inSubmitOrder
, right at the beginning of the post
handler, we need to double check that there are still available tickets at the rate the purchaser is trying to buy at. If there aren't they should be bounced back to the workshop detail page with a note that the rate is sold out. Right now we only check that tickets are available before starting the purchase process, but there could be situations where tickets sell out while someone is in the process of purchasing.
@@ -49,7 +49,7 @@ def get_queryset(self): | |||
queryset = Workshop.objects.filter(private_code=self.private_code) | |||
|
|||
if queryset is None or len(queryset) == 0: | |||
queryset = Workshop.objects.filter(draft=False, public=True) | |||
queryset = Workshop.objects.filter(draft=False) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
@@ -67,12 +67,15 @@ class WorkshopDetail(FormMixin, DetailView): | |||
form_class = OrderForm | |||
context_object_name = 'workshop' | |||
|
|||
# discount_code is needed on POST as well, so only getting it on |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know if this dispatch
is quite what we need. Query params on GET requests are generally frowned upon. How about we just stash the discount code in the session on GET? See below for more.
def dispatch(self, request, *args, **kwargs): | ||
self.discount_code = self.request.GET.get('rate') | ||
return super().dispatch(request, *args, **kwargs) | ||
|
||
def get(self, request, *args, **kwargs): | ||
response = super().get(request, *args, **kwargs) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Before the call to super()
you can do:
self.request.session['discount_code'] = request.GET.get('rate')
@@ -83,7 +86,7 @@ def get_form_kwargs(self): | |||
return kwargs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
kwargs['discount_code'] = self.request.session.get('discount_code')
rates = [] | ||
for rate in self.object.rate_set.order_by('price'): | ||
for rate in self.object.filter_rates(self.discount_code): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for rate in self.object.filter_rates(self.request.session.get('discount_code'))
This should be good to go, @thermokarst! Did I miss something that it's re-assigned to me? Edit: Ahhh, I did miss something. |
Ok, this one should be good to go after tests! Thanks @thermokarst 👍 |
Thanks for this @jakereps !! 🌮 🌮 🌮 |
Placeholder for private workshops and special rate functionality.
Resolves #64
Resolves #65