<reponame>manav2994/MALT-Malware-Analysis-Literature-survey-Tool<gh_stars>1-10
from django.shortcuts import render
from django.db import models
from django.http import HttpResponse
import django_tables2 as tables
#import MySQLdb
import datetime
import pytz
from django_tables2.config import RequestConfig
import itertools
from django.db import connection
from djqscsv import render_to_csv_response
import psycopg2
import os


##### Modify with your database here #####
#db = psycopg2.connect(host = "localhost", user = "postgres", password = "<PASSWORD>", database = "forensics")
DATABASE_URL = os.environ['DATABASE_URL']
db = psycopg2.connect(DATABASE_URL, sslmode='require')

cursor = db.cursor()
cursor.execute("SET SCHEMA '{}'".format('forensics'))
sqlcmd2 = "SET search_path TO forensics;"
cursor.execute(sqlcmd2)
print('Switched')
#author_id = cursor.fetchone()
#print("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% ", author_id)
category_list = ['All', 'DIMVA', 'USENIX Security Symposium ', 'RAID', 'KDD', 'COMPSAC Workshops', 'IEEE Trans. Information Forensics and Security', 'ACM Conference on Computer and Communications Security', 'ACSAC','Comput. Secur.',  'J. Comput. Virol. Hacking Tech.','MALWARE', 'BADGERS@EuroSys', 'Comput. Secur.', 'Internet Measurement Conference']

#changed from ppaers to forensics
class forensics(models.Model):
    citation = models.CharField(max_length=10, blank=True, null=True)
    title = models.CharField(max_length=150, blank=True, null=True)
    year = models.CharField(max_length=20, blank=True, null=True)
    venue = models.CharField(max_length=20, blank=True, null=True)
    abstract = models.CharField(max_length=400, blank=True, null=True)
    url = models.CharField(max_length=2, blank=True, null=True)

    class Meta:
        db_table = "papers"



class papersTable(tables.Table):
    id = tables.Column(verbose_name="id", empty_values=(), orderable=False)
    citation = tables.Column(verbose_name="Citations")
    #url = tables.Column(verbose_name="Url")
    venue = tables.Column(verbose_name="Venue")
    title = tables.Column(verbose_name="Title")
    year = tables.Column(verbose_name="Year")
    #abstract = tables.Column(verbose_name="Abstract")


    def render_counter(self):
        self.row_counter = getattr(self, 'row_counter', itertools.count(1))
        return next(self.row_counter)

    class Meta:
        model = forensics
        #^ changed from papers to forensics   print('DEbug--------------------------------------------------------------------')
        attrs = {
            "class": "info-table",
        }
        fields = ("id", "title","venue", "year", "citation")


def to_render(html_render, data, table):
    html_render['table'] = table
    html_render['category_list'] = category_list


def table_show(request):
    data = forensics.objects.all()
    data = data.values("id", "title","venue", "year", "citation")
    table = papersTable(data)
    #print(table.model)
    RequestConfig(request, paginate={'per_page': 100}).configure(table)

    html_render = {}
    to_render(html_render, data, table)
    return render(request, "index.html", html_render)


# rendering "Search by Title"
def papers_search(request):
    data = forensics.objects.all()
    html_render = {}

    data = data.filter(models.Q(id__icontains=request.GET['keywd_input']))
    data = data.values("id", "title","venue", "year", "citation")
    table = papersTable(data)  # , order_by="-time")
    RequestConfig(request, paginate={'per_page': 100}).configure(table)
    to_render(html_render, data, table)
    html_render['keywd_input'] = request.GET['keywd_input']

    return render(request, "index.html", html_render)


# rendering "Filter"
def papers_filter(request):
    data = forensics.objects.all()
    html_render = {}

    if request.GET['filter_category'] == 'All':
        pass
    else:
        data = data.filter(models.Q(venue__icontains=request.GET['filter_category']))

    data = data.values("id", "title","venue", "year", "citation")
    table = papersTable(data)
    RequestConfig(request, paginate={'per_page': 100}).configure(table)
    to_render(html_render, data, table)
    html_render['filter_category'] = request.GET['filter_category']

    return render(request, "index.html", html_render)


def download_excel(requst):
    data = forensics.objects.all()
    print(type(data))
    data = data.values("id", "title","venue", "year", "citation", "abstract", "url")
    print(type(data))
    return render_to_csv_response(data, filename="table_download.csv")

from django.shortcuts import render
from django.db import models
from django.http import HttpResponse
import django_tables2 as tables
#import MySQLdb
import datetime
import pytz
from django_tables2.config import RequestConfig
import itertools
from django.db import connection
from djqscsv import render_to_csv_response
import psycopg2
import os


