From dd3dcb00feb6a7348d6d1662c3e11748e74d82f5 Mon Sep 17 00:00:00 2001 From: Mathieu Pillard Date: Fri, 21 Dec 2018 15:29:19 +0100 Subject: [PATCH] Remove SiteEvent models and associated code (#10259) Remove SiteEvent models and associated code --- src/olympia/amo/templatetags/jinja_helpers.py | 5 -- src/olympia/amo/tests/test_models.py | 22 ++++----- src/olympia/constants/base.py | 13 ------ src/olympia/stats/views.py | 41 +---------------- src/olympia/urls.py | 5 -- src/olympia/zadmin/forms.py | 8 ---- src/olympia/zadmin/models.py | 24 ---------- .../zadmin/templates/zadmin/site_events.html | 46 ------------------- .../zadmin/templatetags/jinja_helpers.py | 1 - src/olympia/zadmin/tests/test_views.py | 46 ------------------- src/olympia/zadmin/urls.py | 6 --- src/olympia/zadmin/views.py | 28 ----------- 12 files changed, 10 insertions(+), 235 deletions(-) delete mode 100644 src/olympia/zadmin/templates/zadmin/site_events.html diff --git a/src/olympia/amo/templatetags/jinja_helpers.py b/src/olympia/amo/templatetags/jinja_helpers.py index 40a84216c3..e08562e9ac 100644 --- a/src/olympia/amo/templatetags/jinja_helpers.py +++ b/src/olympia/amo/templatetags/jinja_helpers.py @@ -430,11 +430,6 @@ def loc(s): return trim_whitespace(s) -@library.global_function -def site_event_type(type): - return amo.SITE_EVENT_CHOICES[type] - - @library.global_function @jinja2.contextfunction def remora_url(context, url, lang=None, app=None, prefix=''): diff --git a/src/olympia/amo/tests/test_models.py b/src/olympia/amo/tests/test_models.py index 1a91774ed3..745a254e94 100644 --- a/src/olympia/amo/tests/test_models.py +++ b/src/olympia/amo/tests/test_models.py @@ -1,5 +1,3 @@ -from datetime import datetime - import pytest from mock import Mock @@ -10,7 +8,7 @@ from olympia.addons.models import Addon from olympia.amo import models as amo_models from olympia.amo.tests import TestCase from olympia.users.models import UserProfile -from olympia.zadmin.models import SiteEvent +from olympia.zadmin.models import Config pytestmark = pytest.mark.django_db @@ -197,22 +195,20 @@ class BasePreviewMixin(object): class BaseQuerysetTestCase(TestCase): def test_queryset_transform(self): - # We test with the SiteEvent model because it's a simple model + # We test with the Config model because it's a simple model # with no translated fields, no caching or other fancy features. - SiteEvent.objects.create(start=datetime.now(), description='Zero') - first = SiteEvent.objects.create(start=datetime.now(), - description='First') - second = SiteEvent.objects.create(start=datetime.now(), - description='Second') - SiteEvent.objects.create(start=datetime.now(), description='Third') - SiteEvent.objects.create(start=datetime.now(), description='') + Config.objects.create(key='a', value='Zero') + first = Config.objects.create(key='b', value='First') + second = Config.objects.create(key='c', value='Second') + Config.objects.create(key='d', value='Third') + Config.objects.create(key='e', value='') seen_by_first_transform = [] seen_by_second_transform = [] with self.assertNumQueries(0): # No database hit yet, everything is still lazy. - qs = amo_models.BaseQuerySet(SiteEvent) - qs = qs.exclude(description='').order_by('id')[1:3] + qs = amo_models.BaseQuerySet(Config) + qs = qs.exclude(value='').order_by('key')[1:3] qs = qs.transform( lambda items: seen_by_first_transform.extend(list(items))) qs = qs.transform( diff --git a/src/olympia/constants/base.py b/src/olympia/constants/base.py index a750cf8385..d6ac3f97fb 100644 --- a/src/olympia/constants/base.py +++ b/src/olympia/constants/base.py @@ -390,19 +390,6 @@ VALIDATOR_SKELETON_EXCEPTION_WEBEXT = { VERSION_SEARCH = re.compile(r'\.(\d+)$') -# Types of SiteEvent -SITE_EVENT_OTHER = 1 -SITE_EVENT_EXCEPTION = 2 -SITE_EVENT_RELEASE = 3 -SITE_EVENT_CHANGE = 4 - -SITE_EVENT_CHOICES = { - SITE_EVENT_OTHER: _('Other'), - SITE_EVENT_EXCEPTION: _('Exception'), - SITE_EVENT_RELEASE: _('Release'), - SITE_EVENT_CHANGE: _('Change'), -} - # For use in urls. ADDON_ID = r"""(?P[^/<>"']+)""" ADDON_UUID = r'(?P[\w]{8}-[\w]{4}-[\w]{4}-[\w]{4}-[\w]{12})' diff --git a/src/olympia/stats/views.py b/src/olympia/stats/views.py index 4c29593044..ff1513f933 100644 --- a/src/olympia/stats/views.py +++ b/src/olympia/stats/views.py @@ -12,7 +12,6 @@ from django.conf import settings from django.core.exceptions import PermissionDenied from django.core.files.storage import get_storage_class from django.db import connection -from django.db.models import Q from django.db.transaction import non_atomic_requests from django.utils.cache import add_never_cache_headers, patch_cache_control @@ -25,11 +24,10 @@ from olympia import amo from olympia.access import acl from olympia.stats.decorators import addon_view_stats from olympia.lib.cache import memoize -from olympia.amo.decorators import allow_cross_site_request, json_view +from olympia.amo.decorators import allow_cross_site_request from olympia.amo.urlresolvers import reverse from olympia.amo.utils import AMOJSONEncoder, render from olympia.stats.forms import DateForm -from olympia.zadmin.models import SiteEvent from .models import DownloadCount, ThemeUserCount, UpdateCount @@ -380,43 +378,6 @@ def get_daterange_or_404(start, end): ) -@json_view -@non_atomic_requests -def site_events(request, start, end): - """Return site events in the given timeframe.""" - start, end = get_daterange_or_404(start, end) - qs = SiteEvent.objects.filter( - Q(start__gte=start, start__lte=end) | - Q(end__gte=start, end__lte=end)) - - events = list(site_event_format(request, qs)) - - type_pretty = unicode(amo.SITE_EVENT_CHOICES[amo.SITE_EVENT_RELEASE]) - - releases = product_details.firefox_history_major_releases - - for version, date_ in releases.items(): - events.append({ - 'start': date_, - 'type_pretty': type_pretty, - 'type': amo.SITE_EVENT_RELEASE, - 'description': 'Firefox %s released' % version, - }) - return events - - -def site_event_format(request, events): - for e in events: - yield { - 'start': e.start.isoformat(), - 'end': e.end.isoformat() if e.end else None, - 'type_pretty': unicode(amo.SITE_EVENT_CHOICES[e.event_type]), - 'type': e.event_type, - 'description': e.description, - 'url': e.more_info_url, - } - - def daterange(start_date, end_date): for n in range((end_date - start_date).days): yield start_date + timedelta(n) diff --git a/src/olympia/urls.py b/src/olympia/urls.py index 3a226723c7..27fa46d6e0 100644 --- a/src/olympia/urls.py +++ b/src/olympia/urls.py @@ -9,7 +9,6 @@ from django.views.static import serve as serve_static from olympia.addons import views as addons_views from olympia.amo.urlresolvers import reverse from olympia.amo.utils import urlparams -from olympia.stats import views as stats_views from olympia.versions import views as version_views from olympia.versions.urls import download_patterns @@ -85,10 +84,6 @@ urlpatterns = [ # API v3+. url(r'^api/', include('olympia.api.urls')), - # Site events data. - url(r'^statistics/events-(?P\d{8})-(?P\d{8})\.json$', - stats_views.site_events, name='amo.site_events'), - # Site statistics that we are going to catch, the rest will fall through. url(r'^statistics/', include('olympia.stats.urls')), diff --git a/src/olympia/zadmin/forms.py b/src/olympia/zadmin/forms.py index b48f4bb8b4..2c1aa9b546 100644 --- a/src/olympia/zadmin/forms.py +++ b/src/olympia/zadmin/forms.py @@ -13,7 +13,6 @@ from olympia.addons.models import Addon from olympia.bandwagon.models import ( Collection, FeaturedCollection, MonthlyPick) from olympia.files.models import File -from olympia.zadmin.models import SiteEvent LOGGER_NAME = 'z.zadmin' @@ -125,10 +124,3 @@ class FileStatusForm(ModelForm): FileFormSet = modelformset_factory(File, form=FileStatusForm, formset=BaseModelFormSet, extra=0) - - -class SiteEventForm(ModelForm): - class Meta: - model = SiteEvent - fields = ('start', 'end', 'event_type', 'description', - 'more_info_url') diff --git a/src/olympia/zadmin/models.py b/src/olympia/zadmin/models.py index a232c1c22f..2f90f77d7c 100644 --- a/src/olympia/zadmin/models.py +++ b/src/olympia/zadmin/models.py @@ -185,27 +185,3 @@ class EmailPreview(ModelBase): class Meta: db_table = 'email_preview' - - -class SiteEvent(models.Model): - """Information records about downtime, releases, and other pertinent - events on the site.""" - - SITE_EVENT_CHOICES = amo.SITE_EVENT_CHOICES.items() - - start = models.DateField(db_index=True, - help_text='The time at which the event began.') - end = models.DateField( - db_index=True, null=True, blank=True, - help_text='If the event was a range, the time at which it ended.') - event_type = models.PositiveIntegerField(choices=SITE_EVENT_CHOICES, - db_index=True, default=0) - description = models.CharField(max_length=255, blank=True, null=True) - # An outbound link to an explanatory blog post or bug. - more_info_url = models.URLField(max_length=255, blank=True, null=True) - - class Meta: - db_table = 'zadmin_siteevent' - - def __unicode__(self): - return self.description diff --git a/src/olympia/zadmin/templates/zadmin/site_events.html b/src/olympia/zadmin/templates/zadmin/site_events.html deleted file mode 100644 index bc7a67e6eb..0000000000 --- a/src/olympia/zadmin/templates/zadmin/site_events.html +++ /dev/null @@ -1,46 +0,0 @@ -{% extends 'zadmin/base.html' %} - -{% set title = 'Site Events' %} - -{% block title %}{{ page_title(title) }}{% endblock %} - -{% block extrahead %} - -{% endblock %} - -{% block content %} -

{{ title }}

- -
- {% csrf_token %} - {{ form.as_p() }} - -
- - - - - - {% for event in events %} - -
ID - Type - Start - End - Description - URL - Actions -
{{ event.id }} - {{ site_event_type(event.event_type) }} - {{ event.start }} - {{ event.end }} - {{ event.description }} - {{ event.more_info_url }} - edit - remove - {% else %} -
No Records Found. - {% endfor %} -
-{% endblock %} diff --git a/src/olympia/zadmin/templatetags/jinja_helpers.py b/src/olympia/zadmin/templatetags/jinja_helpers.py index 2ef9abb4ba..3c70119d47 100644 --- a/src/olympia/zadmin/templatetags/jinja_helpers.py +++ b/src/olympia/zadmin/templatetags/jinja_helpers.py @@ -26,7 +26,6 @@ def admin_site_links(): ('View site settings', reverse('zadmin.settings')), ('View request environment', reverse('zadmin.env')), ('Django admin pages', reverse('zadmin.home')), - ('Site Events', reverse('zadmin.site_events')), ], 'tools': [ ('Manage elasticsearch', reverse('zadmin.elastic')), diff --git a/src/olympia/zadmin/tests/test_views.py b/src/olympia/zadmin/tests/test_views.py index 37f2637f03..b11e09a964 100644 --- a/src/olympia/zadmin/tests/test_views.py +++ b/src/olympia/zadmin/tests/test_views.py @@ -104,52 +104,6 @@ class TestHomeAndIndex(TestCase): assert response.status_code == 200 -class TestSiteEvents(TestCase): - fixtures = ['base/users', 'zadmin/tests/siteevents'] - - def setUp(self): - super(TestSiteEvents, self).setUp() - self.client.login(email='admin@mozilla.com') - - def test_get(self): - url = reverse('zadmin.site_events') - response = self.client.get(url) - assert response.status_code == 200 - events = response.context['events'] - assert len(events) == 1 - - def test_add(self): - url = reverse('zadmin.site_events') - new_event = { - 'event_type': 2, - 'start': '2012-01-01', - 'description': 'foo', - } - response = self.client.post(url, new_event, follow=True) - assert response.status_code == 200 - events = response.context['events'] - assert len(events) == 2 - - def test_edit(self): - url = reverse('zadmin.site_events', args=[1]) - modified_event = { - 'event_type': 2, - 'start': '2012-01-01', - 'description': 'bar', - } - response = self.client.post(url, modified_event, follow=True) - assert response.status_code == 200 - events = response.context['events'] - assert events[0].description == 'bar' - - def test_delete(self): - url = reverse('zadmin.site_events.delete', args=[1]) - response = self.client.get(url, follow=True) - assert response.status_code == 200 - events = response.context['events'] - assert len(events) == 0 - - class TestEmailPreview(TestCase): fixtures = ['base/addon_3615', 'base/users'] diff --git a/src/olympia/zadmin/urls.py b/src/olympia/zadmin/urls.py index ff866cc565..a806d63904 100644 --- a/src/olympia/zadmin/urls.py +++ b/src/olympia/zadmin/urls.py @@ -54,12 +54,6 @@ urlpatterns = [ url(r'^email-devs$', views.email_devs, name='zadmin.email_devs'), url(r'^addon-search$', views.addon_search, name='zadmin.addon-search'), - # Site Event admin. - url(r'^events/(?P\d+)?$', views.site_events, - name='zadmin.site_events'), - url(r'^events/(?P\d+)/delete$', views.delete_site_event, - name='zadmin.site_events.delete'), - # The Django admin. url(r'^models/', include((admin.site.get_urls(), 'admin'), namespace=admin.site.name)), diff --git a/src/olympia/zadmin/views.py b/src/olympia/zadmin/views.py index 8085c46cd9..fe10d61762 100644 --- a/src/olympia/zadmin/views.py +++ b/src/olympia/zadmin/views.py @@ -27,8 +27,6 @@ from olympia.bandwagon.models import Collection from olympia.files.models import File, FileUpload from olympia.stats.search import get_mappings as get_stats_mappings from olympia.versions.models import Version -from olympia.zadmin.forms import SiteEventForm -from olympia.zadmin.models import SiteEvent from . import tasks from .decorators import admin_required @@ -335,29 +333,3 @@ def recalc_hash(request, file_id): messages.success(request, 'File hash and size recalculated for file %d.' % file.id) return {'success': 1} - - -@admin.site.admin_view -def site_events(request, event_id=None): - event = get_object_or_404(SiteEvent, pk=event_id) if event_id else None - data = request.POST or None - - if event: - form = SiteEventForm(data, instance=event) - else: - form = SiteEventForm(data) - - if request.method == 'POST' and form.is_valid(): - form.save() - return redirect('zadmin.site_events') - pager = amo.utils.paginate(request, SiteEvent.objects.all(), 30) - events = pager.object_list - return render(request, 'zadmin/site_events.html', { - 'form': form, 'events': events}) - - -@admin.site.admin_view -def delete_site_event(request, event_id): - event = get_object_or_404(SiteEvent, pk=event_id) - event.delete() - return redirect('zadmin.site_events')