Changeset - 31e51a774223
[Not reviewed]
www/conservancy/__init__.py
Show inline comments
 
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:
www/conservancy/apps/blog/models.py
Show inline comments
 
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()
 

	
 
    class Meta:
 
    class Meta(object):
 
        db_table = 'techblog_entrytag' # legacy
 

	
 
    def __unicode__(self):
 
        return self.label
 

	
 
    def get_absolute_url(self):
 
        return u"/blog/?tag=%s" % self.slug
 

	
 
class Entry(models.Model, bsoup.SoupModelMixin):
 
    """Blog entry"""
 

	
 
    headline = models.CharField(max_length=200)
 
    slug = models.SlugField(unique_for_date='pub_date')
 
    summary = models.TextField(help_text="Use raw HTML.  Unlike in the press release model, this summary is not included at the beginning of the body when the entry is displayed.")
 
    body = models.TextField(help_text="Use raw HTML.  Include the full body of the post.")
 
    pub_date = models.DateTimeField()
 
    author = models.ForeignKey(Person)
 
    tags = models.ManyToManyField(EntryTag, null=True, blank=True)
 

	
 
    date_created = models.DateTimeField(auto_now_add=True)
 
    date_last_modified = models.DateTimeField(auto_now=True)
 

	
 
    class Meta:
 
    class Meta(object):
 
        db_table = 'techblog_entries' # legacy
 
        verbose_name_plural = 'entries'
 
        ordering = ('-pub_date',)
 
        get_latest_by = 'pub_date'
 

	
 
    SOUP_ATTRS = ['body']
 

	
 
    def __unicode__(self):
 
        return self.headline
 

	
 
    def get_absolute_url(self):
 
        return (u"/blog/%s/%s/"
www/conservancy/apps/contacts/models.py
Show inline comments
 
from builtins import object
 
from django.db import models
 

	
 
class ContactEntry(models.Model):
 
    """Conservancy contact system
 

	
 
    Hopefully this will be deprecated soon"""
 

	
 
    email = models.EmailField() # should make it unique, but we really cannot
 
    subscribe_conservancy = models.BooleanField(default=False)
 

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

	
www/conservancy/apps/contacts/views.py
Show inline comments
 
from builtins import object
 
from django.shortcuts import render
 
from django import forms
 
from conservancy.apps.contacts.models import ContactEntry
 
from django.forms import ModelForm
 

	
 
def subscribe(request):
 
    """Mailing list subscription form
 
    """
 

	
 
    class ContactEntryForm(ModelForm):
 
        class Meta:
 
        class Meta(object):
 
            model = ContactEntry
 

	
 
    ContactEntryForm.base_fields['subscribe_conservancy'].label = 'Receive Software Freedom Conservancy updates'
 

	
 
    if request.method == 'POST':
 
        form = ContactEntryForm(request.POST)
 
        if form.is_valid():
 
            form.save()
 
            return render(request, 'contacts/subscribe_success.html', {'form': form.cleaned_data})
 
    else:
 
        form = ContactEntryForm()
 

	
www/conservancy/apps/events/models.py
Show inline comments
 
from builtins import object
 
from django.db import models
 
from conservancy.apps.staff.models import Person
 
from conservancy.apps.worldmap.models import EarthLocation
 
from datetime import datetime, timedelta
 

	
 
class EventTag(models.Model):
 
    """Tagging for events
 

	
 
    (currently unused)
 
    """
 

	
 
    label = models.CharField(max_length=100)
...
 
@@ -37,25 +38,25 @@ class Event(models.Model):
 
    datetime = models.CharField("Date and Time", max_length=300, blank=True)
 
    slug = models.SlugField(unique_for_year='date')
 
    description = models.TextField(blank=True)
 
    people = models.ManyToManyField(Person, null=True, blank=True)
 
    location = models.CharField(max_length=1000)
 
    earth_location = models.ForeignKey(EarthLocation, null=True, blank=True,
 
                                       help_text="Label will not be displayed")
 
    tags = models.ManyToManyField(EventTag, null=True, blank=True)
 

	
 
    date_created = models.DateTimeField(auto_now_add=True)
 
    date_last_modified = models.DateTimeField(auto_now=True)
 

	
 
    class Meta:
 
    class Meta(object):
 
        ordering = ("-date",)
 

	
 
    def __unicode__(self):
 
        return u"%s (%s)" % (self.title, self.date)
 

	
 
    def get_absolute_url(self):
 
        return u"/events/%s/%s/" % (self.date.strftime("%Y"), self.slug)
 

	
 
    def day_after(self):
 
        return self.date + timedelta(days=1)
 

	
 
    # for aggregate feed
...
 
@@ -77,18 +78,18 @@ class EventMedia(models.Model):
 
                                       ('A', 'Audio'),
 
                                       ('V', 'Video')))
 
    local = models.CharField(max_length=300, blank=True,
 
                             help_text="Local filename of the resource.  File should be uploaded into the static directory that corresponds to the event.")
 
    # verify_exists removed https://docs.djangoproject.com/en/1.7/releases/1.4/
 
    remote = models.URLField(blank=True,
 
                             help_text="Remote URL of the resource.  Required if 'local' is not given.")
 
    novel = models.BooleanField(help_text="Is it a new piece of media or another form of an old one?  If it is new it will be included in the event-media RSS feed and shown on the front page for a bit.", default=False)
 

	
 
    date_created = models.DateTimeField(auto_now_add=True)
 
    date_last_modified = models.DateTimeField(auto_now=True)
 

	
 
    class Meta:
 
    class Meta(object):
 
        verbose_name_plural = 'event media'
 

	
 
    def __unicode__(self):
 
        return u"%s media: %s" % (self.event, self.format)
 

	
