Skip to content
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

Merged
merged 14 commits into from
Oct 9, 2016

Conversation

jakereps
Copy link
Member

Placeholder for private workshops and special rate functionality.

Resolves #64
Resolves #65

@jakereps jakereps added the stat:DO-NOT-MERGE Please do not merge this until this label has been removed. label Aug 29, 2016
@jakereps jakereps closed this Aug 31, 2016
@jakereps jakereps reopened this Aug 31, 2016
@jakereps jakereps force-pushed the special-rates branch 3 times, most recently from fd14f40 to 0b446ad Compare September 9, 2016 23:20
@thermokarst thermokarst self-assigned this Sep 9, 2016
@thermokarst thermokarst removed the stat:DO-NOT-MERGE Please do not merge this until this label has been removed. label Sep 9, 2016
Copy link
Contributor

@thermokarst thermokarst left a 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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When adding more than one discount rate, all the rates have the same UUID value:

image

Copy link
Member Author

@jakereps jakereps Sep 14, 2016

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');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be great to have the same helper URL show up in the Inline Rate Editor:

image

Copy link
Member Author

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,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The max_digits needs to be bumped up to 8, I think:

image

<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 }}
Copy link
Contributor

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
Copy link
Contributor

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):
Copy link
Contributor

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)
Copy link
Contributor

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):
Copy link
Contributor

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):
Copy link
Contributor

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'))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call.

@jakereps
Copy link
Member Author

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!

@jakereps
Copy link
Member Author

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? ¯_(ツ)_/¯

Copy link
Contributor

@thermokarst thermokarst left a 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)
Copy link
Contributor

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
Copy link
Contributor

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)
Copy link
Contributor

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
Copy link
Contributor

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):
Copy link
Contributor

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'))

@thermokarst thermokarst assigned jakereps and unassigned thermokarst Oct 5, 2016
@jakereps
Copy link
Member Author

jakereps commented Oct 5, 2016

This should be good to go, @thermokarst! Did I miss something that it's re-assigned to me?

Edit: Ahhh, I did miss something.

@jakereps
Copy link
Member Author

jakereps commented Oct 5, 2016

Ok, this one should be good to go after tests! Thanks @thermokarst 👍

@thermokarst thermokarst merged commit a371ea8 into qiime2:master Oct 9, 2016
@thermokarst
Copy link
Contributor

Thanks for this @jakereps !! 🌮 🌮 🌮

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants