Add a global setting for the canonical url.
This is used in the emails, because when people come from different urls, they get different urls in the emails; it was pulling the base url from the http request's notion of things.
This commit is contained in:
@@ -20,8 +20,9 @@ from google.appengine.api import users
|
||||
|
||||
import django.template
|
||||
|
||||
import models
|
||||
import email
|
||||
import library
|
||||
import models
|
||||
|
||||
def get_default_sender():
|
||||
return models.Settings.get_settings().from_email
|
||||
@@ -83,7 +84,7 @@ def send_change_message(request, change, template, template_args):
|
||||
to_users = set([change.owner] + change.reviewers + change.cc)
|
||||
subject = make_change_subject(change)
|
||||
args = {
|
||||
'url': request.build_absolute_uri('/%s' % change.key().id()),
|
||||
'url': library.change_url(change)
|
||||
}
|
||||
if template_args:
|
||||
args.update(template_args)
|
||||
|
||||
@@ -205,3 +205,8 @@ def abbrevtimesince(d, arg=None):
|
||||
except KeyError:
|
||||
r.append(p)
|
||||
return ', '.join(r)
|
||||
|
||||
|
||||
def change_url(change):
|
||||
base = models.Settings.get_settings().canonical_url
|
||||
return "%s/%s" % (base, change.key().id())
|
||||
|
||||
@@ -109,6 +109,7 @@ class Settings(BackedUpModel):
|
||||
internal_api_key = db.StringProperty()
|
||||
xsrf_key = db.StringProperty()
|
||||
from_email = db.StringProperty()
|
||||
canonical_url = db.StringProperty(default='')
|
||||
|
||||
_Key = MemCacheKey('Settings_Singleton')
|
||||
|
||||
|
||||
@@ -61,6 +61,7 @@ urlpatterns = patterns(
|
||||
(r'^admin/settings/analytics$', 'views.admin_settings_analytics'),
|
||||
(r'^admin/settings/from_email$', 'views.admin_settings_from_email'),
|
||||
(r'^admin/settings/from_email_test$', 'views.admin_settings_from_email_test'),
|
||||
(r'^admin/settings/canonical_url$', 'views.admin_settings_canonical_url'),
|
||||
(r'^admin/users$', 'people.admin_users'),
|
||||
(r'^admin/people_info$', 'people.admin_people_info'),
|
||||
(r'^admin/user/(.+)$', 'people.admin_user'),
|
||||
|
||||
@@ -1443,6 +1443,31 @@ def admin_settings_from_email(request):
|
||||
return HttpResponseRedirect('/admin/settings')
|
||||
return process_form(request, AdminSettingsFromEmailForm, None, done)
|
||||
|
||||
class AdminSettingsCanonicalUrlForm(BaseForm):
|
||||
_template = 'admin_settings_canonical_url.html'
|
||||
|
||||
url = forms.CharField(required=True)
|
||||
|
||||
@classmethod
|
||||
def _init(cls, state):
|
||||
settings = models.Settings.get_settings()
|
||||
return {'initial': {
|
||||
'url': settings.canonical_url,
|
||||
}
|
||||
}
|
||||
|
||||
def _save(self, cd, change):
|
||||
settings = models.Settings.get_settings()
|
||||
settings.canonical_url = cd['url']
|
||||
settings.put()
|
||||
|
||||
@gae_admin_required
|
||||
def admin_settings_canonical_url(request):
|
||||
def done():
|
||||
return HttpResponseRedirect('/admin/settings')
|
||||
return process_form(request, AdminSettingsCanonicalUrlForm, None, done)
|
||||
|
||||
|
||||
@gae_admin_required
|
||||
def admin_settings_from_email_test(request):
|
||||
if request.method == 'POST':
|
||||
|
||||
@@ -22,4 +22,13 @@
|
||||
<code>{%if settings.analytics %}{{settings.analytics}}{%else%}NONE SET{%endif%}</code>
|
||||
<input type="submit" value="Edit" style="margin-left: 30px;"/>
|
||||
</form>
|
||||
|
||||
<h3>Canonical URL</h3>
|
||||
(used in emails)<br/>
|
||||
<code>{%if settings.canonical_url %}{{settings.canonical_url}}{%else%}NONE SET{%endif%}</code>
|
||||
<form method="get" action="/admin/settings/canonical_url" style="margin-left: 30px; display: inline;">
|
||||
<input type="submit" value="Edit"/>
|
||||
</form>
|
||||
|
||||
|
||||
{%endblock%}
|
||||
|
||||
15
webapp/templates/admin_settings_canonical_url.html
Normal file
15
webapp/templates/admin_settings_canonical_url.html
Normal file
@@ -0,0 +1,15 @@
|
||||
{%extends "admin_base.html"%}
|
||||
{%block title1%}Settings: From email{%endblock%}
|
||||
{%block body%}
|
||||
|
||||
<form action="/admin/settings/canonical_url" method="post">
|
||||
<table>
|
||||
{{form}}
|
||||
|
||||
<p>The url should contain the http and should not contain a trailing slash.
|
||||
For example: http://review.source.android.com.</p>
|
||||
<tr><td><input name="save" type="submit" value="Save"></td></tr>
|
||||
</table>
|
||||
</form>
|
||||
|
||||
{%endblock%}
|
||||
Reference in New Issue
Block a user