Skip to content

Commit

Permalink
Added fabric task to launch Django 1.8 upgrade.
Browse files Browse the repository at this point in the history
Fixed migrations issues with Django 1.8
  • Loading branch information
yaniv14 committed Jun 5, 2015
1 parent 6c2f5ba commit 14d5fe6
Show file tree
Hide file tree
Showing 12 changed files with 90 additions and 35 deletions.
5 changes: 2 additions & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
# django
Django==1.8.1
Django==1.8.2

# django apps
django-floppyforms==1.4.0
#South==0.7.6
django-floppyforms==1.4.1

# general libs
pillow==2.8.1
Expand Down
18 changes: 18 additions & 0 deletions src/communities/legacy_mapping.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#encoding: utf8
from __future__ import unicode_literals

TITLE_TO_SLUG = {
'איגוד הביטקוין': 'bitcoin-org-il',
'אליאב': 'eliav',
'* בדיקות פרודקשיין *': 'production-test',
'בי״ס עמית': 'amit',
'הבר קיימא': 'barkayma',
'הסדנא לידע ציבורי': 'hasadna',
'הפורום לממשל פתוח': 'open-government',
'התנועה לאיכות השלטון': 'mqg',
'מעיין ברוך': 'maayan-baruch',
'מרצ': 'meretz',
'נטף': 'nataf',
'נען': 'naan',
'קהילה פתוחה': 'open-community',
}
5 changes: 3 additions & 2 deletions src/communities/migrations/0004_auto_20150513_1023.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from communities.models import Committee, Community

from django.db import models, migrations


def copy_communities(apps, schema_editor):
# Community = apps.get_model("communities", "Community")
Community = apps.get_model("communities", "Community")
Committee = apps.get_model("communities", "Committee")
communities = Community.objects.all()
for c in communities:
committe = Committee.objects.create(pk=c.id, community=c)
Expand Down Expand Up @@ -37,6 +37,7 @@ def copy_communities(apps, schema_editor):
committe.register_missing_board_members = c.register_missing_board_members
committe.inform_system_manager = c.inform_system_manager
committe.no_meetings_community = c.no_meetings_community
committe.slug = "main"

for member in c.upcoming_meeting_participants.all():
committe.upcoming_meeting_participants.add(member)
Expand Down
24 changes: 24 additions & 0 deletions src/communities/migrations/0009_auto_20150603_1359.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from communities.legacy_mapping import TITLE_TO_SLUG

from django.db import models, migrations


def create_community_slug(apps, schema_editor):
Community = apps.get_model("communities", "Community")
communities = Community.objects.filter(slug__isnull=True)
for c in communities:
c.slug = TITLE_TO_SLUG.get(c.name, "c{}".format(c.id))
c.save()


class Migration(migrations.Migration):

dependencies = [
('communities', '0008_auto_20150514_1518'),
]

operations = [
migrations.RunPython(create_community_slug),
]
20 changes: 9 additions & 11 deletions src/communities/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
from communities.forms import EditUpcomingMeetingForm, \
PublishUpcomingMeetingForm, UpcomingMeetingParticipantsForm, \
EditUpcomingMeetingSummaryForm
from communities.models import SendToOption
from communities.notifications import send_mail
from issues.models import IssueStatus, Issue, Proposal
from meetings.models import Meeting
Expand Down Expand Up @@ -49,7 +48,6 @@ def get_context_data(self, **kwargs):
class CommunityModelMixin(ProtectedMixin):
model = models.Community
slug_url_kwarg = 'community_slug'
query_pk_and_slug = True

@property
def community(self):
Expand All @@ -58,8 +56,10 @@ def community(self):

class CommitteeModelMixin(ProtectedMixin):
model = models.Committee
slug_url_kwarg = 'committee_slug'
query_pk_and_slug = True

def get_object(self):
return models.Committee.objects.get(slug=self.kwargs['committee_slug'],
community__slug=self.kwargs['community_slug'])

