-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rewrite the request infrastructure to facilitate more interation and to intrinsically enforce some of our policies (must sell at known store, must provide URL if you can, etc). This also moves requests to logged-in users only, which should help following through on confusing requests.
- Loading branch information
Showing
26 changed files
with
610 additions
and
150 deletions.
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
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
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
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,28 @@ | ||
/* WARN: This migration drops all old requests since the storage format changed significantly */ | ||
COPY requests TO '/tmp/cb_old_requests.csv' DELIMITER ',' CSV HEADER; | ||
|
||
CREATE TABLE requests_pre_v1_19 AS SELECT * FROM requests; | ||
|
||
DELETE FROM requests; | ||
ALTER TABLE requests ADD COLUMN vendor_id INTEGER NOT NULL; | ||
ALTER TABLE requests ADD CONSTRAINT vendor_id FOREIGN KEY(vendor_id) REFERENCES vendors(id) MATCH FULL; | ||
ALTER TABLE requests ADD COLUMN vendor_url TEXT; | ||
|
||
ALTER TABLE vendors ADD COLUMN product_urls BOOLEAN; | ||
UPDATE vendors SET product_urls=True WHERE name='Amazon'; | ||
UPDATE vendors SET product_urls=True WHERE name='TalDepot'; | ||
|
||
CREATE TABLE request_posts ( | ||
id SERIAL, | ||
"timestamp" timestamp without time zone NOT NULL, | ||
request_id INTEGER NOT NULL, | ||
user_id INTEGER NOT NULL, | ||
post TEXT, | ||
staff_post BOOLEAN NOT NULL DEFAULT FALSE, | ||
deleted BOOLEAN NOT NULL DEFAULT FALSE | ||
); | ||
ALTER TABLE request_posts ADD CONSTRAINT request_id FOREIGN KEY(request_id) REFERENCES requests(id) MATCH FULL; | ||
ALTER TABLE request_posts ADD CONSTRAINT user_id FOREIGN KEY(user_id) REFERENCES users(id) MATCH FULL; | ||
|
||
/* ALTER TABLE requests ADD COLUMN response TEXT; */ | ||
|
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
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,33 @@ | ||
from .model import * | ||
|
||
from sqlalchemy_utils import ArrowType | ||
|
||
class RequestPost(Base): | ||
__tablename__ = 'request_posts' | ||
|
||
id = Column(Integer, primary_key=True, nullable=False) | ||
timestamp = Column(ArrowType, nullable=False, default=datetime.datetime.utcnow) | ||
request_id = Column(Integer, ForeignKey("requests.id"), nullable=False) | ||
user_id = Column(Integer, ForeignKey("users.id"), nullable=False) | ||
post = Column(Text) | ||
# Allow admin users to post as users or admins by tracking the view that the post is posted from | ||
staff_post = Column(Boolean, default=False, nullable=False) | ||
deleted = Column(Boolean, default=False, nullable=False) | ||
|
||
def __init__(self, request, user, post, staff_post=False, deleted=False): | ||
self.request_id = request.id | ||
self.user_id = user.id | ||
self.post = post | ||
self.staff_post = staff_post | ||
self.deleted = deleted | ||
|
||
@classmethod | ||
def from_id(cls, id): | ||
return DBSession.query(cls).filter(cls.id == id).one() | ||
|
||
@classmethod | ||
def all(cls): | ||
return DBSession.query(cls).filter(cls.deleted==False)\ | ||
.order_by(desc(cls.timestamp))\ | ||
.all() | ||
|
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
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
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
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
Oops, something went wrong.