Merge branch 'Tresorerie' of https://ae-dev.utbm.fr/ae/Sith into Tresorerie

This commit is contained in:
Pierre Brunet 2017-03-12 20:22:52 +01:00
commit 5f9ec9a2ab
7 changed files with 60 additions and 23 deletions

View File

@ -56,6 +56,12 @@ Finally, when building a class based view, which is highly advised, you just hav
CanEditMixin, or CanViewMixin, which are located in core.views. Your view will then be protected using either the CanEditMixin, or CanViewMixin, which are located in core.views. Your view will then be protected using either the
appropriate group fields, or the right method to check user permissions. appropriate group fields, or the right method to check user permissions.
#### Counting the number of line of code
```
# apt install cloc
$ cloc --exclude-dir=doc,env .
```

View File

@ -5,7 +5,9 @@
{% endblock %} {% endblock %}
{% block content %} {% block content %}
{% if user.is_in_group(settings.SITH_GROUP_ACCOUNTING_ADMIN_ID) or user.is_root %}
<p><a href="{{ url('accounting:co_new') }}">{% trans %}Create new company{% endtrans %}</a></p> <p><a href="{{ url('accounting:co_new') }}">{% trans %}Create new company{% endtrans %}</a></p>
{% endif %}
</br> </br>
<table> <table>

View File

@ -736,9 +736,9 @@ class Page(models.Model):
name = models.CharField(_('page unix name'), max_length=30, name = models.CharField(_('page unix name'), max_length=30,
validators=[ validators=[
validators.RegexValidator( validators.RegexValidator(
r'^[\w.+-]+$', r'^[A-z.+-]+$',
_('Enter a valid page name. This value may contain only ' _('Enter a valid page name. This value may contain only '
'letters, numbers ' 'and ./+/-/_ characters.') 'unaccented letters, numbers ' 'and ./+/-/_ characters.')
), ),
], ],
blank=False) blank=False)
@ -846,6 +846,14 @@ class Page(models.Model):
p.set_lock_recursive(user) p.set_lock_recursive(user)
self.set_lock(user) self.set_lock(user)
def unset_lock_recursive(self):
"""
Unlocks recursively all the child pages
"""
for p in self.children.all():
p.unset_lock_recursive()
self.unset_lock()
def unset_lock(self): def unset_lock(self):
"""Always try to unlock, even if there is no lock""" """Always try to unlock, even if there is no lock"""
self.lock_user = None self.lock_user = None
@ -886,6 +894,16 @@ class Page(models.Model):
except: except:
return self.name return self.name
def delete(self):
self.unset_lock_recursive()
self.set_lock_recursive(User.objects.get(id=0))
for child in self.children.all():
child.parent = self.parent
child.save()
child.unset_lock_recursive()
super(Page, self).delete()
class PageRev(models.Model): class PageRev(models.Model):
""" """
This is the true content of the page. This is the true content of the page.

View File

