From: Charles Connell Date: Thu, 1 May 2014 18:59:21 +0000 (-0400) Subject: Remove some old code X-Git-Tag: release-20150131~102 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=e129e31a066a781eae1f038f44d12bf14ee5445d;p=oweals%2Fkarmaworld.git Remove some old code --- diff --git a/karmaworld/apps/notes/gdrive.py b/karmaworld/apps/notes/gdrive.py index 169a98b..b597722 100644 --- a/karmaworld/apps/notes/gdrive.py +++ b/karmaworld/apps/notes/gdrive.py @@ -33,24 +33,6 @@ PDF_MIMETYPE = 'application/pdf' PPT_MIMETYPES = ['application/vnd.ms-powerpoint', 'application/vnd.openxmlformats-officedocument.presentationml.presentation'] -def extract_file_details(fileobj): - details = None - year = None - - fileobj.open() - filebuf = fileobj.read() - with magic.Magic() as m: - details = m.id_buffer(filebuf) - fileobj.close() - - result = re.search(r'Create Time/Date:[^,]+(?P\d{4})', details) - if result: - if 'year' in result.groupdict(): - year = result.groupdict()['year'] - - return {'year': year} - - def build_api_service(): """ Build and returns a Drive service object authorized with the service @@ -256,9 +238,6 @@ def convert_raw_document(raw_document, user=None): note_markdown = NoteMarkdown(note=note, markdown=markdown) note_markdown.save() - note_details = extract_file_details(fp_file) - if 'year' in note_details and note_details['year']: - note.year = note_details['year'] # If we know the user who uploaded this, # associate them with the note diff --git a/karmaworld/apps/quizzes/create_quiz.py b/karmaworld/apps/quizzes/create_quiz.py deleted file mode 100644 index 4441e6c..0000000 --- a/karmaworld/apps/quizzes/create_quiz.py +++ /dev/null @@ -1,100 +0,0 @@ -import random -from karmaworld.apps.notes.models import Note -from karmaworld.apps.quizzes.models import MultipleChoiceQuestion, Quiz, TrueFalseQuestion, MultipleChoiceOption, \ - Keyword, FlashCardQuestion - -KEYWORD_MULTIPLE_CHOICE = 1 -DEFINITION_MULTIPLE_CHOICE = 2 -KEYWORD_DEFINITION_TRUE_FALSE = 3 -FLASHCARD_KEYWORD_BLANK = 4 -GENERATED_QUESTION_TYPE = ( - KEYWORD_MULTIPLE_CHOICE, - DEFINITION_MULTIPLE_CHOICE, - KEYWORD_DEFINITION_TRUE_FALSE, - FLASHCARD_KEYWORD_BLANK, -) - -MULTIPLE_CHOICE_CHOICES = 4 - - -def _create_keyword_multiple_choice(keyword, keywords, quiz): - question_object = MultipleChoiceQuestion.objects.create( - question_text=keyword.definition, - quiz=quiz) - - MultipleChoiceOption.objects.create( - text=keyword.word, - correct=True, - question=question_object) - - for other_keyword in random.sample(keywords.exclude(id=keyword.id), MULTIPLE_CHOICE_CHOICES - 1): - MultipleChoiceOption.objects.create( - text=other_keyword.word, - correct=False, - question=question_object) - - -def _create_definition_multiple_choice(keyword, keywords, quiz): - question_object = MultipleChoiceQuestion.objects.create( - question_text=keyword.word, - quiz=quiz) - - MultipleChoiceOption.objects.create( - text=keyword.definition, - correct=True, - question=question_object) - - for other_keyword in random.sample(keywords.exclude(id=keyword.id), MULTIPLE_CHOICE_CHOICES - 1): - MultipleChoiceOption.objects.create( - text=other_keyword.definition, - correct=False, - question=question_object) - - -def _create_keyword_definition_true_false(keyword, keywords, quiz): - true = random.choice((True, False)) - - if true: - definition = keyword.definition - else: - other_keyword = keywords.exclude(id=keyword.id) - definition = other_keyword.definition - - question_text = 'Is the following a correct definition of {w}:
{d}'. \ - format(w=keyword.word, d=definition) - - TrueFalseQuestion.objects.create( - text=question_text, - quiz=quiz, - true=true) - - -def _create_keyword_flashcard_blank(keyword, quiz): - FlashCardQuestion.objects.create( - definition_side=keyword.definition, - keyword_side=keyword.word, - quiz=quiz) - - -def quiz_from_keywords(note_id): - note_object = Note.objects.get(id=note_id) - quiz_object = Quiz.objects.create(note=note_object, name=note_object.name) - keywords = Keyword.objects.filter(note=note_object) - - for keyword in keywords: - if keyword.word and keyword.definition: - question_type = random.choice(GENERATED_QUESTION_TYPE) - - if question_type is KEYWORD_MULTIPLE_CHOICE: - _create_keyword_multiple_choice(keyword, keywords, quiz_object) - - elif question_type is DEFINITION_MULTIPLE_CHOICE: - _create_definition_multiple_choice(keyword, keywords, quiz_object) - - elif question_type is KEYWORD_DEFINITION_TRUE_FALSE: - _create_keyword_definition_true_false(keyword, keywords, quiz_object) - - elif question_type is FLASHCARD_KEYWORD_BLANK: - _create_keyword_flashcard_blank(keyword, quiz_object) - - diff --git a/karmaworld/apps/quizzes/management/commands/create_quiz.py b/karmaworld/apps/quizzes/management/commands/create_quiz.py deleted file mode 100644 index a0a49da..0000000 --- a/karmaworld/apps/quizzes/management/commands/create_quiz.py +++ /dev/null @@ -1,20 +0,0 @@ -#!/usr/bin/env python -# -*- coding:utf8 -*- -# Copyright (C) 2014 FinalsClub Foundation -from argparse import ArgumentError -from django.core.management import BaseCommand -from karmaworld.apps.quizzes.create_quiz import quiz_from_keywords - - -class Command(BaseCommand): - args = '' - help = """ - Create a quiz out of the keywords and definitions - already on file for the given note. - """ - - def handle(self, *args, **kwargs): - if len(args) != 1: - raise ArgumentError("Incorrect arguments, see usage") - quiz_from_keywords(args[0]) - diff --git a/karmaworld/apps/quizzes/management/commands/import_quiz.py b/karmaworld/apps/quizzes/management/commands/import_quiz.py deleted file mode 100644 index dd6886f..0000000 --- a/karmaworld/apps/quizzes/management/commands/import_quiz.py +++ /dev/null @@ -1,20 +0,0 @@ -#!/usr/bin/env python -# -*- coding:utf8 -*- -# Copyright (C) 2014 FinalsClub Foundation -from argparse import ArgumentError -from django.core.management import BaseCommand -from karmaworld.apps.quizzes.xml_import import quiz_from_xml, keywords_from_xml - - -class Command(BaseCommand): - args = ' ' - help = """ - Import a quiz from an IQ Metrics XML file - """ - - def handle(self, *args, **kwargs): - if len(args) != 2: - raise ArgumentError("Incorrect arguments, see usage") - quiz_from_xml(args[0], args[1]) - keywords_from_xml(args[0], args[1]) - diff --git a/karmaworld/apps/quizzes/xml_import.py b/karmaworld/apps/quizzes/xml_import.py deleted file mode 100644 index cb37238..0000000 --- a/karmaworld/apps/quizzes/xml_import.py +++ /dev/null @@ -1,146 +0,0 @@ -from StringIO import StringIO -from karmaworld.apps.notes.models import Note -import re -from bs4 import BeautifulSoup -from karmaworld.apps.quizzes.models import MultipleChoiceQuestion, Quiz, TrueFalseQuestion, MultipleChoiceOption, \ - Keyword -from pyth.plugins.plaintext.writer import PlaintextWriter -from pyth.plugins.rtf15.reader import Rtf15Reader - -FOUR_MULTIPLE_CHOICE = r'^A. (?P.*)[\n]+B. (?P.*)[\n]+C. (?P.*)[\n]+D. (?P.*)$' -TRUE_FALSE_CHOICE = r'^A. (?PTrue|False)[\n]+B. (?PTrue|False)$' - - -def _rtf2plain(str): - if str: - doc = Rtf15Reader.read(StringIO(str)) - return PlaintextWriter.write(doc).getvalue() - else: - return str - - -def _category_from_question(question): - category_string = question.find('Category').string - if category_string == 'Knowledge': - category = MultipleChoiceQuestion.KNOWLEDGE - elif category_string == 'Understand': - category = MultipleChoiceQuestion.UNDERSTAND - elif category_string == 'Remember': - category = MultipleChoiceQuestion.REMEMBER - elif category_string == 'Analyze': - category = MultipleChoiceQuestion.ANALYZE - else: - category = None - - return category - - -def _difficulty_from_question(question): - difficulty_string = question.find('Difficulty').string - if difficulty_string == 'Easy': - difficulty = MultipleChoiceQuestion.EASY - elif difficulty_string == 'Medium': - difficulty = MultipleChoiceQuestion.MEDIUM - elif difficulty_string == 'Hard': - difficulty = MultipleChoiceQuestion.HARD - else: - difficulty = None - - return difficulty - - -def _true_false(question, quiz_object): - question_text = _rtf2plain(question.find('QuestionText').string) - explanation_text = _rtf2plain(question.find('Explanation').string) - category = _category_from_question(question) - difficulty = _difficulty_from_question(question) - - correct_answer_letter = question.find('Answer').string - - options_string = question.find('AnswerOptions').string - options_string = _rtf2plain(options_string) - match_options = re.match(TRUE_FALSE_CHOICE, options_string) - option_a = match_options.group('A') - option_b = match_options.group('B') - - if correct_answer_letter == 'A': - correct_answer_string = option_a - else: - correct_answer_string = option_b - - if correct_answer_string == 'True': - correct_answer = True - else: - correct_answer = False - - TrueFalseQuestion.objects.create(text=question_text, - explanation=explanation_text, - difficulty=difficulty, - category=category, - true=correct_answer, - quiz=quiz_object) - - -def _multiple_choice(question, quiz_object): - question_text = _rtf2plain(question.find('QuestionText').string) - explanation_text = _rtf2plain(question.find('Explanation').string) - category = _category_from_question(question) - difficulty = _difficulty_from_question(question) - - question_object = MultipleChoiceQuestion.objects.create(question_text=question_text, - explanation=explanation_text, - difficulty=difficulty, - category=category, - quiz=quiz_object) - - correct_answer = question.find('Answer').string - - options_string = question.find('AnswerOptions').string - options_string = _rtf2plain(options_string) - match_options = re.match(FOUR_MULTIPLE_CHOICE, options_string) - option_a = match_options.group('A') - option_b = match_options.group('B') - option_c = match_options.group('C') - option_d = match_options.group('D') - - MultipleChoiceOption.objects.create(text=option_a, - correct=(correct_answer == 'A'), - question=question_object) - MultipleChoiceOption.objects.create(text=option_b, - correct=(correct_answer == 'B'), - question=question_object) - MultipleChoiceOption.objects.create(text=option_c, - correct=(correct_answer == 'C'), - question=question_object) - MultipleChoiceOption.objects.create(text=option_d, - correct=(correct_answer == 'D'), - question=question_object) - - -def quiz_from_xml(filename, note_id): - with open(filename, 'r') as file: - soup = BeautifulSoup(file.read(), "xml") - - note_object = Note.objects.get(id=note_id) - quiz_name = soup.find('EChapterTitle').string - quiz_object = Quiz.objects.create(name=quiz_name, note=note_object) - - questions = soup.find_all('TestBank') - for question in questions: - type_string = question.find('Type').string - if type_string == 'Multiple Choice': - _multiple_choice(question, quiz_object) - - elif type_string == 'True/False': - _true_false(question, quiz_object) - - -def keywords_from_xml(filename, note_id): - with open(filename, 'r') as file: - soup = BeautifulSoup(file.read(), "xml") - - note_object = Note.objects.get(id=note_id) - - keywords = soup.find_all('WordPhrase') - for word in keywords: - Keyword.objects.create(word=word.string, note=note_object) diff --git a/karmaworld/assets/css/global.css b/karmaworld/assets/css/global.css index ecda509..3d5ba30 100644 --- a/karmaworld/assets/css/global.css +++ b/karmaworld/assets/css/global.css @@ -351,3 +351,7 @@ button.search-icon { border-bottom: 1px solid #a9a9a9; } +.light { + opacity: 0.8; + font-size: 0.8em; +} diff --git a/karmaworld/templates/notes/note_detail.html b/karmaworld/templates/notes/note_detail.html index a08222f..7fd36a0 100644 --- a/karmaworld/templates/notes/note_detail.html +++ b/karmaworld/templates/notes/note_detail.html @@ -169,11 +169,15 @@
Tags: - {% for tag in note.tags.all %} - - {{ tag.name }}{% if not forloop.last %}, {% endif %} - - {% endfor %} + {% if note.tags.all %} + {% for tag in note.tags.all %} + + {{ tag.name }}{% if not forloop.last %}, {% endif %} + + {% endfor %} + {% else %} + (none defined yet) + {% endif %}
@@ -299,7 +303,13 @@ {% for keyword in keywords %} {{ keyword.word }} - {{ keyword.definition }} + + {% if keyword.definition %} + {{ keyword.definition }} + {% else %} + (not defined yet) + {% endif %} + {% endfor %}