Skip to content

Commit

Permalink
bug674526 - check.py on bugsy, homepage, privacy
Browse files Browse the repository at this point in the history
  • Loading branch information
peterbe committed Jul 28, 2011
1 parent 48d548a commit cf0f409
Show file tree
Hide file tree
Showing 10 changed files with 87 additions and 75 deletions.
87 changes: 45 additions & 42 deletions apps/bugsy/management/commands/process_bugogram.py
Expand Up @@ -42,28 +42,25 @@
from urllib2 import urlopen
import re

from django.core.management.base import BaseCommand, CommandError
try:
import json
except ImportError:
import simplejson as json
from django.core.management.base import BaseCommand
from django.utils import simplejson as json
import bugsy

basebug = {
"rep_platform":"All",
"op_sys": "All",
"product": "Mozilla Localizations",
"component": "{{ component }}",
"cc": "{{ bugmail }}"
"rep_platform": "All",
"op_sys": "All",
"product": "Mozilla Localizations",
"component": "{{ component }}",
"cc": "{{ bugmail }}"
}

json_license = '''{% comment %}
json_license = """{% comment %}
***** BEGIN LICENSE BLOCK *****
Version: MPL 1.1/GPL 2.0/LGPL 2.1
The contents of this file are subject to the Mozilla Public License Version
1.1 (the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
The contents of this file are subject to the Mozilla Public License Version
1.1 (the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.mozilla.org/MPL/
Software distributed under the License is distributed on an "AS IS" basis,
Expand Down Expand Up @@ -94,45 +91,51 @@
***** END LICENSE BLOCK *****
{% endcomment %}
'''
"""


class Command(BaseCommand):
option_list = BaseCommand.option_list + (
make_option('-q', '--quiet', dest = 'quiet', action = 'store_true',
help = 'Run quietly'),
make_option('-q', '--quiet', dest='quiet', action='store_true',
help='Run quietly'),
)
help = 'TEMPORARY Download bugograms for new locales from wikimo'

sectioner = re.compile('===? (.*?) ===?\n(.*?)(?===)', re.M|re.S)
props = re.compile('^; (.*?) : (.*?)$', re.M|re.S)
sectioner = re.compile('===? (.*?) ===?\n(.*?)(?===)', re.M | re.S)
props = re.compile('^; (.*?) : (.*?)$', re.M | re.S)
params = re.compile('%\((.*?)\)s')

def handle(self, *args, **options):
quiet = options.get('quiet', False)
for alias, pn in (('fx', 'L10n:Bugogram'),
('fennec', 'L10n:Mobile/Bugogram')):

for alias, pn in (('fx','L10n:Bugogram'), ('fennec', 'L10n:Mobile/Bugogram')):
page = urlopen(
'http://wiki.mozilla.org/index.php?title=%s&action=raw' % pn
).read()

page = urlopen('http://wiki.mozilla.org/index.php?title=%s&action=raw'%pn).read()

allbugs = []

for section in self.sectioner.finditer(page):
title = section.group(1)
content = self.params.sub(lambda m: '{{ %s }}' % m.group(1),
title = section.group(1)
content = self.params.sub(lambda m: '{{ %s }}' % m.group(1),
section.group(2))
offset = 0
props = {}
for m in self.props.finditer(content):
offset = m.end(2)
props[m.group(1)] = m.group(2)
if not props:
continue
properties = basebug.copy()
properties.update(props)
properties['comment'] = content[offset:].strip()
properties['title'] = title

allbugs.append(properties)

fname = os.path.join(*(bugsy.__path__+['templates','bugsy','new-%s-locales.json'%alias]))
open(fname, 'w').write(json_license + json.dumps(allbugs, indent=2) + "\n")
offset = 0
props = {}
for m in self.props.finditer(content):
offset = m.end(2)
props[m.group(1)] = m.group(2)
if not props:
continue
properties = basebug.copy()
properties.update(props)
properties['comment'] = content[offset:].strip()
properties['title'] = title

allbugs.append(properties)

fname = os.path.join(*(bugsy.__path__ +
['templates',
'bugsy',
'new-%s-locales.json' % alias]))
open(fname, 'w').write(
json_license + json.dumps(allbugs, indent=2) + "\n")
13 changes: 6 additions & 7 deletions apps/bugsy/views.py
Expand Up @@ -38,15 +38,11 @@
'''

from django.http import HttpResponse
from django.shortcuts import render_to_response, redirect
from django.utils.safestring import mark_safe
from django.shortcuts import render_to_response
from django.template import Context, Template, RequestContext
from django.template.loader import render_to_string
from django.utils import simplejson

import re

from bugsy.models import *
from life.models import Locale


Expand All @@ -59,15 +55,18 @@ def homesnippet(request):
return render_to_string('bugsy/snippet.html', {
}, context_instance=RequestContext(request))


def teamsnippet(request, locale):
return render_to_string('bugsy/team-snippet.html', {'locale': locale}
, context_instance=RequestContext(request))
return render_to_string('bugsy/team-snippet.html',
{'locale': locale},
context_instance=RequestContext(request))


def file_bugs(request):
return render_to_response('bugsy/file-bugs.html', {
}, context_instance=RequestContext(request))


def get_bug_links(request):
locale_codes = request.GET.getlist('locales')
locales = Locale.objects.filter(code__in=locale_codes)
Expand Down
2 changes: 1 addition & 1 deletion apps/homepage/models.py
@@ -1 +1 @@
# needed so that Django thinks this is an app
# needed so that Django thinks this is an app
18 changes: 11 additions & 7 deletions apps/homepage/tests.py
Expand Up @@ -42,6 +42,7 @@
from life.models import Locale
from commons.tests.mixins import EmbedsTestCaseMixin


class HomepageTestCase(TestCase, EmbedsTestCaseMixin):
def setUp(self):
super(HomepageTestCase, self).setUp()
Expand All @@ -67,8 +68,9 @@ def test_secure_session_cookies(self):
url = reverse('accounts.views.login')
# run it as a mocked AJAX request because that's how elmo does it
response = self.client.post(url,
{'username':'peterbe', 'password':'secret'},
**{'X-Requested-With':'XMLHttpRequest'})
{'username': 'peterbe',
'password': 'secret'},
**{'X-Requested-With': 'XMLHttpRequest'})
eq_(response.status_code, 200)
ok_('class="errorlist"' in response.content)

Expand All @@ -79,19 +81,21 @@ def test_secure_session_cookies(self):
user.save()

response = self.client.post(url,
{'username':'peterbe',
'password':'secret',
{'username': 'peterbe',
'password': 'secret',
'next': '/foo'},
**{'X-Requested-With':'XMLHttpRequest'})
**{'X-Requested-With': 'XMLHttpRequest'})
# even though it's
eq_(response.status_code, 302)
ok_(response['Location'].endswith('/foo'))

# if this fails it's because settings.SESSION_COOKIE_SECURE isn't true
# if this fails it's because settings.SESSION_COOKIE_SECURE
# isn't true
assert settings.SESSION_COOKIE_SECURE
ok_(self.client.cookies['sessionid']['secure'])

# if this fails it's because settings.SESSION_COOKIE_HTTPONLY isn't true
# if this fails it's because settings.SESSION_COOKIE_HTTPONLY
# isn't true
assert settings.SESSION_COOKIE_HTTPONLY
ok_(self.client.cookies['sessionid']['httponly'])

Expand Down
2 changes: 1 addition & 1 deletion apps/homepage/urls.py
Expand Up @@ -37,7 +37,7 @@
'''URL mappings for the l10n_site integration pages.
'''

from django.conf.urls.defaults import *
from django.conf.urls.defaults import patterns

urlpatterns = patterns('homepage.views',
(r'^$', 'index'),
Expand Down
2 changes: 2 additions & 0 deletions apps/homepage/views.py
Expand Up @@ -61,12 +61,14 @@ def index(request):
'bugs': bugs_div,
}, context_instance=RequestContext(request))


def teams(request):
locs = Locale.objects.order_by('name')
return render_to_response('homepage/teams.html', {
'locales': locs,
}, context_instance=RequestContext(request))


def locale_team(request, code):
try:
loc = Locale.objects.get(code=code)
Expand Down
6 changes: 2 additions & 4 deletions apps/privacy/models.py
Expand Up @@ -39,17 +39,15 @@

from django.db import models
from django.utils.html import strip_tags

from django.contrib.auth.models import User
from django.contrib.admin.models import LogEntry, ADDITION, CHANGE
from django.contrib.contenttypes.models import ContentType

from datetime import datetime

class CTMixin:
"""Mixin to create a cached query for the ContentType for this model.
"""
_ct = None

@classmethod
def contenttype(cls):
if cls._ct is None:
Expand All @@ -71,7 +69,7 @@ class Meta:
permissions = (('activate_policy', 'Can activate a policy'),)

def __unicode__(self):
return "%d" % self.id
return "%d" % self.id


class Comment(models.Model, CTMixin):
Expand Down
5 changes: 3 additions & 2 deletions apps/privacy/tests.py
Expand Up @@ -39,7 +39,8 @@
from django.core.urlresolvers import reverse
from django.test import TestCase
from django.contrib.auth.models import User, Permission
from models import Policy, Comment, CHANGE, LogEntry
from django.contrib.admin.models import LogEntry, CHANGE
from models import Policy, Comment
from commons.tests.mixins import EmbedsTestCaseMixin


Expand All @@ -59,7 +60,7 @@ def test_render_show_policy(self):
text="Hi Mozilla",
active=True
)
log_entry = LogEntry.objects.create(
LogEntry.objects.create(
content_type=Policy.contenttype(),
user=user,
object_id=policy.id,
Expand Down
2 changes: 1 addition & 1 deletion apps/privacy/urls.py
Expand Up @@ -37,7 +37,7 @@
'''URL mappings for the privacy app.
'''

from django.conf.urls.defaults import *
from django.conf.urls.defaults import patterns

urlpatterns = patterns('privacy.views',
(r'^(?P<id>\d+)?$', 'show_policy'),
Expand Down
25 changes: 15 additions & 10 deletions apps/privacy/views.py
Expand Up @@ -41,16 +41,17 @@
from django.db.models import Count
from django.shortcuts import render_to_response, get_object_or_404
from django.template import RequestContext
from django.http import (HttpResponseRedirect, HttpResponse,
from django.http import (HttpResponseRedirect,
HttpResponseForbidden, Http404)
from django.utils.encoding import force_unicode
from django.views.decorators import cache
from privacy.models import Policy, Comment, LogEntry, ADDITION, CHANGE
from django.contrib.admin.models import LogEntry, ADDITION, CHANGE
from privacy.models import Policy, Comment

# We're not using the permission decorators from django.contrib.auth here
# because we don't have a login-view for one, and it's not giving
# us the flexibility to not use those.


def show_policy(request, id=None):
"""Display the currently active policy, or, if id is given, the
specified policy.
Expand All @@ -65,8 +66,8 @@ def show_policy(request, id=None):
if p is not None and p.active:
logs = LogEntry.objects.filter(content_type=Policy.contenttype())
logs = logs.filter(object_id=p.id,
action_flag = CHANGE,
change_message = 'activate')
action_flag=CHANGE,
change_message='activate')
logs = logs.order_by('-action_time')
activation = logs.values_list('action_time', flat=True)[0]
else:
Expand Down Expand Up @@ -103,6 +104,7 @@ def versions(request):
detail['active_time'].append([lo.action_time])
else:
detail['active_time'][-1].append(lo.action_time)

