Terrrydactyl has uploaded a new change for review.

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

Change subject: [WIP] Add ability to tag a cohort
......................................................................

[WIP] Add ability to tag a cohort

Change-Id: I4b1a6810d4ad11f4a4cef4f9ed5b3de6603266eb
---
A 
database_migrations/versions/2f1dcf6b94a9_added_tag_and_cohort_tag_databases.py
M wikimetrics/controllers/cohorts.py
A wikimetrics/models/cohort_tag.py
A wikimetrics/models/tag.py
M wikimetrics/static/js/cohortList.js
M wikimetrics/templates/cohorts.html
6 files changed, 120 insertions(+), 1 deletion(-)


  git pull ssh://gerrit.wikimedia.org:29418/analytics/wikimetrics 
refs/changes/91/133091/1

diff --git 
a/database_migrations/versions/2f1dcf6b94a9_added_tag_and_cohort_tag_databases.py
 
b/database_migrations/versions/2f1dcf6b94a9_added_tag_and_cohort_tag_databases.py
new file mode 100644
index 0000000..58b4d81
--- /dev/null
+++ 
b/database_migrations/versions/2f1dcf6b94a9_added_tag_and_cohort_tag_databases.py
@@ -0,0 +1,41 @@
+"""Added tag and cohort_tag databases
+
+Revision ID: 2f1dcf6b94a9
+Revises: 43970813b4bb
+Create Date: 2014-05-08 20:13:12.215671
+
+"""
+
+# revision identifiers, used by Alembic.
+revision = '2f1dcf6b94a9'
+down_revision = '43970813b4bb'
+
+from alembic import op
+import sqlalchemy as sa
+
+
+def upgrade():
+    ### commands auto generated by Alembic - please adjust! ###
+    op.create_table(
+        'tag',
+        sa.Column('id', sa.Integer(), nullable=False),
+        sa.Column('name', sa.String(length=50), nullable=False),
+        sa.PrimaryKeyConstraint('id')
+    )
+    op.create_table(
+        'cohort_tag',
+        sa.Column('id', sa.Integer(), nullable=False),
+        sa.Column('cohort_id', sa.Integer(), nullable=False),
+        sa.Column('tag_id', sa.Integer(), nullable=False),
+        sa.ForeignKeyConstraint(['cohort_id'], ['cohort.id'], ),
+        sa.ForeignKeyConstraint(['tag_id'], ['tag.id'], ),
+        sa.PrimaryKeyConstraint('id')
+    )
+    ### end Alembic commands ###
+
+
+def downgrade():
+    ### commands auto generated by Alembic - please adjust! ###
+    op.drop_table('tag')
+    op.drop_table('cohort_tag')
+    ### end Alembic commands ###
diff --git a/wikimetrics/controllers/cohorts.py 
b/wikimetrics/controllers/cohorts.py
index 984bff4..b1a351f 100644
--- a/wikimetrics/controllers/cohorts.py
+++ b/wikimetrics/controllers/cohorts.py
@@ -15,7 +15,7 @@
 from ..models import (
     Cohort, CohortUser, CohortUserRole,
     User, WikiUser, CohortWikiUser, MediawikiUser,
-    ValidateCohort
+    ValidateCohort, Tag
 )
 from ..exceptions import DatabaseError
 
@@ -356,3 +356,22 @@
         return json_error(e.message)
     finally:
         session.close()
