-
Notifications
You must be signed in to change notification settings - Fork 41
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
Fork functionality #385
base: develop
Are you sure you want to change the base?
Fork functionality #385
Changes from 3 commits
e30eed4
e895be9
276a222
4fd6b66
7397b65
375a2c5
520fbaf
e97671f
8ad78e5
29de21c
159f0a6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
## Purpose | ||
_Describe the problem or feature in addition to a link to the issues._ | ||
|
||
Example: | ||
Fixes # . | ||
|
||
## Approach | ||
_How does this change address the problem?_ | ||
|
||
#### Open Questions and Pre-Merge TODOs | ||
- [ ] Use github checklists. When solved, check the box and explain the answer. | ||
|
||
## Learning | ||
_Describe the research stage_ | ||
|
||
_Links to blog posts, patterns, libraries or addons used to solve this problem_ | ||
|
||
#### Blog Posts | ||
- [How to Pull Request](https://github.com/flexyford/pull-request) Github Repo with Learning focused Pull Request Template. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -333,10 +333,11 @@ def delete_graph_to_group(request, group_id, graph_id): | |
|
||
|
||
def search_graphs1(request, owner_email=None, names=None, nodes=None, edges=None, tags=None, member_email=None, | ||
is_public=None, query=None, limit=20, offset=0, order='desc', sort='name'): | ||
is_public=None, is_forked=None, query=None, limit=20, offset=0, order='desc', sort='name'): | ||
sort_attr = getattr(db.Graph, sort if sort is not None else 'name') | ||
orber_by = getattr(db, order if order is not None else 'desc')(sort_attr) | ||
is_public = int(is_public) if is_public is not None else None | ||
is_forked = int(is_forked) if is_forked is not None else None | ||
|
||
if member_email is not None: | ||
member_user = users.controllers.get_user(request, member_email) | ||
|
@@ -362,6 +363,7 @@ def search_graphs1(request, owner_email=None, names=None, nodes=None, edges=None | |
owner_email=owner_email, | ||
graph_ids=graph_ids, | ||
is_public=is_public, | ||
is_forked=is_forked, | ||
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. Formatting doesnt look right. 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. Fixing it now. |
||
group_ids=group_ids, | ||
names=names, | ||
nodes=nodes, | ||
|
@@ -586,3 +588,9 @@ def add_edge(request, name=None, head_node_id=None, tail_node_id=None, is_direct | |
def delete_edge_by_id(request, edge_id): | ||
db.delete_edge(request.db_session, id=edge_id) | ||
return | ||
|
||
def add_graph_to_fork(request, forked_graph_id, parent_graph_id, owner_email): | ||
if forked_graph_id is not None and parent_graph_id is not None: | ||
db.add_fork(request.db_session, forked_graph_id, parent_graph_id, owner_email) | ||
else: | ||
raise Exception("Required Parameter is missing!") |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -126,7 +126,7 @@ def get_graph_by_id(db_session, id): | |
|
||
|
||
@with_session | ||
def find_graphs(db_session, owner_email=None, group_ids=None, graph_ids=None, is_public=None, names=None, nodes=None, | ||
def find_graphs(db_session, owner_email=None, group_ids=None, graph_ids=None, is_public=None, is_forked=None, names=None, nodes=None, | ||
edges=None, | ||
tags=None, limit=None, offset=None, order_by=desc(Graph.updated_at)): | ||
query = db_session.query(Graph) | ||
|
@@ -151,6 +151,8 @@ def find_graphs(db_session, owner_email=None, group_ids=None, graph_ids=None, is | |
options_group.append(subqueryload('nodes')) | ||
if edges is not None and len(edges) > 0: | ||
options_group.append(subqueryload(Graph.edges)) | ||
if is_forked is not None: | ||
options_group.append(joinedload(Graph.forked_graphs)) | ||
if group_ids is not None and len(group_ids) > 0: | ||
options_group.append(joinedload('shared_with_groups')) | ||
if len(options_group) > 0: | ||
|
@@ -159,6 +161,9 @@ def find_graphs(db_session, owner_email=None, group_ids=None, graph_ids=None, is | |
if group_ids is not None: | ||
query = query.filter(Graph.groups.any(Group.id.in_(group_ids))) | ||
|
||
if is_forked is not None: | ||
query = query.filter(Graph.forked_graphs.any()) | ||
|
||
edges = [] if edges is None else edges | ||
nodes = [] if nodes is None else nodes | ||
names = [] if names is None else names | ||
|
@@ -458,3 +463,9 @@ def find_edges(db_session, is_directed=None, names=None, edges=None, graph_id=No | |
query = query.limit(limit).offset(offset) | ||
|
||
return total, query.all() | ||
|
||
@with_session | ||
def add_fork(db_session, forked_graph_id, parent_graph_id, owner_email): | ||
fork = GraphFork( graph_id=forked_graph_id, parent_graph_id=parent_graph_id, owner_email=owner_email) | ||
db_session.add(fork) | ||
return 1 | ||
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. return fork object. Refer to other functions. 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. Also add python docs. Refer to other functions. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
"""add_graph_fork_table | ||
|
||
Revision ID: bdce7c016932 | ||
Revises: bb9a45e2ee5e | ||
Create Date: 2018-05-19 16:15:09.911000 | ||
|
||
""" | ||
from alembic import op | ||
import sqlalchemy as sa | ||
|
||
|
||
# revision identifiers, used by Alembic. | ||
revision = 'bdce7c016932' | ||
down_revision = 'bb9a45e2ee5e' | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
def upgrade(): | ||
pass | ||
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. Add table. 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. Fixing it. |
||
|
||
|
||
def downgrade(): | ||
op.drop_table('graph_fork') |
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.
make sure you are using pycharm editor and running auto formatting before committing the code.
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.
Looking into this issue.
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.
Fixed. Followed PEP8 conventions for all python codes.