Skip to content
Browse files

Add export functionality to the webapp

  • Loading branch information...
1 parent 591345a commit 0073bfaaaead9ea9fc7f4d1b883c12fbbedef53e @holdenk committed Jan 22, 2013
Showing with 51 additions and 10 deletions.
  1. +1 −0 frontend/unicorn/unicorn/urls.py
  2. +1 −0 frontend/unicorn/verify/models.py
  3. +14 −0 frontend/unicorn/verify/views.py
  4. +25 −0 generate_django_csv.pl
  5. +10 −10 main.pl
View
1 frontend/unicorn/unicorn/urls.py
@@ -15,5 +15,6 @@
url(r'^admin/', include(admin.site.urls)),
url(r'^$', 'verify.views.index'),
url(r'^review', 'verify.views.review'),
+ url(r'^export', 'verify.views.export'),
url(r'accounts/', include('social_auth.urls')),
)
View
1 frontend/unicorn/verify/models.py
@@ -5,6 +5,7 @@ class PatchInfo(models.Model):
diff_url=models.CharField(max_length=1000, help_text="The URL of the github diff")
target_username=models.CharField(max_length=1000, help_text="The target github user to apply the pull request to (if approved)")
message_txt=models.CharField(max_length=1000, help_text="The commit message text")
+ twitter_txt=models.CharField(max_length=200, help_text="The text for the twitter msg")
reviewer_username=models.CharField(max_length=1000, help_text="The username of the reviewer", null=True, blank=True)
good = models.BooleanField(max_length=1000, help_text="Is this patch good",
default=False)
View
14 frontend/unicorn/verify/views.py
@@ -2,10 +2,12 @@
from django.http import HttpResponse
from django.template import Context, loader
from django.contrib.auth.decorators import login_required
+from django.contrib.auth.decorators import permission_required
from models import PatchInfo
from social_auth.models import *
from django.db.models import Q
from datetime import date, timedelta, datetime
+import csv
def index(request):
t = loader.get_template("index.html")
@@ -41,3 +43,15 @@ def review(request):
newpatch = False
c = Context({'ghusername' : githubusername, 'patch': patch, 'newpatch': newpatch, 'reviewlink': reviewlink, 'id': id})
return HttpResponse(t.render(c))
+
+@permission_required('verify.export')
+def export(request):
+ patches = PatchInfo.objects.filter(good=True,examined=True,exported=False)
+ response = HttpResponse(mimetype='text/csv')
+ response['Content-Disposition'] = 'attachment; filename="approved_patches.csv"'
+ writer = csv.writer(response)
+ writer.writerow(['diff_url','target_username','message_txt','twitter_txt','good'])
+ for patch in patches:
+ writer.writerow([patch.diff_url,patch.target_username,patch.message_txt,patch.twitter_txt,patch.good])
+ patches.update(exported=True)
+ return response
View
25 generate_django_csv.pl
@@ -0,0 +1,25 @@
+# Generate the import file for our frontend
+use strict;
+use warnings;
+my $out;
+my $batchsize = 100;
+my $batchnum = 0;
+while (-f "django_export/".$batchnum.".csv") {
+ $batchnum++;
+}
+open ($out, ">django_export/".$batchnum.".csv");
+print $out "diff_url,message_txt,target_username\n";
+my $urlcount = 0;
+#hitinfo should contain url,msg,ruser
+while ($hitinfo = <>) {
+ $urlcount++;
+ chomp ($hitinfo);
+ print $out "$hitinfo\n";
+ if ($urlcount % $batchsize == 0) {
+ close ($out);
+ $batchnum++;
+ open ($out, ">django_export/".$batchnum.".csv");
+ print $out "diff_url,message_txt,twitter_txt,target_username\n";
+ }
+}
+close ($out);
View
20 main.pl
@@ -20,19 +20,19 @@ ()
my $testin = IO::Handle->new();
print "($bingin,$ghin,$bqin)\n";
-# open ($bingin , "perl targets.pl|");
-# open ($ghin, "perl targets2.pl|");
-# open ($bqin, "perl bigquerytargets.pl|");
-# open ($gharchivein , "perl gharchive.pl|");
- open ($testin, "cat testin|");
+ open ($bingin , "perl targets.pl|");
+ open ($ghin, "perl targets2.pl|");
+ open ($bqin, "perl bigquerytargets.pl|");
+ open ($gharchivein , "perl gharchive.pl|");
+ #open ($testin, "cat testin|");
# We only run the fixing on one local machine
open($fixstuff, "|perl fix_pandas.pl");
my $s = IO::Select->new();
-# $s->add($bingin);
-# $s->add($ghin);
-# $s->add($bqin);
-# $s->add($gharchivein);
- $s->add($testin);
+ $s->add($bingin);
+ $s->add($ghin);
+ $s->add($bqin);
+ $s->add($gharchivein);
+ #$s->add($testin);
while (my @ready = $s->can_read()) {
foreach my $fh (@ready) {
print "reading from $fh\n";

0 comments on commit 0073bfa

Please sign in to comment.
Something went wrong with that request. Please try again.