Skip to content
This repository was archived by the owner on Oct 28, 2020. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions remo/base/content_urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

from remo.base.views import (BaseCreateView, BaseDeleteView, BaseListView,
BaseUpdateView)
from remo.events.models import EventGoal
from remo.events.forms import EventGoalForm
from remo.profiles.forms import FunctionalAreaForm
from remo.profiles.models import FunctionalArea
from remo.reports.forms import ActivityForm, CampaignForm
Expand Down Expand Up @@ -67,4 +69,24 @@
model=FunctionalArea, form_class=FunctionalAreaForm,
success_url=reverse_lazy('list_functional_areas')),
name='edit_functional_area'),
url('^event_goals/$',
BaseListView.as_view(
model=EventGoal,
create_object_url=reverse_lazy('create_event_goal')),
name='list_event_goals'),
url('^event_goals/(?P<pk>\d+)/delete/$',
BaseDeleteView.as_view(
model=EventGoal,
success_url=reverse_lazy('list_event_goals')),
name='delete_event_goal'),
url('^event_goals/new/$',
BaseCreateView.as_view(
model=EventGoal, form_class=EventGoalForm,
success_url=reverse_lazy('list_event_goals')),
name='create_event_goal'),
url('^event_goals/(?P<pk>\d+)/edit/$',
BaseUpdateView.as_view(
model=EventGoal, form_class=EventGoalForm,
success_url=reverse_lazy('list_event_goals')),
name='edit_event_goal'),
)
11 changes: 8 additions & 3 deletions remo/base/static/base/css/app-fd4.less
Original file line number Diff line number Diff line change
Expand Up @@ -1394,6 +1394,10 @@ small.error {
content: "e";
}

.pict-icon.medal:after {
content: ")";
}

.pict-table-icon {
font-family: "ModernPictogramsNormal";
}
Expand Down Expand Up @@ -1967,7 +1971,7 @@ ul.mreports li.editable a {
margin-top: 10px;
}
}
.category-select {
.category-goal-select {
margin-top: 10px;
.required-field {
top: 10px;
Expand Down Expand Up @@ -2053,14 +2057,15 @@ ul.mreports li.editable a {
width: 90%;
}
}
.category-select,
.category-goal-select,
.map-point-select {
text-align: left;
button {
width: 90%;
}
}
.event-categories {
.event-categories,
.event-goals {
text-align: left;
}
}
Expand Down
3 changes: 3 additions & 0 deletions remo/base/templates/settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ <h2>Content</h2>
<p>
<a href="{{ url('list_campaigns') }}">Edit campaigns</a>
</p>
<p>
<a href="{{ url('list_event_goals') }}">Edit event goals</a>
</p>
</div>
</section>
{% endif %}
Expand Down
59 changes: 58 additions & 1 deletion remo/base/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
from remo.base.tests import requires_permission, RemoTestCase
from remo.base.tests.browserid_mock import mock_browserid
from remo.base.views import robots_txt
from remo.events.models import EventGoal
from remo.events.tests import EventGoalFactory
from remo.profiles.models import FunctionalArea
from remo.profiles.tasks import check_mozillian_username
from remo.profiles.tests import UserFactory, FunctionalAreaFactory
Expand Down Expand Up @@ -471,6 +473,18 @@ def test_base_content_functional_areas_list(self):
reverse('create_functional_area'))
self.assertTemplateUsed(response, 'base_content_list.html')

def test_base_content_event_goals_list(self):
"""Test list event goals."""
admin = UserFactory.create(groups=['Admin'])
response = self.get(reverse('list_event_goals'), user=admin,
follow=True)
eq_(response.status_code, 200)
eq_(response.context['verbose_name'], 'event goal')
eq_(response.context['verbose_name_plural'], 'event goals')
eq_(response.context['create_object_url'],
reverse('create_event_goal'))
self.assertTemplateUsed(response, 'base_content_list.html')

@requires_permission()
def test_base_content_list_unauthed(self):
"""Test list base content unauthorized."""
Expand Down Expand Up @@ -511,6 +525,16 @@ def test_base_content_functional_area_create_get(self):
eq_(response.context['creating'], True)
self.assertTemplateUsed(response, 'base_content_edit.html')

def test_base_content_event_goals_create_get(self):
"""Test get create event goals."""
admin = UserFactory.create(groups=['Admin'])
response = self.get(reverse('create_event_goal'), user=admin,
follow=True)
eq_(response.status_code, 200)
eq_(response.context['verbose_name'], 'event goal')
eq_(response.context['creating'], True)
self.assertTemplateUsed(response, 'base_content_edit.html')

def test_base_content_activity_create_post(self):
"""Test post create activity."""
admin = UserFactory.create(groups=['Admin'])
Expand Down Expand Up @@ -540,6 +564,16 @@ def test_base_content_functional_area_create_post(self):
query = FunctionalArea.objects.filter(name='test functional area')
eq_(query.exists(), True)

def test_base_content_event_goal_create_post(self):
"""Test post create event goal."""
admin = UserFactory.create(groups=['Admin'])
response = self.post(reverse('create_event_goal'),
data={'name': 'test event goal'},
user=admin, follow=True)
eq_(response.status_code, 200)
query = EventGoal.objects.filter(name='test event goal')
eq_(query.exists(), True)

@requires_permission()
def test_base_content_create_unauthed(self):
"""Test create base content unauthorized."""
Expand Down Expand Up @@ -588,6 +622,18 @@ def test_base_content_functional_area_edit_post(self):
query = FunctionalArea.objects.filter(name='edit functional area')
eq_(query.exists(), True)

def test_base_content_event_goal_edit_post(self):
"""Test post edit event goal."""
admin = UserFactory.create(groups=['Admin'])
goal = EventGoalFactory.create(name='test event goal')
response = self.post(reverse('edit_event_goal',
kwargs={'pk': goal.id}),
data={'name': 'edit event goal'},
user=admin, follow=True)
eq_(response.status_code, 200)
query = EventGoal.objects.filter(name='edit event goal')
eq_(query.exists(), True)

@requires_permission()
def test_base_content_update_unauthed(self):
"""Test update base content unauthorized."""
Expand Down Expand Up @@ -631,7 +677,18 @@ def test_base_content_functional_area_delete_post(self):
kwargs={'pk': area.id}), user=admin,
follow=True)
eq_(response.status_code, 200)
query = Campaign.objects.filter(name='test functional area')
query = FunctionalArea.objects.filter(name='test functional area')
eq_(query.exists(), False)

