-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Locations are now board-specific. Fixes #333.
- Loading branch information
Showing
5 changed files
with
84 additions
and
18 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
"""Location scoped to board | ||
Revision ID: da1dfcda8b3 | ||
Revises: d19802512a1 | ||
Create Date: 2016-05-03 11:06:14.239742 | ||
""" | ||
|
||
# revision identifiers, used by Alembic. | ||
revision = 'da1dfcda8b3' | ||
down_revision = 'd19802512a1' | ||
|
||
from alembic import op | ||
import sqlalchemy as sa | ||
|
||
|
||
def upgrade(): | ||
op.add_column('location', sa.Column('board_id', sa.Integer(), nullable=False, server_default=sa.text('1'))) | ||
op.alter_column('location', 'board_id', server_default=None) | ||
op.create_index(op.f('ix_location_board_id'), 'location', ['board_id'], unique=False) | ||
op.drop_constraint(u'location_name_key', 'location', type_='unique') | ||
op.create_unique_constraint('location_board_id_name_key', 'location', ['board_id', 'name']) | ||
op.create_foreign_key('location_board_id_fkey', 'location', 'board', ['board_id'], ['id']) | ||
op.drop_constraint('location_pkey', 'location', type_='primary') | ||
op.create_primary_key('location_pkey', 'location', ['id', 'board_id']) | ||
|
||
|
||
def downgrade(): | ||
op.drop_constraint('location_pkey', 'location', type_='primary') | ||
op.create_primary_key('location_pkey', 'location', ['id']) | ||
op.drop_constraint('location_board_id_fkey', 'location', type_='foreignkey') | ||
op.drop_constraint('location_board_id_name_key', 'location', type_='unique') | ||
op.create_unique_constraint('location_name_key', 'location', ['name']) | ||
op.drop_index(op.f('ix_location_board_id'), table_name='location') | ||
op.drop_column('location', 'board_id') |
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 |
---|---|---|
@@ -1,28 +1,35 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
from . import db, BaseNameMixin | ||
from . import db, BaseScopedNameMixin | ||
from flask import url_for | ||
from .board import Board | ||
|
||
__all__ = ['Location'] | ||
|
||
|
||
class Location(BaseNameMixin, db.Model): | ||
class Location(BaseScopedNameMixin, db.Model): | ||
""" | ||
A location where jobs are listed, using geonameid for primary key. | ||
A location where jobs are listed, using geonameid for primary key. Scoped to a board | ||
""" | ||
__tablename__ = 'location' | ||
id = db.Column(db.Integer, primary_key=True, autoincrement=False) | ||
geonameid = db.synonym('id') | ||
board_id = db.Column(None, db.ForeignKey('board.id'), nullable=False, primary_key=True, index=True) | ||
parent = db.synonym('board_id') | ||
board = db.relationship(Board, backref=db.backref('locations', lazy='dynamic', cascade='all, delete-orphan')) | ||
|
||
#: Landing page description | ||
description = db.Column(db.UnicodeText, nullable=True) | ||
|
||
def url_for(self, action='view', _external=False, **kwargs): | ||
__table_args__ = (db.UniqueConstraint('board_id', 'name'),) | ||
|
||
def url_for(self, action='view', **kwargs): | ||
subdomain = self.board.name if self.board.not_root else None | ||
if action == 'view': | ||
return url_for('browse_by_location', location=self.name, _external=_external, **kwargs) | ||
return url_for('browse_by_location', location=self.name, subdomain=subdomain, **kwargs) | ||
elif action == 'edit': | ||
return url_for('location_edit', name=self.name, _external=_external, **kwargs) | ||
return url_for('location_edit', name=self.name, subdomain=subdomain, **kwargs) | ||
|
||
@classmethod | ||
def get(cls, name): | ||
return cls.query.filter_by(name=name).one_or_none() | ||
def get(cls, name, board): | ||
return cls.query.filter_by(name=name, board=board).one_or_none() |
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