Skip to content

Commit

Permalink
fixing bug on pending version acceptance
Browse files Browse the repository at this point in the history
  • Loading branch information
meomancer committed Jul 18, 2016
1 parent ea2688d commit 44b48c9
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 31 deletions.
54 changes: 32 additions & 22 deletions django_project/base/templates/project/includes/project-panel.html
Original file line number Diff line number Diff line change
Expand Up @@ -58,32 +58,42 @@ <h3 class="panel-title">
{% endif %}
<h4 class="text-muted">
Latest Versions
<a href="{% url 'version-create' project_slug=project.slug %}"
class="btn btn-default pull-right btn-sm tooltip-toggle"
data-title="Create New Version">
{% show_button_icon "add" %}
</a>
{% if project.approved %}
<a href="{% url 'version-create' project_slug=project.slug %}"
class="btn btn-default pull-right btn-sm tooltip-toggle"
data-title="Create New Version">
{% show_button_icon "add" %}
</a>
{% endif %}
</h4>
<hr/>
{% if project.versions %}
{% for version in project.latest_versions %}
<p>
<a href="{% url "version-detail" project_slug=version.project.slug slug=version.slug %}">
<strong><span class="text-muted">Version:</span> {{ version.name }}</strong>
</a>
<span class="btn-group pull-right">
<a href="{% url "version-detail" project_slug=version.project.slug slug=version.slug %}"
class="btn btn-default btn-xs tooltip-toggle"
data-placement="top" data-title="Changelog List">
<span class="glyphicon glyphicon-list"></span>
</a>
<a href="{% url "version-thumbs" project_slug=version.project.slug slug=version.slug %}"
class="btn btn-default btn-xs tooltip-toggle"
data-placement="top" data-title="Changelog Thumbs">
<span class="glyphicon glyphicon-th"></span>
</a>
</span>
</p>
{% if version.approved or user.is_authenticated %}
<p>
{% if version.approved %}
<a href="{% url "version-detail" project_slug=version.project.slug slug=version.slug %}">
<strong><span class="text-muted">Version:</span> {{ version.name }}</strong>
</a>
{% else %}
<a href="{% url "pending-version-list" version.project.slug%}">
<strong><span class="text-muted">Version:</span> {{ version.name }}</strong> <b class="text-muted">(pending)</b>
</a>
{% endif %}
<span class="btn-group pull-right">
<a href="{% url "version-detail" project_slug=version.project.slug slug=version.slug %}"
class="btn btn-default btn-xs tooltip-toggle"
data-placement="top" data-title="Changelog List">
<span class="glyphicon glyphicon-list"></span>
</a>
<a href="{% url "version-thumbs" project_slug=version.project.slug slug=version.slug %}"
class="btn btn-default btn-xs tooltip-toggle"
data-placement="top" data-title="Changelog Thumbs">
<span class="glyphicon glyphicon-th"></span>
</a>
</span>
</p>
{% endif %}
{% endfor %}
{% if project.more_than_threshold %}
<strong><span class="text-muted">Latest {{ project.threshold }} of {{ project.versions.count }} versionss</span></strong>
Expand Down
5 changes: 4 additions & 1 deletion django_project/base/views/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,10 @@ def get_queryset(self):
return qs.filter(owner=self.request.user)

def get_success_url(self):
return reverse('project-detail', kwargs={'slug': self.object.slug})
if self.object.approved:
return reverse('project-detail', kwargs={'slug': self.object.slug})
else:
return reverse('pending-project-list')

def form_valid(self, form):
"""Check that there is no referential integrity error when saving."""
Expand Down
12 changes: 9 additions & 3 deletions django_project/changes/models/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@
from common.utilities import version_slugify
import os
import logging
from core.settings.contrib import STOP_WORDS
from django.conf.global_settings import MEDIA_ROOT
from django.db import models
from .entry import Entry
from .sponsorship_period import SponsorshipPeriod
from core.settings.contrib import STOP_WORDS
from django.core.exceptions import ValidationError
from django.conf.global_settings import MEDIA_ROOT
from django.contrib.auth.models import User
from django.utils.translation import ugettext_lazy as _
from django.db import models

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -98,6 +99,11 @@ class Meta:
app_label = 'changes'
# ordering = ['-datetime_created']

def clean(self):
if not self.project.approved:
raise ValidationError(
"can't create version because project is not approved yet")

def save(self, *args, **kwargs):
if not self.pk:
words = self.name.split()
Expand Down
18 changes: 13 additions & 5 deletions django_project/changes/views/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,13 @@ def get_object(self, queryset=None):
'Requested project does not exist.')
try:
obj = queryset.filter(project=project).get(slug=slug)
if not obj.approved:
raise Http404(
'Sorry! The project you are requesting a version for '
'could not be found or you do not have permission to '
'view the version. Also the version may not be '
'approved yet. Try logging in as a staff member if '
'you wish to view it.')
return obj
except Version.DoesNotExist:
raise Http404(
Expand Down Expand Up @@ -439,10 +446,10 @@ def form_valid(self, form):


class PendingVersionListView(
StaffuserRequiredMixin,
VersionMixin,
PaginationMixin,
ListView):
StaffuserRequiredMixin,
VersionMixin,
PaginationMixin,
ListView):
"""List view for pending Version. Staff see all """
context_object_name = 'versions'
template_name = 'version/list.html'
Expand Down Expand Up @@ -515,7 +522,8 @@ def get_redirect_url(self, project_slug, slug):
:returns: A url.
:rtype: str
"""
project = Project.objects.get(slug=project_slug)
project = Project.objects.filter(slug=project_slug)
project = get_object_or_404(project, approved=True)
version_qs = Version.unapproved_objects.filter(project=project)
version = get_object_or_404(version_qs, slug=slug)
version.approved = True
Expand Down

0 comments on commit 44b48c9

Please sign in to comment.