class CreateCommunity(TemplateView): template_name = "managers/manage_create/community/create_manager_community.html" def get_context_data(self, **kwargs): from communities.forms import CommunityForm context = super(CreateCommunity, self).get_context_data(**kwargs) context["form"] = CommunityForm() return context def post(self, request, *args, **kwargs): from communities.forms import CommunityForm from common.templates import render_for_platform self.form_post = CommunityForm(request.POST) if request.is_ajax() and self.form_post.is_valid( ) and request.user.is_community_manager(): post = self.form_post.save(commit=False) community = post.create_manager_community(creator=request.user, city=post.city, title=post.title, category=post.category) return render_for_platform( request, 'communities/detail/admin_community.html', { 'community': community, 'membersheeps': [request.user] }) else: from django.http import HttpResponseBadRequest return HttpResponseBadRequest()
class CommunityCreate(TemplateView): template_name = None def get(self, request, *args, **kwargs): from common.templates import get_settings_template self.template_name = get_settings_template( "communities/manage/create_community.html", request.user, request.META['HTTP_USER_AGENT']) return super(CommunityCreate, self).get(request, *args, **kwargs) def get_context_data(self, **kwargs): from communities.forms import CommunityForm from communities.models import CommunityCategory c = super(CommunityCreate, self).get_context_data(**kwargs) c["form"], c["categories"] = CommunityForm( ), CommunityCategory.objects.only("id") return c def post(self, request, *args, **kwargs): from common.templates import render_for_platform from communities.forms import CommunityForm self.form = CommunityForm(request.POST) if self.form.is_valid() and request.is_ajax(): new_community, membersheeps = self.form.save(commit=False), [ request.user, ] community = Community.create_community( name=new_community.name, category=new_community.category, type=new_community.type, creator=request.user) data = { 'is_stat_open': True, 'is_settings_open': True, 'is_message_open': True, 'is_photo_open': True, 'is_post_open': True, 'is_member_open': True, 'is_doc_open': True, 'is_video_open': True, 'is_music_open': True, 'is_good_open': True, 'community': community, 'post_list_pk': community.get_post_list().pk, 'membersheeps': membersheeps, } return render_for_platform( request, 'communities/detail/public_community.html', data) else: from django.http import HttpResponseBadRequest return HttpResponseBadRequest()
class SuggestCommunityView(TemplateView): template_name = None def get(self, request, *args, **kwargs): from common.templates import get_detect_platform_template if request.user.is_identified(): self.template_name = get_detect_platform_template( "communities/manage/suggest_community.html", request.user, request.META['HTTP_USER_AGENT']) else: raise Http404 return super(SuggestCommunityView, self).get(request, *args, **kwargs) def get_context_data(self, **kwargs): from communities.forms import CommunityForm from communities.models import CommunityCategory c = super(SuggestCommunityView, self).get_context_data(**kwargs) c["form"], c["categories"] = CommunityForm( ), CommunityCategory.objects.only("id") return c def post(self, request, *args, **kwargs): from common.templates import render_for_platform from communities.forms import CommunityForm self.form = CommunityForm(request.POST) if self.form.is_valid() and request.is_ajax( ) and request.user.is_identified(): _community = self.form.save(commit=False) community = _community.suggest_community( name=_community.name, category=_community.category, creator=request.user, description=_community.description) return render_for_platform( request, 'communities/detail/suggest_community.html', { 'community': community, 'user': request.user }) else: from django.http import HttpResponseBadRequest return HttpResponseBadRequest()
class PublishCommunity(TemplateView): template_name = "managers/manage_create/community/create_publish_community.html" def get(self, request, *args, **kwargs): self.community = Community.objects.get(pk=self.kwargs["pk"]) return super(PublishCommunity, self).get(request, *args, **kwargs) def get_context_data(self, **kwargs): from communities.forms import CommunityForm context = super(PublishCommunity, self).get_context_data(**kwargs) context["form"] = CommunityForm(instance=self.community) context["community"] = self.community return context def post(self, request, *args, **kwargs): from communities.forms import CommunityForm from common.templates import render_for_platform self.community = Community.objects.get(pk=self.kwargs["pk"]) self.form_post = CommunityForm(request.POST, instance=self.community) if request.is_ajax() and self.form_post.is_valid( ) and request.user.is_community_manager(): post, membersheeps = self.form_post.save(commit=False), [ self.community.creator ] new_post = post.create_publish_community( manager_id=request.user.pk, name=post.name, city=post.city, category=post.category) return render_for_platform( request, 'communities/detail/admin_community.html', { 'community': community, 'membersheeps': membersheeps, 'user': request.user }) else: from django.http import HttpResponseBadRequest return HttpResponseBadRequest()