-
Notifications
You must be signed in to change notification settings - Fork 84
Development #12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
flash42
wants to merge
49
commits into
CodecoolBase:master
Choose a base branch
from
gergicsmilan:development
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Development #12
Changes from all commits
Commits
Show all changes
49 commits
Select commit
Hold shift + click to select a range
c8311e0
clear boards function implemented
gergicsmilan 14b00ce
implemented connection.py and (Fru: sql installéson fájl)
gergicsmilan b4c0b23
sql requests implemented for board, card and status tables
fkcreates 730c2f4
test
fkcreates 0311eea
test2
fkcreates dd8c177
listing board and cards dinamically from sql database is implemented
fkcreates 6945d9e
my chg
gergicsmilan 49a7c4a
merge
gergicsmilan e37f8c0
bootstrap initialized
fkcreates b18339a
Merge branch 'development' of https://github.com/gergicsmilan/proman-…
gergicsmilan 2640d5b
created post req function, implemented add new board function..
gergicsmilan 6062e05
delete board button added
kornelgatter 786bea4
adding new card feature is available for the user
fkcreates 9fc8f38
renamed button to add new card
fkcreates 58895c9
fixed button position
gergicsmilan 6dea3b9
delete button event listener function added to dom
kornelgatter ec4b934
pep 8 issues handled
fkcreates e8d95c7
Merge branch 'development' of https://github.com/gergicsmilan/proman-…
gergicsmilan 25f448a
merge
kornelgatter a6c1c2c
dfgkdfh
BalintAts 9f724aa
conslicthandling
BalintAts f559e1d
merge conflict handling
fkcreates dae238e
toggle button done with Dany
BalintAts 1d1fd21
delete board implemented
kornelgatter 0471dd0
toggle button done with Dani
BalintAts 19d2a70
merge conflict resolve
kornelgatter 02d093e
trying things
fkcreates acc9d78
Merge branch 'development' of https://github.com/gergicsmilan/proman-…
fkcreates af8475c
fsrfusehfih
BalintAts 0b3a079
fixed add new board click bug
gergicsmilan 49e5139
merge conflict handled
gergicsmilan 14837fa
Merge branch 'development' of https://github.com/gergicsmilan/proman-…
fkcreates 3d68801
delete card implemented, with bugs
kornelgatter ddba51f
some bugs fixed
kornelgatter 339789f
Merge branch 'development' of https://github.com/gergicsmilan/proman-…
kornelgatter 8dafd5e
delete card implemented
kornelgatter d584d70
Merge branch 'deletecard' into development
kornelgatter f572585
Merge branch 'development' of https://github.com/gergicsmilan/proman-…
fkcreates 0019178
conflict
BalintAts 851b1f0
megint elbaszodott
BalintAts 37c2f61
dragndrop kesz
BalintAts 8c9ef5b
second try on renaming, taking out original board title is ok, switch…
fkcreates dd2ad3e
escape and enter keydowns work well, not implementing in database yet…
fkcreates b04cdcb
renaming board user story works with little bug: once you rename the …
fkcreates ef26a0b
conflict handling
BalintAts a6b18f9
conflict with stupid kapcsos
BalintAts 2daae6a
registration, navbar, reg modal, login modal
gergicsmilan b4aa34c
merge conflict handling well
fkcreates 471cf56
changes with Dani, refactoring a bit of the code
fkcreates 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 hidden or 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,52 @@ | ||
| # Creates a decorator to handle the database connection/cursor opening/closing. | ||
| # Creates the cursor with RealDictCursor, thus it returns real dictionaries, where the column names are the keys. | ||
| import os | ||
| import psycopg2 | ||
| import psycopg2.extras | ||
|
|
||
|
|
||
| def get_connection_string(): | ||
| # setup connection string | ||
| # to do this, please define these environment variables first | ||
| user_name = os.environ.get('PSQL_USER_NAME') | ||
| password = os.environ.get('PSQL_PASSWORD') | ||
| host = os.environ.get('PSQL_HOST') | ||
| database_name = os.environ.get('PSQL_DB_NAME') | ||
|
|
||
| env_variables_defined = user_name and password and host and database_name | ||
|
|
||
| if env_variables_defined: | ||
|
|
||
| # this string describes all info for psycopg2 to connect to the database | ||
| return 'postgresql://{user_name}:{password}@{host}/{database_name}'.format( | ||
| user_name=user_name, | ||
| password=password, | ||
| host=host, | ||
| database_name=database_name | ||
| ) | ||
| else: | ||
| raise KeyError('Some necessary environment variable(s) are not defined') | ||
|
|
||
|
|
||
| def open_database(): | ||
| try: | ||
| connection_string = get_connection_string() | ||
| connection = psycopg2.connect(connection_string) | ||
| connection.autocommit = True | ||
| except psycopg2.DatabaseError as exception: | ||
| print('Database connection problem') | ||
| raise exception | ||
| return connection | ||
|
|
||
|
|
||
| def connection_handler(function): | ||
| def wrapper(*args, **kwargs): | ||
| connection = open_database() | ||
| # we set the cursor_factory parameter to return with a RealDictCursor cursor (cursor which provide dictionaries) | ||
| dict_cur = connection.cursor(cursor_factory=psycopg2.extras.RealDictCursor) | ||
| ret_value = function(dict_cur, *args, **kwargs) | ||
| dict_cur.close() | ||
| connection.close() | ||
| return ret_value | ||
|
|
||
| return wrapper |
This file contains hidden or 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 hidden or 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 hidden or 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,51 +1,118 @@ | ||
| import csv | ||
| import connection | ||
|
|
||
| STATUSES_FILE = './data/statuses.csv' | ||
| BOARDS_FILE = './data/boards.csv' | ||
| CARDS_FILE = './data/cards.csv' | ||
|
|
||
| _cache = {} # We store cached data in this dict to avoid multiple file readings | ||
| @connection.connection_handler | ||
| def get_statuses(cursor): | ||
| cursor.execute(""" | ||
| SELECT id, title FROM status; | ||
| """) | ||
|
|
||
| statuses = cursor.fetchall() | ||
| return statuses | ||
|
|
||
| def _read_csv(file_name): | ||
| """ | ||
| Reads content of a .csv file | ||
| :param file_name: relative path to data file | ||
| :return: OrderedDict | ||
| """ | ||
| with open(file_name) as boards: | ||
| rows = csv.DictReader(boards, delimiter=',', quotechar='"') | ||
| formatted_data = [] | ||
| for row in rows: | ||
| formatted_data.append(dict(row)) | ||
| return formatted_data | ||
|
|
||
| @connection.connection_handler | ||
| def get_boards(cursor): | ||
| cursor.execute(""" | ||
| SELECT id, title FROM board; | ||
| """) | ||
|
|
||
| def _get_data(data_type, file, force): | ||
| """ | ||
| Reads defined type of data from file or cache | ||
| :param data_type: key where the data is stored in cache | ||
| :param file: relative path to data file | ||
| :param force: if set to True, cache will be ignored | ||
| :return: OrderedDict | ||
| """ | ||
| if force or data_type not in _cache: | ||
| _cache[data_type] = _read_csv(file) | ||
| return _cache[data_type] | ||
| boards = cursor.fetchall() | ||
| return boards | ||
|
|
||
|
|
||
| def clear_cache(): | ||
| for k in list(_cache.keys()): | ||
| _cache.pop(k) | ||
| @connection.connection_handler | ||
| def get_cards(cursor): | ||
| cursor.execute(""" | ||
| SELECT id, board_id, title, status_id, card_order FROM card; | ||
| """) | ||
|
|
||
| cards = cursor.fetchall() | ||
| return cards | ||
|
|
||
| def get_statuses(force=False): | ||
| return _get_data('statuses', STATUSES_FILE, force) | ||
|
|
||
| @connection.connection_handler | ||
| def get_cards_for_board(cursor, board_id): | ||
| cursor.execute("""SELECT id, board_id, title, status_id, card_order FROM card | ||
| WHERE board_id = %(board_id)s; | ||
| """, | ||
| {'board_id': board_id}) | ||
|
|
||
| def get_boards(force=False): | ||
| return _get_data('boards', BOARDS_FILE, force) | ||
| cards = cursor.fetchall() | ||
|
Author
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. Useless variable definition |
||
| return cards | ||
|
|
||
|
|
||
| def get_cards(force=False): | ||
| return _get_data('cards', CARDS_FILE, force) | ||
| @connection.connection_handler | ||
| def get_cards(cursor): | ||
| cursor.execute("""SELECT id, board_id, title, status_id, card_order FROM card; | ||
| """) | ||
|
|
||
| cards = cursor.fetchall() | ||
| print(cards) | ||
|
Author
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. printing in production code? |
||
| return cards | ||
|
|
||
|
|
||
| @connection.connection_handler | ||
| def add_new_board(cursor, board_title): | ||
| cursor.execute("""INSERT INTO board (title) VALUES (%(board_title)s); | ||
| """, | ||
| {'board_title': board_title}) | ||
|
|
||
|
|
||
| @connection.connection_handler | ||
| def add_new_card(cursor, card_title, board_id, status_id): | ||
| cursor.execute(""" | ||
| INSERT INTO card (title, board_id, status_id) VALUES (%(card_title)s, %(board_id)s, %(status_id)s); | ||
| """, | ||
| {'card_title': card_title, | ||
| 'board_id': board_id, | ||
| 'status_id': status_id}) | ||
|
|
||
|
|
||
| @connection.connection_handler | ||
| def delete_board(cursor, board_id): | ||
| cursor.execute(""" | ||
| DELETE FROM card | ||
| WHERE board_id = %(board_id)s; | ||
|
|
||
| DELETE FROM board | ||
| WHERE id = %(board_id)s; | ||
| """, | ||
| {'board_id': board_id}) | ||
|
|
||
|
|
||
| @connection.connection_handler | ||
| def delete_card(cursor, id): | ||
| cursor.execute(""" | ||
| DELETE FROM card | ||
| WHERE id = %(id)s; | ||
| """, | ||
| {'id': id}) | ||
|
|
||
|
|
||
| @connection.connection_handler | ||
| def change_status(cursor, id, status_id): | ||
| cursor.execute(""" | ||
| UPDATE card | ||
| SET status_id = %(status_id)s | ||
| WHERE id = %(id)s; | ||
| """, {'id': id, 'status_id': status_id}) | ||
|
|
||
|
|
||
| @connection.connection_handler | ||
| def rename_board(cursor, board_id, title): | ||
| cursor.execute(""" | ||
| UPDATE board | ||
| SET title = %(title)s | ||
| WHERE id = %(board_id)s; | ||
| """, | ||
| {'board_id': board_id, | ||
| 'title': title}) | ||
|
|
||
|
|
||
| @connection.connection_handler | ||
| def addNewUser(cursor, username, password): | ||
| cursor.execute(""" | ||
| INSERT INTO users (username, password) VALUES(%(username)s, %(password)s); | ||
| """, | ||
| {'username': username, 'password': password}) | ||
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.
Useless variable definition