diff --git a/company/edit_forms.py b/company/edit_forms.py index 74c25cef..a4786137 100644 --- a/company/edit_forms.py +++ b/company/edit_forms.py @@ -4,6 +4,7 @@ from django.utils.translation import ugettext as _, get_language from country.models import Country from city.models import City from company.models import Company +from theme.models import Theme class BaseForm(forms.ModelForm): @@ -107,6 +108,13 @@ class SocialForm(BaseForm): fields = ('facebook', 'twitter', 'vk', 'linkedin') +class ThemeForm(BaseForm): + theme = forms.ModelMultipleChoiceField(queryset=Theme.objects.all()) + class Meta: + model = Company + fields = ('theme',) + + class TagForm(BaseForm): tag = forms.CharField(required=False, widget=forms.HiddenInput(attrs={'class': 'select2'})) class Meta: diff --git a/company/edit_views.py b/company/edit_views.py index f2ed62ad..86b67258 100644 --- a/company/edit_views.py +++ b/company/edit_views.py @@ -87,9 +87,56 @@ class SocialView(BaseView): form_class = SocialForm +class ThemeView(BaseView): + form_class = ThemeForm + + def form_valid(self, form): + 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() + + + form = self.form_class(self.request.POST, instance=company) + + company = form.save() + try: + rating = company.rating + except AttributeError: + rating = company.master.rating + themes = [{'text': item.name,'id': str(item.id),'url': '/members/theme/%s/'%item.url} for item in company.theme.all()] + response = {'success': True, 'rating': rating, 'tags': themes} + return HttpResponse(json.dumps(response), content_type='application/json') + + class TagView(BaseView): form_class = TagForm + def form_valid(self, form): + 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() + + + form = self.form_class(self.request.POST, instance=company) + + company = form.save() + try: + rating = company.rating + except AttributeError: + rating = company.master.rating + tags = [{'text': item.name,'id': str(item.id),'url': '/members/tag/%s/'%item.url} for item in company.tag.all()] + response = {'success': True, 'rating': rating, 'tags': tags} + return HttpResponse(json.dumps(response), content_type='application/json') + + class FoundationView(BaseView): form_class = FoundationForm diff --git a/company/urls.py b/company/urls.py index 88c9e07f..8c42af1c 100644 --- a/company/urls.py +++ b/company/urls.py @@ -9,7 +9,6 @@ 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()), @@ -32,6 +31,7 @@ urlpatterns = patterns('', 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/theme/(?P.*)/$', login_required(ThemeView.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())), diff --git a/company/views.py b/company/views.py index 07691436..3b419b84 100644 --- a/company/views.py +++ b/company/views.py @@ -15,7 +15,7 @@ from .edit_forms import NameForm as CompNameForm, HomeForm as CompHomeForm, Phon EmailForm as CompEmailForm, WebPageForm as CompWebPageForm, SocialForm as CompSocialForm,\ TagForm as CompTagForm, DescriptionForm as CompDescr, StaffForm as CompStaff, \ FoundationForm as CompFound, SpecializationForm as CompSpec, AddressForm as CompAddress,\ - LogoForm as CompLogo + LogoForm as CompLogo, ThemeForm as CompThemeForm class CompanySearchView(ListView): @@ -112,11 +112,17 @@ class MemberDetail(DetailView): 'staff_form': CompStaff(instance=company), 'found_form': CompFound(instance=company), 'logo_form': CompLogo(instance=company) } - tags = [{'id': str(tag.id), 'text': tag.name } for tag in company.tag.all()] + tags = [{'id': str(tag.id), 'text': tag.name, 'url': '/members/tag/%s/'%tag.url} for tag in company.tag.all()] tag_form = CompTagForm() tag_form.fields['tag'].widget.attrs['data-predifined'] = json.dumps(tags) tag_form.fields['tag'].widget.attrs['value'] = '' - forms.update({'tag_form': tag_form}) + + #themes = [{'id': str(item.id), 'text': item.name } for item in company.theme.all()] + theme_form = CompThemeForm(instance=company) + + #theme_form.fields['theme'].widget.attrs['data-predifined'] = json.dumps(themes) + #theme_form.fields['tag'].widget.attrs['value'] = '' + forms.update({'tag_form': tag_form, 'theme_form': theme_form}) lang = get_language() comp_transl = company.translations.get(language_code=lang) diff --git a/templates/client/accounts/user.html b/templates/client/accounts/user.html index 5d76c2cf..0e9cbe80 100644 --- a/templates/client/accounts/user.html +++ b/templates/client/accounts/user.html @@ -12,10 +12,11 @@ {% block content_list %} - {% if request.user == member %} - {% include 'client/includes/accounts/current_user.html' %} - {% else %} + {% if request.user != member or request.GET.logout %} {% include 'client/includes/accounts/simple_user.html' %} + {% else %} + {% include 'client/includes/accounts/current_user.html' %} + {% endif %} {% endblock %} diff --git a/templates/client/company/company_detail.html b/templates/client/company/company_detail.html index 5e7892bc..934b7b7d 100644 --- a/templates/client/company/company_detail.html +++ b/templates/client/company/company_detail.html @@ -13,11 +13,10 @@ {% endblock %} {% block content_list %} - {% if request.user == object.creator %} - - {% include 'client/includes/company/company_edit.html' with company=object %} - {% else %} + {% if request.user != object.creator or request.GET.logout %} {% include 'client/includes/company/company_object.html' with company=object %} + {% else %} + {% include 'client/includes/company/company_edit.html' with company=object %} {% endif %} diff --git a/templates/client/includes/accounts/simple_user.html b/templates/client/includes/accounts/simple_user.html index d14e9558..9f47d95d 100644 --- a/templates/client/includes/accounts/simple_user.html +++ b/templates/client/includes/accounts/simple_user.html @@ -48,16 +48,24 @@
    {% if member.profile.facebook %} -
  • Facebook
  • +
  • + Facebook +
  • {% endif %} {% if member.profile.linkedin %} -
  • LinkedIn
  • +
  • + LinkedIn +
  • {% endif %} {% if member.profile.vk %} -
  • В контакте
  • +
  • + В контакте +
  • {% endif %} {% if member.profile.twitter %} -
  • Twitter
  • +
  • + Twitter +
  • {% endif %}
@@ -75,7 +83,7 @@ {% endif %} {% if member.profile.web_page %} {% endif %} diff --git a/templates/client/includes/company/company_edit.html b/templates/client/includes/company/company_edit.html index a663a328..f4c768e2 100644 --- a/templates/client/includes/company/company_edit.html +++ b/templates/client/includes/company/company_edit.html @@ -189,9 +189,10 @@ {% with themes=company.theme.all %}
- {% for th in themes %} - {{ th.name }}{% ifnotequal forloop.counter themes|length %},{% endifnotequal %} - {% endfor %} +
+ {% csrf_token %} +
{{ theme_form.theme }}
+
{% endwith %} diff --git a/templates/client/includes/company/company_object.html b/templates/client/includes/company/company_object.html index 3fb825e8..24e292d7 100644 --- a/templates/client/includes/company/company_object.html +++ b/templates/client/includes/company/company_object.html @@ -53,16 +53,24 @@ -->
    {% if company.facebook %} -
  • Facebook
  • +
  • + Facebook +
  • {% endif %} {% if company.linkedin %} -
  • LinkedIn
  • +
  • + LinkedIn +
  • {% endif %} {% if company.vk %} -
  • В контакте
  • +
  • + В контакте +
  • {% endif %} {% if company.twitter %} -
  • Twitter
  • +
  • + Twitter +
  • {% endif %}
@@ -80,7 +88,7 @@ {% endif %} {% if company.web_page %} {% endif %}