# Path: kraut_parser/models.py
# class Observable(models.Model):
#     name = models.CharField(max_length=255)
#     creation_time = models.DateTimeField(auto_now_add=True)
#     last_modified = models.DateTimeField(auto_now=True)
#     description = models.TextField(null=True, blank=True)
#     short_description = models.CharField(max_length=255, null=True, blank=True)
#     namespace = models.ManyToManyField('Namespace', blank=True)
#     indicators = models.ManyToManyField(Indicator, blank=True)
#     compositions = models.ManyToManyField(ObservableComposition, blank=True)
#     observable_type = models.CharField(max_length=255, null=True, blank=True)
#     observable_id = models.CharField(max_length=255, unique=True)
# 
#     def __unicode__(self):
#         return u"%s" % (self.name)
# 
# class File_Object(models.Model):
#     file_meta = models.ManyToManyField(File_Meta_Object, blank=True)
#     file_custom = models.ManyToManyField(File_Custom_Properties, blank=True)
#     md5_hash = models.CharField(max_length=32, null=True, blank=True)
#     sha256_hash = models.CharField(max_length=64, null=True, blank=True)
#     observables = models.ManyToManyField(Observable)
# 
#     def __unicode__(self):
#         if self.md5_hash:
#             return u"%s" % (self.md5_hash)
#         elif self.sha256_hash:
#             return u"%s" % (self.sha256_hash)
#         else:
#             return u"File Object"
# 
#     class Meta:
#         index_together = (("md5_hash", "sha256_hash"),)


from django.http import HttpResponse
from rest_framework import status
from django.db.models import Prefetch, Q
from django.shortcuts import render
from django.contrib.auth.decorators import login_required
from kraut_parser.models import Observable, File_Object
# vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4



# Create your views here.

@login_required
def base_search(request):
    context = {'sterm': None, 'result': []}
    if not request.method == 'POST':
        return HttpResponse(status=status.HTTP_400_BAD_REQUEST)
    sterm = request.POST.get('searchbar', None)
    context['sterm'] = sterm
    ### search observable objects

# Path: kraut_parser/models.py
# class Observable(models.Model):
#     name = models.CharField(max_length=255)
#     creation_time = models.DateTimeField(auto_now_add=True)
#     last_modified = models.DateTimeField(auto_now=True)
#     description = models.TextField(null=True, blank=True)
#     short_description = models.CharField(max_length=255, null=True, blank=True)
#     namespace = models.ManyToManyField('Namespace', blank=True)
#     indicators = models.ManyToManyField(Indicator, blank=True)
#     compositions = models.ManyToManyField(ObservableComposition, blank=True)
#     observable_type = models.CharField(max_length=255, null=True, blank=True)
#     observable_id = models.CharField(max_length=255, unique=True)
# 
#     def __unicode__(self):
#         return u"%s" % (self.name)
# 
# class File_Object(models.Model):
#     file_meta = models.ManyToManyField(File_Meta_Object, blank=True)
#     file_custom = models.ManyToManyField(File_Custom_Properties, blank=True)
#     md5_hash = models.CharField(max_length=32, null=True, blank=True)
#     sha256_hash = models.CharField(max_length=64, null=True, blank=True)
#     observables = models.ManyToManyField(Observable)
# 
#     def __unicode__(self):
#         if self.md5_hash:
#             return u"%s" % (self.md5_hash)
#         elif self.sha256_hash:
#             return u"%s" % (self.sha256_hash)
#         else:
#             return u"File Object"
# 
#     class Meta:
#         index_together = (("md5_hash", "sha256_hash"),)


# Path: kraut_search/views.py
from django.http import HttpResponse
from rest_framework import status
from django.db.models import Prefetch, Q
from django.shortcuts import render
from django.contrib.auth.decorators import login_required
from kraut_parser.models import Observable, File_Object

# vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4



# Create your views here.

@login_required
def base_search(request):
    context = {'sterm': None, 'result': []}
    if not request.method == 'POST':
        return HttpResponse(status=status.HTTP_400_BAD_REQUEST)
    sterm = request.POST.get('searchbar', None)
    context['sterm'] = sterm
    ### search observable objects

    queryset = Observable.objects.filter(