Commits

Richard Gerkin committed b5bfab2

Fixes

  • Participants
  • Parent commits 3f6a7ca

Comments (0)

Files changed (12)

     page = urlopen(url)
     return json.load(page)
 
-def update_repos(force_clone=False):
+def get_repos(force_clone=False,pull=True):
     forks = get_scidash_forks()
+    repos = []
     for fork in forks: 
         repo,created = m.Repo.objects.get_or_create(github_id=fork['id'])
         repo.name = fork['name']
         repo.owner = fork['owner']['login']
+        repo.owner_url = fork['owner']['html_url']
         repo.url = fork['html_url']
+        repo.watchers_count = fork['watchers_count']
         repo.save()
         if created or force_clone:
             repo.clone()
-        else:
+        elif pull is True:
             repo.pull()
+        repos.append(repo)
+    return repos
 
+def list_repos():
+    return get_repos(pull=False)
+
+
 
 class Repo(SciDash,m.Model):
     github_id = m.BigIntegerField()
+    url = m.CharField(max_length=100)
     owner = m.CharField(max_length=50)
-    url = m.CharField(max_length=100)
+    owner_url = m.CharField(max_length=100)
+    followers = m.ManyToManyField(User) # Followers on SciDash (not on Github)
 
     @property
     def gittle_url(self):
         abstract = False
         app_label = 'scidash'
         verbose_name_plural = "Capabilities"
+    repo = m.ForeignKey('Repo')
     dependencies=m.ManyToManyField('self',null=True,blank=True)
     def __str__(self):
         return u'%s' % self.name

templates/scidash/base.html

 	  		</div>
 	  	  	<div class="row"> <!-- Footer -->	
 	  	  		<br>	 
-			  	<div class='span2 offset4'>
+			  	<div class='span3 offset3'>
+			  	  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 			  	  {% if not request.user.is_anonymous %}
 					<a class='btn btn-primary btn-large' href="{% url 'fantasci.views.logout' %}?next={{ request.path }}">Logout</a>
 			  	  {% else %}
 					<a class='btn btn-large btn-primary' href="{% url 'fantasci.views.login' %}?next={{ request.path }}">Login</a>
 				  {% endif %}	  
 				</div>	
-			  	<div class='span2 offset1'>
+			  	<div class='span3 offset1'>
 			  		<a class='btn btn-primary btn-large' href="/scidash/contact">
 						Contact
 					</a>
 				<div class='span4 offset4'
 				<small>
 			  	  {% if not request.user.is_anonymous %}
-					Logged in as <b>{{request.user.first_name}} {{request.user.last_name}} ({{ request.user.username }})</b>
+					<br>Logged in as <b>{{request.user.first_name}} {{request.user.last_name}} ({{ request.user.username }})</b>
 					<br>
 				  {% endif %}
 			  		<br>Created 2012-2013 <a href='http://github.com/scidash'>SciDash</a>
 {% endblock %}    
 </html>
 
+<script>
+	function csrfSafeMethod(method) {
+    	// these HTTP methods do not require CSRF protection
+    	return (/^(GET|HEAD|OPTIONS|TRACE)$/.test(method));
+		}
+	
+	function sameOrigin(url) {
+	    // test that a given url is a same-origin URL
+	    // url could be relative or scheme relative or absolute
+	    var host = document.location.host; // host + port
+	    var protocol = document.location.protocol;
+	    var sr_origin = '//' + host;
+	    var origin = protocol + sr_origin;
+	    // Allow absolute or scheme relative URLs to same origin
+	    return (url == origin || url.slice(0, origin.length + 1) == origin + '/') ||
+	        (url == sr_origin || url.slice(0, sr_origin.length + 1) == sr_origin + '/') ||
+	        // or any other URL that isn't scheme relative or absolute i.e relative.
+	        !(/^(\/\/|http:|https:).*/.test(url));
+		}
+
+	var csrftoken = jQuery.cookie('csrftoken');
+
+	$.ajaxSetup({
+    	beforeSend: function(xhr, settings) {
+        	if (!csrfSafeMethod(settings.type) && sameOrigin(settings.url)) {
+	            // Send the token to same-origin, relative URLs only.
+	            // Send the token only if the method warrants CSRF protection
+	            // Using the CSRFToken value acquired earlier
+	            xhr.setRequestHeader("X-CSRFToken", csrftoken);
+	        	}
+	    	}
+		});
+</script>
+

