Replace django-moderation with CaseStudy.visible
This commit is contained in:
parent
9a98520cca
commit
63a52a1f7f
@ -1,12 +1,33 @@
|
|||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
from moderation.admin import ModerationAdmin
|
|
||||||
from leaflet.admin import LeafletGeoAdmin
|
from leaflet.admin import LeafletGeoAdmin
|
||||||
|
|
||||||
from .models import CaseStudy
|
from .models import CaseStudy
|
||||||
|
|
||||||
|
|
||||||
class CaseStudyAdmin(LeafletGeoAdmin):
|
class CaseStudyAdmin(LeafletGeoAdmin):
|
||||||
pass
|
list_display = ('id', 'date_created', 'entry_name', 'approved')
|
||||||
|
actions = ['approve', 'unapprove']
|
||||||
|
|
||||||
|
def approve(self, request, queryset):
|
||||||
|
updated = queryset.update(approved=True)
|
||||||
|
if updated == 1:
|
||||||
|
message_bit = "1 case study was"
|
||||||
|
else:
|
||||||
|
message_bit = "{0} case studies were".format(updated)
|
||||||
|
self.message_user(request, "{0} successfully approved".format(
|
||||||
|
message_bit
|
||||||
|
))
|
||||||
|
approve.short_description = "Approve selected case studies"
|
||||||
|
|
||||||
|
def unapprove(self, request, queryset):
|
||||||
|
updated = queryset.update(approved=False)
|
||||||
|
if updated == 1:
|
||||||
|
message_bit = "1 case study was"
|
||||||
|
else:
|
||||||
|
message_bit = "{0} case studies were".format(updated)
|
||||||
|
self.message_user(request, "{0} successfully un-approved".format(
|
||||||
|
message_bit
|
||||||
|
))
|
||||||
|
unapprove.short_description = "Un-approve selected case studies"
|
||||||
|
|
||||||
admin.site.register(CaseStudy, CaseStudyAdmin)
|
admin.site.register(CaseStudy, CaseStudyAdmin)
|
||||||
|
@ -5,12 +5,11 @@ from crispy_forms.helper import FormHelper
|
|||||||
from crispy_forms.layout import Submit, Layout, HTML, Fieldset
|
from crispy_forms.layout import Submit, Layout, HTML, Fieldset
|
||||||
from crispy_forms.bootstrap import Tab, TabHolder, PrependedText, FormActions
|
from crispy_forms.bootstrap import Tab, TabHolder, PrependedText, FormActions
|
||||||
from leaflet.forms.widgets import LeafletWidget
|
from leaflet.forms.widgets import LeafletWidget
|
||||||
from moderation.forms import BaseModeratedObjectForm
|
|
||||||
|
|
||||||
from .models import CaseStudy
|
from .models import CaseStudy
|
||||||
|
|
||||||
|
|
||||||
class BaseCaseStudyForm(BaseModeratedObjectForm):
|
class BaseCaseStudyForm(forms.models.ModelForm):
|
||||||
"""Base form class for the CaseStudy model."""
|
"""Base form class for the CaseStudy model."""
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
super(BaseCaseStudyForm, self).__init__(*args, **kwargs)
|
super(BaseCaseStudyForm, self).__init__(*args, **kwargs)
|
||||||
@ -204,4 +203,4 @@ class LongCaseStudyForm(BaseCaseStudyForm):
|
|||||||
)))
|
)))
|
||||||
|
|
||||||
class Meta(BaseCaseStudyForm.Meta):
|
class Meta(BaseCaseStudyForm.Meta):
|
||||||
fields = '__all__'
|
exclude = ('approved',)
|
||||||
|
24
apps/map/migrations/0036_auto_20180327_0334.py
Normal file
24
apps/map/migrations/0036_auto_20180327_0334.py
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# Generated by Django 1.11.6 on 2018-03-27 03:34
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('map', '0035_auto_20180326_0157'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterModelOptions(
|
||||||
|
name='casestudy',
|
||||||
|
options={'verbose_name_plural': 'case studies'},
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='casestudy',
|
||||||
|
name='approved',
|
||||||
|
field=models.BooleanField(default=False),
|
||||||
|
),
|
||||||
|
]
|
@ -16,9 +16,18 @@ class Shapefile(models.Model):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class CaseStudyQuerySet(models.QuerySet):
|
||||||
|
def approved(self):
|
||||||
|
return self.filter(
|
||||||
|
approved=True
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class CaseStudy(models.Model):
|
class CaseStudy(models.Model):
|
||||||
"""Model for case studies submitted to the Ojuso Platform"""
|
"""Model for case studies submitted to the Ojuso Platform"""
|
||||||
|
|
||||||
|
approved = models.BooleanField(default=False)
|
||||||
|
|
||||||
# Choice lists for drop-downs
|
# Choice lists for drop-downs
|
||||||
SECTOR_CHOICES = (
|
SECTOR_CHOICES = (
|
||||||
(_('Renewable Energy Generation'), (
|
(_('Renewable Energy Generation'), (
|
||||||
@ -965,6 +974,8 @@ class CaseStudy(models.Model):
|
|||||||
blank=True
|
blank=True
|
||||||
)
|
)
|
||||||
|
|
||||||
|
objects = CaseStudyQuerySet.as_manager()
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
"""The String representation of the case study. (Entry name with country name.)"""
|
"""The String representation of the case study. (Entry name with country name.)"""
|
||||||
return "%s in %s" % (self.entry_name, self.country.name)
|
return "%s in %s" % (self.entry_name, self.country.name)
|
||||||
|
@ -1,10 +0,0 @@
|
|||||||
from moderation import moderation
|
|
||||||
from moderation.moderator import GenericModerator
|
|
||||||
from apps.map.models import CaseStudy
|
|
||||||
|
|
||||||
|
|
||||||
class CaseStudyModerator(GenericModerator):
|
|
||||||
notify_user = True
|
|
||||||
auto_approve_for_superusers = True
|
|
||||||
|
|
||||||
moderation.register(CaseStudy, CaseStudyModerator)
|
|
@ -60,7 +60,6 @@ INSTALLED_APPS = [
|
|||||||
'django_extensions',
|
'django_extensions',
|
||||||
'envelope',
|
'envelope',
|
||||||
'leaflet',
|
'leaflet',
|
||||||
'moderation',
|
|
||||||
'raven.contrib.django.raven_compat',
|
'raven.contrib.django.raven_compat',
|
||||||
'registration',
|
'registration',
|
||||||
'rest_framework',
|
'rest_framework',
|
||||||
@ -252,10 +251,6 @@ LEAFLET_CONFIG = {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
# Moderation
|
|
||||||
# https://django-moderation.readthedocs.io/
|
|
||||||
MODERATION_MODERATORS = ('livvy@base.nu',)
|
|
||||||
|
|
||||||
# Sentry - Error Reporting
|
# Sentry - Error Reporting
|
||||||
RAVEN_CONFIG = {
|
RAVEN_CONFIG = {
|
||||||
'dsn': 'https://296dda892e6e4838835a2330dd621569:10943d15104244d683fe5ccc0c898386@sentry.io/227480',
|
'dsn': 'https://296dda892e6e4838835a2330dd621569:10943d15104244d683fe5ccc0c898386@sentry.io/227480',
|
||||||
|
@ -41,9 +41,10 @@ class CaseStudySerializer(gis_serializers.GeoFeatureModelSerializer):
|
|||||||
|
|
||||||
|
|
||||||
class CaseStudyViewSet(viewsets.ModelViewSet):
|
class CaseStudyViewSet(viewsets.ModelViewSet):
|
||||||
queryset = CaseStudy.objects.all()
|
queryset = CaseStudy.objects.approved()
|
||||||
serializer_class = CaseStudySerializer
|
serializer_class = CaseStudySerializer
|
||||||
|
|
||||||
|
|
||||||
apirouter = routers.DefaultRouter()
|
apirouter = routers.DefaultRouter()
|
||||||
apirouter.register(r'users', UserViewSet)
|
apirouter.register(r'users', UserViewSet)
|
||||||
apirouter.register(r'case-studies', CaseStudyViewSet)
|
apirouter.register(r'case-studies', CaseStudyViewSet)
|
||||||
|
@ -16,7 +16,6 @@ django-extensions==1.7.9
|
|||||||
django-geojson==2.10.0
|
django-geojson==2.10.0
|
||||||
#django-leaflet==0.22.0
|
#django-leaflet==0.22.0
|
||||||
-e git://github.com/makinacorpus/django-leaflet.git@a43acc5fed6674b413a6fab0feeb7c44e67c2ca8#egg=django-leaflet
|
-e git://github.com/makinacorpus/django-leaflet.git@a43acc5fed6674b413a6fab0feeb7c44e67c2ca8#egg=django-leaflet
|
||||||
django-moderation==0.5.0
|
|
||||||
django-multiselectfield==0.1.8
|
django-multiselectfield==0.1.8
|
||||||
django-multiupload==0.5.2
|
django-multiupload==0.5.2
|
||||||
django-registration-redux==1.6
|
django-registration-redux==1.6
|
||||||
|
Loading…
Reference in New Issue
Block a user