From e14192d2d13a28b0ba4317a336a3d4aa65ddb158 Mon Sep 17 00:00:00 2001 From: Martin Mahner Date: Wed, 20 Mar 2013 13:08:41 +0100 Subject: [PATCH] Save the recently used lexer to use it next time again. Fixes issue #3 --- dpaste/forms.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/dpaste/forms.py b/dpaste/forms.py index 8e1e0ab..426a13b 100644 --- a/dpaste/forms.py +++ b/dpaste/forms.py @@ -48,6 +48,11 @@ class SnippetForm(forms.ModelForm): 'data-source': '["%s"]' % '","'.join(dict(LEXER_LIST).keys()) } + # Set the recently used lexer if we have any + session_lexer = self.request.session.get('lexer') + if session_lexer and session_lexer in dict(LEXER_LIST).keys(): + self.fields['lexer'].initial = session_lexer + def clean_lexer(self): lexer = self.cleaned_data.get('lexer') if not lexer: @@ -82,6 +87,9 @@ class SnippetForm(forms.ModelForm): else: 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'] + return self.request, self.instance class Meta: