mirror of
https://github.com/DarrenOfficial/dpaste.git
synced 2024-11-23 11:56:36 +11:00
Removed MAX_SNIPPETS_PER_USER
No need to purge them from the session, they are purged from the db anyway.
This commit is contained in:
parent
f6b69b1209
commit
053808f2bf
4 changed files with 3 additions and 43 deletions
|
@ -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']
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
# -------------------------------------------------------------------------
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue