How to use the timesketch.apps.sketch.models.Sketch.objects.get function in timesketch

To help you get started, we’ve selected a few timesketch examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github google / timesketch / timesketch / apps / ui / views.py View on Github external
def explore(request, sketch_id):
    """Renders the search interface."""
    sketch = Sketch.objects.get(id=sketch_id)
    view = request.GET.get('view', 0)
    timelines = [t.timeline.datastore_index for t in sketch.timelines.all()]
    timelines = ",".join(timelines)
    context = {"timelines": timelines, "sketch": sketch, "view": view}
    return render(request, 'explore.html', context)
github google / timesketch / timesketch / apps / ui / views.py View on Github external
def views(request, sketch_id):
    """List of all saved views in a specific sketch."""
    sketch = Sketch.objects.get(id=sketch_id)
    views = SavedView.objects.filter(sketch=sketch).exclude(
        name="").order_by("created")
    context = {"sketch": sketch, "views": views}
    return render(request, 'views.html', context)
github google / timesketch / timesketch / apps / api / v1_resources.py View on Github external
def obj_get_list(self, bundle, **kwargs):
        datastore_index = bundle.request.GET['index']
        datastore_id = bundle.request.GET['id']
        sketch_id = bundle.request.GET['sketch']
        sketch = Sketch.objects.get(id=sketch_id)
        result = EventComment.objects.filter(datastore_index=datastore_index,
            datastore_id=datastore_id, sketch=sketch)
        return result
github google / timesketch / timesketch / apps / ui / views.py View on Github external
def settings(request, sketch_id):
    """Settings for a sketch."""
    sketch = Sketch.objects.get(id=sketch_id)
    context = {"sketch": sketch}
    return render(request, 'settings.html', context)
github google / timesketch / timesketch / apps / api / v1_resources.py View on Github external
def obj_create(self, bundle, **kwargs):
        datastore_index = json.loads(bundle.request.body)['data']['index']
        datastore_id = json.loads(bundle.request.body)['data']['id']
        sketch_id = json.loads(bundle.request.body)['data']['sketch']
        sketch = Sketch.objects.get(pk=sketch_id)
        body = json.loads(bundle.request.body)['data']['body']
        result = EventComment.objects.create(user=bundle.request.user,
            datastore_index=datastore_index, datastore_id=datastore_id, 
            body=body, sketch=sketch, created=utils.now())
        bundle.obj = result
        bundle.data['data']['created'] = result.created
        bundle.data['data']['user'] = {}
        bundle.data['data']['user']['first_name'] = result.user.first_name
        bundle.data['data']['user']['last_name'] = result.user.last_name
        bundle.data['data']['user']['profile'] = {}
        bundle.data['data']['user']['profile']['avatar'] = result.user.userprofile.get_avatar_url()
        datastore = DATASTORE(datastore_index)
        datastore.add_label_to_event(datastore_id, sketch_id,
            bundle.request.user.id, "__ts_comment")
        return bundle
github google / timesketch / timesketch / apps / ui / views.py View on Github external
def add_timeline(request, sketch_id):
    """Add timeline to sketch."""
    sketch = Sketch.objects.get(id=sketch_id)
    if request.method == 'POST':
        form_timelines = request.POST.getlist('timelines')
        if form_timelines:
            for timeline_id in form_timelines:
                timeline = Timeline.objects.get(id=timeline_id)
                sketch_timeline = SketchTimeline.objects.create(
                    timeline=timeline, sketch=sketch, user=request.user)
                sketch_timeline.color = sketch_timeline.generate_color()
                sketch_timeline.save()
        return redirect("/sketch/%s/timelines/" % sketch.id)
    timelines = set()
    for timeline in Timeline.objects.all():
        if not timeline in [x.timeline for x in sketch.timelines.all()]:
            if timeline.can_read(request.user):
                timelines.add(timeline)
    return render(request, 'add_timeline.html', {'sketch': sketch,
github google / timesketch / timesketch / apps / api / v1_resources.py View on Github external
def obj_create(self, bundle, **kwargs):
        req_data = json.loads(bundle.request.body)['data']
        sketch = Sketch.objects.get(id=req_data['sketch'])
        if req_data['sketch_acl'] == "public":
            sketch.make_public(bundle.request.user)
        else:
            sketch.make_private(bundle.request.user)
        return bundle
github google / timesketch / timesketch / apps / api / v1_resources.py View on Github external
def obj_get_list(self, bundle, **kwargs):
        query = bundle.request.GET['q']
        query_filter = json.loads(bundle.request.GET['filter'])
        indexes_to_search = query_filter.get("indexes")
        sketch = Sketch.objects.get(id=bundle.request.GET['sketch'])
        datastore = DATASTORE(indexes_to_search)
        result = []
        try:
            self.query_result = datastore.search(sketch.id, query, query_filter)
        except ElasticHttpNotFoundError:
            self.query_result = {'hits': {'hits': []}}

        for event in self.query_result['hits']['hits']:
            event["_source"]["req_user"] = bundle.request.user.id
            event["_source"]["sketch"] = str(sketch.id)
            result.append(DatastoreObject(initial=event))
        # Save state to an unnamed view
        SavedView.objects.create(user=bundle.request.user, sketch=sketch,
                                 query=query, filter=json.dumps(query_filter),
                                 name="")
        return result
github google / timesketch / timesketch / apps / ui / views.py View on Github external
def sketch(request, sketch_id):
    """Renders specific sketch."""  
    sketch = Sketch.objects.get(id=sketch_id)
    if not sketch.can_read(request.user):
        return HttpResponseForbidden()
    saved_views = SavedView.objects.filter(sketch=sketch).exclude(
        name="").order_by("created")
    context = {"sketch": sketch, "views": saved_views}
    return render(request, 'sketch.html', context)