@property
def community(self):
Expand Down Expand Up @@ -139,9 +139,7 @@ def post(self, request, *args, **kwargs):
def get_context_data(self, **kwargs):
d = super(UpcomingMeetingView, self).get_context_data(**kwargs)
sorted_issues = {'by_time': [], 'by_rank': []}
open_issues = Issue.objects.filter(active=True, \
committee=self.committee) \
.exclude(status=IssueStatus.ARCHIVED)
open_issues = Issue.objects.filter(active=True, committee=self.committee).exclude(status=IssueStatus.ARCHIVED)
for i in open_issues.order_by('-created_at'):
sorted_issues['by_time'].append(i.id)
for i in open_issues.order_by('-order_by_votes'):
Expand All @@ -164,7 +162,7 @@ def get_context_data(self, **kwargs):
d = super(PublishUpcomingMeetingPreviewView, self).get_context_data(**kwargs)
d['can_straw_vote'] = self.committee.upcoming_proposals_any(
{'is_open': True}, user=self.request.user, committee=self.committee) \
and self.community.upcoming_meeting_is_published
and self.committee.upcoming_meeting_is_published
upcoming_issues = self.committee.upcoming_issues(
user=self.request.user, committee=self.committee)
d['issue_container'] = []
Expand Down Expand Up @@ -220,7 +218,7 @@ def get_form(self, form_class):
form = super(PublishUpcomingView, self).get_form(form_class)
c = self.get_object()
if not c.upcoming_meeting_started:
form.fields['send_to'].choices = SendToOption.publish_choices
form.fields['send_to'].choices = models.SendToOption.publish_choices

return form

Expand All @@ -230,8 +228,8 @@ def form_valid(self, form):
c = self.object

# increment agenda if publishing agenda.
if not c.upcoming_meeting_started and form.cleaned_data['send_to'] != SendToOption.ONLY_ME:
if form.cleaned_data['send_to'] == SendToOption.ALL_MEMBERS:
if not c.upcoming_meeting_started and form.cleaned_data['send_to'] != models.SendToOption.ONLY_ME:
if form.cleaned_data['send_to'] == models.SendToOption.ALL_MEMBERS:
c.upcoming_meeting_is_published = True
c.upcoming_meeting_published_at = datetime.datetime.now()
c.upcoming_meeting_version += 1
Expand Down
21 changes: 21 additions & 0 deletions src/fabfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,27 @@ def deploy(restart=True):
reload_app()


#Just for deploying after changing to Django 1.8 - Maybe remove after use?
@task
def upgrade_to_django_18(restart=True):
upgrade_pip()
with virtualenv(env.code_dir):
run("git pull")
run("pip install -r requirements.txt")
run("pip install -r deploy-requirements.txt")
run("cd src && python manage.py migrate auth --fake-initial")
run("cd src && python manage.py migrate admin --fake-initial")
run("cd src && python manage.py migrate sessions --fake-initial")
run("cd src && python manage.py migrate taggit --fake-initial")
run("cd src && python manage.py migrate issues 0003 --fake")
run("cd src && python manage.py migrate --noinput")
run("cd src && python manage.py collectstatic --noinput")
run("git log -n 1 --format=\"%ai %h\" > static/version.txt")
run("git log -n 1 > static/version-full.txt")
if restart:
reload_app()


@task
def hard_reload():
run("sudo supervisorctl restart opencommunity")
Expand Down
5 changes: 2 additions & 3 deletions src/issues/migrations/0005_auto_20150513_1232.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@
from communities.models import Committee

from django.db import models, migrations
from issues.models import Issue


def community_to_committee(apps, schema_editor):
# Issue = apps.get_model("issues", "Issue")
Issue = apps.get_model("issues", "Issue")
issues = Issue.objects.all()
for i in issues:
i.committee = Committee.objects.get(pk=i.community.id)
i.committee_id = i.community_id
i.save()


Expand Down
5 changes: 2 additions & 3 deletions src/meetings/migrations/0004_auto_20150513_1232.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@
from communities.models import Committee

from django.db import models, migrations
from meetings.models import Meeting


def community_to_committee(apps, schema_editor):
# Meeting = apps.get_model("meetings", "Meeting")
Meeting = apps.get_model("meetings", "Meeting")
meetings = Meeting.objects.all()
for m in meetings:
m.committee = Committee.objects.get(pk=m.community.id)
m.committee_id = m.community_id
m.save()


