Switch to relative imports

The relative imports make it clearer what code is within the project and where
it's coming from.
This commit is contained in:
Ben Sturmfels 2023-10-20 09:44:24 +11:00
parent 439f777bda
commit b7e2ce2a4d
Signed by: bsturmfels
GPG key ID: 023C05E2C9C068F0
31 changed files with 131 additions and 84 deletions

View file

@ -2,10 +2,6 @@ import hashlib
from django.conf import settings from django.conf import settings
# This is backwards compatibilty support for a custom function we wrote
# ourselves that is no longer necessary in modern Django.
from django.shortcuts import render as render_template_with_context
class ParameterValidator: class ParameterValidator:
def __init__(self, given_hash_or_params, params_hash_key=None): def __init__(self, given_hash_or_params, params_hash_key=None):

View file

@ -1,8 +1,7 @@
# Generated by Django 1.11.29 on 2023-01-27 06:02 # Generated by Django 1.11.29 on 2023-01-27 06:02
import conservancy.apps.assignment.models
from django.db import migrations, models from django.db import migrations, models
from ..models import validate_mutiple_urls
class Migration(migrations.Migration): class Migration(migrations.Migration):
@ -24,6 +23,6 @@ class Migration(migrations.Migration):
migrations.AlterField( migrations.AlterField(
model_name='assignment', model_name='assignment',
name='repositories', name='repositories',
field=models.TextField(help_text='List of URLs, one per line', validators=[conservancy.apps.assignment.models.validate_mutiple_urls], verbose_name='Code repositories containing contributions of yours whose copyright you are assigning'), field=models.TextField(help_text='List of URLs, one per line', validators=[validate_mutiple_urls], verbose_name='Code repositories containing contributions of yours whose copyright you are assigning'),
), ),
] ]

View file

@ -1,11 +1,14 @@
from django.contrib import admin from django.contrib import admin
from conservancy.apps.blog.models import EntryTag, Entry
from .models import EntryTag, Entry
class EntryTagAdmin(admin.ModelAdmin): class EntryTagAdmin(admin.ModelAdmin):
prepopulated_fields = {'slug': ('label',)} prepopulated_fields = {'slug': ('label',)}
admin.site.register(EntryTag, EntryTagAdmin) admin.site.register(EntryTag, EntryTagAdmin)
class EntryAdmin(admin.ModelAdmin): class EntryAdmin(admin.ModelAdmin):
list_display = ('pub_date', 'headline', 'author') list_display = ('pub_date', 'headline', 'author')
list_filter = ['pub_date'] list_filter = ['pub_date']

View file

@ -1,8 +1,11 @@
from datetime import datetime, timedelta
from django.db import models from django.db import models
from django.conf import settings from django.conf import settings
from conservancy import bsoup
from conservancy.apps.staff.models import Person from ... import bsoup
from datetime import datetime, timedelta from ..staff.models import Person
class EntryTag(models.Model): class EntryTag(models.Model):
"""Tagging for blog entries""" """Tagging for blog entries"""

View file

@ -1,8 +1,10 @@
from django.conf.urls import url, include
from conservancy.apps.blog.models import Entry, EntryTag # relative import
from conservancy.apps.staff.models import Person
from datetime import datetime from datetime import datetime
from conservancy.apps.blog.views import last_name, BlogYearArchiveView, BlogMonthArchiveView, BlogDayArchiveView, BlogDateDetailView, custom_index, query
from django.conf.urls import url, include
from .models import Entry, EntryTag
from ..staff.models import Person
from .views import last_name, BlogYearArchiveView, BlogMonthArchiveView, BlogDayArchiveView, BlogDateDetailView, custom_index, query
extra_context = {} extra_context = {}

View file

@ -1,12 +1,14 @@
from conservancy.apps.blog.models import Entry, EntryTag # relative import from datetime import datetime
# from django.views.generic.list_detail import object_list from functools import reduce
from django.views.generic import ListView from django.views.generic import ListView
from django.views.generic.dates import YearArchiveView, MonthArchiveView, DayArchiveView, DateDetailView from django.views.generic.dates import YearArchiveView, MonthArchiveView, DayArchiveView, DateDetailView
from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
from conservancy.apps.staff.models import Person
from django.shortcuts import get_object_or_404, render from django.shortcuts import get_object_or_404, render
from datetime import datetime
from functools import reduce from .models import Entry, EntryTag
from ..staff.models import Person
def OR_filter(field_name, objs): def OR_filter(field_name, objs):
from django.db.models import Q from django.db.models import Q

View file