##### Modify with your database here #####
#db = psycopg2.connect(host = "localhost", user = "postgres", password = "<PASSWORD>", database = "forensics")
DATABASE_URL = os.environ['DATABASE_URL']
db = psycopg2.connect(DATABASE_URL, sslmode='require')

cursor = db.cursor()
cursor.execute("SET SCHEMA '{}'".format('forensics'))
sqlcmd2 = "SET search_path TO forensics;"
cursor.execute(sqlcmd2)
print('Switched')
#author_id = cursor.fetchone()
#print("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% ", author_id)
category_list = ['All', 'DIMVA', 'USENIX Security Symposium ', 'RAID', 'KDD', 'COMPSAC Workshops', 'IEEE Trans. Information Forensics and Security', 'ACM Conference on Computer and Communications Security', 'ACSAC','Comput. Secur.',  'J. Comput. Virol. Hacking Tech.','MALWARE', 'BADGERS@EuroSys', 'Comput. Secur.', 'Internet Measurement Conference']

#changed from ppaers to forensics
class forensics(models.Model):
    citation = models.CharField(max_length=10, blank=True, null=True)
    title = models.CharField(max_length=150, blank=True, null=True)
    year = models.CharField(max_length=20, blank=True, null=True)
    venue = models.CharField(max_length=20, blank=True, null=True)
    abstract = models.CharField(max_length=400, blank=True, null=True)
    url = models.CharField(max_length=2, blank=True, null=True)

    class Meta:
        db_table = "papers"



class papersTable(tables.Table):
    id = tables.Column(verbose_name="id", empty_values=(), orderable=False)
    citation = tables.Column(verbose_name="Citations")
    #url = tables.Column(verbose_name="Url")
    venue = tables.Column(verbose_name="Venue")
    title = tables.Column(verbose_name="Title")
    year = tables.Column(verbose_name="Year")
    #abstract = tables.Column(verbose_name="Abstract")


    def render_counter(self):
        self.row_counter = getattr(self, 'row_counter', itertools.count(1))
        return next(self.row_counter)

    class Meta:
        model = forensics
        #^ changed from papers to forensics   print('DEbug--------------------------------------------------------------------')
        attrs = {
            "class": "info-table",
        }
        fields = ("id", "title","venue", "year", "citation")


def to_render(html_render, data, table):
    html_render['table'] = table
    html_render['category_list'] = category_list


def table_show(request):
    data = forensics.objects.all()
    data = data.values("id", "title","venue", "year", "citation")
    table = papersTable(data)
    #print(table.model)
    RequestConfig(request, paginate={'per_page': 100}).configure(table)

    html_render = {}
    to_render(html_render, data, table)
    return render(request, "index.html", html_render)


# rendering "Search by Title"
def papers_search(request):
    data = forensics.objects.all()
    html_render = {}

    data = data.filter(models.Q(id__icontains=request.GET['keywd_input']))
    data = data.values("id", "title","venue", "year", "citation")
    table = papersTable(data)  # , order_by="-time")
    RequestConfig(request, paginate={'per_page': 100}).configure(table)
    to_render(html_render, data, table)
    html_render['keywd_input'] = request.GET['keywd_input']

    return render(request, "index.html", html_render)


# rendering "Filter"
def papers_filter(request):
    data = forensics.objects.all()
    html_render = {}

    if request.GET['filter_category'] == 'All':
        pass
    else:
        data = data.filter(models.Q(venue__icontains=request.GET['filter_category']))

    data = data.values("id", "title","venue", "year", "citation")
    table = papersTable(data)
    RequestConfig(request, paginate={'per_page': 100}).configure(table)
    to_render(html_render, data, table)
    html_render['filter_category'] = request.GET['filter_category']

    return render(request, "index.html", html_render)


def download_excel(requst):
    data = forensics.objects.all()
    print(type(data))
    data = data.values("id", "title","venue", "year", "citation", "abstract", "url")
    print(type(data))
    return render_to_csv_response(data, filename="table_download.csv")
#import MySQLdb ##### Modify with your database here ##### #db = psycopg2.connect(host = "localhost", user = "postgres", password = "<PASSWORD>", database = "forensics") #author_id = cursor.fetchone() #print("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% ", author_id) #changed from ppaers to forensics #url = tables.Column(verbose_name="Url") #abstract = tables.Column(verbose_name="Abstract") #^ changed from papers to forensics   print('DEbug--------------------------------------------------------------------') #print(table.model) # rendering "Search by Title" # , order_by="-time") # rendering "Filter"