templates/scidash/capability_list.html

 <div align=center><input name='add_model' value='Add a Model' type=submit></div>
 </form>
 {% endif %}
-<table align=center width=100% caption='Models' id='models'>
+<table align=center width=100% caption='Capabilities' id='capabilities'>
   <thead>
     <tr>
       <th>Name</th>
-      <th>Publication</th>
-      <th>Capabilities</th>
-      <th>Tests<br>Passed</th>
-      <th>Tests<br>Failed</th>
-      <th>Tests<br>Queued</th>
+      <th>Requirements</th>
+      <th># Models</th>
+      <th># Tests</th>
     </tr>
   </thead>
   <tbody>
-    {% for model in models %}
+    {% for capability in capabilities %}
     <tr>
-      <td><a href='/scidash/models/{{ model.id }}'>{{ model.name }}</a></td>
-      <td>{{ model.publication }}</td>
-      <td width=250><ul>{% for capability in model.capabilities.all %}<li>{{ capability }}{% endfor %}</ul></td>
-      <td>{{ model.nPassed }}</td>
-      <td>{{ model.nFailed }}</td>
-      <td>{{ model.nQueued }}</td>
+      <td><a href='/scidash/capabilities/{{ capability.id }}'>{{ capability.name }}</a></td>
+      <td width=250>
+       {% if capability.requirements.all %}
+        <ul>
+         {% for requirement in capability.requirements.all %}
+          <li>{{ requirement }}</li>
+         {% endfor %}
+        </ul>
+       {% endif %}
+      </td>
+      <td>{{ capability.model_set.all|length }}</td>
+      <td>{{ capability.test_set.all|length }}</td>
     </tr>
     {% endfor %}
   </tbody>
 
 <script language="javascript" type="text/javascript">
 $(document).ready(function() {
-        modelsTable = $('#models').dataTable();
+        capabilitiesTable = $('#capabilities').dataTable();
         }
     );    
 </script>

templates/scidash/community.html

 </style>
 <div class='row' style='align:center'>
 	<span class='span8' style='padding-left:30px;'>
-	<table align=center>
-		<tr>
-			<th class='lead'>Repository Name</th>
-			<th class='lead'>Maintainer</th>
-			<th class='lead'>Watchers</th>
-	  {% for fork in forks %}
-		<tr>
-			<td>
-				<a href='/scidash/repo/{{fork.id}}'>{{ fork.name }}</a>
-			</td>
-			<td>
-				<a href='{{ fork.owner.html_url}}'>{{ fork.owner.login }}</a>
-			</td>
-			<td style='text-align:center'>
-				<a class='btn btn-medium btn-info' href='{{ fork.html_url }}'>{{ fork.watchers_count }}</a>
-			</td>
-			<td style='text-align:center'>
-				
-			</td>
-		</tr>
-	  {% endfor %}
-	</table>
+	  {% include "scidash/repo_list.html" %}
 	</span>
 	<span class='span4' style='align:center;padding-right:10px;'>
 	  {% include "scidash/twitter.html" %}
+	  <br><br>
 	</span>
 </div>
 {% endblock %}

templates/scidash/docs.html

 {% extends "scidash/base.html" %}
 
 {% block content %}
