def save(self, *args, **kwargs): # normalize text so it's easy to work with if not self.to_lines: self.to_lines = '' self.to_lines = normalize_newlines(self.to_lines.rstrip()) self.from_lines = normalize_newlines(self.from_lines.rstrip()) self.subject = normalize_newlines(self.subject.rstrip()) self.memo_text = normalize_newlines(self.memo_text.rstrip()) self.memo_text = many_newlines.sub('\n\n', self.memo_text) super(Memo, self).save(*args, **kwargs)
def save(self, *args, **kwargs): # normalize text so it's easy to work with if not self.to_lines: self.to_lines = '' self.to_lines = normalize_newlines(self.to_lines.rstrip()) self.from_lines = normalize_newlines(self.from_lines.rstrip()) self.subject = normalize_newlines(self.subject.rstrip()) self.memo_text = normalize_newlines(self.memo_text.rstrip()) self.memo_text = many_newlines.sub('\n\n', self.memo_text) super(Memo, self).save(*args, **kwargs)
def letter_paragraphs(self): """ Return list of paragraphs in the letter (for PDF creation) """ text = self.offer_letter_text text = normalize_newlines(text) return text.split("\n\n")
def save(self, check_diff=True, minor_change=False, *args, **kwargs): # check coherence of the data model: exactly one of full text, diff text, file, redirect. if not minor_change: # minor_change flag set when .diff_to has changed the .config only has_wikitext = bool(self.wikitext) has_difffrom = bool(self.diff_from) has_diff = bool(self.diff) has_file = bool(self.file_attachment) has_redirect = bool(self.redirect) assert (has_wikitext and not has_difffrom and not has_diff and not has_file and not has_redirect) \ or (not has_wikitext and has_difffrom and has_diff and not has_file and not has_redirect) \ or (not has_wikitext and not has_difffrom and not has_diff and has_file and not has_redirect) \ or (not has_wikitext and not has_difffrom and not has_diff and not has_file and has_redirect) # normalize newlines so our diffs are consistent later self.wikitext = normalize_newlines(self.wikitext) # set the SyntaxHighlighter brushes used on this page. self.set_brushes([]) wikitext = self.get_wikitext() if wikitext: self.get_creole() brushes = brushes_used(self.Creole.parser.parse(wikitext)) self.set_brushes(list(brushes)) self.set_syntax(bool(brushes)) super(PageVersion, self).save(*args, **kwargs) # update the *previous* PageVersion so it's a diff instead of storing full text if check_diff and not minor_change: prev = self.previous_version() if prev: prev.diff_to(self) self.page.expire_offering_cache()
def letter_paragraphs(self): """ Return list of paragraphs in the letter (for PDF creation) """ text = self.offer_letter_text or self.default_letter_text() text = normalize_newlines(text) return text.split("\n\n")
def save(self, check_diff=True, minor_change=False, *args, **kwargs): # check coherence of the data model: exactly one of full text, diff text, file, redirect. if not minor_change: # minor_change flag set when .diff_to has changed the .config only has_wikitext = bool(self.wikitext) has_difffrom = bool(self.diff_from) has_diff = bool(self.diff) has_file = bool(self.file_attachment) has_redirect = bool(self.redirect) assert (has_wikitext and not has_difffrom and not has_diff and not has_file and not has_redirect) \ or (not has_wikitext and has_difffrom and has_diff and not has_file and not has_redirect) \ or (not has_wikitext and not has_difffrom and not has_diff and has_file and not has_redirect) \ or (not has_wikitext and not has_difffrom and not has_diff and not has_file and has_redirect) # normalize newlines so our diffs are consistent later self.wikitext = normalize_newlines(self.wikitext) self.wikitext = ensure_sanitary_markup(self.wikitext, self.markup(), restricted=False) super(PageVersion, self).save(*args, **kwargs) # update the *previous* PageVersion so it's a diff instead of storing full text if check_diff and not minor_change: prev = self.previous_version() if prev: prev.diff_to(self) self.page.expire_offering_cache()
def text_preview(self): """ A max-one-line preview of the note content, for the compact display. """ text = normalize_newlines(self.text.rstrip()) lines = text.split('\n') text = lines[0] if len(text) > 70: text = text[:100] + u' \u2026' elif len(lines) > 1: text += u' \u2026' return text
def text_preview(self): """ A max-one-line preview of the note content, for the compact display. """ text = normalize_newlines(self.text.rstrip()) lines = text.split('\n') text = lines[0] if len(text) > 70: text = text[:100] + u' \u2026' elif len(lines) > 1: text += u' \u2026' return text
def save(self, check_diff=True, minor_change=False, *args, **kwargs): # check coherence of the data model: exactly one of full text, diff text, file. if not minor_change: # minor_change flag set when .diff_to has changed the .config only has_wikitext = bool(self.wikitext) has_difffrom = bool(self.diff_from) has_diff = bool(self.diff) has_file = bool(self.file_attachment) assert (has_wikitext and not has_difffrom and not has_diff and not has_file) \ or (not has_wikitext and has_difffrom and has_diff and not has_file) \ or (not has_wikitext and not has_difffrom and not has_diff and has_file) # normalize newlines so our diffs are consistent later self.wikitext = normalize_newlines(self.wikitext) # set the SyntaxHighlighter brushes used on this page. self.set_brushes([]) wikitext = self.get_wikitext() if wikitext: self.get_creole() brushes = brushes_used(self.Creole.parser.parse(wikitext)) self.set_brushes(list(brushes)) self.set_syntax(bool(brushes)) super(PageVersion, self).save(*args, **kwargs) # update the *previous* PageVersion so it's a diff instead of storing full text if check_diff and not minor_change: prev = self.previous_version() if prev: prev.diff_to(self) # invalidate cache for all pages in this offering: makes sure current page, and all <<filelist>> are up to date for pv in PageVersion.objects.filter( page__offering=self.page.offering): key = pv.html_cache_key() cache.delete(key) # other cache cleanup cache.delete(self.wikitext_cache_key()) cache.delete(self.page.version_cache_key())
def save(self, check_diff=True, minor_change=False, *args, **kwargs): # check coherence of the data model: exactly one of full text, diff text, file. if not minor_change: # minor_change flag set when .diff_to has changed the .config only has_wikitext = bool(self.wikitext) has_difffrom = bool(self.diff_from) has_diff = bool(self.diff) has_file = bool(self.file_attachment) assert (has_wikitext and not has_difffrom and not has_diff and not has_file) \ or (not has_wikitext and has_difffrom and has_diff and not has_file) \ or (not has_wikitext and not has_difffrom and not has_diff and has_file) # normalize newlines so our diffs are consistent later self.wikitext = normalize_newlines(self.wikitext) # set the SyntaxHighlighter brushes used on this page. self.set_brushes([]) wikitext = self.get_wikitext() if wikitext: self.get_creole() brushes = brushes_used(self.Creole.parser.parse(wikitext)) self.set_brushes(list(brushes)) self.set_syntax(bool(brushes)) super(PageVersion, self).save(*args, **kwargs) # update the *previous* PageVersion so it's a diff instead of storing full text if check_diff and not minor_change: prev = self.previous_version() if prev: prev.diff_to(self) # invalidate cache for all pages in this offering: makes sure current page, and all <<filelist>> are up to date for pv in PageVersion.objects.filter(page__offering=self.page.offering): key = pv.html_cache_key() cache.delete(key) # other cache cleanup cache.delete(self.wikitext_cache_key()) cache.delete(self.page.version_cache_key())
def save(self, *args, **kwargs): self.template_text = normalize_newlines(self.template_text.rstrip()) super(MemoTemplate, self).save(*args, **kwargs)
def to_text(self, fieldsubmission): txt = normalize_newlines(fieldsubmission.data['info']) if len(txt) > MAX_TEXT_LEN: txt = txt[0:MAX_TEXT_LEN] + '...' return txt.replace('\n', '\\\\')
def import_note(self, advisor, fn, i, row): emplid = row['Student ID'] date_str = row['Date Modified'] notes = normalize_newlines(row['Notes']) files = [ row.get('Transcript', None), row.get('Files', None), row.get('Files2', None), row.get('Files3', None), ] files = map(self.get_filepath, files) files = filter(bool, files) # fix mis-typed emplids we found # Lindsay if emplid == '960022098': emplid = '963022098' elif emplid == '30108409': emplid = '301078409' elif emplid == '30115964': emplid = '301115964' elif emplid == '30117882': emplid = '301178882' # Michael Sean elif emplid == '30105659': emplid = '301040985' # ? # Dijana elif emplid == '30120965': emplid = '301202965' if not emplid or emplid == '0': if self.verbosity > 0: print 'No emplid on row %i' % (i + 2) return p = add_person(emplid, commit=self.commit) if not p: if self.verbosity > 0: print u"Can't find person on row %i (emplid %s)" % (i + 2, emplid) return if self.verbosity > 1: print u"Importing %s with %i file(s)." % (emplid, len(files)) try: date = datetime.datetime.strptime(date_str, '%m-%d-%Y').date() except ValueError: date = datetime.datetime.strptime(date_str, '%Y-%m-%d').date() created = datetime.datetime.combine(date, datetime.time(hour=12, minute=0)) key = '%s-%i' % (fn, i) note, _ = self.get_advisornote(key, p, advisor, created, delete_old_file=self.commit) if files: path = files[0] self.attach_file(note, path) for j, path in enumerate(files[1:]): # these get stashed in accompanying notes k = key + '-auxfile-' + str(i) n, _ = self.get_advisornote(k, p, advisor, created, delete_old_file=self.commit, offset=(j + 1)) n.text = '[Additional file for previous note.]' self.attach_file(n, path) if self.commit: n.save() note.text = notes if self.commit: note.save()
def save(self, *args, **kwargs): self.template_text = normalize_newlines(self.template_text.rstrip()) super(MemoTemplate, self).save(*args, **kwargs)