3 # Copyright (C) 2012 FinalsClub Foundation
4 from django.forms import ModelForm, IntegerField, HiddenInput, Form, CharField, Textarea
5 from django.forms import TextInput
6 from django_filepicker.widgets import FPFileWidget
7 from django.template.loader import render_to_string
8 from wysihtml5.widgets import RichTextEditor
10 from karmaworld.apps.notes.models import Note, NoteMarkdown
13 class NoteForm(ModelForm):
14 html = CharField(widget=RichTextEditor)
16 def save(self, *args, **kwargs):
17 # TODO: use transaction.atomic for this when we switch to Django 1.6+
18 instance = super(NoteForm, self).save(*args, **kwargs)
19 instance.tags.set(*self.cleaned_data['tags'])
20 if instance.is_hidden:
21 instance.is_hidden = False
23 if self.cleaned_data.get('html'):
25 note_markdown = instance.notemarkdown
26 except NoteMarkdown.DoesNotExist:
27 note_markdown = NoteMarkdown(note=instance)
28 note_markdown.html = self.cleaned_data['html']
29 note_markdown.full_clean()
35 fields = ('name', 'tags', 'html')
40 class NoteDeleteForm(Form):
41 note = IntegerField(widget=HiddenInput())
43 class FileUploadForm(ModelForm):
49 'fp_file': FPFileWidget(attrs={
50 'id': 'filepicker-file-upload',