Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Add export functionality to the webapp

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

0 comments on commit 0073bfa

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