@ -1,5 +1,7 @@
from django.contrib import admin from django.contrib import admin
from conservancy.apps.contacts.models import ContactEntry
from .models import ContactEntry
class ContactEntryAdmin(admin.ModelAdmin): class ContactEntryAdmin(admin.ModelAdmin):
list_display = ('email', 'subscribe_conservancy') list_display = ('email', 'subscribe_conservancy')

View file

@ -1,8 +1,10 @@
from django.shortcuts import render from django.shortcuts import render
from django import forms from django import forms
from conservancy.apps.contacts.models import ContactEntry
from django.forms import ModelForm from django.forms import ModelForm
from .models import ContactEntry
def subscribe(request): def subscribe(request):
"""Mailing list subscription form """Mailing list subscription form
""" """

View file

@ -1,5 +1,6 @@
from django.conf.urls import url, include from django.conf.urls import url, include
from conservancy.apps.contractpatch import views as cpatch_views
from . import views as cpatch_views
urlpatterns = [ urlpatterns = [
url(r'', cpatch_views.index), url(r'', cpatch_views.index),

View file

@ -1,13 +1,16 @@
from conservancy import render_template_with_context
from conservancy.apps.blog.models import Entry as BlogEntry
from datetime import datetime from datetime import datetime
from django.shortcuts import render
from ..blog.models import Entry
def index(request): def index(request):
filters = { filters = {
'pub_date__lte': datetime.now(), 'pub_date__lte': datetime.now(),
'tags__slug': 'ContractPatch', 'tags__slug': 'ContractPatch',
} }
context = { context = {
'blog_entries': BlogEntry.objects.filter(**filters)[:3], 'blog_entries': Entry.objects.filter(**filters)[:3],
} }
return render_template_with_context(request, "contractpatch/index.html", context) return render(request, "contractpatch/index.html", context)

View file

@ -1,5 +1,6 @@
from django.contrib import admin from django.contrib import admin
from conservancy.apps.events.models import EventTag, Event, EventMedia
from .models import EventTag, Event, EventMedia
admin.site.register(EventTag) admin.site.register(EventTag)

View file

@ -1,8 +1,11 @@
from django.db import models
from conservancy.apps.staff.models import Person
from conservancy.apps.worldmap.models import EarthLocation
from datetime import datetime, timedelta from datetime import datetime, timedelta
from django.db import models
from ..staff.models import Person
from ..worldmap.models import EarthLocation
class EventTag(models.Model): class EventTag(models.Model):
"""Tagging for events """Tagging for events

View file

@ -1,5 +1,6 @@
from django.conf.urls import patterns, url, include from django.conf.urls import patterns, url, include
from conservancy.apps.events.models import Event
from .models import Event
info_dict = { info_dict = {
'queryset': Event.objects.all(), 'queryset': Event.objects.all(),

View file

@ -3,9 +3,9 @@ from django.shortcuts import render
from django.http import Http404, HttpResponse from django.http import Http404, HttpResponse
from django.template import loader from django.template import loader
from django.core.exceptions import ObjectDoesNotExist from django.core.exceptions import ObjectDoesNotExist
from conservancy.apps.events.models import Event
# for debugging... from .models import Event
from django.http import HttpResponse
def event_detail(request, year, slug, queryset, **kwargs): def event_detail(request, year, slug, queryset, **kwargs):
"""This view shows event detail. """This view shows event detail.

View file

@ -1,14 +1,17 @@
from django.contrib import admin from django.contrib import admin
from conservancy.apps.fundgoal import models as fundgoal_models
from . import models
class FundraisingGoalAdmin(admin.ModelAdmin): class FundraisingGoalAdmin(admin.ModelAdmin):
list_display = ('fundraiser_code_name', 'fundraiser_goal_amount') list_display = ('fundraiser_code_name', 'fundraiser_goal_amount')
class GoalProviderAdmin(admin.ModelAdmin): class GoalProviderAdmin(admin.ModelAdmin):
fields = [ fields = [
'fundraising_goal', 'fundraising_goal',
'provider_name', 'provider_name',
] ]
admin.site.register(fundgoal_models.FundraisingGoal, FundraisingGoalAdmin) admin.site.register(models.FundraisingGoal, FundraisingGoalAdmin)
admin.site.register(fundgoal_models.GoalProvider, GoalProviderAdmin) admin.site.register(models.GoalProvider, GoalProviderAdmin)

View file

@ -1,6 +1,7 @@
from conservancy.apps.fundgoal.models import FundraisingGoal
from django.http import JsonResponse from django.http import JsonResponse
from .models import FundraisingGoal
def view(request): def view(request):
"""JSON version of request """JSON version of request

View file

@ -1,5 +1,7 @@
from django.contrib import admin from django.contrib import admin
from conservancy.apps.news.models import PressRelease, ExternalArticleTag, ExternalArticle
from .models import PressRelease, ExternalArticleTag, ExternalArticle
class PressReleaseAdmin(admin.ModelAdmin): class PressReleaseAdmin(admin.ModelAdmin):
list_display = ("headline", "pub_date") list_display = ("headline", "pub_date")

View file

@ -1,10 +1,13 @@
from datetime import datetime, timedelta
from django.db import models from django.db import models
from django.conf import settings from django.conf import settings
from conservancy import bsoup
from conservancy.apps.staff.models import Person
from conservancy.apps.events.models import Event
from django.contrib.sites.models import Site from django.contrib.sites.models import Site
from datetime import datetime, timedelta
from ... import bsoup
from ..staff.models import Person
from ..events.models import Event
class PressRelease(models.Model, bsoup.SoupModelMixin): class PressRelease(models.Model, bsoup.SoupModelMixin):
"""News release model""" """News release model"""

View file

@ -19,8 +19,9 @@
from django.conf.urls import url, include from django.conf.urls import url, include
from django.conf import settings from django.conf import settings
from conservancy.apps.news.models import PressRelease, ExternalArticle
from conservancy.apps.news.views import NewsYearArchiveView, NewsMonthArchiveView, NewsDayArchiveView, NewsDateDetailView, listing from .models import PressRelease, ExternalArticle
from .views import NewsYearArchiveView, NewsMonthArchiveView, NewsDayArchiveView, NewsDateDetailView, listing
info_dict = { info_dict = {
'queryset': PressRelease.objects.all().filter(sites__id__exact=settings.SITE_ID), 'queryset': PressRelease.objects.all().filter(sites__id__exact=settings.SITE_ID),

View file

@ -1,15 +1,15 @@
# from django.views.generic.list_detail import object_list from datetime import datetime
from django.views.generic import ListView from django.views.generic import ListView
from django.shortcuts import render from django.shortcuts import render
from django.views.generic.dates import YearArchiveView, MonthArchiveView, DayArchiveView, DateDetailView from django.views.generic.dates import YearArchiveView, MonthArchiveView, DayArchiveView, DateDetailView
from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
from conservancy.apps.news.models import ExternalArticle
from conservancy.apps.news.models import PressRelease
from conservancy.apps.events.models import Event
from datetime import datetime
# for debugging...
from django.http import HttpResponse from django.http import HttpResponse
from .models import ExternalArticle
from .models import PressRelease
from ..events.models import Event
class NewsListView(ListView): class NewsListView(ListView):
extra_context = {} extra_context = {}

View file

@ -1,5 +1,7 @@
from django.contrib import admin from django.contrib import admin
from conservancy.apps.staff.models import Person
from .models import Person
class PersonAdmin(admin.ModelAdmin): class PersonAdmin(admin.ModelAdmin):
list_display = ("username", "formal_name", "casual_name", list_display = ("username", "formal_name", "casual_name",

View file

@ -1,5 +1,7 @@
from django.contrib import admin from django.contrib import admin
from conservancy.apps.summit_registration.models import SummitRegistration
from .models import SummitRegistration
class SummitRegistrationAdmin(admin.ModelAdmin): class SummitRegistrationAdmin(admin.ModelAdmin):
list_display = ('name', 'email', 'affiliation', 'cle_credit') list_display = ('name', 'email', 'affiliation', 'cle_credit')

View file

@ -1,7 +1,8 @@
from django.conf.urls import url from django.conf.urls import url
from django.views.generic import TemplateView from django.views.generic import TemplateView
from conservancy.apps.supporter import views as supp_views
from conservancy.static import views as static_views from . import views as supp_views
from ...static import views as static_views
INDEX_VIEW = supp_views.index INDEX_VIEW = supp_views.index
urlpatterns = [ urlpatterns = [

View file

@ -1,5 +1,8 @@
from django.shortcuts import render
import conservancy import conservancy
def index(request): def index(request):
with conservancy.ParameterValidator(request.GET, 'upgrade_id') as validator: with conservancy.ParameterValidator(request.GET, 'upgrade_id') as validator:
try: try:
@ -13,4 +16,4 @@ def index(request):
'partial_amount': partial_amount, 'partial_amount': partial_amount,
'minimum_amount': 120 - partial_amount, 'minimum_amount': 120 - partial_amount,
} }
return conservancy.render_template_with_context(request, "supporter/index.html", context) return render(request, "supporter/index.html", context)

View file

@ -1,5 +1,7 @@
from django.contrib import admin from django.contrib import admin
from conservancy.apps.supporters.models import Supporter
from .models import Supporter
class SupporterAdmin(admin.ModelAdmin): class SupporterAdmin(admin.ModelAdmin):
list_display = ('display_name', 'display_until_date') list_display = ('display_name', 'display_until_date')

View file

@ -1,5 +1,7 @@
from django.contrib import admin from django.contrib import admin
from conservancy.apps.worldmap.models import EarthLocation
from .models import EarthLocation
class EarthLocationAdmin(admin.ModelAdmin): class EarthLocationAdmin(admin.ModelAdmin):
list_display = ("label", "html_map_link") list_display = ("label", "html_map_link")

View file

@ -1,14 +1,16 @@
from django.contrib.syndication.views import Feed
from django.utils.feedgenerator import Rss201rev2Feed
from conservancy.apps.news.models import PressRelease
from conservancy.apps.blog.models import Entry as BlogEntry
from django.shortcuts import render
from django.conf import settings
from datetime import datetime from datetime import datetime
from functools import reduce
import itertools import itertools
import operator import operator
from functools import reduce
from django.conf import settings
from django.contrib.syndication.views import Feed
from django.shortcuts import render
from django.utils.feedgenerator import Rss201rev2Feed
from .apps.blog.models import Entry as BlogEntry
from .apps.news.models import PressRelease
class ConservancyFeedBase(Feed): class ConservancyFeedBase(Feed):
def copyright_holder(self): return "Software Freedom Conservancy" def copyright_holder(self): return "Software Freedom Conservancy"

View file

@ -1,19 +1,21 @@
from conservancy import render_template_with_context
from conservancy.apps.supporters.models import Supporter as Supporter
from conservancy.apps.news.models import PressRelease
from conservancy.apps.blog.models import Entry as BlogEntry
from datetime import datetime from datetime import datetime
from django.shortcuts import render
from .apps.blog.models import Entry
from .apps.news.models import PressRelease
from .apps.supporters.models import Supporter
def view(request): def view(request):
"""Conservancy front page view """Conservancy front page view
Performs all object queries necessary to render the front page. Performs all object queries necessary to render the front page.
""" """
now = datetime.now() now = datetime.now()
context = { context = {
'press_releases': PressRelease.objects.all().filter(pub_date__lte=now, sites=2)[:5], 'press_releases': PressRelease.objects.all().filter(pub_date__lte=now, sites=2)[:5],
'supporters_count': Supporter.objects.all().filter(display_until_date__gte=now).count(), 'supporters_count': Supporter.objects.all().filter(display_until_date__gte=now).count(),
'blog': BlogEntry.objects.all().filter(pub_date__lte=now)[:5], 'blog': Entry.objects.all().filter(pub_date__lte=now)[:5],
} }
return render_template_with_context(request, "frontpage.html", context) return render(request, "frontpage.html", context)

View file

@ -1,7 +1,7 @@
from datetime import datetime as DateTime from datetime import datetime as DateTime
import conservancy.settings from . import settings
from conservancy.apps.fundgoal.models import FundraisingGoal as FundraisingGoal from .apps.fundgoal.models import FundraisingGoal
SITE_FUNDGOAL = 'cy2022-end-year-match' SITE_FUNDGOAL = 'cy2022-end-year-match'
@ -18,8 +18,8 @@ def sitefundraiser(request):
'sitefundgoal': fundgoal_lookup(SITE_FUNDGOAL), 'sitefundgoal': fundgoal_lookup(SITE_FUNDGOAL),
} }
if conservancy.settings.FORCE_CANONICAL_HOSTNAME: if settings.FORCE_CANONICAL_HOSTNAME:
_HOST_URL_VAR = {'host_url': 'https://' + conservancy.settings.FORCE_CANONICAL_HOSTNAME} _HOST_URL_VAR = {'host_url': 'https://' + settings.FORCE_CANONICAL_HOSTNAME}
def host_url(request): def host_url(request):
return _HOST_URL_VAR return _HOST_URL_VAR
else: else:

View file

@ -1,7 +1,10 @@
from django.shortcuts import render
from conservancy.apps.supporters.models import Supporter as Supporter
from datetime import datetime, timedelta from datetime import datetime, timedelta
from django.shortcuts import render
from .apps.supporters.models import Supporter
def view(request): def view(request):
"""Conservancy Sponsors Page view """Conservancy Sponsors Page view

View file

@ -20,9 +20,9 @@
from django.conf.urls import url, include from django.conf.urls import url, include
from django.contrib import admin from django.contrib import admin
from conservancy import feeds, frontpage, sponsors from . import feeds, frontpage, sponsors
import conservancy.apps.fundgoal.views as fundgoal_views from .apps.fundgoal import views as fundgoal_views
import conservancy.static.views as static_views from .static import views as static_views
admin.autodiscover() admin.autodiscover()