Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Bug 951897 - Expose ssl_only attributive of Product to REST API #34

Merged
merged 1 commit into from

2 participants

@rail

No description provided.

@rhelmer rhelmer commented on the diff
apps/api/views.py
@@ -136,6 +136,7 @@ def product_add(request):
# check languages
langs = request.POST.getlist('languages')
locales = product_details.languages.keys()
+ ssl_only = bool(request.POST.get('ssl_only', False) == "true")
@rhelmer Owner
rhelmer added a note

why is the bool(... == "true") necessary, isn't this enough?

ssl_only = request.POST.get('ssl_only', False)

? Is it because if ssl_only is set it'll be type str not bool?

@rhelmer Owner
rhelmer added a note

So I think the nice way to do this would be with django forms (BooleanField), but I think this version of django is too old and still treats it as str (looks like it was fixed in 1.3, tuxedo is still 1.2) ... can wait until we upgrade, lgtm

@rail
rail added a note

Is it because if ssl_only is set it'll be type str not bool?

Yes.
I find that bool(...) is easier to read, kind of a return type of the code on the right.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@rhelmer rhelmer merged commit 6ae9084 into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
View
2  apps/api/templates/api/docs/product_add.html
@@ -14,6 +14,8 @@
* ``languages``: Language code for this product. Add this parameter multiple
times for multiple languages. If undefined or empty, location is is considered
not language-specific. (Known languages: {{ languages|join:", " }})
+* ``ssl_only``: Use "true" to serve the product over HTTPS only. Any other
+ value is interpreted as false.
{% endblock %}
{% block errorcodes %}
View
3  apps/api/views.py
@@ -136,6 +136,7 @@ def product_add(request):
# check languages
langs = request.POST.getlist('languages')
locales = product_details.languages.keys()
+ ssl_only = bool(request.POST.get('ssl_only', False) == "true")
@rhelmer Owner
rhelmer added a note

why is the bool(... == "true") necessary, isn't this enough?

ssl_only = request.POST.get('ssl_only', False)

? Is it because if ssl_only is set it'll be type str not bool?

@rhelmer Owner
rhelmer added a note

So I think the nice way to do this would be with django forms (BooleanField), but I think this version of django is too old and still treats it as str (looks like it was fixed in 1.3, tuxedo is still 1.2) ... can wait until we upgrade, lgtm

@rail
rail added a note

Is it because if ssl_only is set it'll be type str not bool?

Yes.
I find that bool(...) is easier to read, kind of a return type of the code on the right.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
if [l for l in langs if l not in locales]:
return xml.error('invalid language code(s)', errno=103)
@@ -143,7 +144,7 @@ def product_add(request):
products = Product.objects.filter(name__exact=prodname)
if not products:
try:
- prod = Product(name=prodname)
+ prod = Product(name=prodname, ssl_only=ssl_only)
prod.save()
for lang in langs:
prod.languages.create(lang=lang)
Something went wrong with that request. Please try again.