Skip to content

Commit

Permalink
Merge pull request #3412 from rtfd/humitos/profile/allow-promos
Browse files Browse the repository at this point in the history
Show/Hide "See paid advertising" checkbox depending on USE_PROMOS
  • Loading branch information
ericholscher authored Dec 21, 2017
2 parents 6fd8282 + 9bf3e2c commit 561d15d
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 15 deletions.
35 changes: 22 additions & 13 deletions readthedocs/core/forms.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
# -*- coding: utf-8 -*-
"""Forms for core app."""

from __future__ import absolute_import
from builtins import object
from __future__ import (
absolute_import, division, print_function, unicode_literals)

import logging
from builtins import object

from django.contrib.auth.models import User
from haystack.forms import SearchForm
from haystack.query import SearchQuerySet
from django import forms
from django.conf import settings
from django.contrib.auth.models import User
from django.forms.fields import CharField
from django.utils.translation import ugettext_lazy as _
from haystack.forms import SearchForm
from haystack.query import SearchQuerySet

from .models import UserProfile

Expand All @@ -22,8 +26,10 @@ class UserProfileForm(forms.ModelForm):

class Meta(object):
model = UserProfile
# Don't allow users edit someone else's user page,
fields = ['first_name', 'last_name', 'homepage', 'allow_ads']
# Don't allow users edit someone else's user page
fields = ['first_name', 'last_name', 'homepage']
if settings.USE_PROMOS:
fields.append('allow_ads')

def __init__(self, *args, **kwargs):
super(UserProfileForm, self).__init__(*args, **kwargs)
Expand All @@ -46,7 +52,10 @@ def save(self, commit=True):


class UserDeleteForm(forms.ModelForm):
username = CharField(label=_('Username'), help_text=_('Please type your username to confirm.'))
username = CharField(
label=_('Username'),
help_text=_('Please type your username to confirm.'),
)

class Meta(object):
model = User
Expand All @@ -56,7 +65,7 @@ def clean_username(self):
data = self.cleaned_data['username']

if self.instance.username != data:
raise forms.ValidationError(_("Username does not match!"))
raise forms.ValidationError(_('Username does not match!'))

return data

Expand All @@ -73,10 +82,10 @@ def valid_value(self, value):
"""
Although this is a choice field, no choices need to be supplied.
Instead, we just validate that the value is in the correct format
for facet filtering (facet_name:value)
Instead, we just validate that the value is in the correct format for
facet filtering (facet_name:value)
"""
if ":" not in value:
if ':' not in value:
return False
return True

Expand Down Expand Up @@ -109,7 +118,7 @@ def clean_selected_facets(self):
cleaned_facets = []
clean = SearchQuerySet().query.clean
for facet in facets:
field, value = facet.split(":", 1)
field, value = facet.split(':', 1)
if not value: # Ignore empty values
continue
value = clean(value)
Expand Down
4 changes: 4 additions & 0 deletions readthedocs/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,10 @@ def INSTALLED_APPS(self): # noqa
apps.append('readthedocsext.embed')
return apps

@property
def USE_PROMOS(self): # noqa
return 'readthedocsext.donate' in self.INSTALLED_APPS

TEMPLATE_LOADERS = (
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
Expand Down
2 changes: 1 addition & 1 deletion readthedocs/templates/profiles/private/edit_profile.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

{% block edit_content %}
<form method="POST" action=".">{% csrf_token %}
{{ form }}
{{ form.as_p }}
<input type="submit" name="submit" value="{% trans "OK, save it!" %}" id="submit"/>
</form>
{% endblock %}
2 changes: 1 addition & 1 deletion readthedocs/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
groups = [basic_urls, rtd_urls, project_urls, api_urls, core_urls, i18n_urls,
deprecated_urls]

if 'readthedocsext.donate' in settings.INSTALLED_APPS:
if settings.USE_PROMOS:
# Include donation URL's
groups.append([
url(r'^sustainability/', include('readthedocsext.donate.urls')),
Expand Down

0 comments on commit 561d15d

Please sign in to comment.