-<table width='800px' align=center><tr><td>
-<h3>The paper for SciUnit is available <a href='http://goo.gl/PLoIOR' style='text-decoration:underline'>here</a><br><br>
-Code for the SciUnit framework is available <a href=https://github.com/scidash/sciunit style='text-decoration:underline'>here</a><br></h3>
+<style>
+    a.border {
+        padding: 5px; 
+        border: 2px solid #000;
+    }
+</style>
 <br>
+<div class='row' style='text-align:justify;padding-left:20px;'>
+    <h3>
+    <div class='span3 offset3'>
+        <a href='http://goo.gl/PLoIOR' class='border'>
+            The Paper
+        </a>
+    </div>
+    <div class='span3 offset1'>
+        <a href='https://github.com/scidash/sciunit' class='border'>
+            The Code
+        </a>
+    </div>
+    </h3>
+<div>
+<br><br><br><br>
 <table width=100% cellpadding="5" cellspacing="5" id=glossary>
 <thead>
 <tr><th width=100px>Term</th><th>Definition</th></tr>

templates/scidash/profile.html

 {% extends "scidash/base.html" %}
 
 {% block content %}
-<br>
-<table align=center width='800 px'><tr><td>
-{% include "scidash/test_list.html" %}
-<br><hr width='100%'><br>
-{% include "scidash/model_list.html" %}
-</td></tr></table>
+<div class='row' style='text-align:center'>
+	<h3>
+		<!--My SciDash Suite Repositories-->
+	</h3>
+</div>
+<style>
+	th,td {
+		font-size:150%;
+		padding:5px 25px;
+		text-align:center;
+	}
+</style>
+<div class='row' style='align:center'>
+	<span class='span12' style='padding-left:30px;'>
+	  {% include "scidash/repo_list.html" %}
+	</span>
+</div>
 {% endblock %}

templates/scidash/repo.html

 {% endblock %}
 
 {% block content %}
-<h3 align='center'>{{ repo.owner }}/{{ repo.name }}</h3>
+<h3 align='center'>
+	{{ repo.owner }}/{{ repo.name }}
+  {% if request.user in repo.followers.all %} 
+	<button id='unfollow' class='btn btn-medium'><b>Unfollow</b></button>
+  {% else %}
+    <button id='follow' class='btn btn-medium'><b>Follow</b></button>
+  {% endif %}
+	</b>
+</h3>
 <div class='row'>
 	<span class='span6 offset3'>
 		<ul class="nav nav-pills">
    	$('#'+name).show();
 	}
 
+function follow(follow,repo_github_id,user_id) {
+	if( follow ) {
+		un = ''
+	}
+	else {
+		un = 'un'
+	}
+	$.post('/scidash/repo/'+repo_github_id+'/'+un+'follow/', 
+        {
+            'user_id':user_id,
+        }, 
+        function(result) {
+            if(result == 'Success') {
+                location.reload();
+            }
+            else {
+                alert(result);
+                }
+            }
+   		);
+   }
+
 $(document).ready(function() {
 	$('.tab_content').hide();
    	$('#record_matrix').show();    
     $('.tab_button').click(
     	function() {show_tab($(this).attr('id'))}
 		)
-	})
+   	$('#follow').click( function() {follow(true,{{repo.github_id}},{{request.user.id}})} );
+   	$('#unfollow').click( function() {follow(false,{{repo.github_id}},{{request.user.id}})} );
+   })
 </script>
 {% endblock %}
 

templates/scidash/repo_list.html

+<table align=center>
+	<tr>
+		<th class='lead'>Repository Name</th>
+		<th class='lead'>Maintainer</th>
+		<th class='lead'>Watchers</th>
+  {% for repo in repos %}
+  {% if community or request.user in repo.followers.all %}
+	<tr>
+		<td>
+			<a href='/scidash/repo/{{repo.github_id}}'>{{ repo.name }}</a>
+		</td>
+		<td>
+			<a href='{{ repo.owner_url}}'>{{ repo.owner }}</a>
+		</td>
+		<td style='text-align:center'>
+			<a class='btn btn-medium btn-info' href='{{ repo.url }}'>{{ repo.watchers_count }}</a>
+		</td>
+		<td style='text-align:center'>
+			
+		</td>
+	</tr>
+  {% endif %}
+  {% endfor %}
+</table>
 django.core.management.setup_environ(settings)
 
 import scidash.models as m
