Save the recently used lexer to use it next time again. Fixes issue #3

This commit is contained in:
Martin Mahner 2013-03-20 13:08:41 +01:00
parent d42a2d3c79
commit e14192d2d1

View file

@ -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: