mirror of
https://github.com/nottinghamtec/PyRIGS.git
synced 2026-02-16 11:39:41 +00:00
1
.gitignore
vendored
1
.gitignore
vendored
@@ -100,3 +100,4 @@ atlassian-ide-plugin.xml
|
|||||||
com_crashlytics_export_strings.xml
|
com_crashlytics_export_strings.xml
|
||||||
crashlytics.properties
|
crashlytics.properties
|
||||||
crashlytics-build.properties
|
crashlytics-build.properties
|
||||||
|
.vagrant
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ from z3c.rml import rml2pdf
|
|||||||
|
|
||||||
from RIGS import models
|
from RIGS import models
|
||||||
|
|
||||||
|
import re
|
||||||
|
|
||||||
class InvoiceIndex(generic.ListView):
|
class InvoiceIndex(generic.ListView):
|
||||||
model = models.Invoice
|
model = models.Invoice
|
||||||
@@ -63,8 +64,10 @@ class InvoicePrint(generic.View):
|
|||||||
|
|
||||||
pdfData = buffer.read()
|
pdfData = buffer.read()
|
||||||
|
|
||||||
|
escapedEventName = re.sub('[^a-zA-Z0-9 \n\.]', '', object.name)
|
||||||
|
|
||||||
response = HttpResponse(content_type='application/pdf')
|
response = HttpResponse(content_type='application/pdf')
|
||||||
response['Content-Disposition'] = "filename=Invoice %05d | %s.pdf" % (invoice.pk, object.name)
|
response['Content-Disposition'] = "filename=Invoice %05d | %s.pdf" % (invoice.pk, escapedEventName)
|
||||||
response.write(pdfData)
|
response.write(pdfData)
|
||||||
return response
|
return response
|
||||||
|
|
||||||
|
|||||||
@@ -234,6 +234,15 @@ class EventManager(models.Manager):
|
|||||||
).order_by('start_date', 'end_date', 'start_time', 'end_time', 'meet_at').select_related('person', 'organisation', 'venue', 'mic')
|
).order_by('start_date', 'end_date', 'start_time', 'end_time', 'meet_at').select_related('person', 'organisation', 'venue', 'mic')
|
||||||
return events
|
return events
|
||||||
|
|
||||||
|
def events_in_bounds(self, start, end):
|
||||||
|
events = self.filter(
|
||||||
|
(models.Q(start_date__gte=start.date(), start_date__lte=end.date())) | # Start date in bounds
|
||||||
|
(models.Q(end_date__gte=start.date(), end_date__lte=end.date())) | # End date in bounds
|
||||||
|
(models.Q(access_at__gte=start, access_at__lte=end)) | # Access at in bounds
|
||||||
|
(models.Q(meet_at__gte=start, meet_at__lte=end)) # Meet at in bounds
|
||||||
|
).order_by('start_date', 'end_date', 'start_time', 'end_time', 'meet_at').select_related('person', 'organisation', 'venue', 'mic')
|
||||||
|
return events
|
||||||
|
|
||||||
def rig_count(self):
|
def rig_count(self):
|
||||||
event_count = self.filter(
|
event_count = self.filter(
|
||||||
(models.Q(start_date__gte=datetime.date.today(), end_date__isnull=True, dry_hire=False,
|
(models.Q(start_date__gte=datetime.date.today(), end_date__isnull=True, dry_hire=False,
|
||||||
@@ -356,7 +365,7 @@ class Event(models.Model, RevisionMixin):
|
|||||||
return reverse_lazy('event_detail', kwargs={'pk': self.pk})
|
return reverse_lazy('event_detail', kwargs={'pk': self.pk})
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return str(self.pk) + ": " + self.name
|
return unicode(self.pk) + ": " + self.name
|
||||||
|
|
||||||
def clean(self):
|
def clean(self):
|
||||||
if self.end_date and self.start_date > self.end_date:
|
if self.end_date and self.start_date > self.end_date:
|
||||||
|
|||||||
@@ -125,7 +125,10 @@ class EventPrint(generic.View):
|
|||||||
merger.write(merged)
|
merger.write(merged)
|
||||||
|
|
||||||
response = HttpResponse(content_type='application/pdf')
|
response = HttpResponse(content_type='application/pdf')
|
||||||
response['Content-Disposition'] = "filename=N%05d | %s.pdf" % (object.pk, object.name)
|
|
||||||
|
escapedEventName = re.sub('[^a-zA-Z0-9 \n\.]', '', object.name)
|
||||||
|
|
||||||
|
response['Content-Disposition'] = "filename=N%05d | %s.pdf" % (object.pk, escapedEventName)
|
||||||
response.write(merged.getvalue())
|
response.write(merged.getvalue())
|
||||||
return response
|
return response
|
||||||
|
|
||||||
@@ -172,9 +175,9 @@ class EventArchive(generic.ArchiveIndexView):
|
|||||||
filter = Q(start_date__gte=start)
|
filter = Q(start_date__gte=start)
|
||||||
|
|
||||||
if filter:
|
if filter:
|
||||||
qs = self.model.objects.filter(filter)
|
qs = self.model.objects.filter(filter).order_by('-start_date')
|
||||||
else:
|
else:
|
||||||
qs = self.model.objects.all()
|
qs = self.model.objects.all().order_by('-start_date')
|
||||||
|
|
||||||
# Preselect related for efficiency
|
# Preselect related for efficiency
|
||||||
qs.select_related('person', 'organisation', 'venue', 'mic')
|
qs.select_related('person', 'organisation', 'venue', 'mic')
|
||||||
|
|||||||
@@ -38,7 +38,7 @@
|
|||||||
|
|
||||||
$('.date').each(function (index, dateElem) {
|
$('.date').each(function (index, dateElem) {
|
||||||
var $dateElem = $(dateElem);
|
var $dateElem = $(dateElem);
|
||||||
var formatted = moment($dateElem.attr('data-date'),"DD/MM/YYYY HH:mm").twitterLong();
|
var formatted = moment($dateElem.attr('data-date')).twitterLong();
|
||||||
$dateElem.text(formatted);
|
$dateElem.text(formatted);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -27,7 +27,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="media-body">
|
<div class="media-body">
|
||||||
<h5>{{ version.revision.user.name }}
|
<h5>{{ version.revision.user.name }}
|
||||||
<span class="pull-right"><small><span class="date" data-date="{{version.revision.date_created}}"></span></small></span>
|
<span class="pull-right"><small><span class="date" data-date="{{version.revision.date_created|date:"c"}}"></span></small></span>
|
||||||
</h5>
|
</h5>
|
||||||
|
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|||||||
@@ -5,13 +5,11 @@
|
|||||||
<div class="row">
|
<div class="row">
|
||||||
{% if not request.is_ajax %}
|
{% if not request.is_ajax %}
|
||||||
<div class="col-sm-12">
|
<div class="col-sm-12">
|
||||||
<div class="col-sm-8">
|
|
||||||
<h1>
|
<h1>
|
||||||
{% if object.is_rig %}N{{ object.pk|stringformat:"05d" }}{% else %}{{ object.pk }}{% endif %}
|
{% if object.is_rig %}N{{ object.pk|stringformat:"05d" }}{% else %}{{ object.pk }}{% endif %}
|
||||||
| {{ object.name }}
|
| {{ object.name }} {% if event.dry_hire %}<span class="badge">Dry Hire</span>{% endif %}
|
||||||
</h1>
|
</h1>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
<div class="col-sm-12 text-right">
|
<div class="col-sm-12 text-right">
|
||||||
<div class="btn-group btn-page">
|
<div class="btn-group btn-page">
|
||||||
<a href="{% url 'event_update' event.pk %}" class="btn btn-default"><span
|
<a href="{% url 'event_update' event.pk %}" class="btn btn-default"><span
|
||||||
|
|||||||
@@ -241,7 +241,7 @@
|
|||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td>24 Hour Emergency Contacts: 07825 065681 or 07825 065678</td>
|
<td>24 Hour Emergency Contacts: 07825 065681 and 07825 065678</td>
|
||||||
</tr>
|
</tr>
|
||||||
</blockTable>
|
</blockTable>
|
||||||
</keepTogether>
|
</keepTogether>
|
||||||
|
|||||||
@@ -2,8 +2,25 @@
|
|||||||
|
|
||||||
<button title="Changes to {{ change.field.verbose_name }}" type="button" class="btn btn-default btn-xs" data-container="body" data-html="true" data-trigger='hover' data-toggle="popover" data-content='
|
<button title="Changes to {{ change.field.verbose_name }}" type="button" class="btn btn-default btn-xs" data-container="body" data-html="true" data-trigger='hover' data-toggle="popover" data-content='
|
||||||
|
|
||||||
{% if change.new %}<div class="alert alert-success {% if change.long %}overflow-ellipsis{% endif %}">{{change.new|linebreaksbr}}</div>{% endif %}
|
{% if change.new %}
|
||||||
{% if change.old %}<div class="alert alert-danger {% if change.long %}overflow-ellipsis{% endif %}">{{change.old|linebreaksbr}}</div>{% endif %}
|
<div class="alert alert-success {% if change.long %}overflow-ellipsis{% endif %}">
|
||||||
|
{% if change.linebreaks %}
|
||||||
|
{{change.new|linebreaksbr}}
|
||||||
|
{% else %}
|
||||||
|
{{change.new}}
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
{% if change.old %}
|
||||||
|
<div class="alert alert-danger {% if change.long %}overflow-ellipsis{% endif %}">
|
||||||
|
{% if change.linebreaks %}
|
||||||
|
{{change.old|linebreaksbr}}
|
||||||
|
{% else %}
|
||||||
|
{{change.old}}
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
'>{{ change.field.verbose_name }}</button>
|
'>{{ change.field.verbose_name }}</button>
|
||||||
|
|
||||||
|
|||||||
@@ -145,8 +145,8 @@ urlpatterns = patterns('',
|
|||||||
url(r'^ical/(?P<api_pk>\d+)/(?P<api_key>\w+)/rigs.ics$', api_key_required(ical.CalendarICS()), name="ics_calendar"),
|
url(r'^ical/(?P<api_pk>\d+)/(?P<api_key>\w+)/rigs.ics$', api_key_required(ical.CalendarICS()), name="ics_calendar"),
|
||||||
|
|
||||||
# API
|
# API
|
||||||
url(r'^api/(?P<model>\w+)/$', (views.SecureAPIRequest.as_view()), name="api_secure"),
|
url(r'^api/(?P<model>\w+)/$', login_required(views.SecureAPIRequest.as_view()), name="api_secure"),
|
||||||
url(r'^api/(?P<model>\w+)/(?P<pk>\d+)/$', (views.SecureAPIRequest.as_view()), name="api_secure"),
|
url(r'^api/(?P<model>\w+)/(?P<pk>\d+)/$', login_required(views.SecureAPIRequest.as_view()), name="api_secure"),
|
||||||
|
|
||||||
# Legacy URL's
|
# Legacy URL's
|
||||||
url(r'^rig/show/(?P<pk>\d+)/$', RedirectView.as_view(permanent=True,pattern_name='event_detail')),
|
url(r'^rig/show/(?P<pk>\d+)/$', RedirectView.as_view(permanent=True,pattern_name='event_detail')),
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ import simplejson
|
|||||||
from reversion.models import Version
|
from reversion.models import Version
|
||||||
from django.contrib.contenttypes.models import ContentType # Used to lookup the content_type
|
from django.contrib.contenttypes.models import ContentType # Used to lookup the content_type
|
||||||
from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
|
from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
|
||||||
from django.db.models import ForeignKey, IntegerField, EmailField
|
from django.db.models import ForeignKey, IntegerField, EmailField, TextField
|
||||||
|
|
||||||
from RIGS import models, forms
|
from RIGS import models, forms
|
||||||
import datetime
|
import datetime
|
||||||
@@ -58,6 +58,12 @@ def model_compare(oldObj, newObj, excluded_keys=[]):
|
|||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
@property
|
||||||
|
def linebreaks(self):
|
||||||
|
if isinstance(self.field, TextField):
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
changes = []
|
changes = []
|
||||||
|
|
||||||
for thisField in theFields:
|
for thisField in theFields:
|
||||||
|
|||||||
@@ -221,8 +221,8 @@ class SecureAPIRequest(generic.View):
|
|||||||
'venue': 'RIGS.view_venue',
|
'venue': 'RIGS.view_venue',
|
||||||
'person': 'RIGS.view_person',
|
'person': 'RIGS.view_person',
|
||||||
'organisation': 'RIGS.view_organisation',
|
'organisation': 'RIGS.view_organisation',
|
||||||
'profile': None,
|
'profile': 'RIGS.view_profile',
|
||||||
'event': 'RIGS.view_event',
|
'event': None,
|
||||||
}
|
}
|
||||||
|
|
||||||
'''
|
'''
|
||||||
@@ -300,10 +300,9 @@ class SecureAPIRequest(generic.View):
|
|||||||
# Probably a calendar request
|
# Probably a calendar request
|
||||||
start_datetime = datetime.datetime.strptime( start, "%Y-%m-%dT%H:%M:%SZ" )
|
start_datetime = datetime.datetime.strptime( start, "%Y-%m-%dT%H:%M:%SZ" )
|
||||||
end_datetime = datetime.datetime.strptime( end, "%Y-%m-%dT%H:%M:%SZ" )
|
end_datetime = datetime.datetime.strptime( end, "%Y-%m-%dT%H:%M:%SZ" )
|
||||||
all_objects = self.models[model].objects
|
objects = self.models[model].objects.events_in_bounds(start_datetime,end_datetime)
|
||||||
|
|
||||||
results = []
|
results = []
|
||||||
filter = Q(start_date__lte=end_datetime) & Q(start_date__gte=start_datetime)
|
|
||||||
objects = all_objects.filter(filter).select_related('person', 'organisation', 'venue', 'mic').order_by('-start_date')
|
|
||||||
for item in objects:
|
for item in objects:
|
||||||
data = {
|
data = {
|
||||||
'pk': item.pk,
|
'pk': item.pk,
|
||||||
@@ -331,27 +330,6 @@ class SecureAPIRequest(generic.View):
|
|||||||
if item.access_at:
|
if item.access_at:
|
||||||
data['access_at'] = item.access_at.strftime('%Y-%m-%dT%H:%M:%SZ')
|
data['access_at'] = item.access_at.strftime('%Y-%m-%dT%H:%M:%SZ')
|
||||||
|
|
||||||
if item.venue:
|
|
||||||
data['venue'] = item.venue.name
|
|
||||||
|
|
||||||
if item.person:
|
|
||||||
data['person'] = item.person.name
|
|
||||||
|
|
||||||
if item.organisation:
|
|
||||||
data['organisation'] = item.organisation.name
|
|
||||||
|
|
||||||
if item.mic:
|
|
||||||
data['mic'] = {
|
|
||||||
'name':item.mic.get_full_name(),
|
|
||||||
'initials':item.mic.initials
|
|
||||||
}
|
|
||||||
|
|
||||||
if item.description:
|
|
||||||
data['description'] = item.description
|
|
||||||
|
|
||||||
if item.notes:
|
|
||||||
data['notes'] = item.notes
|
|
||||||
|
|
||||||
data['url'] = str(reverse_lazy('event_detail',kwargs={'pk':item.pk}))
|
data['url'] = str(reverse_lazy('event_detail',kwargs={'pk':item.pk}))
|
||||||
|
|
||||||
results.append(data)
|
results.append(data)
|
||||||
|
|||||||
133
Vagrantfile
vendored
Normal file
133
Vagrantfile
vendored
Normal file
@@ -0,0 +1,133 @@
|
|||||||
|
# -*- mode: ruby -*-
|
||||||
|
# vi: set ft=ruby :
|
||||||
|
require 'yaml'
|
||||||
|
|
||||||
|
unless File.exist?('config/vagrant.yml')
|
||||||
|
raise "There is no config/vagrant.yml file.\nCopy config/vagrant.template.yml, make any changes you need, then try again."
|
||||||
|
end
|
||||||
|
|
||||||
|
settings = YAML.load_file 'config/vagrant.yml'
|
||||||
|
|
||||||
|
$script = <<SCRIPT
|
||||||
|
echo Beginning Vagrant provisioning...
|
||||||
|
date > /etc/vagrant_provisioned_at
|
||||||
|
SCRIPT
|
||||||
|
|
||||||
|
# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
|
||||||
|
VAGRANTFILE_API_VERSION = '2'
|
||||||
|
|
||||||
|
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
|
||||||
|
# The most common configuration options are documented and commented below.
|
||||||
|
# For a complete reference, please see the online documentation at
|
||||||
|
# https://docs.vagrantup.com.
|
||||||
|
|
||||||
|
config.vm.provision 'shell', inline: $script
|
||||||
|
|
||||||
|
# Every Vagrant development environment requires a box. You can search for
|
||||||
|
# boxes at https://atlas.hashicorp.com/search.
|
||||||
|
config.vm.box = 'ubuntu/trusty64'
|
||||||
|
|
||||||
|
# Share an additional folder to the guest VM. The first argument is
|
||||||
|
# the path on the host to the actual folder. The second argument is
|
||||||
|
# the path on the guest to mount the folder. And the optional third
|
||||||
|
# argument is a set of non-required options.
|
||||||
|
config.vm.synced_folder ".", "/vagrant"
|
||||||
|
|
||||||
|
# Create a forwarded port mapping which allows access to a specific port
|
||||||
|
# within the machine from a port on the host machine. In the example below,
|
||||||
|
# accessing "localhost:5000" will access port 5000 on the guest machine.
|
||||||
|
config.vm.network "forwarded_port", guest: 5000, host: 5000
|
||||||
|
|
||||||
|
# PostgreSQL Server port forwarding
|
||||||
|
config.vm.network "forwarded_port", host: 15432, guest: 5432
|
||||||
|
|
||||||
|
# You can provision with just one of these scripts by user its name, eg:
|
||||||
|
# $ vagrant provision --provision-with postgresql
|
||||||
|
|
||||||
|
config.vm.provision 'build',
|
||||||
|
type: 'shell',
|
||||||
|
path: 'config/vagrant/build_dependency_setup.sh'
|
||||||
|
|
||||||
|
config.vm.provision 'git',
|
||||||
|
type: 'shell',
|
||||||
|
path: 'config/vagrant/git_setup.sh'
|
||||||
|
|
||||||
|
config.vm.provision 'postgresql',
|
||||||
|
type: 'shell',
|
||||||
|
path: 'config/vagrant/postgresql_setup.sh',
|
||||||
|
args: [
|
||||||
|
settings['db']['name'],
|
||||||
|
settings['db']['user'],
|
||||||
|
settings['db']['password'],
|
||||||
|
]
|
||||||
|
|
||||||
|
config.vm.provision 'python',
|
||||||
|
type: 'shell',
|
||||||
|
path: 'config/vagrant/python_setup.sh'
|
||||||
|
|
||||||
|
config.vm.provision 'virtualenv',
|
||||||
|
type: 'shell',
|
||||||
|
path: 'config/vagrant/virtualenv_setup.sh',
|
||||||
|
args: [
|
||||||
|
settings['virtualenv']['envname'],
|
||||||
|
]
|
||||||
|
|
||||||
|
# Will install foreman and, if there's a Procfile, start it:
|
||||||
|
config.vm.provision 'foreman',
|
||||||
|
type: 'shell',
|
||||||
|
path: 'config/vagrant/foreman_setup.sh',
|
||||||
|
args: [
|
||||||
|
settings['virtualenv']['envname'],
|
||||||
|
settings['django']['settings_module'],
|
||||||
|
settings['foreman']['procfile'],
|
||||||
|
]
|
||||||
|
|
||||||
|
# Disable automatic box update checking. If you disable this, then
|
||||||
|
# boxes will only be checked for updates when the user runs
|
||||||
|
# `vagrant box outdated`. This is not recommended.
|
||||||
|
# config.vm.box_check_update = false
|
||||||
|
|
||||||
|
# Create a forwarded port mapping which allows access to a specific port
|
||||||
|
# within the machine from a port on the host machine. In the example below,
|
||||||
|
# accessing "localhost:8080" will access port 80 on the guest machine.
|
||||||
|
# config.vm.network "forwarded_port", guest: 80, host: 8080
|
||||||
|
|
||||||
|
# Create a private network, which allows host-only access to the machine
|
||||||
|
# using a specific IP.
|
||||||
|
# config.vm.network "private_network", ip: "192.168.33.10"
|
||||||
|
|
||||||
|
# Create a public network, which generally matched to bridged network.
|
||||||
|
# Bridged networks make the machine appear as another physical device on
|
||||||
|
# your network.
|
||||||
|
# config.vm.network "public_network"
|
||||||
|
|
||||||
|
# Provider-specific configuration so you can fine-tune various
|
||||||
|
# backing providers for Vagrant. These expose provider-specific options.
|
||||||
|
# Example for VirtualBox:
|
||||||
|
#
|
||||||
|
config.vm.provider "virtualbox" do |vb|
|
||||||
|
# # Display the VirtualBox GUI when booting the machine
|
||||||
|
# vb.gui = true
|
||||||
|
#
|
||||||
|
# # Customize the amount of memory on the VM:
|
||||||
|
vb.memory = "1024"
|
||||||
|
end
|
||||||
|
#
|
||||||
|
# View the documentation for the provider you are using for more
|
||||||
|
# information on available options.
|
||||||
|
|
||||||
|
# Define a Vagrant Push strategy for pushing to Atlas. Other push strategies
|
||||||
|
# such as FTP and Heroku are also available. See the documentation at
|
||||||
|
# https://docs.vagrantup.com/v2/push/atlas.html for more information.
|
||||||
|
# config.push.define "atlas" do |push|
|
||||||
|
# push.app = "YOUR_ATLAS_USERNAME/YOUR_APPLICATION_NAME"
|
||||||
|
# end
|
||||||
|
|
||||||
|
# Enable provisioning with a shell script. Additional provisioners such as
|
||||||
|
# Puppet, Chef, Ansible, Salt, and Docker are also available. Please see the
|
||||||
|
# documentation for more information about their specific syntax and use.
|
||||||
|
# config.vm.provision "shell", inline: <<-SHELL
|
||||||
|
# sudo apt-get update
|
||||||
|
# sudo apt-get install -y apache2
|
||||||
|
# SHELL
|
||||||
|
end
|
||||||
11
config/vagrant.yml
Normal file
11
config/vagrant.yml
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
django:
|
||||||
|
settings_module: PyRIGS.settings
|
||||||
|
virtualenv:
|
||||||
|
envname: myvirtualenv
|
||||||
|
foreman:
|
||||||
|
procfile: Procfile
|
||||||
|
db:
|
||||||
|
name: postgres_db
|
||||||
|
user: postgres_db
|
||||||
|
password: postgres_db
|
||||||
|
|
||||||
16
config/vagrant/build_dependency_setup.sh
Normal file
16
config/vagrant/build_dependency_setup.sh
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
# Via https://github.com/kiere/vagrant-heroku-cedar-14/blob/master/config/vagrant/build_dependency_setup.sh
|
||||||
|
|
||||||
|
echo "=== Begin Vagrant Provisioning using 'config/vagrant/build_dependency_setup.sh'"
|
||||||
|
|
||||||
|
# Install build dependencies for a sane build environment
|
||||||
|
apt-get -y update
|
||||||
|
apt-get -y install autoconf bison build-essential libssl-dev libyaml-dev libreadline6-dev zlib1g-dev libncurses5-dev libffi-dev libgdbm3 libgdbm-dev
|
||||||
|
|
||||||
|
# Other things that we may need installed before anything else.
|
||||||
|
apt-get install -y libmemcached-dev
|
||||||
|
apt-get build-dep python-lxml
|
||||||
|
|
||||||
|
echo "=== End Vagrant Provisioning using 'config/vagrant/build_dependency_setup.sh'"
|
||||||
|
|
||||||
36
config/vagrant/foreman_setup.sh
Normal file
36
config/vagrant/foreman_setup.sh
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Install and (if there's a Procfile) start foreman.
|
||||||
|
# Needs to come after the virtualenv has been set up.
|
||||||
|
|
||||||
|
# Expects three arguments:
|
||||||
|
VIRTUALENV_NAME=$1
|
||||||
|
DJANGO_SETTINGS_MODULE=$2
|
||||||
|
PROCFILE=$3
|
||||||
|
|
||||||
|
echo "=== Begin Vagrant Provisioning using 'config/vagrant/foreman_setup.sh'"
|
||||||
|
|
||||||
|
gem install foreman --no-ri --no-rdoc
|
||||||
|
|
||||||
|
if ! grep -Fq "DJANGO_SETTINGS_MODULE" /home/vagrant/.bashrc; then
|
||||||
|
echo "export DJANGO_SETTINGS_MODULE=${DJANGO_SETTINGS_MODULE}" >> /home/vagrant/.bashrc
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
if [[ -f /vagrant/$PROCFILE ]]; then
|
||||||
|
echo "Procfile found; starting foreman."
|
||||||
|
|
||||||
|
export DJANGO_SETTINGS_MODULE="$DJANGO_SETTINGS_MODULE"
|
||||||
|
|
||||||
|
# Ensure the virtualenv settings in .profile are loaded:
|
||||||
|
source /home/vagrant/.profile
|
||||||
|
|
||||||
|
# Run with & to release the terminal.
|
||||||
|
# Although that may also rely on the Procfile's processes having their
|
||||||
|
# output sent to a file, not stdout/stderr.
|
||||||
|
foreman start -f /vagrant/$PROCFILE &
|
||||||
|
else
|
||||||
|
echo "No Procfile found; not starting foreman."
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "=== End Vagrant Provisioning using 'config/vagrant/foreman_setup.sh'"
|
||||||
14
config/vagrant/git_setup.sh
Normal file
14
config/vagrant/git_setup.sh
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
# Via https://github.com/kiere/vagrant-heroku-cedar-14/blob/master/config/vagrant/git_setup.sh
|
||||||
|
|
||||||
|
echo "=== Begin Vagrant Provisioning using 'config/vagrant/git_setup.sh'"
|
||||||
|
|
||||||
|
# Install Git if not available
|
||||||
|
if [ -z `which git` ]; then
|
||||||
|
echo "===== Installing Git"
|
||||||
|
apt-get -y update
|
||||||
|
apt-get -y install git-core
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "=== End Vagrant Provisioning using 'config/vagrant/git_setup.sh'"
|
||||||
112
config/vagrant/postgresql_setup.sh
Normal file
112
config/vagrant/postgresql_setup.sh
Normal file
@@ -0,0 +1,112 @@
|
|||||||
|
#!/bin/sh -e
|
||||||
|
|
||||||
|
# Expects three arguments:
|
||||||
|
# $1 - database name
|
||||||
|
# $2 - database user
|
||||||
|
# #3 - database user password
|
||||||
|
|
||||||
|
# Via https://github.com/kiere/vagrant-heroku-cedar-14/blob/master/config/vagrant/postgresql_setup.sh
|
||||||
|
|
||||||
|
echo "=== Begin Vagrant Provisioning using 'config/vagrant/postgresql_setup.sh'"
|
||||||
|
|
||||||
|
APP_DB_NAME=$1
|
||||||
|
APP_DB_USER=$2
|
||||||
|
APP_DB_PASS=$3
|
||||||
|
|
||||||
|
# Edit the following to change the version of PostgreSQL that is installed
|
||||||
|
PG_VERSION=9.4
|
||||||
|
|
||||||
|
###########################################################
|
||||||
|
# Changes below this line are probably not necessary
|
||||||
|
###########################################################
|
||||||
|
print_db_usage () {
|
||||||
|
echo "Your PostgreSQL database has been setup and can be accessed on your local machine on the forwarded port (default: 15432)"
|
||||||
|
echo " Host: localhost"
|
||||||
|
echo " Port: 15432"
|
||||||
|
echo " Database: $APP_DB_NAME"
|
||||||
|
echo " Username: $APP_DB_USER"
|
||||||
|
echo " Password: $APP_DB_PASS"
|
||||||
|
echo ""
|
||||||
|
echo "Admin access to postgres user via VM:"
|
||||||
|
echo " vagrant ssh"
|
||||||
|
echo " sudo su - postgres"
|
||||||
|
echo ""
|
||||||
|
echo "psql access to app database user via VM:"
|
||||||
|
echo " vagrant ssh"
|
||||||
|
echo " sudo su - postgres"
|
||||||
|
echo " PGUSER=$APP_DB_USER PGPASSWORD=$APP_DB_PASS psql -h localhost $APP_DB_NAME"
|
||||||
|
echo ""
|
||||||
|
echo "Env variable for application development:"
|
||||||
|
echo " DATABASE_URL=postgresql://$APP_DB_USER:$APP_DB_PASS@localhost:15432/$APP_DB_NAME"
|
||||||
|
echo ""
|
||||||
|
echo "Local command to access the database via psql:"
|
||||||
|
echo " PGUSER=$APP_DB_USER PGPASSWORD=$APP_DB_PASS psql -h localhost -p 15432 $APP_DB_NAME"
|
||||||
|
}
|
||||||
|
|
||||||
|
export DEBIAN_FRONTEND=noninteractive
|
||||||
|
|
||||||
|
PROVISIONED_ON=/etc/vm_provision_on_timestamp
|
||||||
|
if [ -f "$PROVISIONED_ON" ]
|
||||||
|
then
|
||||||
|
echo "VM was already provisioned at: $(cat $PROVISIONED_ON)"
|
||||||
|
echo "To run system updates manually login via 'vagrant ssh' and run 'apt-get update && apt-get upgrade'"
|
||||||
|
echo ""
|
||||||
|
print_db_usage
|
||||||
|
exit
|
||||||
|
fi
|
||||||
|
|
||||||
|
PG_REPO_APT_SOURCE=/etc/apt/sources.list.d/pgdg.list
|
||||||
|
if [ ! -f "$PG_REPO_APT_SOURCE" ]
|
||||||
|
then
|
||||||
|
# Add PG apt repo:
|
||||||
|
echo "deb http://apt.postgresql.org/pub/repos/apt/ precise-pgdg main" > "$PG_REPO_APT_SOURCE"
|
||||||
|
|
||||||
|
# Add PGDG repo key:
|
||||||
|
wget --quiet -O - http://apt.postgresql.org/pub/repos/apt/ACCC4CF8.asc | apt-key add -
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Update package list and upgrade all packages
|
||||||
|
apt-get update
|
||||||
|
apt-get -y upgrade
|
||||||
|
|
||||||
|
apt-get -y install "postgresql-$PG_VERSION" "postgresql-contrib-$PG_VERSION"
|
||||||
|
apt-get -y install libpq-dev # For building ruby 'pg' gem
|
||||||
|
|
||||||
|
PG_CONF="/etc/postgresql/$PG_VERSION/main/postgresql.conf"
|
||||||
|
PG_HBA="/etc/postgresql/$PG_VERSION/main/pg_hba.conf"
|
||||||
|
PG_DIR="/var/lib/postgresql/$PG_VERSION/main"
|
||||||
|
|
||||||
|
# Edit postgresql.conf to change listen address to '*':
|
||||||
|
sed -i "s/#listen_addresses = 'localhost'/listen_addresses = '*'/" "$PG_CONF"
|
||||||
|
|
||||||
|
# Append to pg_hba.conf to add password auth:
|
||||||
|
echo "host all all all md5" >> "$PG_HBA"
|
||||||
|
|
||||||
|
# Explicitly set default client_encoding
|
||||||
|
echo "client_encoding = utf8" >> "$PG_CONF"
|
||||||
|
|
||||||
|
# Restart so that all new config is loaded:
|
||||||
|
service postgresql restart
|
||||||
|
|
||||||
|
cat << EOF | su - postgres -c psql
|
||||||
|
-- Create the database user:
|
||||||
|
CREATE USER $APP_DB_USER PASSWORD '$APP_DB_PASS';
|
||||||
|
EOF
|
||||||
|
|
||||||
|
cat << EOF | su - postgres -c psql
|
||||||
|
-- Create the database:
|
||||||
|
CREATE DATABASE $APP_DB_NAME WITH OWNER=$APP_DB_USER
|
||||||
|
LC_COLLATE='en_US.utf8'
|
||||||
|
LC_CTYPE='en_US.utf8'
|
||||||
|
ENCODING='UTF8'
|
||||||
|
TEMPLATE=template0;
|
||||||
|
EOF
|
||||||
|
|
||||||
|
# Tag the provision time:
|
||||||
|
date > "$PROVISIONED_ON"
|
||||||
|
|
||||||
|
echo "Successfully created PostgreSQL dev virtual machine."
|
||||||
|
echo ""
|
||||||
|
print_db_usage
|
||||||
|
|
||||||
|
echo "=== End Vagrant Provisioning using 'config/vagrant/postgresql_setup.sh'"
|
||||||
23
config/vagrant/python_setup.sh
Normal file
23
config/vagrant/python_setup.sh
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Install python and required python modules.
|
||||||
|
# pip and virtualenv are in virtualenv_setup.sh
|
||||||
|
|
||||||
|
# Initial part of this via
|
||||||
|
# https://github.com/torchbox/vagrant-django-base/blob/master/install.sh
|
||||||
|
|
||||||
|
echo "=== Begin Vagrant Provisioning using 'config/vagrant/python_setup.sh'"
|
||||||
|
|
||||||
|
apt-get update -y
|
||||||
|
|
||||||
|
# Python dev packages
|
||||||
|
apt-get install -y python python-dev python-setuptools python-pip
|
||||||
|
|
||||||
|
# Dependencies for image processing with Pillow (drop-in replacement for PIL)
|
||||||
|
# supporting: jpeg, tiff, png, freetype, littlecms
|
||||||
|
apt-get install -y libjpeg-dev libtiff-dev zlib1g-dev libfreetype6-dev liblcms2-dev
|
||||||
|
|
||||||
|
# lxml dependencies
|
||||||
|
apt-get install -y libxml2-dev libxslt1-dev python-dev
|
||||||
|
|
||||||
|
echo "=== End Vagrant Provisioning using 'config/vagrant/python_setup.sh'"
|
||||||
66
config/vagrant/virtualenv_setup.sh
Normal file
66
config/vagrant/virtualenv_setup.sh
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# This will:
|
||||||
|
# * Install pip, virtualenv and virtualenvwrapper.
|
||||||
|
# * Set up virtualenvwrapper's paths etc.
|
||||||
|
# * Create a new virtualenv.
|
||||||
|
# * Install any pip requirements from the requirements.txt file.
|
||||||
|
|
||||||
|
# Expects one argument, the name of the virtualenv.
|
||||||
|
|
||||||
|
# The name we'll use for the virtualenv in which we'll install requirements:
|
||||||
|
VENV_NAME=$1
|
||||||
|
|
||||||
|
echo "=== Begin Vagrant Provisioning using 'config/vagrant/virtualenv_setup.sh'"
|
||||||
|
|
||||||
|
# virtualenv global setup
|
||||||
|
if ! command -v pip; then
|
||||||
|
easy_install -U pip
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ ! -f /usr/local/bin/virtualenv ]]; then
|
||||||
|
easy_install virtualenv virtualenvwrapper
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
# If it doesn't look like .bashrc has the required virtualenvwrapper lines in,
|
||||||
|
# then add them.
|
||||||
|
if ! grep -Fq "WORKON_HOME" /home/vagrant/.profile; then
|
||||||
|
echo "Adding virtualenvwrapper locations to .profile"
|
||||||
|
|
||||||
|
if [[ -d /vagrant/config/virtualenvwrapper/vagrant ]]; then
|
||||||
|
echo "export VIRTUALENVWRAPPER_HOOK_DIR=/vagrant/config/virtualenvwrapper/vagrant" >> /home/vagrant/.profile
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "export WORKON_HOME=/home/vagrant/.virtualenvs" >> /home/vagrant/.profile
|
||||||
|
echo "export PROJECT_HOME=/home/vagrant/Devel" >> /home/vagrant/.profile
|
||||||
|
echo "source /usr/local/bin/virtualenvwrapper.sh" >> /home/vagrant/.profile
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Get .virtualenvwrapper env variables set up:
|
||||||
|
source /home/vagrant/.profile
|
||||||
|
|
||||||
|
if [[ -d /home/vagrant/.virtualenvs/$VENV_NAME ]]; then
|
||||||
|
echo "Activating virtualenv $VENV_NAME."
|
||||||
|
workon $VENV_NAME
|
||||||
|
else
|
||||||
|
echo "Making new virtualenv $VENV_NAME."
|
||||||
|
# Also switches to the virtualenv:
|
||||||
|
mkvirtualenv $VENV_NAME
|
||||||
|
|
||||||
|
# So that we can install things with pip while ssh'd in as vagrant user:
|
||||||
|
sudo chown -R vagrant:vagrant /home/vagrant/.virtualenvs/$VENV_NAME/
|
||||||
|
|
||||||
|
# Automatically switch to the virtual env on log in:
|
||||||
|
echo "workon $VENV_NAME" >> /home/vagrant/.profile
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
# If we have a requirements.txt file in this project, then install
|
||||||
|
# everything in it with pip in a new virtualenv.
|
||||||
|
if [[ -f /vagrant/requirements.txt ]]; then
|
||||||
|
echo "Installing from ./requirements.txt with pip."
|
||||||
|
pip install -r /vagrant/requirements.txt
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "=== End Vagrant Provisioning using 'config/vagrant/virtualenv_setup.sh'"
|
||||||
@@ -112,7 +112,7 @@
|
|||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
{% else %}
|
{% else %}
|
||||||
<a href="{% url "login" %}?next={{ request.path }}">
|
<a href="{% url "login" %}">
|
||||||
<span class="icon-user"></span>
|
<span class="icon-user"></span>
|
||||||
Login
|
Login
|
||||||
</a>
|
</a>
|
||||||
|
|||||||
Reference in New Issue
Block a user