mirror of
https://github.com/DarrenOfficial/dpaste.git
synced 2024-11-15 16:12:51 +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())
|
'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):
|
def clean_lexer(self):
|
||||||
lexer = self.cleaned_data.get('lexer')
|
lexer = self.cleaned_data.get('lexer')
|
||||||
if not lexer:
|
if not lexer:
|
||||||
|
@ -82,6 +87,9 @@ class SnippetForm(forms.ModelForm):
|
||||||
else:
|
else:
|
||||||
self.request.session['snippet_list'] = [self.instance.pk]
|
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
|
return self.request, self.instance
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
|
|
Loading…
Reference in a new issue