This repository has been archived by the owner on Feb 8, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 308
Profile statements i18n #3010
Merged
Merged
Profile statements i18n #3010
Changes from 21 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
acd7d43
retire the "making the world better" statement prefix
Changaco 0e2390e
move privacy options to the privacy section
Changaco e2c6f11
implement editing "number" on "Account" page
Changaco 417dafb
allow profile statements in multiple languages
Changaco 637f442
remove ad-hoc `_clip` function, use `excerpt_intro` instead
Changaco 1bfed1a
fix title
Changaco 894ecba
drop unnecessary functions
Changaco 21251e4
remove obsolete function
Changaco 335d0a4
move COUNTRIES constant to i18n module
Changaco a28eeec
move the initialization of LOCALE_EN back to i18n module
Changaco cf1bbe0
use an OrderedDict for COUNTRIES
Changaco 93e3f17
use the data from babel for COUNTRIES instead of duplicating it
Changaco 0b5c348
add a `languages_2` OrderedDict to locales
Changaco 6c936a4
restrict statement languages
Changaco ea42bdc
implement upserting and fetching statements
Changaco fc8982e
implement UI for multilingual statements
Changaco a6f826f
use the jsEdit generic code for the bitcoin input
Changaco 7e9ce63
use the jsEdit generic code for the username input
Changaco b3866d9
fix tests
Changaco 5003227
new failing test
Changaco 0b14117
fix failing test
Changaco 215c2cf
Put "Team" option on a new line
chadwhitacre File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
BEGIN; | ||
|
||
CREATE TABLE statements | ||
( participant bigint NOT NULL REFERENCES participants(id) | ||
, lang text NOT NULL | ||
, content text NOT NULL CHECK (content <> '') | ||
, UNIQUE (participant, lang) | ||
); | ||
|
||
INSERT INTO statements | ||
SELECT id, 'en', concat('I am making the world better by ', statement) | ||
FROM participants | ||
WHERE statement <> '' | ||
AND number = 'singular'; | ||
|
||
INSERT INTO statements | ||
SELECT id, 'en', concat('We are making the world better by ', statement) | ||
FROM participants | ||
WHERE statement <> '' | ||
AND number = 'plural'; | ||
|
||
CREATE FUNCTION enumerate(anyarray) RETURNS TABLE (rank bigint, value anyelement) AS $$ | ||
SELECT row_number() over() as rank, value FROM unnest($1) value; | ||
$$ LANGUAGE sql STABLE; | ||
|
||
END; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -208,9 +208,44 @@ def update_number(self, number): | |
# Statement | ||
# ========= | ||
|
||
def update_statement(self, statement): | ||
self.db.run("UPDATE participants SET statement=%s WHERE id=%s", (statement, self.id)) | ||
self.set_attributes(statement=statement) | ||
def get_statement(self, langs): | ||
"""Get the participant's statement in the language that best matches | ||
the list provided. | ||
""" | ||
return self.db.one(""" | ||
SELECT content, lang | ||
FROM statements | ||
JOIN enumerate(%(langs)s) langs ON langs.value = statements.lang | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This makes me really nervous. We have some assurance that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It doesn't matter what |
||
WHERE participant=%(id)s | ||
ORDER BY langs.rank | ||
LIMIT 1 | ||
""", dict(id=self.id, langs=langs), default=(None, None)) | ||
|
||
def get_statement_langs(self): | ||
return self.db.all("SELECT lang FROM statements WHERE participant=%s", | ||
(self.id,)) | ||
|
||
def upsert_statement(self, lang, statement): | ||
if not statement: | ||
self.db.run("DELETE FROM statements WHERE participant=%s AND lang=%s", | ||
(self.id, lang)) | ||
return | ||
r = self.db.one(""" | ||
UPDATE statements | ||
SET content=%s | ||
WHERE participant=%s | ||
AND lang=%s | ||
RETURNING true | ||
""", (statement, self.id, lang)) | ||
if not r: | ||
try: | ||
self.db.run(""" | ||
INSERT INTO statements | ||
(lang, content, participant) | ||
VALUES (%s, %s, %s) | ||
""", (lang, statement, self.id)) | ||
except IntegrityError: | ||
return self.upsert_statement(lang, statement) | ||
|
||
|
||
# Pricing | ||
|
@@ -418,7 +453,7 @@ def clear_takes(self, cursor): | |
|
||
|
||
def clear_personal_information(self, cursor): | ||
"""Clear personal information such as statement and goal. | ||
"""Clear personal information such as statements and goal. | ||
""" | ||
if self.IS_PLURAL: | ||
self.remove_all_members(cursor) | ||
|
@@ -433,10 +468,10 @@ def clear_personal_information(self, cursor): | |
); | ||
|
||
DELETE FROM emails WHERE participant = %(username)s; | ||
DELETE FROM statements WHERE participant=%(participant_id)s; | ||
|
||
UPDATE participants | ||
SET statement='' | ||
, goal=NULL | ||
SET goal=NULL | ||
, anonymous_giving=False | ||
, anonymous_receiving=False | ||
, number='singular' | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.