www/conservancy/apps/fundgoal/models.py
Show inline comments
 
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 __unicode__(self):
 
        return self.fundraiser_code_name
 

	
 
    def percentage_there(self):
 
        return (self.fundraiser_so_far_amount / self.fundraiser_goal_amount ) * 100
 
    
 
    class Meta:
 
    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)
 
        else:
www/conservancy/apps/news/models.py
Show inline comments
 
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"""
 

	
 
    headline = models.CharField(max_length=300)
 
    subhead = models.CharField(max_length=300, blank=True)
 
    slug = models.SlugField(unique_for_date="pub_date",
 
                            help_text=("automatically built from headline"))
 
    summary = models.TextField(help_text="First paragraph (raw HTML)")
 
    body = models.TextField(help_text="Remainder of post (raw HTML)",
 
                            blank=True)
 
    pub_date = models.DateTimeField("date [to be] published")
 
    sites = models.ManyToManyField(Site)
 

	
 
    date_last_modified = models.DateTimeField(auto_now=True)
 

	
 
    class Meta:
 
    class Meta(object):
 
        ordering = ("-pub_date",)
 
        get_latest_by = "pub_date"
 

	
 
    SOUP_ATTRS = ['summary', 'body']
 

	
 
    def __unicode__(self):
 
        return self.headline
 

	
 
    def get_absolute_url(self):
 
        return u"/news/%s/%s/" % (self.pub_date.strftime("%Y/%b/%d").lower(),
 
                                  self.slug)
 

	
www/conservancy/apps/staff/models.py
Show inline comments
 
from builtins import object
 
from django.db import models
 

	
 
class Person(models.Model):
 
    """Staff members
 

	
 
    Referenced from other models (blog, events, etc)
 
    """
 

	
 
    username = models.CharField(max_length=20)
 
    formal_name = models.CharField(max_length=200)
 
    casual_name = models.CharField(max_length=200)
 
#    title = models.CharField(max_length=200, blank=True)
 
#    biography = models.TextField(blank=True)
 
#    phone = models.CharField(max_length=30, blank=True)
 
#    gpg_key = models.TextField(blank=True)
 
#    gpg_fingerprint = models.CharField(max_length=100, blank=True)
 
    currently_employed = models.BooleanField(default=True)
 

	
 
    date_created = models.DateTimeField(auto_now_add=True)
 
    date_last_modified = models.DateTimeField(auto_now=True)
 

	
 
    class Meta:
 
    class Meta(object):
 
        verbose_name_plural = 'people'
 

	
 
    def __unicode__(self):
 
        return self.username
 

	
 
    def biography_url(self):
 
        return u"/about/#%s" % self.username
 

	
www/conservancy/apps/summit_registration/models.py
Show inline comments
 
from builtins import object
 
from django.db import models
 

	
 
class SummitRegistration(models.Model):
 
    """Form fields for summit registrants"""
 

	
 
    name = models.CharField(max_length=300)
 
    affiliation = models.CharField(max_length=700, blank=True)
 
    address = models.TextField(blank=True)
 
    email = models.EmailField(blank=True)
 
    phone = models.CharField(max_length=100, blank=True)
 
    date_created = models.DateField(auto_now_add=True)
 
    cle_credit = models.BooleanField(default=True)
 

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

	
www/conservancy/apps/summit_registration/views.py
Show inline comments
 
from builtins import object
 
from django.shortcuts import render
 
from django import forms
 
from conervancy.apps.summit_registration.models import SummitRegistration
 

	
 
def register(request):
 
    """Summit registration form view
 
    """
 

	
 
    class SummitForm(ModelForm):
 
        class Meta:
 
        class Meta(object):
 
            model = SummitRegistration
 

	
 
    SummitForm.base_fields['email'].label = 'Email address'
 
    SummitForm.base_fields['phone'].label = 'Phone number'
 
    SummitForm.base_fields['address'].label = 'Mailing address'
 
    SummitForm.base_fields['cle_credit'].label = 'Attending for CLE credit?'
 

	
 
    if request.method == 'POST':
 
        form = SummitForm(request.POST)
 
        if form.is_valid():
 
            form.save()
 
            return render(reqeust, 'summit_registration/register_success.html', {'form': form.cleaned_data})
www/conservancy/apps/supporters/models.py
Show inline comments
 
from builtins import object
 
from django.db import models
 

	
 
class Supporter(models.Model):
 
    """Conservancy Supporter listing"""
 

	
 
    display_name = models.CharField(max_length=200, blank=False)
 
    display_until_date = models.DateTimeField("date until which this supporter name is displayed")
 
    ledger_entity_id = models.CharField(max_length=200, blank=False)
 

	
 
    def test(self):
 
        return "TESTING"
 
    def __unicode__(self):
 
        return self.display_name
 

	
 
    class Meta:
 
    class Meta(object):
 
        ordering = ('ledger_entity_id',)
www/conservancy/apps/worldmap/models.py
Show inline comments
 
from builtins import object
 
from django.db import models
 

	
 
class EarthLocation(models.Model):
 
    """Represents latitude and longitude, with a label"""
 

	
 
    label = models.CharField(max_length=300, unique=True)
 
    latitude = models.DecimalField(max_digits=9, decimal_places=6)
 
    longitude = models.DecimalField(max_digits=9, decimal_places=6)
 

	
 
    date_created = models.DateTimeField(auto_now_add=True)
 
    date_last_modified = models.DateTimeField(auto_now=True)
 

	
 
    class Meta:
 
    class Meta(object):
 
        unique_together = (("latitude", "longitude"),)
 

	
 
    def __unicode__(self):
 
        return self.label
 

	
 
    def google_maps_link(self):
 
        return ("http://maps.google.com/maps?ll=%s,%s&z=15"
 
                % (self.latitude, self.longitude))
 

	
 
    default_map_link = google_maps_link
 

	
 
    def html_map_link(self): # for Admin, fixme: fix_ampersands
www/conservancy/bsoup.py
Show inline comments
 
# -*- encoding: utf-8 -*-
 

	
 
from builtins import object
 
import io
 
import itertools
 
import re
 

	
 
import bs4
 
import bs4.element
 

	
 
class BeautifulSoup(bs4.BeautifulSoup):
 
    """A wrapper of the original BeautifulSoup class, with convenience methods added."""
 

	
 
    IMAGE_ATTRS = {
 
        'img': 'src',
...
 
@@ -96,25 +97,25 @@ class BeautifulSoup(bs4.BeautifulSoup):
 
            try:
 
                elem[self.IMAGE_ATTRS[elem.name]]
 
            except KeyError:
 
                pass
 
            else:
 
                yield elem
 

	
 
    def iter_videos(self):
 
        """Return an iterator of all video source elements in this document."""
 
        return self.find_all(self.is_video_source, src=True)
 

	
 

	
 
class SoupModelMixin:
 
class SoupModelMixin(object):
 
    """Mixin for models to parse HTML with BeautifulSoup.
 

	
 
    Classes that use this mixin must define `SOUP_ATTRS`, a list of strings
 
    that name attributes with HTML in them.  After that, all the public methods
 
    are usable.
 
    """
 

	
 
    OG_PREVIEW_ATTR = 'data-ogpreview'
 
    SOUP_ATTRS = []
 

	
 
    def _get_soup(self):
 
        try:
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
0 comments (0 inline, 0 general)