-from scidash.github import get_repos
+import scidash.github as github
 
 def main():
-	get_repos() # Get a list of SciDash forks from GitHub 
+	github.get_repos() # Get a list of SciDash forks from GitHub 
 				# Clone them if they do not yet exist.
 				# Pull and update if they do.     
 	index_repos() # Add their contents to the database.  
 
 def test_repos():
 	repos = stored_repos()
-    for repo in repos:
-    	test_repo(repo)
+	for repo in repos:
+		test_repo(repo)
 
 def test_repo(repo):
 	modelz = repo.source_models()
-    suites = repo.source_suites()
+	suites = repo.source_suites()
 	for model in modelz:
 		print '\r'
 		print 'For model %s...' % model.name
     url(r'^tests/create/$', 'test_create'),
     url(r'^models/add/$', 'model_add'),
     url(r'^repo/(?P<github_id>\d+)/$', 'repo_summary'),
+    url(r'^repo/(?P<github_id>\d+)/follow/$', 'repo_follow'),
+    url(r'^repo/(?P<github_id>\d+)/unfollow/$', 'repo_unfollow'),
+    url(r'^contact/$', 'contact'),
 )
 
 urlpatterns += patterns('django.views.generic.simple',
 def index(request):
     return render_it(request,TEMPLATE_DIR+'/index.html',locals())
     
+def contact(request):
+    return render_it(request,TEMPLATE_DIR+'/contact.html',locals())
+
 def docs(request):
     try:
         search = request.GET['search']
     return render_it(request,TEMPLATE_DIR+'/docs.html',locals())
     
 def community(request):
-    forks = u.get_scidash_forks()
+    repos = u.github.list_repos()
+    print repos
     models = m.Model.objects.all()
     tests = m.Test.objects.all()
     for i,model in enumerate(models):
         test.nPassed = records.filter(passed=True).count()
         test.nFailed = records.filter(passed=False).count()
         test.nQueued = 0
+    community = True
     return render_it(request,TEMPLATE_DIR+'/community.html',locals())
 
 def repo_summary(request,github_id):
     tabs += [('test_list','Tests'),('suite_list','Suites'),('record_list','Records')]
     models = repo.model_set.all()
     tests = repo.test_set.all()
+    capabilities = repo.capability_set.all()
     for model in models:
         model.records = model.record_set.all()
         for record in model.records:
 def profile(request,user_id):
     user = m.User.objects.get(id=user_id)
     mine = (user.email == request.user.email) # If this person is viewing their own profile: 
+    repos = u.github.list_repos()
     return render_it(request,TEMPLATE_DIR+'/profile.html',locals())
     
 @login_required(login_url='/scidash/login')
 def test_create(request):
     pass    
 
+def repo_follow_unfollow(request,repo_github_id,follow):
+    user_id = request.POST['user_id']
+    try:
+        user = m.User.objects.get(id=user_id)
+    except:
+        return HttpResponse("No such user %d" % user_id)
+    repo = m.Repo.objects.get(github_id=repo_github_id)
+    if follow:
+        repo.followers.add(user)
+    else:
+        repo.followers.remove(user)
+    print follow,repo,user
+    repo.save()
+    return HttpResponse('Success')
+
+def repo_unfollow(request,github_id):
+    print "Unfollow"
+    return repo_follow_unfollow(request,github_id,False)
+
+def repo_follow(request,github_id):
+    print "Follow"
+    return repo_follow_unfollow(request,github_id,True)
+
 def baseDict(request,options={}):
     s = settings
     if 'refresh' in options: