@ -2,14 +2,14 @@
import json
import datetime
from django . http import HttpResponseRedirect , HttpResponse , HttpResponsePermanentRedirect
from django . contrib import messages
from django . contrib . contenttypes . models import ContentType
from django . conf import settings
from django . views . generic import ListView , DetailView
from django . utils . translation import ugettext as _
from django . shortcuts import get_object_or_404 , render_to_response
from django . shortcuts import get_object_or_404
from django . http import Http404
from django . utils import translation
from django . views . generic . edit import FormMixin
from django . core . mail import EmailMessage
#models
from accounts . models import User
from models import Exposition
@ -23,9 +23,7 @@ from service.order_forms import AdvertiseForm
from functions . search_forms import ExpositionSearchForm
from functions . custom_views import ExpoSearchView
from meta . views import MetadataMixin
from functions . cache_mixin import JitterCacheMixin , CacheMixin
from functions . cache_mixin import JitterCacheMixin
class ExpositionBy ( JitterCacheMixin , MetadataMixin , ListView ) :
@ -156,12 +154,28 @@ class ExpoDetail(JitterCacheMixin, MetadataMixin, DetailView):
def get_context_data ( self , * * kwargs ) :
context = super ( ExpoDetail , self ) . get_context_data ( * * kwargs )
context [ ' advertising_form ' ] = AdvertiseForm ( )
obj = self . object
context [ ' city ' ] = str ( obj . city_id )
context [ ' country ' ] = str ( obj . country_id )
context [ ' themes ' ] = [ str ( item . id ) for item in obj . theme . all ( ) ]
return context
class ExpositionProgramme ( MetadataMixin , DetailView ) :
model = Exposition
slug_field = ' url '
template_name = ' client/exposition/programm.html '
queryset = Exposition . objects . language ( ) . select_related ( ' place ' , ' city ' , ' country ' , ' paid_new ' )
def get_context_data ( self , * * kwargs ) :
context = super ( ExpositionProgramme , self ) . get_context_data ( * * kwargs )
obj = self . object
context [ ' city ' ] = str ( obj . city_id )
context [ ' country ' ] = str ( obj . country_id )
context [ ' themes ' ] = [ str ( item . id ) for item in obj . theme . all ( ) ]
return context
class ExpositionPrice ( MetadataMixin , DetailView ) :
@ -170,20 +184,47 @@ class ExpositionPrice(MetadataMixin, DetailView):
template_name = ' client/exposition/price.html '
queryset = Exposition . objects . language ( ) . select_related ( ' place ' , ' city ' , ' country ' , ' paid_new ' )
def get_context_data ( self , * * kwargs ) :
context = super ( ExpositionPrice , self ) . get_context_data ( * * kwargs )
obj = self . object
context [ ' city ' ] = str ( obj . city_id )
context [ ' country ' ] = str ( obj . country_id )
context [ ' themes ' ] = [ str ( item . id ) for item in obj . theme . all ( ) ]
return context
class ExpositionStatistic ( MetadataMixin , DetailView ) :
model = Exposition
slug_field = ' url '
template_name = ' client/exposition/statistic.html '
queryset = Exposition . objects . language ( ) . select_related ( ' place ' , ' city ' , ' country ' , ' paid_new ' )
def get_context_data ( self , * * kwargs ) :
context = super ( ExpositionStatistic , self ) . get_context_data ( * * kwargs )
obj = self . object
context [ ' city ' ] = str ( obj . city_id )
context [ ' country ' ] = str ( obj . country_id )
context [ ' themes ' ] = [ str ( item . id ) for item in obj . theme . all ( ) ]
return context
from django . views . generic . edit import FormMixin , ModelFormMixin
class ExpositionThankView ( MetadataMixin , DetailView ) :
model = Exposition
slug_field = ' url '
template_name = ' client/service/thank_u_page.html '
def get_context_data ( self , * * kwargs ) :
context = super ( ExpositionThankView , self ) . get_context_data ( * * kwargs )
obj = self . object
context [ ' city ' ] = str ( obj . city_id )
context [ ' country ' ] = str ( obj . country_id )
context [ ' themes ' ] = [ str ( item . id ) for item in obj . theme . all ( ) ]
return context
def visit_redirect ( request , slug ) :
obj = get_object_or_404 ( Exposition , url = slug )
redirect = obj . get_permanent_url ( ) + ' price/ '
@ -226,7 +267,12 @@ class ExpositionServiceView(MetadataMixin, FormMixin, DetailView):
raise Http404
context [ ' form ' ] = self . get_form ( self . form_class )
context [ ' service ' ] = self . service
context [ ' object ' ] = self . get_object ( )
obj = self . get_object ( )
context [ ' object ' ] = obj
context [ ' city ' ] = str ( obj . city_id )
context [ ' country ' ] = str ( obj . country_id )
context [ ' themes ' ] = [ str ( item . id ) for item in obj . theme . all ( ) ]
return context
def form_valid ( self , form ) :
@ -248,8 +294,6 @@ class ExpositionServiceView(MetadataMixin, FormMixin, DetailView):
' city ' : user . profile . city . name if user . profile . city else ' ' ,
' phone ' : user . profile . phone if user . profile . phone else ' ' }
return initial
else :
return self . initial . copy ( )
@ -260,12 +304,12 @@ class ExpoList(MetadataMixin, JitterCacheMixin, ListView):
model = Exposition
paginate_by = settings . CLIENT_PAGINATION
template_name = ' client/exposition/exposition_list.html '
search_form = ExpositionSearchForm
catalog_url = ' /expo/ '
year = None
month = None
def get_queryset ( self ) :
MONTHES = settings . MONTHES
if self . request . user . is_staff :
qs = self . model . objects . upcoming ( )
else :
@ -286,24 +330,21 @@ class ExpoList(MetadataMixin, JitterCacheMixin, ListView):
context = super ( ExpoList , self ) . get_context_data ( * * kwargs )
context [ ' month ' ] = self . month
context [ ' catalog_url ' ] = self . catalog_url
context [ ' search_form ' ] = self . search_form
context [ ' year ' ] = self . year
context [ ' month ' ] = self . month
return context
MONTHES = settings . MONTHES
class ExpoCatalog ( MetadataMixin , ListView ) :
model = Exposition
paginate_by = settings . CLIENT_PAGINATION
template_name = ' client/exposition/catalog.html '
search_form = ExpositionSearchForm
filter_object = None
year = None
month = None
country = None
city = None
paid = None
def get_filtered_qs ( self ) :
# diferent for views
@ -352,12 +393,8 @@ class ExpoCatalog(MetadataMixin, ListView):
return qs . order_by ( ' data_begin ' )
def get_context_data ( self , * * kwargs ) :
context = super ( ExpoCatalog , self ) . get_context_data ( * * kwargs )
if self . paid :
context [ ' paid ' ] = self . paid
context [ ' search_form ' ] = self . search_form
context [ ' filter_object ' ] = self . filter_object
context [ ' year ' ] = self . year
context [ ' month ' ] = self . month
@ -366,6 +403,7 @@ class ExpoCatalog(MetadataMixin, ListView):
context [ ' tag_for_filter ' ] = self . kwargs [ ' tag ' ]
return context
class ExpoCountryCatalog ( ExpoCatalog ) :
catalog_url = ' /expo/country/ '
def get_filtered_qs ( self ) :
@ -382,6 +420,7 @@ class ExpoCountryCatalog(ExpoCatalog):
context [ ' country ' ] = str ( self . kwargs [ ' country ' ] . id )
return context
class ExpoCityCatalog ( ExpoCatalog ) :
catalog_url = ' /expo/city/ '
def get_filtered_qs ( self ) :
@ -411,11 +450,8 @@ class ExpoThemeCatalog(ExpoCatalog):
city_slug = self . kwargs . get ( ' city_slug ' )
theme = get_object_or_404 ( Theme , url = slug )
self . kwargs [ ' theme ' ] = theme
qs = self . model . enable . upcoming ( ) . filter ( theme = theme )
qs = self . model . enable . upcoming ( ) . filter ( theme = theme ) . exclude ( paid__isnull = False )
paid = list ( self . model . enable . filter ( theme = theme ) . filter ( paid__isnull = False ) )
if paid :
self . paid = paid
if country_slug :
country = get_object_or_404 ( Country , url = country_slug )
self . country = country
@ -434,9 +470,9 @@ class ExpoThemeCatalog(ExpoCatalog):
def get_context_data ( self , * * kwargs ) :
context = super ( ExpoThemeCatalog , self ) . get_context_data ( * * kwargs )
if self . country :
context [ ' country ' ] = str ( self . country . id )
context [ ' country ' ] = self . country
if self . city :
context [ ' city ' ] = str ( self . city . id )
context [ ' city ' ] = self . city
context [ ' theme_for_filter ' ] = self . kwargs [ ' theme ' ]
context [ ' themes ' ] = [ str ( self . kwargs [ ' theme ' ] . id ) ]
return context
@ -444,16 +480,13 @@ class ExpoThemeCatalog(ExpoCatalog):
class ExpoTagCatalog ( ExpoCatalog ) :
catalog_url = ' /expo/tag/ '
def get_filtered_qs ( self ) :
#this method used in parent get_queryset
slug = self . kwargs . get ( ' slug ' )
tag = get_object_or_404 ( Tag , url = slug )
self . kwargs [ ' tag ' ] = tag
qs = self . model . enable . upcoming ( ) . filter ( tag = tag ) . exclude ( paid__isnull = False )
paid = list ( self . model . enable . filter ( tag = tag ) . filter ( paid__isnull = False ) )
if paid :
self . paid = paid
qs = self . model . enable . upcoming ( ) . filter ( tag = tag )
self . filter_object = tag
return qs
@ -469,12 +502,8 @@ class ExpoTagCatalog(ExpoCatalog):
class ExpoVisitors ( MetadataMixin , ListView ) :
paginate_by = settings . CLIENT_PAGINATION
model = Exposition
#template_name = 'event_visitors.html'
template_name = ' client/exposition/visitors.html '
obj = None
search_form = ExpositionSearchForm
def get_queryset ( self ) :
slug = self . kwargs . get ( ' slug ' )
@ -485,20 +514,19 @@ class ExpoVisitors(MetadataMixin, ListView):
def get_context_data ( self , * * kwargs ) :
context = super ( ExpoVisitors , self ) . get_context_data ( * * kwargs )
context [ ' object ' ] = self . obj
context [ ' search_form ' ] = self . search_form
obj = self . obj
context [ ' object ' ] = obj
context [ ' city ' ] = str ( obj . city_id )
context [ ' country ' ] = str ( obj . country_id )
context [ ' themes ' ] = [ str ( item . id ) for item in obj . theme . all ( ) ]
return context
class ExpoMembers ( MetadataMixin , ListView ) :
paginate_by = settings . CLIENT_PAGINATION
model = Exposition
#template_name = 'event_visitors.html'
template_name = ' client/exposition/members.html '
obj = None
search_form = ExpositionSearchForm
def get_queryset ( self ) :
slug = self . kwargs . get ( ' slug ' )
@ -509,8 +537,11 @@ class ExpoMembers(MetadataMixin, ListView):
def get_context_data ( self , * * kwargs ) :
context = super ( ExpoMembers , self ) . get_context_data ( * * kwargs )
context [ ' object ' ] = self . obj
context [ ' search_form ' ] = self . search_form
obj = self . obj
context [ ' object ' ] = obj
context [ ' city ' ] = str ( obj . city_id )
context [ ' country ' ] = str ( obj . country_id )
context [ ' themes ' ] = [ str ( item . id ) for item in obj . theme . all ( ) ]
return context
@ -546,11 +577,9 @@ def add_note(request, slug):
return HttpResponse ( json . dumps ( args ) , content_type = ' application/json ' )
from django . core . mail import send_mail
from django . core . mail import EmailMessage
def send_to_organiser ( request , slug ) :
exposition = get_object_or_404 ( Exposition , url = slug )
mail_send = exposition . paid . organiser
mail_send = ' evm@expomap.ru '
name = request . POST . get ( ' person_inf ' )
email = request . POST . get ( ' person ' )
phone = request . POST . get ( ' phone ' , ' ' )
@ -562,5 +591,4 @@ def send_to_organiser(request, slug):
msg . send ( )
redirect_to = ' %s service/thanks/ ' % exposition . get_permanent_url ( )
return HttpResponse ( json . dumps ( { ' success ' : True , ' redirect_to ' : redirect_to } ) , content_type = ' application/json ' )
return HttpResponse ( json . dumps ( { ' success ' : True , ' redirect_to ' : redirect_to } ) , content_type = ' application/json ' )