Changeset - 60010999d25f
[Not reviewed]
0 8 0
Ben Sturmfels (bsturmfels) - 8 months ago 2023-09-07 12:59:23
ben@sturm.com.au
Remove use of python3-future
8 files changed with 37 insertions and 26 deletions:
0 comments (0 inline, 0 general)
README.md
Show inline comments
 
Software Freedom Conservancy website
 
====================================
 

	
 

	
 
Contributing
 
============
 
------------
 

	
 
The canonical location for this repository is [on Conservancy’s
 
Kallithea instance](http://k.sfconservancy.org/website).  Copies of
 
Kallithea instance](https://k.sfconservancy.org/website).  Copies of
 
this repository elsewhere, such as Github, are for backup purposes
 
only..
 

	
 

	
 
License
 
=======
 
-------
 

	
 
The software included herein, such as the Python source files, are generally
 
licensed [AGPLv3](AGPLv3)-or-later.  The Javascript is a hodgepodge of
 
licensing, but all of it is compatible with [AGPLv3](AGPLv3)-or-later.  See
 
the notices at the top of each Javascript file for licensing details.
 

	
 
The content and text (such as the HTML files) is currently
 
[CC-BY-SA-3.0](CC-By-SA-3.0).
 

	
 
Server Configuration
 
====================
 

	
 
conservancy's webserver runs on a machine called
 
dogwood.sfconservancy.org, which is a standard Debian installation.
 
Server configuration
 
--------------------
 

	
 
conservancy's webserver runs on a machine called aspen.sfconservancy.org, which
 
is a standard Debian installation.
 

	
 
The following packages are installed to make Django and Apache work on a
 
squeeze install:
 

	
 
    $ aptitude install python-django apache2 sqlite3 python2.5-sqlite libapache2-mod-python
 

	
 
    $ aptitude install python-django apache2 sqlite3 python3-sqlite libapache2-mod-wsgi-py3
 

	
 

	
 
Django Setup
 
============
 
Django setup
 
------------
 

	
 
0. Make sure the Python module 'djangopw', with the global variable
 
   'djangoadmin_password' is somewhere importable in the default
 
   PYTHON_PATH.
 

	
 

	
 
Local development
 
---------
 

	
 
    python3 -m pip install -r requirements.txt
 
    cd www
 
    python manage.py runserver
 

	
 
Deploying
 
---------
 

	
 
Changes pushed to the https://k.sfconservancy.org/website repository are
 
automatically deployed to the production website by the `conservancy-www-update`
 
SystemD timer. See `systemd/conservancy-www-update.timer` for details.
requirements.txt
Show inline comments
 
beautifulsoup4==4.9.3
 
Django==1.11.29
 
soupsieve==1.9.6
 
html5lib==0.999999999
 
future
 

	
 
django_countries==5.5  # Supports both Python 2 and 3.
www/conservancy/__init__.py
Show inline comments
 
from past.builtins import basestring
 
from builtins import object
 
import hashlib
 

	
 
from django.conf import settings
 
from django.template import RequestContext
 

	
 
# 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(object):
 
    def __init__(self, given_hash_or_params, params_hash_key=None):
 
        if params_hash_key is None:
 
            self.given_hash = given_hash_or_params
 
        else:
 
            self.given_hash = given_hash_or_params.get(params_hash_key)
 
        seed = getattr(settings, 'CONSERVANCY_SECRET_KEY', '').encode('utf-8')
 
        self.hasher = hashlib.sha256(seed)
 
        if isinstance(self.given_hash, basestring):
 
        if isinstance(self.given_hash, str):
 
            self.hash_type = type(self.given_hash)
 
        else:
 
            self.hash_type = type(self.hasher.hexdigest())
 
        self.valid = None
 
        if not (self.given_hash and seed):
 
            self.fail()
 

	
 
    def __enter__(self):
 
        self.valid = self.valid and None
 
        return self
 

	
 
    def __exit__(self, exc_type, exc_value, exc_tb):
www/conservancy/apps/blog/models.py
Show inline comments
 
from future import standard_library
 
standard_library.install_aliases()
 
from builtins import object
 
from django.db import models
 
from django.conf import settings
 
from conservancy import bsoup
 
from conservancy.apps.staff.models import Person
 
from datetime import datetime, timedelta
 

	
 
class EntryTag(models.Model):
 
    """Tagging for blog entries"""
 

	
 
    label = models.CharField(max_length=100)
 
    slug = models.SlugField()
www/conservancy/apps/fundgoal/models.py
Show inline comments
 
from __future__ import division
 
from past.utils import old_div
 
from builtins import object
 
import random
 

	
 
from django.db import models
 

	
 

	
 
class FundraisingGoal(models.Model):
 
    """Conservancy fundraiser Goal"""
 

	
 
    fundraiser_code_name = models.CharField(max_length=200, blank=False, unique=True)
 
    fundraiser_goal_amount = models.DecimalField(max_digits=10, decimal_places=2)
 
    fundraiser_so_far_amount = models.DecimalField(max_digits=10, decimal_places=2)
 
    fundraiser_donation_count = models.IntegerField()
 
    fundraiser_donation_count_disclose_threshold = models.IntegerField()
 
    fundraiser_endtime = models.DateTimeField(null=True)
 

	
 
    def __str__(self):
 
        return self.fundraiser_code_name
 

	
 
    def percentage_there(self):
 
        return (old_div(self.fundraiser_so_far_amount, self.fundraiser_goal_amount) ) * 100
 
    
 
        return self.fundraiser_so_far_amount / self.fundraiser_goal_amount * 100
 

	
 
    class Meta(object):
 
        ordering = ('fundraiser_code_name',)
 

	
 
    def providers(self):
 
        return GoalProvider.objects.filter(fundraising_goal=self)
 

	
 
    def random_providers(self, k=None):
 
        providers = self.providers()
 
        if not providers.exists():
 
            return None
 
        elif k is None:
 
            return random.choice(providers)
www/conservancy/apps/news/models.py
Show inline comments
 
from future import standard_library
 
standard_library.install_aliases()
 
from builtins import object
 
from django.db import models
 
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 datetime import datetime, timedelta
 

	
 
class PressRelease(models.Model, bsoup.SoupModelMixin):
 
    """News release model"""
 

	
www/conservancy/apps/news/templatetags/fill_url.py
Show inline comments
 
from future import standard_library
 
standard_library.install_aliases()
 
from builtins import zip
 
import urllib.parse
 

	
 
from django import template
 

	
 
register = template.Library()
 

	
 
@register.filter(name='fill_url')
 
def fill_url(given_url, base_url):
 
    """"Fill out" missing pieces of one URL from another.
 

	
 
    This function parses the given URL, and if it's missing any pieces
www/conservancy/middleware.py
Show inline comments
 
from builtins import object
 
from future.utils import raise_
 
from django import http
 
from django.conf import settings
 
from django.utils.cache import patch_response_headers
 

	
 
class ForceCanonicalHostnameMiddleware(object):
 

	
 
    def process_request(self, request):
 
        """Modified common middleware for Conservancy site
 

	
 
        * Performs redirects to strip trailing "index.html"
 
        * performs redirects based on APPEND_SLASH
 
        * performs redirects based on site-specific REDIRECT_TABLE
...
 
@@ -20,25 +19,25 @@ class ForceCanonicalHostnameMiddleware(object):
 
            url = 'https://sfconservancy.org%s' % request.path
 
            return http.HttpResponseRedirect(url)
 

	
 
        # Check for a redirect based on settings.APPEND_SLASH
 
        host = request.get_host()
 
        old_url = [host, request.path]
 
        new_url = old_url[:]
 
        # Append a slash if append_slash is set and the URL doesn't have a
 
        # trailing slash or a file extension.
 
        if settings.APPEND_SLASH and (old_url[1][-1] != '/') and ('.' not in old_url[1].split('/')[-1]):
 
            new_url[1] = new_url[1] + '/'
 
            if settings.DEBUG and request.method == 'POST':
 
                raise_(RuntimeError, "You called this URL via POST, but the URL doesn't end in a slash and you have APPEND_SLASH set. Django can't redirect to the slash URL while maintaining POST data. Change your form to point to %s%s (note the trailing slash), or set APPEND_SLASH=False in your Django settings." % (new_url[0], new_url[1]))
 
                raise(RuntimeError, "You called this URL via POST, but the URL doesn't end in a slash and you have APPEND_SLASH set. Django can't redirect to the slash URL while maintaining POST data. Change your form to point to %s%s (note the trailing slash), or set APPEND_SLASH=False in your Django settings." % (new_url[0], new_url[1]))
 
        # Strip trailing index.html
 
        if new_url[1].endswith('/index.html'):
 
            new_url[1] = new_url[1][:new_url[1].rfind('index.html')]
 
        # Consult redirect table (if exists)
 
        if hasattr(settings, "REDIRECT_TABLE"):
 
            if new_url[1] in settings.REDIRECT_TABLE:
 
                new_url[1] = settings.REDIRECT_TABLE[new_url[1]]
 
        if new_url != old_url:
 
            # Force canonical hostname
 
            if settings.FORCE_CANONICAL_HOSTNAME:
 
                new_url[0] = settings.FORCE_CANONICAL_HOSTNAME
 
            # Redirect
0 comments (0 inline, 0 general)