def test_base_content_event_goal_delete_post(self):
"""Test delete event goal."""
admin = UserFactory.create(groups=['Admin'])
goal = EventGoalFactory.create(name='test event goal')
response = self.post(reverse('delete_event_goal',
kwargs={'pk': goal.id}), user=admin,
follow=True)
eq_(response.status_code, 200)
query = EventGoal.objects.filter(name='test event goal')
eq_(query.exists(), False)

@requires_permission()
Expand Down
10 changes: 8 additions & 2 deletions remo/events/admin.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from django.contrib import admin

from models import Attendance, Metric, Event
from models import Attendance, Event, EventGoal, Metric


class AttendanceInline(admin.StackedInline):
Expand All @@ -13,9 +13,14 @@ class MetricInline(admin.StackedInline):
model = Metric


class EventGoalAdmin(admin.ModelAdmin):
"""Metric Inline."""
model = EventGoal


class EventAdmin(admin.ModelAdmin):
"""Event Admin."""
inlines = [MetricInline, AttendanceInline]
inlines = [AttendanceInline, MetricInline]
model = Event
list_display = ('name', 'start', 'end')
search_fields = ('name', 'country', 'region', 'venue')
Expand All @@ -25,3 +30,4 @@ def owner_display_name(self, obj):


admin.site.register(Event, EventAdmin)
admin.site.register(EventGoal, EventGoalAdmin)
22 changes: 18 additions & 4 deletions remo/events/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from datetimewidgets import SplitSelectDateTimeWidget
from remo.base.helpers import get_full_name
from remo.base.utils import validate_datetime
from remo.events.models import EventGoal
from remo.profiles.models import FunctionalArea
from remo.remozilla.models import Bug

Expand Down Expand Up @@ -79,6 +80,8 @@ class EventForm(happyforms.ModelForm):
"""Form of an event."""
categories = forms.ModelMultipleChoiceField(
queryset=FunctionalArea.active_objects.all())
goals = forms.ModelMultipleChoiceField(
queryset=EventGoal.active_objects.all())
country = forms.ChoiceField(
choices=[],
error_messages={'required': 'Please select one option from the list.'})
Expand All @@ -104,11 +107,15 @@ def __init__(self, *args, **kwargs):

super(EventForm, self).__init__(*args, **kwargs)

# Dynamic categories field.
# Dynamic categories/goals field.
if self.instance.id:
query = Q(active=True) | Q(id__in=self.instance.categories.all())
categories = FunctionalArea.objects.filter(query)
categories_query = (Q(active=True) |
Q(id__in=self.instance.categories.all()))
goals_query = Q(active=True) | Q(id__in=self.instance.goals.all())
categories = FunctionalArea.objects.filter(categories_query)
goals = EventGoal.objects.filter(goals_query)
self.fields['categories'].queryset = categories
self.fields['goals'].queryset = goals

# Dynamic countries field.
countries = product_details.get_regions('en').values()
Expand Down Expand Up @@ -232,7 +239,7 @@ class Meta:
'country', 'city', 'lat', 'lon', 'external_link',
'planning_pad_url', 'timezone', 'estimated_attendance',
'description', 'extra_content', 'hashtag', 'mozilla_event',
'swag_bug', 'budget_bug', 'categories']
'swag_bug', 'budget_bug', 'categories', 'goals']
widgets = {'lat': forms.HiddenInput(attrs={'id': 'lat'}),
'lon': forms.HiddenInput(attrs={'id': 'lon'}),
'start': SplitSelectDateTimeWidget(),
Expand All @@ -245,3 +252,10 @@ class EventCommentForm(happyforms.ModelForm):
class Meta:
model = EventComment
fields = ['comment']


class EventGoalForm(happyforms.ModelForm):
"""Form for EventGoal Model."""

class Meta:
model = EventGoal
Loading