Remove some old code
authorCharles Connell <charles@connells.org>
Thu, 1 May 2014 18:59:21 +0000 (14:59 -0400)
committerCharles Connell <charles@connells.org>
Thu, 1 May 2014 18:59:21 +0000 (14:59 -0400)
karmaworld/apps/notes/gdrive.py
karmaworld/apps/quizzes/create_quiz.py [deleted file]
karmaworld/apps/quizzes/management/commands/create_quiz.py [deleted file]
karmaworld/apps/quizzes/management/commands/import_quiz.py [deleted file]
karmaworld/apps/quizzes/xml_import.py [deleted file]
karmaworld/assets/css/global.css
karmaworld/templates/notes/note_detail.html

index 169a98b1c73074e213f2ea90b940c1995446f657..b5977222760ed5b4e491bbe9d4f585050ff8016d 100644 (file)
@@ -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<year>\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 (file)
index 4441e6c..0000000
+++ /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}:<br/>{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 (file)
index a0a49da..0000000
+++ /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 = '<note ID>'
-    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 (file)
index dd6886f..0000000
+++ /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 = '<IQ-Metrics XML file> <note ID>'
-    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 (file)
index cb37238..0000000
+++ /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<A>.*)[\n]+B. (?P<B>.*)[\n]+C. (?P<C>.*)[\n]+D. (?P<D>.*)$'
-TRUE_FALSE_CHOICE = r'^A. (?P<A>True|False)[\n]+B. (?P<B>True|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)
index ecda509d90515c7d86e733e5eada7d5102c0f868..3d5ba30bbfc2f33dac614d37106a847ceead637f 100644 (file)
@@ -351,3 +351,7 @@ button.search-icon {
   border-bottom: 1px solid #a9a9a9;
 }
 
+.light {
+  opacity: 0.8;
+  font-size: 0.8em;
+}
index a08222fc516ae5eced424390752b41917e5da6c6..7fd36a0f8db8a92596bb61e7f8714c3fd6d579bd 100644 (file)
         <div class="small-12 columns">
           <strong>Tags: </strong>
           <span class="tags">
-            {% for tag in note.tags.all %}
-              <span class="tag-span">
-                {{ tag.name }}{% if not forloop.last %}, {% endif %}
-              </span>
-            {% endfor %}
+            {% if note.tags.all %}
+              {% for tag in note.tags.all %}
+                <span class="tag-span">
+                  {{ tag.name }}{% if not forloop.last %}, {% endif %}
+                </span>
+              {% endfor %}
+            {% else %}
+              <em class="light">(none defined yet)</em>
+            {% endif %}
           </span>
         </div><!-- /note_tags -->
       </div>
                   {% for keyword in keywords %}
                     <tr>
                       <td>{{ keyword.word }}</td>
-                      <td>{{ keyword.definition }}</td>
+                      <td>
+                        {% if keyword.definition %}
+                          {{ keyword.definition }}
+                        {% else %}
+                          <em class="light">(not defined yet)</em>
+                        {% endif %}
+                      </td>
                     </tr>
                   {% endfor %}
                 </table>