From 053808f2bfe6ea841771e05288cd20dedca0f546 Mon Sep 17 00:00:00 2001 From: Martin Mahner Date: Fri, 22 Jun 2018 11:42:41 +0200 Subject: [PATCH] Removed MAX_SNIPPETS_PER_USER No need to purge them from the session, they are purged from the db anyway. --- dpaste/forms.py | 11 +++-------- dpaste/settings/base.py | 4 ---- dpaste/tests/test_snippet.py | 29 ----------------------------- dpaste/views.py | 2 -- 4 files changed, 3 insertions(+), 43 deletions(-) diff --git a/dpaste/forms.py b/dpaste/forms.py index 4230705..63b1e89 100644 --- a/dpaste/forms.py +++ b/dpaste/forms.py @@ -18,6 +18,7 @@ EXPIRE_CHOICES = getattr(settings, 'DPASTE_EXPIRE_CHOICES', ( EXPIRE_DEFAULT = getattr(settings, 'DPASTE_EXPIRE_DEFAULT', 3600) MAX_CONTENT_LENGTH = getattr(settings, 'DPASTE_MAX_CONTENT_LENGTH', 250*1024*1024) + def get_expire_values(expires): if expires == 'never': expire_type = Snippet.EXPIRE_KEEP @@ -104,8 +105,6 @@ class SnippetForm(forms.ModelForm): return self.cleaned_data def save(self, parent=None, *args, **kwargs): - MAX_SNIPPETS_PER_USER = getattr(settings, 'DPASTE_MAX_SNIPPETS_PER_USER', 100) - # Set parent snippet self.instance.parent = parent @@ -118,12 +117,8 @@ class SnippetForm(forms.ModelForm): super(SnippetForm, self).save(*args, **kwargs) # Add the snippet to the user session list - if self.request.session.get('snippet_list', False): - if len(self.request.session['snippet_list']) >= MAX_SNIPPETS_PER_USER: - self.request.session['snippet_list'].pop(0) - self.request.session['snippet_list'] += [self.instance.pk] - else: - self.request.session['snippet_list'] = [self.instance.pk] + self.request.session.setdefault('snippet_list', []) + self.request.session['snippet_list'] += [self.instance.pk] # Save the lexer in the session so we can use it later again self.request.session['lexer'] = self.cleaned_data['lexer'] diff --git a/dpaste/settings/base.py b/dpaste/settings/base.py index a6d7eff..03e4e51 100644 --- a/dpaste/settings/base.py +++ b/dpaste/settings/base.py @@ -136,10 +136,6 @@ DATABASES = { # App specific settings #============================================================================== -# How many recent snippets to save for every user? IDs of this snippets are -# stored in the user session. -MAX_SNIPPETS_PER_USER = 25 - SESSION_COOKIE_SECURE = True CSRF_COOKIE_SECURE = True diff --git a/dpaste/tests/test_snippet.py b/dpaste/tests/test_snippet.py index d86e989..094c33d 100644 --- a/dpaste/tests/test_snippet.py +++ b/dpaste/tests/test_snippet.py @@ -268,35 +268,6 @@ class SnippetTestCase(TestCase): self.assertEqual(response.status_code, 200) self.assertEqual(Snippet.objects.count(), 0) - @override_settings(DPASTE_MAX_SNIPPETS_PER_USER=2) - def test_snippet_that_exceed_history_limit_get_trashed(self): - """ - The maximum number of snippets a user can save in the session are - defined by `DPASTE_MAX_SNIPPETS_PER_USER`. Exceed that number will - remove the oldest snippet from the list. - """ - # Create three snippets but since the setting is 2 only the latest two - # will displayed on the history. - data = self.valid_form_data() - self.client.post(self.new_url, data, follow=True) - self.client.post(self.new_url, data, follow=True) - self.client.post(self.new_url, data, follow=True) - - response = self.client.get(reverse('snippet_history'), follow=True) - one, two, three = Snippet.objects.order_by('published') - - # Only the last two are saved in the session - self.assertEqual(len(self.client.session['snippet_list']), 2) - self.assertFalse(one.id in self.client.session['snippet_list']) - self.assertTrue(two.id in self.client.session['snippet_list']) - self.assertTrue(three.id in self.client.session['snippet_list']) - - # And only the last two are displayed on the history page - self.assertNotContains(response, one.secret_id) - self.assertContains(response, two.secret_id) - self.assertContains(response, three.secret_id) - - # ------------------------------------------------------------------------- # Management Command # ------------------------------------------------------------------------- diff --git a/dpaste/views.py b/dpaste/views.py index b8af852..918bc93 100644 --- a/dpaste/views.py +++ b/dpaste/views.py @@ -166,11 +166,9 @@ class SnippetHistory(TemplateView): url = '{0}#'.format(reverse('snippet_history')) return HttpResponseRedirect(url) - def get_context_data(self, **kwargs): ctx = super(SnippetHistory, self).get_context_data(**kwargs) ctx.update({ - 'snippets_max': getattr(settings, 'DPASTE_MAX_SNIPPETS_PER_USER', 10), 'snippet_list': self.get_user_snippets(), }) return ctx