+
+
+@app.route('/cohorts/<int:cohort_id>/tag/add/<string:tag>', methods=['POST'])
+def add_tag(cohort_id, tag):
+    """
+    Checks if tag exists in the tag table and then adds tag to the cohort.
+    """
+    print tag
+    session = db.get_session()
+    t = session.query(Tag).all()
+    print t
+    # try:
+    #     t = session.query(Tag).all()
+    #     print t
+    #     return json_redirect(url_for('cohorts_index'))
+    # except:
+    #     print "nope!"
+    #     return json_redirect(url_for('cohorts_index'))
+    #
diff --git a/wikimetrics/models/cohort_tag.py b/wikimetrics/models/cohort_tag.py
new file mode 100644
index 0000000..a75d1e2
--- /dev/null
+++ b/wikimetrics/models/cohort_tag.py
@@ -0,0 +1,21 @@
+from sqlalchemy import Column, Integer, ForeignKey, String
+from wikimetrics.configurables import db
+
+__all__ = ['CohortTag']
+
+
+class CohortTag(db.WikimetricsBase):
+    """
+    Represents the join table between `cohort` and `tag`
+    tables to map tags to cohorts.  Uses
+    sqlalchemy.declarative to handle db mapping
+    """
+
+    __tablename__ = 'cohort_tag'
+
+    id        = Column(Integer, primary_key=True)
+    tag_id    = Column(Integer, ForeignKey('tag.id'))
+    cohort_id = Column(Integer, ForeignKey('cohort.id'))
+
+    def __repr__(self):
+        return '<CohortTag("{0}")>'.format(self.id)
\ No newline at end of file
diff --git a/wikimetrics/models/tag.py b/wikimetrics/models/tag.py
new file mode 100644
index 0000000..2ce96c7
--- /dev/null
+++ b/wikimetrics/models/tag.py
@@ -0,0 +1,16 @@
+from sqlalchemy import Column, Integer, String
+from wikimetrics.configurables import db
+
+__all__ = ['Tag']
+
+
+class Tag(db.WikimetricsBase):
+    # TODO: Write description
+
+    __tablename__ = 'tag'
+
+    id      = Column(Integer, primary_key=True)
+    name    = Column(String(50))
+
+    def __repr__(self):
+        return '<Tag("{0}")>'.format(self.id)
\ No newline at end of file
diff --git a/wikimetrics/static/js/cohortList.js 
b/wikimetrics/static/js/cohortList.js
index 9559a94..a25d6b0 100644
--- a/wikimetrics/static/js/cohortList.js
+++ b/wikimetrics/static/js/cohortList.js
@@ -55,6 +55,17 @@
                     }))
                     .fail(site.failure);
             }
+        },
+
+        addTag: function(cohort, event){
+            console.log(cohort);
+            console.log(event);
+            console.log(cohort.tag_name());
+            $.post('/cohorts/' + cohort.id + '/tag/add/' + cohort.tag_name())
+                .done(site.handleWith(function(){
+                    site.showWarning('Something is wrong, you should be 
redirected');
+                }))
+                .fail(site.failure);
         }
     };
     
@@ -92,6 +103,7 @@
             item.total_count = ko.observable(0);
             item.validation_status = ko.observable();
             item.delete_message = ko.observable();
+            item.tag_name = ko.observable();
         });
     }
 });
diff --git a/wikimetrics/templates/cohorts.html 
b/wikimetrics/templates/cohorts.html
index a8289ca..a52bac2 100644
--- a/wikimetrics/templates/cohorts.html
+++ b/wikimetrics/templates/cohorts.html
@@ -29,6 +29,16 @@
                     <a data-bind="click: $root.deleteCohort, attr: { title: 
delete_message }"
                        class="btn btn-danger">Remove Cohort</a>
                 </div>
+                <br />
+                <br />
+                <div>
+                        <form class="navbar-form pull-left">
+                            <input data-bind= "value: tag_name, valueUpdate: 
'afterkeydown'"
+                                type="text" class="span2">
+                            <a data-bind="click: $root.addTag"
+                               class="btn">Add Tags</a>
+                        </form>
+                </div>
                 <div data-bind="if: validated_count() === total_count() && 
!validated()">
                     <hr/>
                     <p>

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I4b1a6810d4ad11f4a4cef4f9ed5b3de6603266eb
Gerrit-PatchSet: 1
Gerrit-Project: analytics/wikimetrics
Gerrit-Branch: master
Gerrit-Owner: Terrrydactyl <tcho...@gmail.com>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to