def do_policies(_pols, _details):
for _p in _pols:
_d = _p.__dict__.copy()
Expand All @@ -128,23 +130,25 @@ def add_policy(request):
c = RequestContext(request, {'current': current})
return render_to_response("privacy/add.html", c)


def post_policy(request):
if not (request.user.has_perm('privacy.add_policy')
and request.user.has_perm('privacy.add_comment')):
return HttpResponseForbidden("not sufficient permissions")
p = Policy.objects.create(text = request.POST['content'])
c = Comment.objects.create(text = request.POST['comment'],
policy = p,
who = request.user)
p = Policy.objects.create(text=request.POST['content'])
c = Comment.objects.create(text=request.POST['comment'],
policy=p,
who=request.user)
LogEntry.objects.log_action(request.user.id,
Policy.contenttype().id, p.id,
force_unicode(p), ADDITION)
LogEntry.objects.log_action(request.user.id,
Comment.contenttype().id, c.id,
force_unicode(c), ADDITION)

return HttpResponseRedirect(reverse('privacy.views.show_policy',
kwargs={'id': p.id}))

return HttpResponseRedirect(reverse('privacy.views.show_policy', kwargs={'id':p.id}))

def activate_policy(request):
"""Activate a selected policy, requires privacy.activate_policy
Expand Down Expand Up @@ -176,6 +180,7 @@ def activate_policy(request):
policy.save()
return HttpResponseRedirect(reverse('privacy.views.versions'))


def add_comment(request):
"""Add a comment to a policy, requires privacy.add_comment
priviledges.
Expand Down

0 comments on commit cf0f409

Please sign in to comment.