From 618df57c1a0769554bbad407a22f10842cff2a2c Mon Sep 17 00:00:00 2001 From: dellsystem Date: Wed, 2 Jan 2013 00:15:55 -0500 Subject: [PATCH] Reorder imports + add blank lines Where necessary. Issue #138, in progress. --- urls.py | 2 +- views/news.py | 5 ++++ views/pages.py | 38 +++++++++++++++++++-------- wiki/admin/courses.py | 3 ++- wiki/admin/departments.py | 4 ++- wiki/admin/faculties.py | 4 ++- wiki/admin/pages.py | 4 ++- wiki/admin/series.py | 7 +++-- wiki/context_processors.py | 1 + wiki/models/courses.py | 2 ++ wiki/models/departments.py | 1 + wiki/models/faculties.py | 1 + wiki/models/page_types.py | 8 ++++++ wiki/models/series.py | 2 ++ wiki/templatetags/wikinotes_markup.py | 5 ++-- wiki/tests/markdown.py | 3 ++- wiki/utils/gitutils.py | 7 +++-- wiki/utils/history.py | 2 ++ wiki/utils/pages.py | 2 ++ wiki/utils/users.py | 1 + 20 files changed, 79 insertions(+), 23 deletions(-) diff --git a/urls.py b/urls.py index 32e9f1f..7b0c714 100755 --- a/urls.py +++ b/urls.py @@ -1,6 +1,6 @@ from django.conf.urls.defaults import patterns, include, url - from django.contrib import admin + admin.autodiscover() """ diff --git a/views/news.py b/views/news.py index 2767f79..10638bd 100644 --- a/views/news.py +++ b/views/news.py @@ -1,17 +1,22 @@ from django.shortcuts import render + from blog.models import BlogPost + def main(request): data = { 'title': 'News', 'blog_posts': BlogPost.objects.order_by('-timestamp').all(), } + return render(request, 'news/main.html', data) + def view(request, slug): post = BlogPost.objects.get(slug=slug) data = { 'title': post, 'post': post, } + return render(request, 'news/view.html', data) diff --git a/views/pages.py b/views/pages.py index afed1c6..492fad9 100644 --- a/views/pages.py +++ b/views/pages.py @@ -1,18 +1,21 @@ +from datetime import datetime +import random as random_module + +from django.contrib.auth.models import User +from django.http import Http404 from django.shortcuts import render, get_object_or_404, redirect -from wiki.models.courses import Course, CourseSemester, Professor -from wiki.utils.constants import terms, years, exam_types -from wiki.utils.gitutils import Git, NoChangesError -from wiki.utils.pages import page_types from django.template import RequestContext -from wiki.models.pages import Page -from django.http import Http404 -import random as random_module + +from views.main import register +from wiki.models.courses import Course, CourseSemester, Professor from wiki.models.history import HistoryItem -from django.contrib.auth.models import User +from wiki.models.pages import Page +from wiki.utils.constants import terms, years, exam_types from wiki.utils.currents import current_term, current_year -from views.main import register -from datetime import datetime +from wiki.utils.gitutils import Git, NoChangesError from wiki.utils.merge3 import Merge3 +from wiki.utils.pages import page_types + def show(request, department, number, page_type, term, year, slug, printview=False): department = department.upper() @@ -45,9 +48,11 @@ def show(request, department, number, page_type, term, year, slug, printview=Fal return render(request, template_file, data) + def printview(request, department, number, page_type, term, year, slug): return show(request, department, number, page_type, term, year, slug, printview=True) + def history(request, department, number, page_type, term, year, slug): course = get_object_or_404(Course, department=department.upper(), number=int(number)) course_sem = get_object_or_404(CourseSemester, course=course, term=term, year=year) @@ -97,6 +102,7 @@ def commit(request, department, number, page_type, term, year, slug, hash): return render(request, "pages/commit.html", data) + def edit(request, department, number, page_type, term, year, slug): if not request.user.is_authenticated(): return register(request) @@ -185,6 +191,7 @@ def edit(request, department, number, page_type, term, year, slug): } return render(request, "pages/edit.html", data) + # semester should only be filled out if the page doesn't exist and we want to create it def create(request, department, number, page_type, semester=None): if not request.user.is_authenticated(): @@ -266,7 +273,16 @@ def create(request, department, number, page_type, semester=None): return render(request, 'pages/create.html', data) + def random(request): pages = Page.objects.all() random_page = random_module.choice(pages) - return show(request, random_page.course_sem.course.department.short_name.upper(), random_page.course_sem.course.number, random_page.page_type, random_page.course_sem.term, random_page.course_sem.year, random_page.slug) + + return show( + request, + random_page.course_sem.course.department.short_name.upper(), + random_page.course_sem.course.number, + random_page.page_type, + random_page.course_sem.term, + random_page.course_sem.year, random_page.slug + ) diff --git a/wiki/admin/courses.py b/wiki/admin/courses.py index dfac3ba..2629044 100755 --- a/wiki/admin/courses.py +++ b/wiki/admin/courses.py @@ -1,6 +1,7 @@ -from wiki.models.courses import Course, CourseSemester, Professor from django.contrib import admin +from wiki.models.courses import Course, CourseSemester, Professor + class CourseAdmin(admin.ModelAdmin): exclude = ('num_watchers', 'latest_activity', 'watchers') diff --git a/wiki/admin/departments.py b/wiki/admin/departments.py index 15d8890..5876ddf 100755 --- a/wiki/admin/departments.py +++ b/wiki/admin/departments.py @@ -1,4 +1,6 @@ -from wiki.models.departments import Department from django.contrib import admin +from wiki.models.departments import Department + + admin.site.register(Department) diff --git a/wiki/admin/faculties.py b/wiki/admin/faculties.py index e3038c8..0dfdb6e 100755 --- a/wiki/admin/faculties.py +++ b/wiki/admin/faculties.py @@ -1,4 +1,6 @@ -from wiki.models.faculties import Faculty from django.contrib import admin +from wiki.models.faculties import Faculty + + admin.site.register(Faculty) diff --git a/wiki/admin/pages.py b/wiki/admin/pages.py index a99e74c..12581f8 100644 --- a/wiki/admin/pages.py +++ b/wiki/admin/pages.py @@ -1,4 +1,6 @@ -from wiki.models.pages import Page from django.contrib import admin +from wiki.models.pages import Page + + admin.site.register(Page) diff --git a/wiki/admin/series.py b/wiki/admin/series.py index 8e0578c..bd7a906 100644 --- a/wiki/admin/series.py +++ b/wiki/admin/series.py @@ -1,12 +1,15 @@ -from wiki.models.series import Series, SeriesPage from django.contrib import admin +from wiki.models.series import Series, SeriesPage + + class SeriesPageInline(admin.TabularInline): model = SeriesPage + class SeriesAdmin(admin.ModelAdmin): inlines = [SeriesPageInline] prepopulated_fields = {"slug": ("name",)} + admin.site.register(Series, SeriesAdmin) -#admin.site.register(SeriesPage) diff --git a/wiki/context_processors.py b/wiki/context_processors.py index 31f758c..b96dd19 100644 --- a/wiki/context_processors.py +++ b/wiki/context_processors.py @@ -1,4 +1,5 @@ from settings import COMPILE_LESS + def less_compilation(request): return {'compile_less': COMPILE_LESS} diff --git a/wiki/models/courses.py b/wiki/models/courses.py index aeb2950..bb809e9 100755 --- a/wiki/models/courses.py +++ b/wiki/models/courses.py @@ -5,6 +5,7 @@ from wiki.models.history import HistoryItem from wiki.utils.currents import current_year, current_term + class Course(models.Model): class Meta: app_label = 'wiki' @@ -61,6 +62,7 @@ def recent_activity(self, limit=5): else: return course_history + class CourseSemester(models.Model): class Meta: app_label = 'wiki' diff --git a/wiki/models/departments.py b/wiki/models/departments.py index bf3b11d..c8e0e14 100755 --- a/wiki/models/departments.py +++ b/wiki/models/departments.py @@ -1,5 +1,6 @@ from django.db import models + class Department(models.Model): class Meta: app_label = 'wiki' diff --git a/wiki/models/faculties.py b/wiki/models/faculties.py index ad5f341..bbe00f7 100755 --- a/wiki/models/faculties.py +++ b/wiki/models/faculties.py @@ -1,5 +1,6 @@ from django.db import models + class Faculty(models.Model): class Meta: app_label = 'wiki' diff --git a/wiki/models/page_types.py b/wiki/models/page_types.py index 478bb3c..0eb2ea5 100644 --- a/wiki/models/page_types.py +++ b/wiki/models/page_types.py @@ -2,7 +2,9 @@ # Done this way because it's better than the 4 other possible ways (believe me I tried them all) # Define all the page types here, and their short names import re + from django.template.defaultfilters import slugify + from wiki.utils.constants import terms, years, exam_types """ HOW TO CREATE A NEW PAGE TYPE @@ -14,6 +16,7 @@ ALTHOUGH IF YOU HAVE CUSTOM NAMES YOU CAN OVERRIDE ANY OF THE RELEVANT METHODS, ETC """ + class PageType: # Defaults - override if necessary uneditable_fields = ['semester', 'subject'] @@ -97,6 +100,7 @@ def find_errors(self, data): else: return [] + class LectureNote(PageType): short_name = 'lecture-notes' long_name = 'Lecture notes' @@ -125,6 +129,7 @@ def get_validators(self, data): #(len(data['subject']) > 0, 'Invalid subject'), ] + class PastExam(PageType): short_name = 'past-exam' long_name = 'Past exam' @@ -146,6 +151,7 @@ def get_validators(self, data): (data['exam_type'] in exam_types, 'Invalid exam type'), ] + class CourseSummary(PageType): short_name = 'summary' long_name = 'Course summary' @@ -161,6 +167,7 @@ def get_validators(self, data): (len(data['subject']) > 0, 'Invalid subject'), ] + class VocabList(PageType): short_name = 'vocab-list' long_name = 'Vocabulary list' @@ -179,6 +186,7 @@ def get_validators(self, data): (len(data['subject']) > 0, 'Invalid subject'), ] + class CourseQuiz(PageType): short_name = 'course-quiz' long_name = 'Multiple choice quiz' diff --git a/wiki/models/series.py b/wiki/models/series.py index 3d5f59e..042f970 100644 --- a/wiki/models/series.py +++ b/wiki/models/series.py @@ -1,5 +1,6 @@ from django.db import models + class Series(models.Model): class Meta: app_label = 'wiki' @@ -19,6 +20,7 @@ def get_absolute_url(self): def get_num_total(self): return self.seriespage_set.count() + class SeriesPage(models.Model): class Meta: app_label = 'wiki' diff --git a/wiki/templatetags/wikinotes_markup.py b/wiki/templatetags/wikinotes_markup.py index 558e14f..290a15b 100644 --- a/wiki/templatetags/wikinotes_markup.py +++ b/wiki/templatetags/wikinotes_markup.py @@ -1,7 +1,8 @@ +import re + +import markdown from django import template from django.utils.html import escape -import markdown -import re register = template.Library() diff --git a/wiki/tests/markdown.py b/wiki/tests/markdown.py index eb20095..766ed9f 100644 --- a/wiki/tests/markdown.py +++ b/wiki/tests/markdown.py @@ -1,8 +1,9 @@ from django.utils import unittest + from wiki.templatetags.wikinotes_markup import wikinotes_markdown as md + class TestMarkdown(unittest.TestCase): - elements = { "bold" : "**bold**", "italic" : "*italic*", diff --git a/wiki/utils/gitutils.py b/wiki/utils/gitutils.py index 3f8a6e8..dd3fb4f 100644 --- a/wiki/utils/gitutils.py +++ b/wiki/utils/gitutils.py @@ -1,12 +1,15 @@ -import git -import gitdb import datetime from math import log from os import makedirs, environ +import git +import gitdb + + class NoChangesError(Exception): pass + class Git: def __init__(self, path_to_repo): self.full_path = path_to_repo.strip('/') # don't need leading/trailing slashes diff --git a/wiki/utils/history.py b/wiki/utils/history.py index 11b4c27..8dfeaf4 100644 --- a/wiki/utils/history.py +++ b/wiki/utils/history.py @@ -1,9 +1,11 @@ import datetime + # Put here because, why not def get_date_x_days_ago(num_days): return datetime.datetime.now() - datetime.timedelta(days=num_days) + # Used by HistoryItem to output a human-readable timestamp # More vague than the built-in timesince filter, which is good # Written by Joey Bratton http://www.joeyb.org/blog/2009/10/08/custom-django-template-filter-for-humanized-timesince diff --git a/wiki/utils/pages.py b/wiki/utils/pages.py index cae9ff8..6ec13e6 100644 --- a/wiki/utils/pages.py +++ b/wiki/utils/pages.py @@ -1,6 +1,8 @@ import inspect + from wiki.models import page_types as types + # A dictionary for reverse lookup of page type by the short name # So, given "course-quiz", find the CourseQuiz object etc page_types = {} diff --git a/wiki/utils/users.py b/wiki/utils/users.py index 38912fa..45aa8fa 100644 --- a/wiki/utils/users.py +++ b/wiki/utils/users.py @@ -1,5 +1,6 @@ import re + def validate_username(username): if re.match('^\w+$', username): return True