From 058c95584b1e863643985e14d9b87dfb43ca2b4c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9D=D0=B0=D0=B7=D0=B0=D1=80=20=D0=9A=D0=BE=D1=82=D1=8E?= =?UTF-8?q?=D0=BA?= Date: Tue, 6 Jan 2015 12:32:02 +0200 Subject: [PATCH] Task 30 --- company/edit_views.py | 12 +++++- company/urls.py | 34 ++++++++-------- templates/client/company/company_detail.html | 2 +- .../client/includes/company/company_edit.html | 39 ++++++++++--------- 4 files changed, 49 insertions(+), 38 deletions(-) diff --git a/company/edit_views.py b/company/edit_views.py index 00ce6279..7c6cd1f3 100644 --- a/company/edit_views.py +++ b/company/edit_views.py @@ -1,13 +1,21 @@ import json -from django.http import HttpResponseRedirect, HttpResponse, Http404 +from django.http import HttpResponseRedirect, HttpResponse, Http404, HttpResponseForbidden from django.utils.translation import get_language from sorl.thumbnail import get_thumbnail from edit_forms import * from accounts.views import ProfileInvalidView +from .models import Company class BaseView(ProfileInvalidView): def form_valid(self, form): - company = self.request.user.company + slug = self.kwargs.get('slug') + if not slug: + raise Http404 + + company = Company.objects.get(url=slug) + if company.creator_id != self.request.user.id: + return HttpResponseForbidden() + if self.form_class.translation: lang = get_language() comp_transl = company.translations.get(language_code=lang) diff --git a/company/urls.py b/company/urls.py index b1d47572..88c9e07f 100644 --- a/company/urls.py +++ b/company/urls.py @@ -6,6 +6,10 @@ from edit_views import * urlpatterns = patterns('', + url(r'company/create-company/$', 'company.views.create_company'), + url(r'company/get-company/$', 'company.views.get_company'), + # + url(r'members/search/$', CompanySearchView.as_view()), #url(r'members/(?P.*)/(?P\d+)/$', CompanyView.as_view()), #url(r'members/(?P\d+)/$', CompanyView.as_view()), @@ -20,21 +24,19 @@ urlpatterns = patterns('', url(r'members/$', MemberList.as_view()), # - url(r'company/create-company/$', 'company.views.create_company'), - url(r'company/get-company/$', 'company.views.get_company'), - # - url(r'company/update/name/$', login_required(NameView.as_view())), - url(r'^company/update/home/$', login_required(HomeView.as_view())), - url(r'^company/update/specialization/$', login_required(SpecializationView.as_view())), - url(r'^company/update/phone/$', login_required(PhoneView.as_view())), - url(r'^company/update/email/$', login_required(EmailView.as_view())), - url(r'^company/update/web-page/$', login_required(WebPageView.as_view())), - url(r'^company/update/social/$', login_required(SocialView.as_view())), - url(r'^company/update/tag/$', login_required(TagView.as_view())), - url(r'^company/update/foundation/$', login_required(FoundationView.as_view())), - url(r'^company/update/staff/$', login_required(StaffView.as_view())), - url(r'^company/update/description/$', login_required(DescriptionView.as_view())), - url(r'^company/update/address/$', login_required(AddressView.as_view())), - url(r'^company/update/logo/$', login_required(LogoView.as_view())), + url(r'company/update/name/(?P.*)/$', login_required(NameView.as_view())), + url(r'^company/update/home/(?P.*)/$', login_required(HomeView.as_view())), + url(r'^company/update/specialization/(?P.*)/$', login_required(SpecializationView.as_view())), + url(r'^company/update/phone/(?P.*)/$', login_required(PhoneView.as_view())), + url(r'^company/update/email/(?P.*)/$', login_required(EmailView.as_view())), + url(r'^company/update/web-page/(?P.*)/$', login_required(WebPageView.as_view())), + url(r'^company/update/social/(?P.*)/$', login_required(SocialView.as_view())), + url(r'^company/update/tag/(?P.*)/$', login_required(TagView.as_view())), + url(r'^company/update/foundation/(?P.*)/$', login_required(FoundationView.as_view())), + url(r'^company/update/staff/(?P.*)/$', login_required(StaffView.as_view())), + url(r'^company/update/description/(?P.*)/$', login_required(DescriptionView.as_view())), + url(r'^company/update/address/(?P.*)/$', login_required(AddressView.as_view())), + url(r'^company/update/logo/(?P.*)/$', login_required(LogoView.as_view())), + ) diff --git a/templates/client/company/company_detail.html b/templates/client/company/company_detail.html index b13977b2..5e7892bc 100644 --- a/templates/client/company/company_detail.html +++ b/templates/client/company/company_detail.html @@ -15,7 +15,7 @@ {% block content_list %} {% if request.user == object.creator %} - {% include 'client/includes/company/company_edit.html' %} + {% include 'client/includes/company/company_edit.html' with company=object %} {% else %} {% include 'client/includes/company/company_object.html' with company=object %} {% endif %} diff --git a/templates/client/includes/company/company_edit.html b/templates/client/includes/company/company_edit.html index 0f033237..c3520619 100644 --- a/templates/client/includes/company/company_edit.html +++ b/templates/client/includes/company/company_edit.html @@ -42,7 +42,7 @@ Указать {% endif %} -
{% csrf_token %} + {% csrf_token %}
@@ -76,8 +76,8 @@
@@ -87,7 +87,7 @@
редактировать
- {% csrf_token %} + {% csrf_token %}
@@ -126,7 +126,7 @@ {% endif %}
- {% csrf_token %} + {% csrf_token %}
@@ -148,12 +148,13 @@
- -
- {% for th in request.user.company.theme.all %} - {{ th.name }}{% ifnotequal forloop.counter request.user.company.theme.all|length %},{% endifnotequal %} - {% endfor %} -
+ {% with themes=company.theme.all %} +
+ {% for th in themes %} + {{ th.name }}{% ifnotequal forloop.counter themes|length %},{% endifnotequal %} + {% endfor %} +
+ {% endwith %}
@@ -171,7 +172,7 @@ {% endif %}
- {% csrf_token %} + {% csrf_token %}
@@ -260,7 +261,7 @@
- {% csrf_token %} + {% csrf_token %}
@@ -323,7 +324,7 @@ {% endif %}
- {% csrf_token %} + {% csrf_token %}
@@ -359,7 +360,7 @@ {% endif %}
- {% csrf_token %} + {% csrf_token %}
@@ -398,7 +399,7 @@ {% endif %}
- {% csrf_token %} + {% csrf_token %}
@@ -441,7 +442,7 @@
- {% csrf_token %} + {% csrf_token %}
@@ -477,7 +478,7 @@
- {% csrf_token %} + {% csrf_token %}
@@ -513,7 +514,7 @@
- {% csrf_token %} + {% csrf_token %}