Skip to content

Commit

Permalink
Clear Buttons clears the session
Browse files Browse the repository at this point in the history
  • Loading branch information
prshnt19 committed Mar 16, 2020
1 parent 9926ead commit f8d500f
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 13 deletions.
4 changes: 2 additions & 2 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
[submodule "sympy"]
path = sympy
url = git://github.com/sympy/sympy.git
url = https://github.com/sympy/sympy.git
[submodule "mpmath"]
path = mpmath
url = https://github.com/fredrik-johansson/mpmath
[submodule "static"]
path = static
url = git@github.com:sympy/sympy-web-static.git
url = https://github.com/sympy/sympy-web-static.git
18 changes: 18 additions & 0 deletions shell/migrations/0005_auto_20200316_2006.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 3.0.2 on 2020-03-16 14:36

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('shell', '0004_auto_20200225_1806'),
]

operations = [
migrations.AlterField(
model_name='searches',
name='query',
field=models.CharField(default=None, max_length=1000),
),
]
2 changes: 1 addition & 1 deletion shell/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

class Searches(models.Model):
user_id = models.ForeignKey(User, on_delete=models.CASCADE)
query = models.CharField(max_length=100, default=None)
query = models.CharField(max_length=1000, default=None)
timestamp = models.DateTimeField(auto_now_add=True)
private = models.BooleanField()

Expand Down
29 changes: 19 additions & 10 deletions shell/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
from django.contrib.sessions.backends.db import SessionStore
from django.views import View
from inspect import currentframe, getframeinfo
# from IPython.terminal.embed import InteractiveShellEmbed
from typing import Dict, Union

import numpy
Expand Down Expand Up @@ -654,6 +655,7 @@ def force_desktop_cookie(request):
def index(request):
searches_query = Searches.objects.filter(private=False).order_by('timestamp')
search_results = searches_query.reverse()[:10]
# ipshell = InteractiveShellEmbed(banner1='banner', exit_msg='exit_msg')
if request.user.is_authenticated:
saved_searches = Searches.objects.filter(user_id=request.user)
else:
Expand Down Expand Up @@ -760,15 +762,21 @@ def evaluate(request):
# print(getframeinfo(currentframe()).lineno, request.user, request.session.session_key)
if not request.user.is_authenticated:
request.user = User.objects.get(username='anonymous')
if request.session.session_key is None:
if session_key is not None:
session = SessionStore(session_key=session_key)
else:
session = SessionStore()
session.create()
request.session = session
session.modified = True
session.save()
# if request.session.session_key is None:
if session_key is not None:
session = SessionStore(session_key=session_key)
else:
session = SessionStore()
session.create()
request.session = session
session.modified = True
session.save()
elif session_key is None:
session = SessionStore()
session.create()
request.session = session
session.modified = True
session.save()
# print(getframeinfo(currentframe()).lineno, request.user, request.session.session_key)
user = request.user

Expand Down Expand Up @@ -850,7 +858,8 @@ def sphinxbanner(request):


def delete(request):
results = Searches.objects.filter(user_id=request.user).delete()
Searches.objects.filter(user_id=request.user).delete()
request.session.clear()
return HttpResponse("Your queries have been deleted.")


Expand Down

0 comments on commit f8d500f

Please sign in to comment.