Expand Down
7 changes: 2 additions & 5 deletions src/ocd/base_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,7 @@ class ProtectedMixin(object):

def dispatch(self, request, *args, **kwargs):
# check with Udi
try:
community = self.community
except:
community = self.committee.community
community = get_object_or_404(Community, slug=self.kwargs['community_slug'])
if not request.user.is_authenticated():
if not community.is_public:
return redirect_to_login(request.build_absolute_uri())
Expand Down Expand Up @@ -99,7 +96,7 @@ class CommitteeMixin(ProtectedMixin):
@property
def committee(self):
if not self._committee:
self._committee = get_object_or_404(Committee, slug=self.kwargs['committee_slug'])
self._committee = get_object_or_404(Committee, slug=self.kwargs['committee_slug'], community__slug=self.kwargs['community_slug'])
return self._committee

def get_context_data(self, **kwargs):
Expand Down
1 change: 1 addition & 0 deletions src/ocd/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

EMAIL_SUBJECT_PREFIX = '[OpenCommunity] '
FROM_EMAIL = "[email protected]"
FROM_EMAIL_NAME = "DemOS"
HOST_URL = "http://localhost:8000"

MANAGERS = (('Boaz Chen', '[email protected]'),)
Expand Down
10 changes: 5 additions & 5 deletions src/ocd/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@

url(r'^about/$', communities.views.About.as_view(), name='about'),

url(r'^c/(?P<community_slug>[a-z0-9_.-]+)/members/', include('users.urls')),
url(r'^c/(?P<community_slug>[a-z0-9_.-]+)/', include('communities.urls')),
url(r'^c/(?P<community_slug>[a-z][a-z0-9-]+)/members/', include('users.urls')),
url(r'^c/(?P<community_slug>[a-z][a-z0-9-]+)/', include('communities.urls')),

url(r'^c/(?P<community_slug>[a-z0-9_.-]+)/(?P<committee_slug>[a-z0-9_.-]+)/upcoming/close/$',
url(r'^c/(?P<community_slug>[a-z][a-z0-9-]+)/(?P<committee_slug>[a-z][a-z0-9-]+)/upcoming/close/$',
MeetingCreateView.as_view(),
name="upcoming_close"),

url(r'^c/(?P<community_slug>[a-z0-9_.-]+)/(?P<committee_slug>[a-z0-9_.-]+)/issues/', include('issues.urls')),
url(r'^c/(?P<community_slug>[a-z0-9_.-]+)/(?P<committee_slug>[a-z0-9_.-]+)/history/', include('meetings.urls')),
url(r'^c/(?P<community_slug>[a-z][a-z0-9-]+)/(?P<committee_slug>[a-z][a-z0-9-]+)/issues/', include('issues.urls')),
url(r'^c/(?P<community_slug>[a-z][a-z0-9-]+)/(?P<committee_slug>[a-z][a-z0-9-]+)/history/', include('meetings.urls')),

url(r'^login/$', 'ocd.views.login_user', {'template_name': 'login.html'}, name="login"),

Expand Down
4 changes: 1 addition & 3 deletions src/users/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from django.contrib.auth.decorators import permission_required
from django.contrib.auth.forms import PasswordResetForm
from django.contrib.auth.tokens import default_token_generator
from django.contrib.sites.models import get_current_site
from django.core.urlresolvers import reverse
from django.http.response import HttpResponse, HttpResponseBadRequest, Http404, HttpResponseRedirect
from django.shortcuts import render, redirect
Expand Down Expand Up @@ -326,8 +325,7 @@ def oc_password_reset(request, is_admin_site=False,
if request.method == "POST":
form = password_reset_form(request.POST)
if form.is_valid():
current_site = get_current_site(request)
from_email = "%s <%s>" % (current_site.name, settings.FROM_EMAIL)
from_email = "%s <%s>" % (settings.FROM_EMAIL_NAME, settings.FROM_EMAIL)
opts = {
'use_https': request.is_secure(),
'token_generator': token_generator,
Expand Down

0 comments on commit 14d5fe6

Please sign in to comment.