@ -23,6 +23,7 @@ function make_preview() {
<p><input type="button" value="{% trans %}Preview{% endtrans %}" onclick="javascript:make_preview();" /></p> <p><input type="button" value="{% trans %}Preview{% endtrans %}" onclick="javascript:make_preview();" /></p>
<p><input type="submit" value="{% trans %}Save{% endtrans %}" /></p> <p><input type="submit" value="{% trans %}Save{% endtrans %}" /></p>
</form> </form>
<a href="{{ url('core:page_delete', page_id=page.id)}}">{% trans %}Delete{% endtrans %}</a>
<div id="preview"> <div id="preview">
</div> </div>
{% endblock %} {% endblock %}

View File

@ -61,6 +61,7 @@ urlpatterns = [
# Page views # Page views
url(r'^page/$', PageListView.as_view(), name='page_list'), url(r'^page/$', PageListView.as_view(), name='page_list'),
url(r'^page/create$', PageCreateView.as_view(), name='page_new'), url(r'^page/create$', PageCreateView.as_view(), name='page_new'),
url(r'^page/(?P<page_id>[0-9]*)/delete$', PageDeleteView.as_view(), name='page_delete'),
url(r'^page/(?P<page_name>[a-z0-9/-_]*)/edit$', PageEditView.as_view(), name='page_edit'), url(r'^page/(?P<page_name>[a-z0-9/-_]*)/edit$', PageEditView.as_view(), name='page_edit'),
url(r'^page/(?P<page_name>[a-z0-9/-_]*)/prop$', PagePropView.as_view(), name='page_prop'), url(r'^page/(?P<page_name>[a-z0-9/-_]*)/prop$', PagePropView.as_view(), name='page_prop'),
url(r'^page/(?P<page_name>[a-z0-9/-_]*)/hist$', PageHistView.as_view(), name='page_hist'), url(r'^page/(?P<page_name>[a-z0-9/-_]*)/hist$', PageHistView.as_view(), name='page_hist'),

View File

@ -1,7 +1,8 @@
# This file contains all the views that concern the page model # This file contains all the views that concern the page model
from django.shortcuts import render, redirect, get_object_or_404 from django.shortcuts import render, redirect, get_object_or_404
from django.core.urlresolvers import reverse_lazy
from django.views.generic import ListView, DetailView from django.views.generic import ListView, DetailView
from django.views.generic.edit import UpdateView, CreateView from django.views.generic.edit import UpdateView, CreateView, DeleteView
from django.contrib.auth.decorators import login_required, permission_required from django.contrib.auth.decorators import login_required, permission_required
from django.utils.decorators import method_decorator from django.utils.decorators import method_decorator
from django.forms.models import modelform_factory from django.forms.models import modelform_factory
@ -159,3 +160,11 @@ class PageEditView(CanEditMixin, UpdateView):
form.instance = new_rev form.instance = new_rev
return super(PageEditView, self).form_valid(form) return super(PageEditView, self).form_valid(form)
class PageDeleteView(CanEditPropMixin, DeleteView):
model = Page
template_name = 'core/delete_confirm.jinja'
pk_url_kwarg = 'page_id'
def get_success_url(self, **kwargs):
return reverse_lazy('core:page_list')

View File

@ -688,26 +688,26 @@ class CashRegisterSummaryForm(forms.Form):
""" """
Provide the cash summary form Provide the cash summary form
""" """
ten_cents = forms.IntegerField(label=_("10 cents"), required=False) ten_cents = forms.IntegerField(label=_("10 cents"), required=False, min_value=0)
twenty_cents = forms.IntegerField(label=_("20 cents"), required=False) twenty_cents = forms.IntegerField(label=_("20 cents"), required=False, min_value=0)
fifty_cents = forms.IntegerField(label=_("50 cents"), required=False) fifty_cents = forms.IntegerField(label=_("50 cents"), required=False, min_value=0)
one_euro = forms.IntegerField(label=_("1 euro"), required=False) one_euro = forms.IntegerField(label=_("1 euro"), required=False, min_value=0)
two_euros = forms.IntegerField(label=_("2 euros"), required=False) two_euros = forms.IntegerField(label=_("2 euros"), required=False, min_value=0)
five_euros = forms.IntegerField(label=_("5 euros"), required=False) five_euros = forms.IntegerField(label=_("5 euros"), required=False, min_value=0)
ten_euros = forms.IntegerField(label=_("10 euros"), required=False) ten_euros = forms.IntegerField(label=_("10 euros"), required=False, min_value=0)
twenty_euros = forms.IntegerField(label=_("20 euros"), required=False) twenty_euros = forms.IntegerField(label=_("20 euros"), required=False, min_value=0)
fifty_euros = forms.IntegerField(label=_("50 euros"), required=False) fifty_euros = forms.IntegerField(label=_("50 euros"), required=False, min_value=0)
hundred_euros = forms.IntegerField(label=_("100 euros"), required=False) hundred_euros = forms.IntegerField(label=_("100 euros"), required=False, min_value=0)
check_1_value = forms.DecimalField(label=_("Check amount"), required=False) check_1_value = forms.DecimalField(label=_("Check amount"), required=False, min_value=0)
check_1_quantity = forms.IntegerField(label=_("Check quantity"), required=False) check_1_quantity = forms.IntegerField(label=_("Check quantity"), required=False, min_value=0)
check_2_value = forms.DecimalField(label=_("Check amount"), required=False) check_2_value = forms.DecimalField(label=_("Check amount"), required=False, min_value=0)
check_2_quantity = forms.IntegerField(label=_("Check quantity"), required=False) check_2_quantity = forms.IntegerField(label=_("Check quantity"), required=False, min_value=0)
check_3_value = forms.DecimalField(label=_("Check amount"), required=False) check_3_value = forms.DecimalField(label=_("Check amount"), required=False, min_value=0)
check_3_quantity = forms.IntegerField(label=_("Check quantity"), required=False) check_3_quantity = forms.IntegerField(label=_("Check quantity"), required=False, min_value=0)
check_4_value = forms.DecimalField(label=_("Check amount"), required=False) check_4_value = forms.DecimalField(label=_("Check amount"), required=False, min_value=0)
check_4_quantity = forms.IntegerField(label=_("Check quantity"), required=False) check_4_quantity = forms.IntegerField(label=_("Check quantity"), required=False, min_value=0)
check_5_value = forms.DecimalField(label=_("Check amount"), required=False) check_5_value = forms.DecimalField(label=_("Check amount"), required=False, min_value=0)
check_5_quantity = forms.IntegerField(label=_("Check quantity"), required=False) check_5_quantity = forms.IntegerField(label=_("Check quantity"), required=False, min_value=0)
comment = forms.CharField(label=_("Comment"), required=False) comment = forms.CharField(label=_("Comment"), required=False)
emptied = forms.BooleanField(label=_("Emptied"), required=False) emptied = forms.BooleanField(label=_("Emptied"), required=False)