mirror of
https://github.com/DarrenOfficial/dpaste.git
synced 2024-12-19 00:09:21 +11:00
Save the recently used lexer to use it next time again. Fixes issue #3
This commit is contained in:
parent
d42a2d3c79
commit
e14192d2d1
1 changed files with 8 additions and 0 deletions
|
@ -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:
|
||||
|
|
Loading…
Reference in a new issue