You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
154 lines
4.4 KiB
154 lines
4.4 KiB
import json
|
|
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):
|
|
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)
|
|
form = self.form_class(self.request.POST, instance=comp_transl)
|
|
|
|
else:
|
|
form = self.form_class(self.request.POST, instance=company)
|
|
|
|
company = form.save()
|
|
try:
|
|
rating = company.rating
|
|
except AttributeError:
|
|
rating = company.master.rating
|
|
response = {'success': True, 'rating': rating}
|
|
return HttpResponse(json.dumps(response), content_type='application/json')
|
|
|
|
|
|
class LogoView(BaseView):
|
|
"""
|
|
instance profile. save user avatar.
|
|
|
|
if call is ajax- return json data, else redirect to profile page
|
|
"""
|
|
form_class = LogoForm
|
|
|
|
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()
|
|
form = self.form_class(self.request.POST, self.request.FILES, instance=company)
|
|
company = form.save()
|
|
if self.request.is_ajax():
|
|
im = get_thumbnail(company.logo, '100x100', format="PNG")
|
|
response = {'success': True, 'url': im.url, 'rating': company.rating}
|
|
return HttpResponse(json.dumps(response), content_type='application/json')
|
|
else:
|
|
return HttpResponseRedirect(company.get_permanent_url())
|
|
|
|
|
|
class NameView(BaseView):
|
|
form_class = NameForm
|
|
|
|
|
|
class HomeView(BaseView):
|
|
form_class = HomeForm
|
|
|
|
class SpecializationView(BaseView):
|
|
form_class = SpecializationForm
|
|
|
|
|
|
class PhoneView(BaseView):
|
|
form_class = PhoneForm
|
|
|
|
|
|
class EmailView(BaseView):
|
|
form_class = EmailForm
|
|
|
|
|
|
class WebPageView(BaseView):
|
|
form_class = WebPageForm
|
|
|
|
|
|
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
|
|
|
|
|
|
class StaffView(BaseView):
|
|
form_class = StaffForm
|
|
|
|
|
|
class DescriptionView(BaseView):
|
|
form_class = DescriptionForm
|
|
|
|
|
|
class AddressView(BaseView):
|
|
form_class = AddressForm |