Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def setUp(self):
self.user1 = User.objects.create(username="testuser1")
self.user2 = User.objects.create(username="testuser2")
self.sketch1 = Sketch.objects.create(
user=self.user1, title="testsketch1")
self.sketch2 = Sketch.objects.create(
user=self.user1, title="testsketch2")
SavedView.objects.create(
user=self.user1, sketch=self.sketch2, query="", filter="")
self.sketch1.make_public(self.user1)
self.sketch2.make_private(self.user1)
def obj_create(self, bundle, **kwargs):
"""Create new timeline for a sketch."""
req_data = json.loads(bundle.request.body)['data']
sketch = Sketch.objects.get(id=req_data['sketch'])
timeline = Timeline.objects.get(id=req_data['timeline'])
try:
sketch_timeline = SketchTimeline.objects.get(timeline=timeline,
sketch=sketch)
except SketchTimeline.DoesNotExist:
sketch_timeline = SketchTimeline.objects.create(timeline=timeline)
sketch_timeline.color = sketch_timeline.generate_color()
sketch_timeline.save()
sketch.timelines.add(sketch_timeline)
sketch.save()
return bundle
def home(request):
"""Renders the available sketches for the user."""
my_sketches = Sketch.objects.filter(user=request.user).order_by("-created")
public_sketches = set()
for sketch in Sketch.objects.all().exclude(user=request.user):
if sketch.is_public():
public_sketches.add(sketch)
context = {"my_sketches": my_sketches, "public_sketches": public_sketches}
return render(request, 'home.html', context)
def alter_list_data_to_serialize(self, request, data):
timeline_colors = {}
timeline_names = {}
sketch = Sketch.objects.get(id=request.GET['sketch'])
for t in sketch.timelines.all():
timeline_colors[t.timeline.datastore_index] = t.color
timeline_names[t.timeline.datastore_index] = t.timeline.title
try:
data['meta']['es_time'] = self.query_result['took']
data['meta']['es_total_count'] = self.query_result['hits']['total']
except KeyError:
data['meta']['es_time'] = 0
data['meta']['es_total_count'] = 0
data['meta']['timeline_colors'] = timeline_colors
data['meta']['timeline_names'] = timeline_names
return data
def home(request):
"""Renders the available sketches for the user."""
my_sketches = Sketch.objects.filter(user=request.user).order_by("-created")
public_sketches = set()
for sketch in Sketch.objects.all().exclude(user=request.user):
if sketch.is_public():
public_sketches.add(sketch)
context = {"my_sketches": my_sketches, "public_sketches": public_sketches}
return render(request, 'home.html', context)
def alter_list_data_to_serialize(self, request, data):
timeline_colors = {}
timeline_names = {}
sketch = Sketch.objects.get(id=request.GET['sketch'])
for t in sketch.timelines.all():
timeline_colors[t.timeline.datastore_index] = t.color
timeline_names[t.timeline.datastore_index] = t.timeline.title
try:
data['meta']['es_time'] = self.query_result['took']
data['meta']['es_total_count'] = self.query_result['hits']['total']
except KeyError:
data['meta']['es_time'] = 0
data['meta']['es_total_count'] = 0
data['meta']['timeline_colors'] = timeline_colors
data['meta']['timeline_names'] = timeline_names
return data
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