Yuvipanda has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/273030

Change subject: Add ability to 'fork' a Query
......................................................................

Add ability to 'fork' a Query

Just sets up a new query with the same text as current one.

Change-Id: Iff66ac232158731e0c1f622e8e5cb3289ec9613c
---
M quarry/web/app.py
M quarry/web/models/query.py
M quarry/web/static/css/query/view.css
M quarry/web/templates/query/view.html
4 files changed, 53 insertions(+), 7 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/analytics/quarry/web 
refs/changes/30/273030/1

diff --git a/quarry/web/app.py b/quarry/web/app.py
index 6212b3b..725da24 100644
--- a/quarry/web/app.py
+++ b/quarry/web/app.py
@@ -126,6 +126,26 @@
     g.conn.session.commit()
     return redirect(url_for('query_show', query_id=query.id))
 
[email protected]("/fork/<int:id>")
+def fork_query(id):
+    if get_user() is None:
+        return redirect("/login?next=fork/{id}".format(id=id))
+    query = Query()
+    query.user = get_user()
+    parent_query = g.conn.session.query(Query).filter(Query.id == id).one()
+    query.title = parent_query.title
+    query.parent_id = parent_query.id
+    query.description = parent_query.description
+    g.conn.session.add(query)
+    g.conn.session.commit()
+
+    query_rev = QueryRevision(query_id=query.id, 
text=parent_query.latest_rev.text)
+    query.latest_rev = query_rev
+    g.conn.session.add(query)
+    g.conn.session.add(query_rev)
+    g.conn.session.commit()
+    return redirect(url_for('query_show', query_id=query.id))
+
 
 @app.route("/query/<int:query_id>")
 def query_show(query_id):
diff --git a/quarry/web/models/query.py b/quarry/web/models/query.py
index a8b9325..c8d73bb 100644
--- a/quarry/web/models/query.py
+++ b/quarry/web/models/query.py
@@ -11,7 +11,7 @@
     user_id = Column(Integer, ForeignKey('user.id'))
     title = Column(Unicode(1024))
     last_touched = Column(DateTime)
-    parent_id = Column(Integer)
+    parent_id = Column(Integer, ForeignKey('query.id'))
     latest_rev_id = Column(Integer, ForeignKey('query_revision.id'))
     published = Column(Boolean, default=False)
     description = Column(UnicodeText)
@@ -24,6 +24,9 @@
     latest_rev = relationship('QueryRevision',
                               primaryjoin='Query.latest_rev_id == 
QueryRevision.id',
                               uselist=False)
+    parent = relationship('Query',
+                          remote_side=[id],
+                          uselist=False)
 
     def to_json(self):
         return {
diff --git a/quarry/web/static/css/query/view.css 
b/quarry/web/static/css/query/view.css
index 8beac69..06bc3a9 100644
--- a/quarry/web/static/css/query/view.css
+++ b/quarry/web/static/css/query/view.css
@@ -36,7 +36,7 @@
     border: none;
 }
 
-#title-actions-container button {
+#title-actions-container a {
     margin-top: 18px;
     float: right;
 }
diff --git a/quarry/web/templates/query/view.html 
b/quarry/web/templates/query/view.html
index afbec52..3d4c6b9 100644
--- a/quarry/web/templates/query/view.html
+++ b/quarry/web/templates/query/view.html
@@ -21,17 +21,40 @@
 {% block content %}
 <div id="content" class="container {% if jsvars.can_edit %}edit{% else 
%}no-edit{% endif %} {% if jsvars.is_starred %}starred{% endif %} {% if 
query.published %}published {% endif %}">
     <div class="row" id="title-container">
-        <div class="col-md-10">
+
+
+        <div class="col-md-12">
             <h2><input type="textbox" id="title" {% if jsvars.can_edit 
%}placeholder="Click to add title..."{% else %}readonly{% endif %} value="{% if 
query.title %}{{query.title}}{% endif %}"> </input></h2>
         </div>
+        {% if query.parent %}
+        <div class='col-md-12'>
+            <small>
+            Fork of
+            <a href='/query/{{query.parent.id}}'>
+                {% if query.parent.title %}
+                {{ query.parent.title }}
+                {% else %}
+                Untitled query #{{ query.parent.id }}
+                {% endif %}
+            </a>
+            by <a href='/{{ query.parent.user.username }}'>{{ 
query.parent.user.username }}</a>
+        </small>
+        </div>
+        {% endif %}
+
         <div class="col-md-2" id="title-actions-container">
             {% if user and not jsvars.can_edit %}
-                <button id="un-star-query" type="button" class="btn btn-info 
btn-sm only-starred">
+                <a id="un-star-query" class="btn btn-info btn-sm only-starred">
                     <span class="glyphicon glyphicon-star"></span> Unstar
-                </button>
-                <button id="star-query" type="button" class="btn btn-info 
btn-sm only-non-starred">
+                </a>
+                <a id="star-query" class="btn btn-info btn-sm 
only-non-starred">
                     <span class="glyphicon glyphicon-star-empty"></span> Star
-                </button>
+                </a>
+            {% endif %}
+            {% if not jsvars.can_edit %}
+            <a id="fork-query" href="/fork/{{ query.id }}"class="btn btn-info 
btn-sm">
+                Fork
+            </a>
             {% endif %}
         </div>
     </div>

-- 
To view, visit https://gerrit.wikimedia.org/r/273030
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Iff66ac232158731e0c1f622e8e5cb3289ec9613c
Gerrit-PatchSet: 1
Gerrit-Project: analytics/quarry/web
Gerrit-Branch: master
Gerrit-Owner: Yuvipanda <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to