parent
a8a789ba89
commit
3a48602148
86 changed files with 2005 additions and 2017 deletions
@ -1,9 +1,100 @@ |
|||||||
# -*- coding: utf-8 -*- |
# -*- coding: utf-8 -*- |
||||||
from hvad.admin import TranslatableAdmin |
from django.shortcuts import render_to_response, get_object_or_404 |
||||||
from django.contrib import admin |
from django.http import HttpResponseRedirect |
||||||
from models import Article |
from django.core.context_processors import csrf |
||||||
|
from django.conf import settings |
||||||
|
from django.contrib.auth.decorators import login_required |
||||||
|
from django.contrib.contenttypes.models import ContentType |
||||||
|
#models and forms |
||||||
|
from forms import ArticleForm, ArticleDeleteForm, Article |
||||||
|
from theme.models import Tag |
||||||
|
from file.models import FileModel, TmpFile |
||||||
|
from file.forms import FileModelForm |
||||||
|
|
||||||
class ArticleAdmin(TranslatableAdmin): |
#custom views |
||||||
pass |
from functions.custom_views import objects_list, add_object_with_file, delete_object |
||||||
|
|
||||||
admin.site.register(Article, ArticleAdmin) |
|
||||||
|
def article_all(request): |
||||||
|
""" |
||||||
|
Return list of all articles with pagination |
||||||
|
""" |
||||||
|
return objects_list(request, Article, 'article_all.html') |
||||||
|
|
||||||
|
def article_add(request): |
||||||
|
""" |
||||||
|
Return form of article and post it on the server. |
||||||
|
|
||||||
|
If form is posted redirect on the page of all articles. |
||||||
|
""" |
||||||
|
#get organiser from current user |
||||||
|
init_data = {'author':request.user.organiser} |
||||||
|
#choices field which will be filled by ajax |
||||||
|
choices = {'tag': Tag} |
||||||
|
return add_object_with_file(request, ArticleForm, 'article_add.html', '/admin/article/all', |
||||||
|
choices, init_data) |
||||||
|
|
||||||
|
|
||||||
|
def article_delete(request, url): |
||||||
|
return delete_object(request, Article, ArticleDeleteForm, url, '/admin/article/all') |
||||||
|
|
||||||
|
|
||||||
|
@login_required |
||||||
|
def article_change(request, url): |
||||||
|
""" |
||||||
|
Return form and fill it with existing Article object data. |
||||||
|
|
||||||
|
If form is posted redirect on the page of all articles. |
||||||
|
""" |
||||||
|
try: |
||||||
|
#check if article_id exists else redirect to the list of cities |
||||||
|
article = Article.objects.get(url=url) |
||||||
|
file_form = FileModelForm(initial={'model': 'article.Article'}) |
||||||
|
article_id = getattr(article, 'id') |
||||||
|
except: |
||||||
|
return HttpResponseRedirect('/admin/article/all') |
||||||
|
|
||||||
|
if request.POST: |
||||||
|
form = ArticleForm(request.POST) |
||||||
|
#set choices filled by ajax |
||||||
|
form.fields['tag'].choices = [(item.id, item.name) for item in Tag.objects.all()] |
||||||
|
|
||||||
|
if form.is_valid(): |
||||||
|
form.save(getattr(article, 'id')) |
||||||
|
return HttpResponseRedirect('/admin/article/all') |
||||||
|
else: |
||||||
|
data = {} |
||||||
|
#fill form with data from database |
||||||
|
data['author'] = article.user |
||||||
|
data['theme'] = [item.id for item in article.theme.all()] |
||||||
|
data['tag'] = [item.id for item in article.tag.all()] |
||||||
|
#hidden field |
||||||
|
data['article_id'] = article_id |
||||||
|
|
||||||
|
#data from translated fields |
||||||
|
for code, name in settings.LANGUAGES: |
||||||
|
obj = Article._meta.translations_model.objects.get(language_code = code,master__id=getattr(article, 'id')) #access to translated fields |
||||||
|
data['main_title_%s' % code] = obj.main_title |
||||||
|
data['preview_%s' % code] = obj.preview |
||||||
|
data['description_%s' % code] = obj.description |
||||||
|
data['title_%s' % code] = obj.title |
||||||
|
data['keywords_%s' % code] = obj.keywords |
||||||
|
data['descriptions_%s' % code] = obj.descriptions |
||||||
|
#fill form |
||||||
|
form = ArticleForm(initial=data) |
||||||
|
#set choices filled by ajax |
||||||
|
form.fields['tag'].choices = [(item.id, item.name) for item in Tag.objects.filter(theme__in=data['theme'])] |
||||||
|
|
||||||
|
args = {} |
||||||
|
args.update(csrf(request)) |
||||||
|
|
||||||
|
args['form'] = form |
||||||
|
args['languages'] = settings.LANGUAGES |
||||||
|
args['file_form'] = file_form |
||||||
|
|
||||||
|
#get list of files which connected with specific model object |
||||||
|
args['files'] = FileModel.objects.filter(content_type=ContentType.objects.get_for_model(article), object_id=getattr(article, 'id')) |
||||||
|
args['obj_id'] = getattr(article, 'id') |
||||||
|
|
||||||
|
|
||||||
|
return render_to_response('article_add.html', args) |
||||||
|
|||||||
@ -0,0 +1,9 @@ |
|||||||
|
# -*- coding: utf-8 -*- |
||||||
|
from hvad.admin import TranslatableAdmin |
||||||
|
from django.contrib import admin |
||||||
|
from models import Article |
||||||
|
|
||||||
|
class ArticleAdmin(TranslatableAdmin): |
||||||
|
pass |
||||||
|
|
||||||
|
admin.site.register(Article, ArticleAdmin) |
||||||
@ -1,100 +0,0 @@ |
|||||||
# -*- coding: utf-8 -*- |
|
||||||
from django.shortcuts import render_to_response, get_object_or_404 |
|
||||||
from django.http import HttpResponseRedirect |
|
||||||
from django.core.context_processors import csrf |
|
||||||
from django.conf import settings |
|
||||||
from django.contrib.auth.decorators import login_required |
|
||||||
from django.contrib.contenttypes.models import ContentType |
|
||||||
#models and forms |
|
||||||
from forms import ArticleForm, ArticleDeleteForm, Article |
|
||||||
from theme.models import Tag |
|
||||||
from file.models import FileModel, TmpFile |
|
||||||
from file.forms import FileModelForm |
|
||||||
|
|
||||||
#custom views |
|
||||||
from functions.custom_views import objects_list, add_object_with_file, delete_object |
|
||||||
|
|
||||||
|
|
||||||
def article_all(request): |
|
||||||
""" |
|
||||||
Return list of all articles with pagination |
|
||||||
""" |
|
||||||
return objects_list(request, Article, 'article_all.html') |
|
||||||
|
|
||||||
def article_add(request): |
|
||||||
""" |
|
||||||
Return form of article and post it on the server. |
|
||||||
|
|
||||||
If form is posted redirect on the page of all articles. |
|
||||||
""" |
|
||||||
#get organiser from current user |
|
||||||
init_data = {'author':request.user.organiser} |
|
||||||
#choices field which will be filled by ajax |
|
||||||
choices = {'tag': Tag} |
|
||||||
return add_object_with_file(request, ArticleForm, 'article_add.html', '/admin/article/all', |
|
||||||
choices, init_data) |
|
||||||
|
|
||||||
|
|
||||||
def article_delete(request, url): |
|
||||||
return delete_object(request, Article, ArticleDeleteForm, url, '/admin/article/all') |
|
||||||
|
|
||||||
|
|
||||||
@login_required |
|
||||||
def article_change(request, url): |
|
||||||
""" |
|
||||||
Return form and fill it with existing Article object data. |
|
||||||
|
|
||||||
If form is posted redirect on the page of all articles. |
|
||||||
""" |
|
||||||
try: |
|
||||||
#check if article_id exists else redirect to the list of cities |
|
||||||
article = Article.objects.get(url=url) |
|
||||||
file_form = FileModelForm(initial={'model': 'article.Article'}) |
|
||||||
article_id = getattr(article, 'id') |
|
||||||
except: |
|
||||||
return HttpResponseRedirect('/admin/article/all') |
|
||||||
|
|
||||||
if request.POST: |
|
||||||
form = ArticleForm(request.POST) |
|
||||||
#set choices filled by ajax |
|
||||||
form.fields['tag'].choices = [(item.id, item.name) for item in Tag.objects.all()] |
|
||||||
|
|
||||||
if form.is_valid(): |
|
||||||
form.save(getattr(article, 'id')) |
|
||||||
return HttpResponseRedirect('/admin/article/all') |
|
||||||
else: |
|
||||||
data = {} |
|
||||||
#fill form with data from database |
|
||||||
data['author'] = article.user |
|
||||||
data['theme'] = [item.id for item in article.theme.all()] |
|
||||||
data['tag'] = [item.id for item in article.tag.all()] |
|
||||||
#hidden field |
|
||||||
data['article_id'] = article_id |
|
||||||
|
|
||||||
#data from translated fields |
|
||||||
for code, name in settings.LANGUAGES: |
|
||||||
obj = Article._meta.translations_model.objects.get(language_code = code,master__id=getattr(article, 'id')) #access to translated fields |
|
||||||
data['main_title_%s' % code] = obj.main_title |
|
||||||
data['preview_%s' % code] = obj.preview |
|
||||||
data['description_%s' % code] = obj.description |
|
||||||
data['title_%s' % code] = obj.title |
|
||||||
data['keywords_%s' % code] = obj.keywords |
|
||||||
data['descriptions_%s' % code] = obj.descriptions |
|
||||||
#fill form |
|
||||||
form = ArticleForm(initial=data) |
|
||||||
#set choices filled by ajax |
|
||||||
form.fields['tag'].choices = [(item.id, item.name) for item in Tag.objects.filter(theme__in=data['theme'])] |
|
||||||
|
|
||||||
args = {} |
|
||||||
args.update(csrf(request)) |
|
||||||
|
|
||||||
args['form'] = form |
|
||||||
args['languages'] = settings.LANGUAGES |
|
||||||
args['file_form'] = file_form |
|
||||||
|
|
||||||
#get list of files which connected with specific model object |
|
||||||
args['files'] = FileModel.objects.filter(content_type=ContentType.objects.get_for_model(article), object_id=getattr(article, 'id')) |
|
||||||
args['obj_id'] = getattr(article, 'id') |
|
||||||
|
|
||||||
|
|
||||||
return render_to_response('article_add.html', args) |
|
||||||
@ -1,9 +1,92 @@ |
|||||||
# -*- coding: utf-8 -*- |
# -*- coding: utf-8 -*- |
||||||
from hvad.admin import TranslatableAdmin |
from django.shortcuts import render_to_response, get_object_or_404 |
||||||
from django.contrib import admin |
from django.http import HttpResponseRedirect |
||||||
|
from django.core.context_processors import csrf |
||||||
|
from django.conf import settings |
||||||
|
from django.contrib.auth.decorators import login_required |
||||||
|
from django.contrib.contenttypes.models import ContentType |
||||||
|
#models and forms |
||||||
|
from forms import CityForm, CityDeleteForm |
||||||
from models import City |
from models import City |
||||||
|
from file.models import FileModel |
||||||
|
from file.forms import FileModelForm |
||||||
|
#custom views |
||||||
|
from functions.custom_views import objects_list, add_object_with_file, delete_object |
||||||
|
|
||||||
class CityAdmin(TranslatableAdmin): |
|
||||||
pass |
|
||||||
|
|
||||||
admin.site.register(City, CityAdmin) |
def city_all(request): |
||||||
|
""" |
||||||
|
return list of all cities with pagination |
||||||
|
""" |
||||||
|
return objects_list(request, City, 'city_all.html') |
||||||
|
|
||||||
|
|
||||||
|
def city_add(request): |
||||||
|
""" |
||||||
|
Return form of city and post it on the server. |
||||||
|
If form is posted redirect on the page of all cities. |
||||||
|
""" |
||||||
|
return add_object_with_file(request, CityForm, 'city_add.html', '/admin/city/all') |
||||||
|
|
||||||
|
def city_delete(request, url): |
||||||
|
return delete_object(request, City, CityDeleteForm, url, '/admin/city/all/') |
||||||
|
|
||||||
|
|
||||||
|
@login_required |
||||||
|
def city_change(request, url): |
||||||
|
""" |
||||||
|
Return form and fill it with existing City object data. |
||||||
|
|
||||||
|
If form is posted redirect on the page of all cities. |
||||||
|
""" |
||||||
|
try: |
||||||
|
#check if city_id exists else redirect to the list of cities |
||||||
|
c = City.objects.get(url=url) |
||||||
|
city_id = getattr(c, 'id') |
||||||
|
file_form = FileModelForm(initial={'model': 'city.City'}) |
||||||
|
except: |
||||||
|
return HttpResponseRedirect('/admin/city/all') |
||||||
|
|
||||||
|
if request.POST: |
||||||
|
form = CityForm(request.POST) |
||||||
|
if form.is_valid(): |
||||||
|
form.save(city_id) |
||||||
|
return HttpResponseRedirect('/admin/city/all') |
||||||
|
else: |
||||||
|
#fill form with data from database |
||||||
|
data = {'population' : c.population, 'phone_code' : c.phone_code, |
||||||
|
'city_id' : city_id} |
||||||
|
|
||||||
|
if c.country: |
||||||
|
data['country'] = c.country.id |
||||||
|
|
||||||
|
if c.code_IATA: |
||||||
|
data['code_IATA'] = c.code_IATA.id |
||||||
|
|
||||||
|
#data from translated fields |
||||||
|
for code, name in settings.LANGUAGES: |
||||||
|
obj = City._meta.translations_model.objects.get(language_code = code,master__id=city_id) #access to translated fields |
||||||
|
data['name_%s' % code] = obj.name |
||||||
|
data['description_%s' % code] = obj.description |
||||||
|
data['famous_places_%s' % code] = obj.famous_places |
||||||
|
data['shoping_%s' % code] = obj.shoping |
||||||
|
data['transport_%s' % code] = obj.transport |
||||||
|
data['title_%s' % code] = obj.title |
||||||
|
data['keywords_%s' % code] = obj.keywords |
||||||
|
data['descriptions_%s' % code] = obj.descriptions |
||||||
|
#fill form |
||||||
|
form = CityForm(initial=data) |
||||||
|
|
||||||
|
|
||||||
|
args = {} |
||||||
|
args.update(csrf(request)) |
||||||
|
args['languages'] = settings.LANGUAGES |
||||||
|
args['form'] = form |
||||||
|
args['file_form'] = file_form |
||||||
|
|
||||||
|
#get list of files which connected with specific model object |
||||||
|
args['files'] = FileModel.objects.filter(content_type=ContentType.objects.get_for_model(c), |
||||||
|
object_id=getattr(c, 'id')) |
||||||
|
args['obj_id'] = city_id |
||||||
|
|
||||||
|
return render_to_response('city_add.html', args) |
||||||
@ -0,0 +1,9 @@ |
|||||||
|
# -*- coding: utf-8 -*- |
||||||
|
from hvad.admin import TranslatableAdmin |
||||||
|
from django.contrib import admin |
||||||
|
from models import City |
||||||
|
|
||||||
|
class CityAdmin(TranslatableAdmin): |
||||||
|
pass |
||||||
|
|
||||||
|
admin.site.register(City, CityAdmin) |
||||||
@ -1,92 +0,0 @@ |
|||||||
# -*- coding: utf-8 -*- |
|
||||||
from django.shortcuts import render_to_response, get_object_or_404 |
|
||||||
from django.http import HttpResponseRedirect |
|
||||||
from django.core.context_processors import csrf |
|
||||||
from django.conf import settings |
|
||||||
from django.contrib.auth.decorators import login_required |
|
||||||
from django.contrib.contenttypes.models import ContentType |
|
||||||
#models and forms |
|
||||||
from forms import CityForm, CityDeleteForm |
|
||||||
from models import City |
|
||||||
from file.models import FileModel |
|
||||||
from file.forms import FileModelForm |
|
||||||
#custom views |
|
||||||
from functions.custom_views import objects_list, add_object_with_file, delete_object |
|
||||||
|
|
||||||
|
|
||||||
def city_all(request): |
|
||||||
""" |
|
||||||
return list of all cities with pagination |
|
||||||
""" |
|
||||||
return objects_list(request, City, 'city_all.html') |
|
||||||
|
|
||||||
|
|
||||||
def city_add(request): |
|
||||||
""" |
|
||||||
Return form of city and post it on the server. |
|
||||||
If form is posted redirect on the page of all cities. |
|
||||||
""" |
|
||||||
return add_object_with_file(request, CityForm, 'city_add.html', '/admin/city/all') |
|
||||||
|
|
||||||
def city_delete(request, url): |
|
||||||
return delete_object(request, City, CityDeleteForm, url, '/admin/city/all/') |
|
||||||
|
|
||||||
|
|
||||||
@login_required |
|
||||||
def city_change(request, url): |
|
||||||
""" |
|
||||||
Return form and fill it with existing City object data. |
|
||||||
|
|
||||||
If form is posted redirect on the page of all cities. |
|
||||||
""" |
|
||||||
try: |
|
||||||
#check if city_id exists else redirect to the list of cities |
|
||||||
c = City.objects.get(url=url) |
|
||||||
city_id = getattr(c, 'id') |
|
||||||
file_form = FileModelForm(initial={'model': 'city.City'}) |
|
||||||
except: |
|
||||||
return HttpResponseRedirect('/admin/city/all') |
|
||||||
|
|
||||||
if request.POST: |
|
||||||
form = CityForm(request.POST) |
|
||||||
if form.is_valid(): |
|
||||||
form.save(city_id) |
|
||||||
return HttpResponseRedirect('/admin/city/all') |
|
||||||
else: |
|
||||||
#fill form with data from database |
|
||||||
data = {'population' : c.population, 'phone_code' : c.phone_code, |
|
||||||
'city_id' : city_id} |
|
||||||
|
|
||||||
if c.country: |
|
||||||
data['country'] = c.country.id |
|
||||||
|
|
||||||
if c.code_IATA: |
|
||||||
data['code_IATA'] = c.code_IATA.id |
|
||||||
|
|
||||||
#data from translated fields |
|
||||||
for code, name in settings.LANGUAGES: |
|
||||||
obj = City._meta.translations_model.objects.get(language_code = code,master__id=city_id) #access to translated fields |
|
||||||
data['name_%s' % code] = obj.name |
|
||||||
data['description_%s' % code] = obj.description |
|
||||||
data['famous_places_%s' % code] = obj.famous_places |
|
||||||
data['shoping_%s' % code] = obj.shoping |
|
||||||
data['transport_%s' % code] = obj.transport |
|
||||||
data['title_%s' % code] = obj.title |
|
||||||
data['keywords_%s' % code] = obj.keywords |
|
||||||
data['descriptions_%s' % code] = obj.descriptions |
|
||||||
#fill form |
|
||||||
form = CityForm(initial=data) |
|
||||||
|
|
||||||
|
|
||||||
args = {} |
|
||||||
args.update(csrf(request)) |
|
||||||
args['languages'] = settings.LANGUAGES |
|
||||||
args['form'] = form |
|
||||||
args['file_form'] = file_form |
|
||||||
|
|
||||||
#get list of files which connected with specific model object |
|
||||||
args['files'] = FileModel.objects.filter(content_type=ContentType.objects.get_for_model(c), |
|
||||||
object_id=getattr(c, 'id')) |
|
||||||
args['obj_id'] = city_id |
|
||||||
|
|
||||||
return render_to_response('city_add.html', args) |
|
||||||
@ -0,0 +1,9 @@ |
|||||||
|
# -*- coding: utf-8 -*- |
||||||
|
from django.contrib import admin |
||||||
|
from hvad.admin import TranslatableAdmin |
||||||
|
from models import Company |
||||||
|
|
||||||
|
class CompanyAdmin(TranslatableAdmin): |
||||||
|
pass |
||||||
|
|
||||||
|
admin.site.register(Company, CompanyAdmin) |
||||||
@ -1,109 +0,0 @@ |
|||||||
# -*- coding: utf-8 -*- |
|
||||||
from django.shortcuts import render_to_response |
|
||||||
from django.http import HttpResponseRedirect, HttpResponse |
|
||||||
from django.core.context_processors import csrf |
|
||||||
from django.conf import settings |
|
||||||
from django.contrib.contenttypes.models import ContentType |
|
||||||
from django.contrib.auth.decorators import login_required |
|
||||||
#models and forms |
|
||||||
from models import Company |
|
||||||
from forms import CompanyForm, CompanyDeleteForm |
|
||||||
from theme.models import Tag |
|
||||||
from city.models import City |
|
||||||
from file.models import FileModel, TmpFile |
|
||||||
from file.forms import FileModelForm |
|
||||||
#custom views |
|
||||||
from functions.custom_views import objects_list, add_object_with_file, delete_object |
|
||||||
|
|
||||||
|
|
||||||
def company_all(request): |
|
||||||
""" |
|
||||||
Return list of all companies with pagination |
|
||||||
""" |
|
||||||
return objects_list(request, Company, 'company_all.html') |
|
||||||
|
|
||||||
|
|
||||||
def company_add(request): |
|
||||||
""" |
|
||||||
Return form of company and post it on the server. |
|
||||||
If form is posted redirect on the page of all companies. |
|
||||||
""" |
|
||||||
return add_object_with_file(request, CompanyForm, 'company_add.html', '/admin/company/all/', |
|
||||||
{'city': City, 'tag': Tag}) |
|
||||||
|
|
||||||
def company_delete(request, url): |
|
||||||
return delete_object(request, Company, CompanyDeleteForm, url, '/admin/company/all') |
|
||||||
|
|
||||||
|
|
||||||
@login_required |
|
||||||
def company_change(request, url): |
|
||||||
""" |
|
||||||
Return form and fill it with existing Company object data. |
|
||||||
|
|
||||||
If form is posted redirect on the page of all companies. |
|
||||||
""" |
|
||||||
company = Company.objects.safe_get(url=url) |
|
||||||
# try get company by id if doesnt work by url |
|
||||||
if company is None: |
|
||||||
company = Company.objects.safe_get(id=url) |
|
||||||
#redirect to list of all companies if cannot find user |
|
||||||
if company is None: |
|
||||||
return HttpResponseRedirect('/admin/company/all/') |
|
||||||
|
|
||||||
company_id = getattr(company, 'id') |
|
||||||
file_form = FileModelForm(initial={'model': 'company.Company'}) |
|
||||||
|
|
||||||
if request.POST: |
|
||||||
form = CompanyForm(request.POST) |
|
||||||
#set choices filled by ajax |
|
||||||
form.fields['tag'].choices = [(item.id, item.name) for item in Tag.objects.all()] |
|
||||||
form.fields['city'].choices = [(item.id, item.name) for item in City.objects.filter(country=request.POST['country'])] |
|
||||||
|
|
||||||
if form.is_valid(): |
|
||||||
form.save(company_id) |
|
||||||
return HttpResponseRedirect('/admin/company/all/') |
|
||||||
else: |
|
||||||
#fill form with data from database |
|
||||||
data = {'url':company.url, 'staff_number':company.staff_number, 'address': company.address, |
|
||||||
'phone':company.phone, 'fax':company.fax, 'web_page':company.web_page, |
|
||||||
'email':company.email, 'social':company.social, 'foundation': company.foundation, |
|
||||||
'company_id':company.id} |
|
||||||
|
|
||||||
if company.country: |
|
||||||
data['country'] = company.country.id |
|
||||||
|
|
||||||
if company.city: |
|
||||||
data['city'] = company.city.id |
|
||||||
|
|
||||||
data['theme'] = [item.id for item in company.theme.all()] |
|
||||||
data['tag'] = [item.id for item in company.tag.all()] |
|
||||||
#data from translated fields |
|
||||||
for code, name in settings.LANGUAGES: |
|
||||||
obj = Company._meta.translations_model.objects.get(language_code = code,master__id=company_id) #access to translated fields |
|
||||||
data['name_%s' % code] = obj.name |
|
||||||
data['description_%s' % code] = obj.description |
|
||||||
data['specialization_%s' % code] = obj.specialization |
|
||||||
data['address_inf_%s' % code] = obj.address_inf |
|
||||||
data['title_%s' % code] = obj.title |
|
||||||
data['keywords_%s' % code] = obj.keywords |
|
||||||
data['descriptions_%s' % code] = obj.descriptions |
|
||||||
#fill form |
|
||||||
form = CompanyForm(initial=data) |
|
||||||
#set choices filled by ajax |
|
||||||
form.fields['city'].choices = [(item.id, item.name) for item in City.objects.filter(country=data['country'])] |
|
||||||
form.fields['tag'].choices = [(item.id, item.name) for item in Tag.objects.filter(theme__in=data['theme'])] |
|
||||||
|
|
||||||
args = {} |
|
||||||
args.update(csrf(request)) |
|
||||||
|
|
||||||
args['form'] = form |
|
||||||
args['languages'] = settings.LANGUAGES |
|
||||||
args['file_form'] = file_form |
|
||||||
|
|
||||||
#get list of files which connected with specific model object |
|
||||||
args['files'] = FileModel.objects.filter(content_type=ContentType.objects.get_for_model(company), object_id=getattr(company, 'id')) |
|
||||||
args['obj_id'] = company_id |
|
||||||
|
|
||||||
return render_to_response('company_add.html', args) |
|
||||||
|
|
||||||
|
|
||||||
@ -0,0 +1,145 @@ |
|||||||
|
# -*- coding: utf-8 -*- |
||||||
|
from django.shortcuts import render_to_response |
||||||
|
from django.http import HttpResponseRedirect, HttpResponse |
||||||
|
from django.core.context_processors import csrf |
||||||
|
from django.conf import settings |
||||||
|
from django.forms.formsets import BaseFormSet, formset_factory |
||||||
|
from django.forms.models import modelformset_factory |
||||||
|
from django.contrib.contenttypes.models import ContentType |
||||||
|
from django.contrib.auth.decorators import login_required |
||||||
|
#models and forms |
||||||
|
from models import Conference, TimeTable |
||||||
|
from forms import ConferenceChangeForm, ConferenceCreateForm, ConferenceDeleteForm, TimeTableForm |
||||||
|
from theme.models import Tag |
||||||
|
from city.models import City |
||||||
|
from file.models import FileModel, TmpFile |
||||||
|
from file.forms import FileModelForm |
||||||
|
#python |
||||||
|
import random |
||||||
|
#custom views |
||||||
|
from functions.custom_views import objects_list, delete_object |
||||||
|
|
||||||
|
|
||||||
|
def conference_all(request): |
||||||
|
""" |
||||||
|
Return list of all conferences with pagination |
||||||
|
""" |
||||||
|
return objects_list(request, Conference, 'conference_all.html') |
||||||
|
|
||||||
|
|
||||||
|
@login_required |
||||||
|
def conference_add(request): |
||||||
|
""" |
||||||
|
Returns form of conference and post it on the server. |
||||||
|
|
||||||
|
If form is posted redirect on the page of all conferences. |
||||||
|
""" |
||||||
|
#if form would be not valid key must be same |
||||||
|
if request.POST.get('key'): |
||||||
|
key = request.POST['key'] |
||||||
|
else: |
||||||
|
key = random.getrandbits(128) |
||||||
|
|
||||||
|
file_form = FileModelForm(initial={'key': key}) |
||||||
|
|
||||||
|
if request.POST: |
||||||
|
form = ConferenceCreateForm(request.POST) |
||||||
|
#set choices filled by ajax |
||||||
|
form.fields['tag'].choices = [(item.id, item.name) for item in Tag.objects.all()] |
||||||
|
form.fields['city'].choices = [(item.id, item.name) for item in City.objects.filter(country=request.POST['country'])] |
||||||
|
|
||||||
|
if form.is_valid(): |
||||||
|
form.save() |
||||||
|
return HttpResponseRedirect('/admin/conference/all/') |
||||||
|
else: |
||||||
|
form = ConferenceCreateForm(initial={'key': key}) |
||||||
|
|
||||||
|
args = {} |
||||||
|
args.update(csrf(request)) |
||||||
|
|
||||||
|
args['form'] = form |
||||||
|
args['languages'] = settings.LANGUAGES |
||||||
|
args['file_form'] = file_form |
||||||
|
args['files'] = TmpFile.objects.filter(key=key) |
||||||
|
|
||||||
|
return render_to_response('conference_add.html', args) |
||||||
|
|
||||||
|
|
||||||
|
def conference_delete(request, url): |
||||||
|
return delete_object(request, Conference, ConferenceDeleteForm, url, '/admin/conference/all') |
||||||
|
|
||||||
|
|
||||||
|
@login_required |
||||||
|
def conference_change(request, url): |
||||||
|
""" |
||||||
|
Return form of conference and fill it with existing Conference object data. |
||||||
|
|
||||||
|
If form of conference is posted redirect on the page of all conferences. |
||||||
|
|
||||||
|
""" |
||||||
|
try: |
||||||
|
#check if conference_id exists else redirect to the list of conferences |
||||||
|
conference = Conference.objects.get(url=url) |
||||||
|
file_form = FileModelForm(initial={'model': 'city.City'}) |
||||||
|
except: |
||||||
|
return HttpResponseRedirect('/admin/conference/all/') |
||||||
|
|
||||||
|
if request.POST: |
||||||
|
form = ConferenceChangeForm(request.POST) |
||||||
|
#set choices filled by ajax |
||||||
|
form.fields['tag'].choices = [(item.id, item.name) for item in Tag.objects.all()] |
||||||
|
form.fields['city'].choices = [(item.id, item.name) for item in City.objects.filter(country=request.POST['country'])] |
||||||
|
|
||||||
|
if form.is_valid(): |
||||||
|
form.save(getattr(conference, 'id')) |
||||||
|
return HttpResponseRedirect('/admin/conference/all/') |
||||||
|
else: |
||||||
|
#fill form with data from database |
||||||
|
data = {'web_page':conference.web_page, 'foundation_year': conference.foundation_year, |
||||||
|
'data_begin':conference.data_begin, 'data_end':conference.data_end, 'currency':conference.currency, |
||||||
|
'tax':conference.tax, 'min_price':conference.min_price, 'max_price':conference.max_price, |
||||||
|
'link':conference.link, 'conference_id':conference.id} |
||||||
|
|
||||||
|
if conference.country: |
||||||
|
data['country'] = conference.country.id |
||||||
|
|
||||||
|
if conference.city: |
||||||
|
data['city'] = conference.city.id |
||||||
|
|
||||||
|
if conference.place: |
||||||
|
data['place'] = conference.place.id |
||||||
|
|
||||||
|
data['theme'] = [item.id for item in conference.theme.all()] |
||||||
|
data['tag'] = [item.id for item in conference.tag.all()] |
||||||
|
#data from translated fields |
||||||
|
for code, name in settings.LANGUAGES: |
||||||
|
obj = Conference._meta.translations_model.objects.get(language_code = code,master__id=getattr(conference, 'id')) #access to translated fields |
||||||
|
data['name_%s' % code] = obj.name |
||||||
|
data['description_%s' % code] = obj.description |
||||||
|
data['main_title_%s' % code] = obj.main_title |
||||||
|
data['time_%s' % code] = obj.time |
||||||
|
data['main_themes_%s' % code] = obj.main_themes |
||||||
|
data['discount_%s' % code] = obj.discount |
||||||
|
data['title_%s' % code] = obj.title |
||||||
|
data['keywords_%s' % code] = obj.keywords |
||||||
|
data['descriptions_%s' % code] = obj.descriptions |
||||||
|
#initial form |
||||||
|
form = ConferenceChangeForm(initial=data) |
||||||
|
#set choices filled by ajax |
||||||
|
form.fields['city'].choices = [(item.id, item.name) for item in City.objects.filter(country=data['country'])] |
||||||
|
form.fields['tag'].choices = [(item.id, item.name) for item in Tag.objects.filter(theme__in=data['theme'])] |
||||||
|
|
||||||
|
args = {} |
||||||
|
args.update(csrf(request)) |
||||||
|
|
||||||
|
args['form'] = form |
||||||
|
args['languages'] = settings.LANGUAGES |
||||||
|
args['file_form'] = file_form |
||||||
|
|
||||||
|
#get list of files which connected with specific model object |
||||||
|
args['files'] = FileModel.objects.filter(content_type=ContentType.objects.get_for_model(conference), object_id=getattr(conference, 'id')) |
||||||
|
args['obj_id'] = getattr(conference, 'id') |
||||||
|
|
||||||
|
return render_to_response('conference_add.html', args) |
||||||
|
|
||||||
|
|
||||||
@ -1,145 +0,0 @@ |
|||||||
# -*- coding: utf-8 -*- |
|
||||||
from django.shortcuts import render_to_response |
|
||||||
from django.http import HttpResponseRedirect, HttpResponse |
|
||||||
from django.core.context_processors import csrf |
|
||||||
from django.conf import settings |
|
||||||
from django.forms.formsets import BaseFormSet, formset_factory |
|
||||||
from django.forms.models import modelformset_factory |
|
||||||
from django.contrib.contenttypes.models import ContentType |
|
||||||
from django.contrib.auth.decorators import login_required |
|
||||||
#models and forms |
|
||||||
from models import Conference, TimeTable |
|
||||||
from forms import ConferenceChangeForm, ConferenceCreateForm, ConferenceDeleteForm, TimeTableForm |
|
||||||
from theme.models import Tag |
|
||||||
from city.models import City |
|
||||||
from file.models import FileModel, TmpFile |
|
||||||
from file.forms import FileModelForm |
|
||||||
#python |
|
||||||
import random |
|
||||||
#custom views |
|
||||||
from functions.custom_views import objects_list, delete_object |
|
||||||
|
|
||||||
|
|
||||||
def conference_all(request): |
|
||||||
""" |
|
||||||
Return list of all conferences with pagination |
|
||||||
""" |
|
||||||
return objects_list(request, Conference, 'conference_all.html') |
|
||||||
|
|
||||||
|
|
||||||
@login_required |
|
||||||
def conference_add(request): |
|
||||||
""" |
|
||||||
Returns form of conference and post it on the server. |
|
||||||
|
|
||||||
If form is posted redirect on the page of all conferences. |
|
||||||
""" |
|
||||||
#if form would be not valid key must be same |
|
||||||
if request.POST.get('key'): |
|
||||||
key = request.POST['key'] |
|
||||||
else: |
|
||||||
key = random.getrandbits(128) |
|
||||||
|
|
||||||
file_form = FileModelForm(initial={'key': key}) |
|
||||||
|
|
||||||
if request.POST: |
|
||||||
form = ConferenceCreateForm(request.POST) |
|
||||||
#set choices filled by ajax |
|
||||||
form.fields['tag'].choices = [(item.id, item.name) for item in Tag.objects.all()] |
|
||||||
form.fields['city'].choices = [(item.id, item.name) for item in City.objects.filter(country=request.POST['country'])] |
|
||||||
|
|
||||||
if form.is_valid(): |
|
||||||
form.save() |
|
||||||
return HttpResponseRedirect('/admin/conference/all/') |
|
||||||
else: |
|
||||||
form = ConferenceCreateForm(initial={'key': key}) |
|
||||||
|
|
||||||
args = {} |
|
||||||
args.update(csrf(request)) |
|
||||||
|
|
||||||
args['form'] = form |
|
||||||
args['languages'] = settings.LANGUAGES |
|
||||||
args['file_form'] = file_form |
|
||||||
args['files'] = TmpFile.objects.filter(key=key) |
|
||||||
|
|
||||||
return render_to_response('conference_add.html', args) |
|
||||||
|
|
||||||
|
|
||||||
def conference_delete(request, url): |
|
||||||
return delete_object(request, Conference, ConferenceDeleteForm, url, '/admin/conference/all') |
|
||||||
|
|
||||||
|
|
||||||
@login_required |
|
||||||
def conference_change(request, url): |
|
||||||
""" |
|
||||||
Return form of conference and fill it with existing Conference object data. |
|
||||||
|
|
||||||
If form of conference is posted redirect on the page of all conferences. |
|
||||||
|
|
||||||
""" |
|
||||||
try: |
|
||||||
#check if conference_id exists else redirect to the list of conferences |
|
||||||
conference = Conference.objects.get(url=url) |
|
||||||
file_form = FileModelForm(initial={'model': 'city.City'}) |
|
||||||
except: |
|
||||||
return HttpResponseRedirect('/admin/conference/all/') |
|
||||||
|
|
||||||
if request.POST: |
|
||||||
form = ConferenceChangeForm(request.POST) |
|
||||||
#set choices filled by ajax |
|
||||||
form.fields['tag'].choices = [(item.id, item.name) for item in Tag.objects.all()] |
|
||||||
form.fields['city'].choices = [(item.id, item.name) for item in City.objects.filter(country=request.POST['country'])] |
|
||||||
|
|
||||||
if form.is_valid(): |
|
||||||
form.save(getattr(conference, 'id')) |
|
||||||
return HttpResponseRedirect('/admin/conference/all/') |
|
||||||
else: |
|
||||||
#fill form with data from database |
|
||||||
data = {'web_page':conference.web_page, 'foundation_year': conference.foundation_year, |
|
||||||
'data_begin':conference.data_begin, 'data_end':conference.data_end, 'currency':conference.currency, |
|
||||||
'tax':conference.tax, 'min_price':conference.min_price, 'max_price':conference.max_price, |
|
||||||
'link':conference.link, 'conference_id':conference.id} |
|
||||||
|
|
||||||
if conference.country: |
|
||||||
data['country'] = conference.country.id |
|
||||||
|
|
||||||
if conference.city: |
|
||||||
data['city'] = conference.city.id |
|
||||||
|
|
||||||
if conference.place: |
|
||||||
data['place'] = conference.place.id |
|
||||||
|
|
||||||
data['theme'] = [item.id for item in conference.theme.all()] |
|
||||||
data['tag'] = [item.id for item in conference.tag.all()] |
|
||||||
#data from translated fields |
|
||||||
for code, name in settings.LANGUAGES: |
|
||||||
obj = Conference._meta.translations_model.objects.get(language_code = code,master__id=getattr(conference, 'id')) #access to translated fields |
|
||||||
data['name_%s' % code] = obj.name |
|
||||||
data['description_%s' % code] = obj.description |
|
||||||
data['main_title_%s' % code] = obj.main_title |
|
||||||
data['time_%s' % code] = obj.time |
|
||||||
data['main_themes_%s' % code] = obj.main_themes |
|
||||||
data['discount_%s' % code] = obj.discount |
|
||||||
data['title_%s' % code] = obj.title |
|
||||||
data['keywords_%s' % code] = obj.keywords |
|
||||||
data['descriptions_%s' % code] = obj.descriptions |
|
||||||
#initial form |
|
||||||
form = ConferenceChangeForm(initial=data) |
|
||||||
#set choices filled by ajax |
|
||||||
form.fields['city'].choices = [(item.id, item.name) for item in City.objects.filter(country=data['country'])] |
|
||||||
form.fields['tag'].choices = [(item.id, item.name) for item in Tag.objects.filter(theme__in=data['theme'])] |
|
||||||
|
|
||||||
args = {} |
|
||||||
args.update(csrf(request)) |
|
||||||
|
|
||||||
args['form'] = form |
|
||||||
args['languages'] = settings.LANGUAGES |
|
||||||
args['file_form'] = file_form |
|
||||||
|
|
||||||
#get list of files which connected with specific model object |
|
||||||
args['files'] = FileModel.objects.filter(content_type=ContentType.objects.get_for_model(conference), object_id=getattr(conference, 'id')) |
|
||||||
args['obj_id'] = getattr(conference, 'id') |
|
||||||
|
|
||||||
return render_to_response('conference_add.html', args) |
|
||||||
|
|
||||||
|
|
||||||
@ -1,16 +1,106 @@ |
|||||||
# -*- coding: utf-8 -*- |
# -*- coding: utf-8 -*- |
||||||
from django.contrib import admin |
from django.shortcuts import render_to_response |
||||||
from hvad.admin import TranslatableAdmin |
from django.http import HttpResponseRedirect, HttpResponse |
||||||
|
from django.core.context_processors import csrf |
||||||
|
from django.conf import settings |
||||||
|
from django.contrib.contenttypes.models import ContentType |
||||||
|
from django.contrib.auth.decorators import login_required |
||||||
|
from django.db.models.loading import get_model |
||||||
|
from django.core.paginator import Paginator, PageNotAnInteger, EmptyPage |
||||||
|
#models and forms |
||||||
from models import Country |
from models import Country |
||||||
from bitfield import BitField |
from forms import CountryForm, CountryDeleteForm |
||||||
from bitfield.forms import BitFieldCheckboxSelectMultiple |
from file.models import FileModel, TmpFile |
||||||
from bitfield.admin import BitFieldListFilter |
from file.forms import FileModelForm |
||||||
|
#custom views |
||||||
|
from functions.custom_views import objects_list, add_object_with_file, delete_object |
||||||
|
|
||||||
|
from django.db.models.deletion import ProtectedError |
||||||
|
|
||||||
class CountryAdmin(TranslatableAdmin): |
|
||||||
formfield_overrides = { |
|
||||||
BitField: {'widget': BitFieldCheckboxSelectMultiple}, |
|
||||||
} |
|
||||||
|
|
||||||
|
def country_all(request): |
||||||
|
""" |
||||||
|
Return list of all countries with pagination |
||||||
|
""" |
||||||
|
return objects_list(request, Country, 'country_all.html') |
||||||
|
|
||||||
admin.site.register(Country, CountryAdmin) |
|
||||||
|
def country_add(request): |
||||||
|
""" |
||||||
|
Return form of country and file and post it on the server. |
||||||
|
""" |
||||||
|
return add_object_with_file(request, CountryForm, 'country_add.html', '/admin/country/all/') |
||||||
|
|
||||||
|
|
||||||
|
def country_delete(request, url): |
||||||
|
return delete_object(request, Country, CountryDeleteForm, url, '/admin/country/all/') |
||||||
|
|
||||||
|
|
||||||
|
@login_required |
||||||
|
def country_change(request, url): |
||||||
|
""" |
||||||
|
Return form of county and file and fill it with existing Country object data. |
||||||
|
|
||||||
|
If form of country is posted redirect on the page of all countries. |
||||||
|
|
||||||
|
FileForm posts with ajax with calling ajax_post function |
||||||
|
""" |
||||||
|
|
||||||
|
#check if country_id exists else redirect to the list of countries |
||||||
|
try: |
||||||
|
c = Country.objects.get(url=url) |
||||||
|
country_id = getattr(c, 'id') |
||||||
|
#initial hidden input for checking model of object |
||||||
|
file_form = FileModelForm(initial={'model': 'country.Country'}) |
||||||
|
except: |
||||||
|
return HttpResponseRedirect('/admin/country/all') |
||||||
|
|
||||||
|
if request.POST: |
||||||
|
#country_id sending for saving capital field in __init__ |
||||||
|
form = CountryForm(request.POST, country_id=country_id) |
||||||
|
|
||||||
|
if form.is_valid(): |
||||||
|
form.save(country_id) |
||||||
|
return HttpResponseRedirect('/admin/country/all/') |
||||||
|
else: |
||||||
|
#fill form with data from database |
||||||
|
data = {'population' : c.population, 'teritory' : c.teritory, #data from NOT translated fields |
||||||
|
'timezone' : c.timezone, 'region' : c.region, 'country_id' : country_id, |
||||||
|
'phone_code' : c.phone_code, 'time_delivery' : c.time_delivery} |
||||||
|
|
||||||
|
if c.capital: |
||||||
|
data['capital'] = c.capital.id |
||||||
|
|
||||||
|
#data from translated fields |
||||||
|
for code, name in settings.LANGUAGES: |
||||||
|
obj = Country._meta.translations_model.objects.get(language_code = code,master__id=country_id) #access to translated fields |
||||||
|
data['name_%s' % code] = obj.name |
||||||
|
data['description_%s' % code] = obj.description |
||||||
|
data['rules_%s' % code] = obj.rules |
||||||
|
data['documents_%s' % code] = obj.documents |
||||||
|
data['consulate_%s' % code] = obj.consulate |
||||||
|
data['title_%s' % code] = obj.title |
||||||
|
data['keywords_%s' % code] = obj.keywords |
||||||
|
data['descriptions_%s' % code] = obj.descriptions |
||||||
|
#data from manytomany fields |
||||||
|
data['big_cities'] = [item.id for item in c.big_cities.all()] |
||||||
|
data['language'] = [item.id for item in c.language.all()] |
||||||
|
data['currency'] = [item.id for item in c.currency.all()] |
||||||
|
#initial forms |
||||||
|
#country_id sending for initialing capital field in __init__ |
||||||
|
form = CountryForm(initial=data, country_id = c.id) |
||||||
|
|
||||||
|
args = {} |
||||||
|
|
||||||
|
args.update(csrf(request)) |
||||||
|
args['languages'] = settings.LANGUAGES |
||||||
|
args['form'] = form |
||||||
|
args['file_form'] = file_form |
||||||
|
|
||||||
|
#get list of files which connected with specific model object |
||||||
|
args['files'] = FileModel.objects.filter(content_type=ContentType.objects.get_for_model(c), object_id=getattr(c, 'id')) |
||||||
|
|
||||||
|
#uses for creating hidden input which will be used for generating ajax url |
||||||
|
args['obj_id'] = country_id |
||||||
|
|
||||||
|
return render_to_response('country_add.html', args) |
||||||
|
|||||||
@ -0,0 +1,16 @@ |
|||||||
|
# -*- coding: utf-8 -*- |
||||||
|
from django.contrib import admin |
||||||
|
from hvad.admin import TranslatableAdmin |
||||||
|
from models import Country |
||||||
|
from bitfield import BitField |
||||||
|
from bitfield.forms import BitFieldCheckboxSelectMultiple |
||||||
|
from bitfield.admin import BitFieldListFilter |
||||||
|
|
||||||
|
|
||||||
|
class CountryAdmin(TranslatableAdmin): |
||||||
|
formfield_overrides = { |
||||||
|
BitField: {'widget': BitFieldCheckboxSelectMultiple}, |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
admin.site.register(Country, CountryAdmin) |
||||||
@ -1,106 +0,0 @@ |
|||||||
# -*- coding: utf-8 -*- |
|
||||||
from django.shortcuts import render_to_response |
|
||||||
from django.http import HttpResponseRedirect, HttpResponse |
|
||||||
from django.core.context_processors import csrf |
|
||||||
from django.conf import settings |
|
||||||
from django.contrib.contenttypes.models import ContentType |
|
||||||
from django.contrib.auth.decorators import login_required |
|
||||||
from django.db.models.loading import get_model |
|
||||||
from django.core.paginator import Paginator, PageNotAnInteger, EmptyPage |
|
||||||
#models and forms |
|
||||||
from models import Country |
|
||||||
from forms import CountryForm, CountryDeleteForm |
|
||||||
from file.models import FileModel, TmpFile |
|
||||||
from file.forms import FileModelForm |
|
||||||
#custom views |
|
||||||
from functions.custom_views import objects_list, add_object_with_file, delete_object |
|
||||||
|
|
||||||
from django.db.models.deletion import ProtectedError |
|
||||||
|
|
||||||
|
|
||||||
def country_all(request): |
|
||||||
""" |
|
||||||
Return list of all countries with pagination |
|
||||||
""" |
|
||||||
return objects_list(request, Country, 'country_all.html') |
|
||||||
|
|
||||||
|
|
||||||
def country_add(request): |
|
||||||
""" |
|
||||||
Return form of country and file and post it on the server. |
|
||||||
""" |
|
||||||
return add_object_with_file(request, CountryForm, 'country_add.html', '/admin/country/all/') |
|
||||||
|
|
||||||
|
|
||||||
def country_delete(request, url): |
|
||||||
return delete_object(request, Country, CountryDeleteForm, url, '/admin/country/all/') |
|
||||||
|
|
||||||
|
|
||||||
@login_required |
|
||||||
def country_change(request, url): |
|
||||||
""" |
|
||||||
Return form of county and file and fill it with existing Country object data. |
|
||||||
|
|
||||||
If form of country is posted redirect on the page of all countries. |
|
||||||
|
|
||||||
FileForm posts with ajax with calling ajax_post function |
|
||||||
""" |
|
||||||
|
|
||||||
#check if country_id exists else redirect to the list of countries |
|
||||||
try: |
|
||||||
c = Country.objects.get(url=url) |
|
||||||
country_id = getattr(c, 'id') |
|
||||||
#initial hidden input for checking model of object |
|
||||||
file_form = FileModelForm(initial={'model': 'country.Country'}) |
|
||||||
except: |
|
||||||
return HttpResponseRedirect('/admin/country/all') |
|
||||||
|
|
||||||
if request.POST: |
|
||||||
#country_id sending for saving capital field in __init__ |
|
||||||
form = CountryForm(request.POST, country_id=country_id) |
|
||||||
|
|
||||||
if form.is_valid(): |
|
||||||
form.save(country_id) |
|
||||||
return HttpResponseRedirect('/admin/country/all/') |
|
||||||
else: |
|
||||||
#fill form with data from database |
|
||||||
data = {'population' : c.population, 'teritory' : c.teritory, #data from NOT translated fields |
|
||||||
'timezone' : c.timezone, 'region' : c.region, 'country_id' : country_id, |
|
||||||
'phone_code' : c.phone_code, 'time_delivery' : c.time_delivery} |
|
||||||
|
|
||||||
if c.capital: |
|
||||||
data['capital'] = c.capital.id |
|
||||||
|
|
||||||
#data from translated fields |
|
||||||
for code, name in settings.LANGUAGES: |
|
||||||
obj = Country._meta.translations_model.objects.get(language_code = code,master__id=country_id) #access to translated fields |
|
||||||
data['name_%s' % code] = obj.name |
|
||||||
data['description_%s' % code] = obj.description |
|
||||||
data['rules_%s' % code] = obj.rules |
|
||||||
data['documents_%s' % code] = obj.documents |
|
||||||
data['consulate_%s' % code] = obj.consulate |
|
||||||
data['title_%s' % code] = obj.title |
|
||||||
data['keywords_%s' % code] = obj.keywords |
|
||||||
data['descriptions_%s' % code] = obj.descriptions |
|
||||||
#data from manytomany fields |
|
||||||
data['big_cities'] = [item.id for item in c.big_cities.all()] |
|
||||||
data['language'] = [item.id for item in c.language.all()] |
|
||||||
data['currency'] = [item.id for item in c.currency.all()] |
|
||||||
#initial forms |
|
||||||
#country_id sending for initialing capital field in __init__ |
|
||||||
form = CountryForm(initial=data, country_id = c.id) |
|
||||||
|
|
||||||
args = {} |
|
||||||
|
|
||||||
args.update(csrf(request)) |
|
||||||
args['languages'] = settings.LANGUAGES |
|
||||||
args['form'] = form |
|
||||||
args['file_form'] = file_form |
|
||||||
|
|
||||||
#get list of files which connected with specific model object |
|
||||||
args['files'] = FileModel.objects.filter(content_type=ContentType.objects.get_for_model(c), object_id=getattr(c, 'id')) |
|
||||||
|
|
||||||
#uses for creating hidden input which will be used for generating ajax url |
|
||||||
args['obj_id'] = country_id |
|
||||||
|
|
||||||
return render_to_response('country_add.html', args) |
|
||||||
@ -1,7 +1,18 @@ |
|||||||
# -*- coding: utf-8 -*- |
# -*- coding: utf-8 -*- |
||||||
from django.contrib import admin |
from forms import LanguageForm, CurrencyForm, IataForm |
||||||
from models import Language, Currency, Iata |
#custom views |
||||||
|
from functions.custom_views import add_object |
||||||
|
|
||||||
admin.site.register(Language) |
|
||||||
admin.site.register(Currency) |
def language_add(request): |
||||||
admin.site.register(Iata) |
""" |
||||||
|
Return LanguageForm and post it on the server |
||||||
|
""" |
||||||
|
return add_object(request, LanguageForm, 'directories_add.html', '/admin/language/add') |
||||||
|
|
||||||
|
|
||||||
|
def currency_add(request): |
||||||
|
""" |
||||||
|
Return CurrencyForm and post it on the server |
||||||
|
""" |
||||||
|
return add_object(request, CurrencyForm, 'directories_add.html', '/admin/currency/add') |
||||||
@ -0,0 +1,7 @@ |
|||||||
|
# -*- coding: utf-8 -*- |
||||||
|
from django.contrib import admin |
||||||
|
from models import Language, Currency, Iata |
||||||
|
|
||||||
|
admin.site.register(Language) |
||||||
|
admin.site.register(Currency) |
||||||
|
admin.site.register(Iata) |
||||||
@ -1,18 +0,0 @@ |
|||||||
# -*- coding: utf-8 -*- |
|
||||||
from forms import LanguageForm, CurrencyForm, IataForm |
|
||||||
#custom views |
|
||||||
from functions.custom_views import add_object |
|
||||||
|
|
||||||
|
|
||||||
def language_add(request): |
|
||||||
""" |
|
||||||
Return LanguageForm and post it on the server |
|
||||||
""" |
|
||||||
return add_object(request, LanguageForm, 'directories_add.html', '/admin/language/add') |
|
||||||
|
|
||||||
|
|
||||||
def currency_add(request): |
|
||||||
""" |
|
||||||
Return CurrencyForm and post it on the server |
|
||||||
""" |
|
||||||
return add_object(request, CurrencyForm, 'directories_add.html', '/admin/currency/add') |
|
||||||
@ -1,9 +1,146 @@ |
|||||||
# -*- coding: utf-8 -*- |
# -*- coding: utf-8 -*- |
||||||
from django.contrib import admin |
from django.shortcuts import render_to_response |
||||||
from hvad.admin import TranslatableAdmin |
from django.http import HttpResponseRedirect, HttpResponse |
||||||
from models import Exposition |
from django.core.context_processors import csrf |
||||||
|
from django.conf import settings |
||||||
|
from django.forms.formsets import BaseFormSet, formset_factory |
||||||
|
from django.forms.models import modelformset_factory |
||||||
|
from django.contrib.contenttypes.models import ContentType |
||||||
|
from django.contrib.auth.decorators import login_required |
||||||
|
#models and forms |
||||||
|
from models import Exposition, TimeTable |
||||||
|
from forms import ExpositionChangeForm, ExpositionCreateForm, ExpositionDeleteForm, TimeTableForm |
||||||
|
from theme.models import Tag |
||||||
|
from city.models import City |
||||||
|
from file.models import FileModel, TmpFile |
||||||
|
from file.forms import FileModelForm |
||||||
|
#python |
||||||
|
import random |
||||||
|
#custom views |
||||||
|
from functions.custom_views import objects_list, delete_object |
||||||
|
|
||||||
class ExpositionAdmin(TranslatableAdmin): |
|
||||||
pass |
|
||||||
|
|
||||||
admin.site.register(Exposition, ExpositionAdmin) |
def exposition_all(request): |
||||||
|
""" |
||||||
|
Return list of all expositions with pagination |
||||||
|
""" |
||||||
|
return objects_list(request, Exposition, 'exposition_all.html') |
||||||
|
|
||||||
|
|
||||||
|
@login_required |
||||||
|
def exposition_add(request): |
||||||
|
""" |
||||||
|
Returns form of exposition and post it on the server. |
||||||
|
|
||||||
|
If form is posted redirect on the page of all expositions. |
||||||
|
""" |
||||||
|
#if form would be not valid key must be same |
||||||
|
if request.POST.get('key'): |
||||||
|
key = request.POST['key'] |
||||||
|
else: |
||||||
|
key = random.getrandbits(128) |
||||||
|
|
||||||
|
file_form = FileModelForm(initial={'key': key}) |
||||||
|
|
||||||
|
if request.POST: |
||||||
|
form = ExpositionCreateForm(request.POST) |
||||||
|
#set choices filled by ajax |
||||||
|
form.fields['tag'].choices = [(item.id, item.name) for item in Tag.objects.all()] |
||||||
|
form.fields['city'].choices = [(item.id, item.name) for item in City.objects.filter(country=request.POST['country'])] |
||||||
|
|
||||||
|
if form.is_valid(): |
||||||
|
form.save() |
||||||
|
return HttpResponseRedirect('/admin/exposition/all/') |
||||||
|
else: |
||||||
|
form = ExpositionCreateForm(initial={'key': key}) |
||||||
|
|
||||||
|
args = {} |
||||||
|
args.update(csrf(request)) |
||||||
|
|
||||||
|
args['form'] = form |
||||||
|
args['file_form'] = file_form |
||||||
|
args['files'] = TmpFile.objects.filter(key=key) |
||||||
|
args['languages'] = settings.LANGUAGES |
||||||
|
return render_to_response('exposition_add.html', args) |
||||||
|
|
||||||
|
|
||||||
|
def exposition_delete(request, url): |
||||||
|
return delete_object(request, Exposition, ExpositionDeleteForm, url, '/admin/exposition/all') |
||||||
|
|
||||||
|
|
||||||
|
@login_required |
||||||
|
def exposition_change(request, url): |
||||||
|
""" |
||||||
|
Return form of exposition and fill it with existing Exposition object data. |
||||||
|
|
||||||
|
If form of exposition is posted redirect on the page of all expositions. |
||||||
|
|
||||||
|
""" |
||||||
|
try: |
||||||
|
#check if exposition_id exists else redirect to the list of expositions |
||||||
|
exposition = Exposition.objects.get(url=url) |
||||||
|
file_form = FileModelForm(initial={'model': 'exposition.Exposition'}) |
||||||
|
except: |
||||||
|
return HttpResponseRedirect('/admin/exposition/all/') |
||||||
|
|
||||||
|
if request.POST: |
||||||
|
form = ExpositionChangeForm(request.POST) |
||||||
|
#set choices filled by ajax |
||||||
|
form.fields['tag'].choices = [(item.id, item.name) for item in Tag.objects.all()] |
||||||
|
form.fields['city'].choices = [(item.id, item.name) for item in City.objects.filter(country=request.POST['country'])] |
||||||
|
|
||||||
|
if form.is_valid(): |
||||||
|
form.save(getattr(exposition, 'id')) |
||||||
|
return HttpResponseRedirect('/admin/exposition/all/') |
||||||
|
else: |
||||||
|
#fill form with data from database |
||||||
|
data = {'web_page':exposition.web_page, 'foundation_year': exposition.foundation_year, |
||||||
|
'data_begin':exposition.data_begin, 'data_end':exposition.data_end, 'periodic':exposition.periodic, |
||||||
|
'audience':exposition.audience, 'min_area':exposition.min_area, 'currency':exposition.currency, |
||||||
|
'tax':exposition.tax, 'min_closed_area':exposition.min_closed_area, |
||||||
|
'max_closed_area':exposition.max_closed_area, 'min_closed_equipped_area':exposition.min_closed_equipped_area, |
||||||
|
'max_closed_equipped_area':exposition.max_closed_equipped_area, |
||||||
|
'min_open_area':exposition.min_open_area, 'max_open_area':exposition.max_open_area, |
||||||
|
'registration_payment':exposition.registration_payment, 'exposition_id':exposition.id} |
||||||
|
|
||||||
|
if exposition.country: |
||||||
|
data['country'] = exposition.country.id |
||||||
|
|
||||||
|
if exposition.city: |
||||||
|
data['city'] = exposition.city.id |
||||||
|
|
||||||
|
if exposition.place: |
||||||
|
data['place'] = exposition.place.id |
||||||
|
|
||||||
|
data['theme'] = [item.id for item in exposition.theme.all()] |
||||||
|
data['tag'] = [item.id for item in exposition.tag.all()] |
||||||
|
#data from translated fields |
||||||
|
for code, name in settings.LANGUAGES: |
||||||
|
obj = Exposition._meta.translations_model.objects.get(language_code = code,master__id=getattr(exposition, 'id')) #access to translated fields |
||||||
|
data['name_%s' % code] = obj.name |
||||||
|
data['description_%s' % code] = obj.description |
||||||
|
data['main_title_%s' % code] = obj.main_title |
||||||
|
data['time_%s' % code] = obj.time |
||||||
|
data['products_%s' % code] = obj.products |
||||||
|
data['title_%s' % code] = obj.title |
||||||
|
data['keywords_%s' % code] = obj.keywords |
||||||
|
data['descriptions_%s' % code] = obj.descriptions |
||||||
|
#initial form |
||||||
|
form = ExpositionChangeForm(initial=data) |
||||||
|
#set choices filled by ajax |
||||||
|
form.fields['city'].choices = [(item.id, item.name) for item in City.objects.filter(country=data['country'])] |
||||||
|
form.fields['tag'].choices = [(item.id, item.name) for item in Tag.objects.filter(theme__in=data['theme'])] |
||||||
|
|
||||||
|
args = {} |
||||||
|
args.update(csrf(request)) |
||||||
|
|
||||||
|
args['form'] = form |
||||||
|
args['languages'] = settings.LANGUAGES |
||||||
|
args['file_form'] = file_form |
||||||
|
|
||||||
|
#get list of files which connected with specific model object |
||||||
|
args['files'] = FileModel.objects.filter(content_type=ContentType.objects.get_for_model(exposition), |
||||||
|
object_id=getattr(exposition, 'id')) |
||||||
|
args['obj_id'] = getattr(exposition, 'id') |
||||||
|
|
||||||
|
return render_to_response('exposition_add.html', args) |
||||||
|
|||||||
@ -0,0 +1,9 @@ |
|||||||
|
# -*- coding: utf-8 -*- |
||||||
|
from django.contrib import admin |
||||||
|
from hvad.admin import TranslatableAdmin |
||||||
|
from models import Exposition |
||||||
|
|
||||||
|
class ExpositionAdmin(TranslatableAdmin): |
||||||
|
pass |
||||||
|
|
||||||
|
admin.site.register(Exposition, ExpositionAdmin) |
||||||
@ -1,146 +0,0 @@ |
|||||||
# -*- coding: utf-8 -*- |
|
||||||
from django.shortcuts import render_to_response |
|
||||||
from django.http import HttpResponseRedirect, HttpResponse |
|
||||||
from django.core.context_processors import csrf |
|
||||||
from django.conf import settings |
|
||||||
from django.forms.formsets import BaseFormSet, formset_factory |
|
||||||
from django.forms.models import modelformset_factory |
|
||||||
from django.contrib.contenttypes.models import ContentType |
|
||||||
from django.contrib.auth.decorators import login_required |
|
||||||
#models and forms |
|
||||||
from models import Exposition, TimeTable |
|
||||||
from forms import ExpositionChangeForm, ExpositionCreateForm, ExpositionDeleteForm, TimeTableForm |
|
||||||
from theme.models import Tag |
|
||||||
from city.models import City |
|
||||||
from file.models import FileModel, TmpFile |
|
||||||
from file.forms import FileModelForm |
|
||||||
#python |
|
||||||
import random |
|
||||||
#custom views |
|
||||||
from functions.custom_views import objects_list, delete_object |
|
||||||
|
|
||||||
|
|
||||||
def exposition_all(request): |
|
||||||
""" |
|
||||||
Return list of all expositions with pagination |
|
||||||
""" |
|
||||||
return objects_list(request, Exposition, 'exposition_all.html') |
|
||||||
|
|
||||||
|
|
||||||
@login_required |
|
||||||
def exposition_add(request): |
|
||||||
""" |
|
||||||
Returns form of exposition and post it on the server. |
|
||||||
|
|
||||||
If form is posted redirect on the page of all expositions. |
|
||||||
""" |
|
||||||
#if form would be not valid key must be same |
|
||||||
if request.POST.get('key'): |
|
||||||
key = request.POST['key'] |
|
||||||
else: |
|
||||||
key = random.getrandbits(128) |
|
||||||
|
|
||||||
file_form = FileModelForm(initial={'key': key}) |
|
||||||
|
|
||||||
if request.POST: |
|
||||||
form = ExpositionCreateForm(request.POST) |
|
||||||
#set choices filled by ajax |
|
||||||
form.fields['tag'].choices = [(item.id, item.name) for item in Tag.objects.all()] |
|
||||||
form.fields['city'].choices = [(item.id, item.name) for item in City.objects.filter(country=request.POST['country'])] |
|
||||||
|
|
||||||
if form.is_valid(): |
|
||||||
form.save() |
|
||||||
return HttpResponseRedirect('/admin/exposition/all/') |
|
||||||
else: |
|
||||||
form = ExpositionCreateForm(initial={'key': key}) |
|
||||||
|
|
||||||
args = {} |
|
||||||
args.update(csrf(request)) |
|
||||||
|
|
||||||
args['form'] = form |
|
||||||
args['file_form'] = file_form |
|
||||||
args['files'] = TmpFile.objects.filter(key=key) |
|
||||||
args['languages'] = settings.LANGUAGES |
|
||||||
return render_to_response('exposition_add.html', args) |
|
||||||
|
|
||||||
|
|
||||||
def exposition_delete(request, url): |
|
||||||
return delete_object(request, Exposition, ExpositionDeleteForm, url, '/admin/exposition/all') |
|
||||||
|
|
||||||
|
|
||||||
@login_required |
|
||||||
def exposition_change(request, url): |
|
||||||
""" |
|
||||||
Return form of exposition and fill it with existing Exposition object data. |
|
||||||
|
|
||||||
If form of exposition is posted redirect on the page of all expositions. |
|
||||||
|
|
||||||
""" |
|
||||||
try: |
|
||||||
#check if exposition_id exists else redirect to the list of expositions |
|
||||||
exposition = Exposition.objects.get(url=url) |
|
||||||
file_form = FileModelForm(initial={'model': 'exposition.Exposition'}) |
|
||||||
except: |
|
||||||
return HttpResponseRedirect('/admin/exposition/all/') |
|
||||||
|
|
||||||
if request.POST: |
|
||||||
form = ExpositionChangeForm(request.POST) |
|
||||||
#set choices filled by ajax |
|
||||||
form.fields['tag'].choices = [(item.id, item.name) for item in Tag.objects.all()] |
|
||||||
form.fields['city'].choices = [(item.id, item.name) for item in City.objects.filter(country=request.POST['country'])] |
|
||||||
|
|
||||||
if form.is_valid(): |
|
||||||
form.save(getattr(exposition, 'id')) |
|
||||||
return HttpResponseRedirect('/admin/exposition/all/') |
|
||||||
else: |
|
||||||
#fill form with data from database |
|
||||||
data = {'web_page':exposition.web_page, 'foundation_year': exposition.foundation_year, |
|
||||||
'data_begin':exposition.data_begin, 'data_end':exposition.data_end, 'periodic':exposition.periodic, |
|
||||||
'audience':exposition.audience, 'min_area':exposition.min_area, 'currency':exposition.currency, |
|
||||||
'tax':exposition.tax, 'min_closed_area':exposition.min_closed_area, |
|
||||||
'max_closed_area':exposition.max_closed_area, 'min_closed_equipped_area':exposition.min_closed_equipped_area, |
|
||||||
'max_closed_equipped_area':exposition.max_closed_equipped_area, |
|
||||||
'min_open_area':exposition.min_open_area, 'max_open_area':exposition.max_open_area, |
|
||||||
'registration_payment':exposition.registration_payment, 'exposition_id':exposition.id} |
|
||||||
|
|
||||||
if exposition.country: |
|
||||||
data['country'] = exposition.country.id |
|
||||||
|
|
||||||
if exposition.city: |
|
||||||
data['city'] = exposition.city.id |
|
||||||
|
|
||||||
if exposition.place: |
|
||||||
data['place'] = exposition.place.id |
|
||||||
|
|
||||||
data['theme'] = [item.id for item in exposition.theme.all()] |
|
||||||
data['tag'] = [item.id for item in exposition.tag.all()] |
|
||||||
#data from translated fields |
|
||||||
for code, name in settings.LANGUAGES: |
|
||||||
obj = Exposition._meta.translations_model.objects.get(language_code = code,master__id=getattr(exposition, 'id')) #access to translated fields |
|
||||||
data['name_%s' % code] = obj.name |
|
||||||
data['description_%s' % code] = obj.description |
|
||||||
data['main_title_%s' % code] = obj.main_title |
|
||||||
data['time_%s' % code] = obj.time |
|
||||||
data['products_%s' % code] = obj.products |
|
||||||
data['title_%s' % code] = obj.title |
|
||||||
data['keywords_%s' % code] = obj.keywords |
|
||||||
data['descriptions_%s' % code] = obj.descriptions |
|
||||||
#initial form |
|
||||||
form = ExpositionChangeForm(initial=data) |
|
||||||
#set choices filled by ajax |
|
||||||
form.fields['city'].choices = [(item.id, item.name) for item in City.objects.filter(country=data['country'])] |
|
||||||
form.fields['tag'].choices = [(item.id, item.name) for item in Tag.objects.filter(theme__in=data['theme'])] |
|
||||||
|
|
||||||
args = {} |
|
||||||
args.update(csrf(request)) |
|
||||||
|
|
||||||
args['form'] = form |
|
||||||
args['languages'] = settings.LANGUAGES |
|
||||||
args['file_form'] = file_form |
|
||||||
|
|
||||||
#get list of files which connected with specific model object |
|
||||||
args['files'] = FileModel.objects.filter(content_type=ContentType.objects.get_for_model(exposition), |
|
||||||
object_id=getattr(exposition, 'id')) |
|
||||||
args['obj_id'] = getattr(exposition, 'id') |
|
||||||
|
|
||||||
return render_to_response('exposition_add.html', args) |
|
||||||
@ -1,13 +0,0 @@ |
|||||||
# -*- coding: utf-8 -*- |
|
||||||
from django.contrib import admin |
|
||||||
from hvad.admin import TranslatableAdmin |
|
||||||
from models import FileModel, TmpFile |
|
||||||
|
|
||||||
class FileModelAdmin(TranslatableAdmin): |
|
||||||
pass |
|
||||||
|
|
||||||
class TmpFileAdmin(TranslatableAdmin): |
|
||||||
pass |
|
||||||
|
|
||||||
admin.site.register(FileModel, FileModelAdmin) |
|
||||||
admin.site.register(TmpFile, TmpFileAdmin) |
|
||||||
@ -0,0 +1,13 @@ |
|||||||
|
# -*- coding: utf-8 -*- |
||||||
|
from django.contrib import admin |
||||||
|
from hvad.admin import TranslatableAdmin |
||||||
|
from models import FileModel, TmpFile |
||||||
|
|
||||||
|
class FileModelAdmin(TranslatableAdmin): |
||||||
|
pass |
||||||
|
|
||||||
|
class TmpFileAdmin(TranslatableAdmin): |
||||||
|
pass |
||||||
|
|
||||||
|
admin.site.register(FileModel, FileModelAdmin) |
||||||
|
admin.site.register(TmpFile, TmpFileAdmin) |
||||||
@ -1,9 +1,163 @@ |
|||||||
# -*- coding: utf-8 -*- |
# -*- coding: utf-8 -*- |
||||||
from django.contrib import admin |
from django.shortcuts import render_to_response |
||||||
from hvad.admin import TranslatableAdmin |
from django.http import HttpResponseRedirect, HttpResponse |
||||||
|
from django.core.context_processors import csrf |
||||||
|
from django.conf import settings |
||||||
|
from django.contrib.contenttypes.models import ContentType |
||||||
|
from django.contrib.auth.decorators import login_required |
||||||
|
from django.db.models.loading import get_model |
||||||
|
import json |
||||||
|
#model and forms |
||||||
from models import News |
from models import News |
||||||
|
from news.forms import NewsForm |
||||||
|
from exposition.models import Exposition |
||||||
|
from conference.models import Conference |
||||||
|
from theme.models import Tag |
||||||
|
from file.models import FileModel, TmpFile |
||||||
|
from file.forms import FileModelForm |
||||||
|
#python |
||||||
|
import random |
||||||
|
#custom views |
||||||
|
from functions.custom_views import objects_list |
||||||
|
|
||||||
class NewsAdmin(TranslatableAdmin): |
|
||||||
pass |
|
||||||
|
|
||||||
admin.site.register(News, NewsAdmin) |
def news_all(request): |
||||||
|
""" |
||||||
|
Return list of all news with pagination |
||||||
|
""" |
||||||
|
return objects_list(request, News, 'news_all.html') |
||||||
|
|
||||||
|
|
||||||
|
@login_required |
||||||
|
def news_add(request): |
||||||
|
""" |
||||||
|
Return form of company and post it on the server. |
||||||
|
If form is posted redirect on the page of all companies. |
||||||
|
""" |
||||||
|
#if form would be not valid key must be same |
||||||
|
if request.POST.get('key'): |
||||||
|
key = request.POST['key'] |
||||||
|
else: |
||||||
|
key = random.getrandbits(128) |
||||||
|
|
||||||
|
file_form = FileModelForm(initial={'key': key}) |
||||||
|
|
||||||
|
if request.POST: |
||||||
|
form = NewsForm(request.POST) |
||||||
|
#set choices filled by ajax |
||||||
|
form.fields['tag'].choices = [(item.id, item.name) for item in Tag.objects.all()] |
||||||
|
|
||||||
|
if request.POST['event'] == 'exposition.Exposition': |
||||||
|
form.fields['event_id'].choices = [(item.id, item.name) for item in Exposition.objects.all()] |
||||||
|
if request.POST['event'] == 'conference.Conference': |
||||||
|
form.fields['event_id'].choices = [(item.id, item.name) for item in Conference.objects.all()] |
||||||
|
|
||||||
|
if form.is_valid(): |
||||||
|
form.save() |
||||||
|
return HttpResponseRedirect('/admin/news/all/') |
||||||
|
else: |
||||||
|
form = NewsForm(initial={'key': key}) |
||||||
|
|
||||||
|
args = {} |
||||||
|
args.update(csrf(request)) |
||||||
|
|
||||||
|
args['form'] = form |
||||||
|
args['languages'] = settings.LANGUAGES |
||||||
|
args['file_form'] = file_form |
||||||
|
args['files'] = TmpFile.objects.filter(key=key) |
||||||
|
|
||||||
|
return render_to_response('news_add.html', args) |
||||||
|
|
||||||
|
@login_required |
||||||
|
def news_change(request, url): |
||||||
|
""" |
||||||
|
Return form and fill it with existing News object data. |
||||||
|
|
||||||
|
If form is posted redirect on the page of all news. |
||||||
|
""" |
||||||
|
try: |
||||||
|
#check if url exists else redirect to the list of seminars |
||||||
|
news = News.objects.get(url=url) |
||||||
|
news_id = getattr(news, 'id') |
||||||
|
file_form = FileModelForm(initial={'model': 'news.News'}) |
||||||
|
except: |
||||||
|
return HttpResponseRedirect('/admin/news/all') |
||||||
|
|
||||||
|
if request.POST: |
||||||
|
form = NewsForm(request.POST) |
||||||
|
#set choices filled by ajax |
||||||
|
form.fields['tag'].choices = [(item.id, item.name) for item in Tag.objects.all()] |
||||||
|
|
||||||
|
if request.POST['event'] == 'exposition.Exposition': |
||||||
|
form.fields['event_id'].choices = [(item.id, item.name) for item in Exposition.objects.all()] |
||||||
|
if request.POST['event'] == 'conference.Conference': |
||||||
|
form.fields['event_id'].choices = [(item.id, item.name) for item in Conference.objects.all()] |
||||||
|
|
||||||
|
if form.is_valid(): |
||||||
|
form.save(news_id) |
||||||
|
return HttpResponseRedirect('/admin/news/all') |
||||||
|
else: |
||||||
|
#fill form with data from database |
||||||
|
data = {'date':news.date, 'type':news.type, 'paid': news.paid} |
||||||
|
|
||||||
|
if news.user: |
||||||
|
data['user'] = news.user.id |
||||||
|
# |
||||||
|
if news.content_type: |
||||||
|
data['event'] = 'conference.Conference' if news.content_type.model=='conference'\ |
||||||
|
else 'exposition.Exposition' |
||||||
|
#if news.content_type.model=='conference': |
||||||
|
# data['event'] = 'conference.Conference' |
||||||
|
#elif news.content_type.model=='exposition': |
||||||
|
# data['event'] = 'exposition.Exposition' |
||||||
|
|
||||||
|
data['event_id'] = news.object_id |
||||||
|
|
||||||
|
data['theme'] = [item.id for item in news.theme.all()] |
||||||
|
data['tag'] = [item.id for item in news.tag.all()] |
||||||
|
#data from translated fields |
||||||
|
for code, name in settings.LANGUAGES: |
||||||
|
obj = News._meta.translations_model.objects.get(language_code = code,master__id=news_id) #access to translated fields |
||||||
|
data['main_title_%s' % code] = obj.main_title |
||||||
|
data['preview_%s' % code] = obj.preview |
||||||
|
data['description_%s' % code] = obj.description |
||||||
|
data['title_%s' % code] = obj.title |
||||||
|
data['keywords_%s' % code] = obj.keywords |
||||||
|
data['descriptions_%s' % code] = obj.descriptions |
||||||
|
|
||||||
|
form = NewsForm(initial=data) |
||||||
|
#set choices filled by ajax |
||||||
|
form.fields['tag'].choices = [(item.id, item.name) for item in Tag.objects.filter(theme__in=data['theme'])] |
||||||
|
if data.get('event'): |
||||||
|
if data['event'] == 'conference.Conference': |
||||||
|
events = [(item.id, item.name) for item in Conference.objects.all()] |
||||||
|
elif data['event'] == 'exposition.Exposition': |
||||||
|
events = [(item.id, item.name) for item in Exposition.objects.all()] |
||||||
|
form.fields['event_id'].choices = events |
||||||
|
|
||||||
|
args = {} |
||||||
|
args.update(csrf(request)) |
||||||
|
|
||||||
|
args['form'] = form |
||||||
|
args['languages'] = settings.LANGUAGES |
||||||
|
args['file_form'] = file_form |
||||||
|
|
||||||
|
#get list of files which connected with specific model object |
||||||
|
args['files'] = FileModel.objects.filter(content_type=ContentType.objects.get_for_model(news), object_id=getattr(news, 'id')) |
||||||
|
args['obj_id'] = news_id |
||||||
|
|
||||||
|
return render_to_response('news_add.html', args) |
||||||
|
|
||||||
|
|
||||||
|
def get_event_id(request): |
||||||
|
""" |
||||||
|
get events(expostions or conferences) |
||||||
|
""" |
||||||
|
|
||||||
|
if request.GET['model'] != 'None': |
||||||
|
Model = get_model(request.GET['model'].split('.')[0], request.GET['model'].split('.')[1]) |
||||||
|
events= Model.objects.all() |
||||||
|
#events = json.dumps([(item.id, item.name) for item in data]) |
||||||
|
return render_to_response('select.html', {'objects': events}) |
||||||
|
else: |
||||||
|
return HttpResponse() |
||||||
|
|||||||
@ -0,0 +1,9 @@ |
|||||||
|
# -*- coding: utf-8 -*- |
||||||
|
from django.contrib import admin |
||||||
|
from hvad.admin import TranslatableAdmin |
||||||
|
from models import News |
||||||
|
|
||||||
|
class NewsAdmin(TranslatableAdmin): |
||||||
|
pass |
||||||
|
|
||||||
|
admin.site.register(News, NewsAdmin) |
||||||
@ -1,163 +0,0 @@ |
|||||||
# -*- coding: utf-8 -*- |
|
||||||
from django.shortcuts import render_to_response |
|
||||||
from django.http import HttpResponseRedirect, HttpResponse |
|
||||||
from django.core.context_processors import csrf |
|
||||||
from django.conf import settings |
|
||||||
from django.contrib.contenttypes.models import ContentType |
|
||||||
from django.contrib.auth.decorators import login_required |
|
||||||
from django.db.models.loading import get_model |
|
||||||
import json |
|
||||||
#model and forms |
|
||||||
from models import News |
|
||||||
from news.forms import NewsForm |
|
||||||
from exposition.models import Exposition |
|
||||||
from conference.models import Conference |
|
||||||
from theme.models import Tag |
|
||||||
from file.models import FileModel, TmpFile |
|
||||||
from file.forms import FileModelForm |
|
||||||
#python |
|
||||||
import random |
|
||||||
#custom views |
|
||||||
from functions.custom_views import objects_list |
|
||||||
|
|
||||||
|
|
||||||
def news_all(request): |
|
||||||
""" |
|
||||||
Return list of all news with pagination |
|
||||||
""" |
|
||||||
return objects_list(request, News, 'news_all.html') |
|
||||||
|
|
||||||
|
|
||||||
@login_required |
|
||||||
def news_add(request): |
|
||||||
""" |
|
||||||
Return form of company and post it on the server. |
|
||||||
If form is posted redirect on the page of all companies. |
|
||||||
""" |
|
||||||
#if form would be not valid key must be same |
|
||||||
if request.POST.get('key'): |
|
||||||
key = request.POST['key'] |
|
||||||
else: |
|
||||||
key = random.getrandbits(128) |
|
||||||
|
|
||||||
file_form = FileModelForm(initial={'key': key}) |
|
||||||
|
|
||||||
if request.POST: |
|
||||||
form = NewsForm(request.POST) |
|
||||||
#set choices filled by ajax |
|
||||||
form.fields['tag'].choices = [(item.id, item.name) for item in Tag.objects.all()] |
|
||||||
|
|
||||||
if request.POST['event'] == 'exposition.Exposition': |
|
||||||
form.fields['event_id'].choices = [(item.id, item.name) for item in Exposition.objects.all()] |
|
||||||
if request.POST['event'] == 'conference.Conference': |
|
||||||
form.fields['event_id'].choices = [(item.id, item.name) for item in Conference.objects.all()] |
|
||||||
|
|
||||||
if form.is_valid(): |
|
||||||
form.save() |
|
||||||
return HttpResponseRedirect('/admin/news/all/') |
|
||||||
else: |
|
||||||
form = NewsForm(initial={'key': key}) |
|
||||||
|
|
||||||
args = {} |
|
||||||
args.update(csrf(request)) |
|
||||||
|
|
||||||
args['form'] = form |
|
||||||
args['languages'] = settings.LANGUAGES |
|
||||||
args['file_form'] = file_form |
|
||||||
args['files'] = TmpFile.objects.filter(key=key) |
|
||||||
|
|
||||||
return render_to_response('news_add.html', args) |
|
||||||
|
|
||||||
@login_required |
|
||||||
def news_change(request, url): |
|
||||||
""" |
|
||||||
Return form and fill it with existing News object data. |
|
||||||
|
|
||||||
If form is posted redirect on the page of all news. |
|
||||||
""" |
|
||||||
try: |
|
||||||
#check if url exists else redirect to the list of seminars |
|
||||||
news = News.objects.get(url=url) |
|
||||||
news_id = getattr(news, 'id') |
|
||||||
file_form = FileModelForm(initial={'model': 'news.News'}) |
|
||||||
except: |
|
||||||
return HttpResponseRedirect('/admin/news/all') |
|
||||||
|
|
||||||
if request.POST: |
|
||||||
form = NewsForm(request.POST) |
|
||||||
#set choices filled by ajax |
|
||||||
form.fields['tag'].choices = [(item.id, item.name) for item in Tag.objects.all()] |
|
||||||
|
|
||||||
if request.POST['event'] == 'exposition.Exposition': |
|
||||||
form.fields['event_id'].choices = [(item.id, item.name) for item in Exposition.objects.all()] |
|
||||||
if request.POST['event'] == 'conference.Conference': |
|
||||||
form.fields['event_id'].choices = [(item.id, item.name) for item in Conference.objects.all()] |
|
||||||
|
|
||||||
if form.is_valid(): |
|
||||||
form.save(news_id) |
|
||||||
return HttpResponseRedirect('/admin/news/all') |
|
||||||
else: |
|
||||||
#fill form with data from database |
|
||||||
data = {'date':news.date, 'type':news.type, 'paid': news.paid} |
|
||||||
|
|
||||||
if news.user: |
|
||||||
data['user'] = news.user.id |
|
||||||
# |
|
||||||
if news.content_type: |
|
||||||
data['event'] = 'conference.Conference' if news.content_type.model=='conference'\ |
|
||||||
else 'exposition.Exposition' |
|
||||||
#if news.content_type.model=='conference': |
|
||||||
# data['event'] = 'conference.Conference' |
|
||||||
#elif news.content_type.model=='exposition': |
|
||||||
# data['event'] = 'exposition.Exposition' |
|
||||||
|
|
||||||
data['event_id'] = news.object_id |
|
||||||
|
|
||||||
data['theme'] = [item.id for item in news.theme.all()] |
|
||||||
data['tag'] = [item.id for item in news.tag.all()] |
|
||||||
#data from translated fields |
|
||||||
for code, name in settings.LANGUAGES: |
|
||||||
obj = News._meta.translations_model.objects.get(language_code = code,master__id=news_id) #access to translated fields |
|
||||||
data['main_title_%s' % code] = obj.main_title |
|
||||||
data['preview_%s' % code] = obj.preview |
|
||||||
data['description_%s' % code] = obj.description |
|
||||||
data['title_%s' % code] = obj.title |
|
||||||
data['keywords_%s' % code] = obj.keywords |
|
||||||
data['descriptions_%s' % code] = obj.descriptions |
|
||||||
|
|
||||||
form = NewsForm(initial=data) |
|
||||||
#set choices filled by ajax |
|
||||||
form.fields['tag'].choices = [(item.id, item.name) for item in Tag.objects.filter(theme__in=data['theme'])] |
|
||||||
if data.get('event'): |
|
||||||
if data['event'] == 'conference.Conference': |
|
||||||
events = [(item.id, item.name) for item in Conference.objects.all()] |
|
||||||
elif data['event'] == 'exposition.Exposition': |
|
||||||
events = [(item.id, item.name) for item in Exposition.objects.all()] |
|
||||||
form.fields['event_id'].choices = events |
|
||||||
|
|
||||||
args = {} |
|
||||||
args.update(csrf(request)) |
|
||||||
|
|
||||||
args['form'] = form |
|
||||||
args['languages'] = settings.LANGUAGES |
|
||||||
args['file_form'] = file_form |
|
||||||
|
|
||||||
#get list of files which connected with specific model object |
|
||||||
args['files'] = FileModel.objects.filter(content_type=ContentType.objects.get_for_model(news), object_id=getattr(news, 'id')) |
|
||||||
args['obj_id'] = news_id |
|
||||||
|
|
||||||
return render_to_response('news_add.html', args) |
|
||||||
|
|
||||||
|
|
||||||
def get_event_id(request): |
|
||||||
""" |
|
||||||
get events(expostions or conferences) |
|
||||||
""" |
|
||||||
|
|
||||||
if request.GET['model'] != 'None': |
|
||||||
Model = get_model(request.GET['model'].split('.')[0], request.GET['model'].split('.')[1]) |
|
||||||
events= Model.objects.all() |
|
||||||
#events = json.dumps([(item.id, item.name) for item in data]) |
|
||||||
return render_to_response('select.html', {'objects': events}) |
|
||||||
else: |
|
||||||
return HttpResponse() |
|
||||||
@ -1,9 +1,117 @@ |
|||||||
# -*- coding: utf-8 -*- |
# -*- coding: utf-8 -*- |
||||||
from django.contrib import admin |
from django.shortcuts import render_to_response |
||||||
from hvad.admin import TranslatableAdmin |
from django.http import HttpResponseRedirect, HttpResponse |
||||||
|
from django.core.context_processors import csrf |
||||||
|
from django.conf import settings |
||||||
|
from django.contrib.contenttypes.models import ContentType |
||||||
|
from django.contrib.auth.decorators import login_required |
||||||
|
#models and forms |
||||||
from models import Organiser |
from models import Organiser |
||||||
|
from accounts.models import User |
||||||
|
from city.models import City |
||||||
|
from theme.models import Tag |
||||||
|
from forms import OrganiserForm |
||||||
|
from file.models import FileModel, TmpFile |
||||||
|
from file.forms import FileModelForm |
||||||
|
#python |
||||||
|
import random |
||||||
|
#custom functions |
||||||
|
from functions.custom_views import objects_list, add_object_with_file |
||||||
|
|
||||||
class OrganiserAdmin(TranslatableAdmin): |
|
||||||
pass |
|
||||||
|
|
||||||
admin.site.register(Organiser, OrganiserAdmin) |
def organiser_all(request): |
||||||
|
""" |
||||||
|
Return list of all organisers with pagination |
||||||
|
""" |
||||||
|
return objects_list(request, Organiser, 'organiser_all.html') |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def organiser_add(request): |
||||||
|
""" |
||||||
|
Return form of organiser and post it on the server. |
||||||
|
If form is posted redirect on the page of all organiser. |
||||||
|
""" |
||||||
|
return add_object_with_file(request, OrganiserForm, 'organiser_add.html', '/admin/organiser/all/', |
||||||
|
choices={'city': City, 'tag': Tag}) |
||||||
|
|
||||||
|
|
||||||
|
def organiser_change(request, url): |
||||||
|
""" |
||||||
|
Return form and fill it with existing Organiser object data. |
||||||
|
|
||||||
|
If form is posted redirect on the page of all organisers. |
||||||
|
""" |
||||||
|
organiser = Organiser.objects.safe_get(url=url) |
||||||
|
# try get user by id if doesnt work by url |
||||||
|
if organiser is None: |
||||||
|
organiser = Organiser.objects.safe_get(id=url) |
||||||
|
#redirect to list of all organisers if cannot find organiser |
||||||
|
if organiser is None: |
||||||
|
return HttpResponseRedirect('/admin/organiser/all/') |
||||||
|
#get id |
||||||
|
organiser_id = getattr(organiser, 'id') |
||||||
|
#init FileModelForm |
||||||
|
file_form = FileModelForm(initial={'model': 'organiser.Organiser'}) |
||||||
|
|
||||||
|
if request.POST: |
||||||
|
form = OrganiserForm(request.POST) |
||||||
|
#set choices filled by ajax |
||||||
|
form.fields['tag'].choices = [(item.id, item.name) for item in Tag.objects.all()] |
||||||
|
form.fields['city'].choices = [(item.id, item.name) for item in City.objects.filter(country=request.POST['country'])] |
||||||
|
|
||||||
|
if form.is_valid(): |
||||||
|
form.save(id=organiser_id) |
||||||
|
return HttpResponseRedirect('/admin/organiser/all/') |
||||||
|
else: |
||||||
|
#fill form with data from database |
||||||
|
data = {'staff_number':organiser.staff_number, 'address': organiser.address, |
||||||
|
'events_number':organiser.events_number, 'phone':organiser.phone, |
||||||
|
'fax':organiser.fax, 'web_page':organiser.web_page, 'url':organiser.url, |
||||||
|
'email':organiser.email, 'social':organiser.social, 'foundation': organiser.foundation} |
||||||
|
|
||||||
|
data['user'] = User.objects.safe_get(organiser=organiser) |
||||||
|
|
||||||
|
if organiser.country: |
||||||
|
data['country'] = organiser.country.id |
||||||
|
|
||||||
|
if organiser.city: |
||||||
|
data['city'] = organiser.city.id |
||||||
|
|
||||||
|
data['theme'] = [item.id for item in organiser.theme.all()] |
||||||
|
data['tag'] = [item.id for item in organiser.tag.all()] |
||||||
|
data['place_exposition'] = [item.id for item in organiser.place_exposition.all()] |
||||||
|
data['place_conference'] = [item.id for item in organiser.place_conference.all()] |
||||||
|
#data from translated fields |
||||||
|
|
||||||
|
for code, name in settings.LANGUAGES: |
||||||
|
obj = Organiser._meta.translations_model.objects.get(language_code = code,master__id=organiser_id) #access to translated fields |
||||||
|
data['name_%s' % code] = obj.name |
||||||
|
data['description_%s' % code] = obj.description |
||||||
|
data['specialization_%s' % code] = obj.specialization |
||||||
|
data['address_inf_%s' % code] = obj.address_inf |
||||||
|
data['representation_%s' % code] = obj.representation |
||||||
|
data['title_%s' % code] = obj.title |
||||||
|
data['keywords_%s' % code] = obj.keywords |
||||||
|
data['descriptions_%s' % code] = obj.descriptions |
||||||
|
|
||||||
|
#fill form |
||||||
|
form = OrganiserForm(initial=data) |
||||||
|
#set choices filled by ajax |
||||||
|
form.fields['city'].choices = [(item.id, item.name) for item in City.objects.filter(country=data.get('country'))] |
||||||
|
form.fields['tag'].choices = [(item.id, item.name) for item in Tag.objects.filter(theme__in=data.get('theme'))] |
||||||
|
|
||||||
|
args = {} |
||||||
|
args.update(csrf(request)) |
||||||
|
|
||||||
|
args['form'] = form |
||||||
|
args['languages'] = settings.LANGUAGES |
||||||
|
args['file_form'] = file_form |
||||||
|
|
||||||
|
#get list of files which connected with specific model object |
||||||
|
args['files'] = FileModel.objects.filter(content_type=ContentType.objects.get_for_model(organiser), |
||||||
|
object_id=getattr(organiser, 'id')) |
||||||
|
args['obj_id'] = organiser_id |
||||||
|
|
||||||
|
return render_to_response('organiser_add.html', args) |
||||||
@ -0,0 +1,9 @@ |
|||||||
|
# -*- coding: utf-8 -*- |
||||||
|
from django.contrib import admin |
||||||
|
from hvad.admin import TranslatableAdmin |
||||||
|
from models import Organiser |
||||||
|
|
||||||
|
class OrganiserAdmin(TranslatableAdmin): |
||||||
|
pass |
||||||
|
|
||||||
|
admin.site.register(Organiser, OrganiserAdmin) |
||||||
@ -1,8 +1,8 @@ |
|||||||
# -*- coding: utf-8 -*- |
# -*- coding: utf-8 -*- |
||||||
from django.conf.urls import patterns, include, url |
from django.conf.urls import patterns, include, url |
||||||
|
|
||||||
urlpatterns = patterns('organiser.views', |
urlpatterns = patterns('organiser.admin', |
||||||
url(r'^add.*/$', 'organiser_add'), |
url(r'^add.*/$', 'organiser_add'), |
||||||
url(r'^change/(?P<url>.*).*/$', 'organiser_change'), |
url(r'^change/(?P<url>.*).*/$', 'organiser_change'), |
||||||
url(r'^all/$', 'organiser_all'), |
url(r'^all/$', 'organiser_all'), |
||||||
) |
) |
||||||
|
|||||||
@ -1,117 +0,0 @@ |
|||||||
# -*- coding: utf-8 -*- |
|
||||||
from django.shortcuts import render_to_response |
|
||||||
from django.http import HttpResponseRedirect, HttpResponse |
|
||||||
from django.core.context_processors import csrf |
|
||||||
from django.conf import settings |
|
||||||
from django.contrib.contenttypes.models import ContentType |
|
||||||
from django.contrib.auth.decorators import login_required |
|
||||||
#models and forms |
|
||||||
from models import Organiser |
|
||||||
from accounts.models import User |
|
||||||
from city.models import City |
|
||||||
from theme.models import Tag |
|
||||||
from forms import OrganiserForm |
|
||||||
from file.models import FileModel, TmpFile |
|
||||||
from file.forms import FileModelForm |
|
||||||
#python |
|
||||||
import random |
|
||||||
#custom functions |
|
||||||
from functions.custom_views import objects_list, add_object_with_file |
|
||||||
|
|
||||||
|
|
||||||
def organiser_all(request): |
|
||||||
""" |
|
||||||
Return list of all organisers with pagination |
|
||||||
""" |
|
||||||
return objects_list(request, Organiser, 'organiser_all.html') |
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def organiser_add(request): |
|
||||||
""" |
|
||||||
Return form of organiser and post it on the server. |
|
||||||
If form is posted redirect on the page of all organiser. |
|
||||||
""" |
|
||||||
return add_object_with_file(request, OrganiserForm, 'organiser_add.html', '/admin/organiser/all/', |
|
||||||
choices={'city': City, 'tag': Tag}) |
|
||||||
|
|
||||||
|
|
||||||
def organiser_change(request, url): |
|
||||||
""" |
|
||||||
Return form and fill it with existing Organiser object data. |
|
||||||
|
|
||||||
If form is posted redirect on the page of all organisers. |
|
||||||
""" |
|
||||||
organiser = Organiser.objects.safe_get(url=url) |
|
||||||
# try get user by id if doesnt work by url |
|
||||||
if organiser is None: |
|
||||||
organiser = Organiser.objects.safe_get(id=url) |
|
||||||
#redirect to list of all organisers if cannot find organiser |
|
||||||
if organiser is None: |
|
||||||
return HttpResponseRedirect('/admin/organiser/all/') |
|
||||||
#get id |
|
||||||
organiser_id = getattr(organiser, 'id') |
|
||||||
#init FileModelForm |
|
||||||
file_form = FileModelForm(initial={'model': 'organiser.Organiser'}) |
|
||||||
|
|
||||||
if request.POST: |
|
||||||
form = OrganiserForm(request.POST) |
|
||||||
#set choices filled by ajax |
|
||||||
form.fields['tag'].choices = [(item.id, item.name) for item in Tag.objects.all()] |
|
||||||
form.fields['city'].choices = [(item.id, item.name) for item in City.objects.filter(country=request.POST['country'])] |
|
||||||
|
|
||||||
if form.is_valid(): |
|
||||||
form.save(id=organiser_id) |
|
||||||
return HttpResponseRedirect('/admin/organiser/all/') |
|
||||||
else: |
|
||||||
#fill form with data from database |
|
||||||
data = {'staff_number':organiser.staff_number, 'address': organiser.address, |
|
||||||
'events_number':organiser.events_number, 'phone':organiser.phone, |
|
||||||
'fax':organiser.fax, 'web_page':organiser.web_page, 'url':organiser.url, |
|
||||||
'email':organiser.email, 'social':organiser.social, 'foundation': organiser.foundation} |
|
||||||
|
|
||||||
data['user'] = User.objects.safe_get(organiser=organiser) |
|
||||||
|
|
||||||
if organiser.country: |
|
||||||
data['country'] = organiser.country.id |
|
||||||
|
|
||||||
if organiser.city: |
|
||||||
data['city'] = organiser.city.id |
|
||||||
|
|
||||||
data['theme'] = [item.id for item in organiser.theme.all()] |
|
||||||
data['tag'] = [item.id for item in organiser.tag.all()] |
|
||||||
data['place_exposition'] = [item.id for item in organiser.place_exposition.all()] |
|
||||||
data['place_conference'] = [item.id for item in organiser.place_conference.all()] |
|
||||||
#data from translated fields |
|
||||||
|
|
||||||
for code, name in settings.LANGUAGES: |
|
||||||
obj = Organiser._meta.translations_model.objects.get(language_code = code,master__id=organiser_id) #access to translated fields |
|
||||||
data['name_%s' % code] = obj.name |
|
||||||
data['description_%s' % code] = obj.description |
|
||||||
data['specialization_%s' % code] = obj.specialization |
|
||||||
data['address_inf_%s' % code] = obj.address_inf |
|
||||||
data['representation_%s' % code] = obj.representation |
|
||||||
data['title_%s' % code] = obj.title |
|
||||||
data['keywords_%s' % code] = obj.keywords |
|
||||||
data['descriptions_%s' % code] = obj.descriptions |
|
||||||
|
|
||||||
#fill form |
|
||||||
form = OrganiserForm(initial=data) |
|
||||||
#set choices filled by ajax |
|
||||||
form.fields['city'].choices = [(item.id, item.name) for item in City.objects.filter(country=data.get('country'))] |
|
||||||
form.fields['tag'].choices = [(item.id, item.name) for item in Tag.objects.filter(theme__in=data.get('theme'))] |
|
||||||
|
|
||||||
args = {} |
|
||||||
args.update(csrf(request)) |
|
||||||
|
|
||||||
args['form'] = form |
|
||||||
args['languages'] = settings.LANGUAGES |
|
||||||
args['file_form'] = file_form |
|
||||||
|
|
||||||
#get list of files which connected with specific model object |
|
||||||
args['files'] = FileModel.objects.filter(content_type=ContentType.objects.get_for_model(organiser), |
|
||||||
object_id=getattr(organiser, 'id')) |
|
||||||
args['obj_id'] = organiser_id |
|
||||||
|
|
||||||
return render_to_response('organiser_add.html', args) |
|
||||||
@ -1,10 +1,170 @@ |
|||||||
# -*- coding: utf-8 -*- |
# -*- coding: utf-8 -*- |
||||||
from django.contrib import admin |
from django.shortcuts import render_to_response |
||||||
from hvad.admin import TranslatableAdmin |
from django.http import HttpResponseRedirect, HttpResponse |
||||||
from models import PlaceConference |
from django.core.context_processors import csrf |
||||||
|
from django.conf import settings |
||||||
|
from django.forms.formsets import formset_factory |
||||||
|
from django.forms.models import modelformset_factory |
||||||
|
|
||||||
class PlaceConferenceAdmin(TranslatableAdmin): |
from django.contrib.auth.decorators import login_required |
||||||
pass |
from django.contrib.contenttypes.models import ContentType |
||||||
|
#models and forms |
||||||
|
from forms import * |
||||||
|
from models import PlaceConference, Hall |
||||||
|
from city.models import City |
||||||
|
from file.models import FileModel, TmpFile |
||||||
|
from file.forms import FileModelForm |
||||||
|
#python |
||||||
|
import random |
||||||
|
#custom views |
||||||
|
from functions.custom_views import objects_list, delete_object |
||||||
|
|
||||||
admin.site.register(PlaceConference, PlaceConferenceAdmin) |
|
||||||
|
|
||||||
|
def conference_all(request): |
||||||
|
""" |
||||||
|
Return list of all place_conferences with pagination |
||||||
|
""" |
||||||
|
return objects_list(request, PlaceConference, 'place_conference_all.html') |
||||||
|
|
||||||
|
|
||||||
|
# http://stackoverflow.com/questions/2406537/django-formsets-make-first-required/4951032#4951032 |
||||||
|
@login_required |
||||||
|
def conference_add(request): |
||||||
|
""" |
||||||
|
Returns form of place_conference and formset of halls and post it on the server. |
||||||
|
|
||||||
|
If forms is posted redirect on the page of all place_conferences. |
||||||
|
""" |
||||||
|
|
||||||
|
#formset of HallForm |
||||||
|
HallFormSet = formset_factory(HallForm) |
||||||
|
if request.POST.get('key'): |
||||||
|
key = request.POST['key'] |
||||||
|
else: |
||||||
|
key = random.getrandbits(128) |
||||||
|
|
||||||
|
file_form = FileModelForm(initial={'key': key}) |
||||||
|
|
||||||
|
if request.POST: |
||||||
|
form = ConferenceForm(request.POST) |
||||||
|
#set choices filled by ajax |
||||||
|
form.fields['city'].choices = [(item.id, item.name) for item in City.objects.filter(country=request.POST['country'])] |
||||||
|
|
||||||
|
formset = HallFormSet(request.POST) |
||||||
|
|
||||||
|
if form.is_valid() and formset.is_valid(): |
||||||
|
place_conference = form.save() |
||||||
|
|
||||||
|
for item in formset.forms: |
||||||
|
#saves forms if its valid and not empty |
||||||
|
if item.is_valid() and item.has_changed(): |
||||||
|
hall = item.save(commit=False) |
||||||
|
hall.place_conference = place_conference |
||||||
|
hall.save() |
||||||
|
|
||||||
|
return HttpResponseRedirect ('/admin/place_conference/all') |
||||||
|
else: |
||||||
|
form = ConferenceForm(initial={'key': key}) |
||||||
|
formset = HallFormSet() |
||||||
|
|
||||||
|
args = {} |
||||||
|
args.update(csrf(request)) |
||||||
|
|
||||||
|
args['languages'] = settings.LANGUAGES |
||||||
|
args['form'] = form |
||||||
|
args['formset'] = formset |
||||||
|
args['file_form'] = file_form |
||||||
|
args['files'] = TmpFile.objects.filter(key=key) |
||||||
|
|
||||||
|
|
||||||
|
return render_to_response('place_conference_add.html', args) |
||||||
|
|
||||||
|
|
||||||
|
def conference_delete(request, url): |
||||||
|
return delete_object(request, PlaceConference, PlaceConferenceFormDelete, url, '/admin/place_conference/all') |
||||||
|
|
||||||
|
|
||||||
|
@login_required |
||||||
|
def conference_change(request, url): |
||||||
|
""" |
||||||
|
Return form of place_conference and formset of halls and fill it with existing PlaceConference and Hall object data. |
||||||
|
|
||||||
|
If form of conference is posted redirect on the page of all conferences. |
||||||
|
|
||||||
|
""" |
||||||
|
try: |
||||||
|
#check if conference_id exists else redirect to the list of place of conference |
||||||
|
place = PlaceConference.objects.get(url=url) |
||||||
|
file_form = FileModelForm(initial={'model': 'place_conference.PlaceConference'}) |
||||||
|
except: |
||||||
|
return HttpResponseRedirect('/admin/place_conference/all') |
||||||
|
|
||||||
|
if request.POST: |
||||||
|
#formset of HallForm |
||||||
|
HallFormSet = formset_factory(HallForm) |
||||||
|
form = ConferenceForm(request.POST) |
||||||
|
#set choices filled by ajax |
||||||
|
form.fields['city'].choices = [(item.id, item.name) for item in City.objects.filter(country=request.POST['country'])] |
||||||
|
formset = HallFormSet(request.POST) |
||||||
|
|
||||||
|
if form.is_valid() and formset.is_valid(): |
||||||
|
place_conference = form.save(getattr(place, 'id')) |
||||||
|
#delete old halls |
||||||
|
Hall.objects.filter(place_conference=getattr(place, 'id')).delete() |
||||||
|
for item in formset.forms: |
||||||
|
#saves new halls if its valid and not empty |
||||||
|
if item.is_valid() and item.has_changed(): |
||||||
|
hall = item.save(commit=False) |
||||||
|
hall.place_conference = place_conference |
||||||
|
hall.save() |
||||||
|
|
||||||
|
return HttpResponseRedirect('/admin/place_conference/all') |
||||||
|
else: |
||||||
|
#initial HallFormSet |
||||||
|
HallFormSet = modelformset_factory(Hall, form=HallForm, exclude=('place_conference',)) |
||||||
|
#fill form with data from database |
||||||
|
data = {'type': place.type, 'address': place.address, |
||||||
|
'phone': place.phone, 'fax': place.fax, 'web_page': place.web_page, 'email': place.email, |
||||||
|
'total_capacity': place.total_capacity, 'amount_halls': place.amount_halls, |
||||||
|
'exposition_hall': place.exposition_hall, 'exp_hall_area': place.exp_hall_area, |
||||||
|
'wifi': place.wifi, 'multimedia_equipment': place.multimedia_equipment, 'conference_call':place.conference_call, |
||||||
|
'translate_equipment': place.translate_equipment, 'banquet_hall': place.banquet_hall, |
||||||
|
'catering': place.catering, 'hotel': place.hotel, 'place_conference_id':place.id} |
||||||
|
|
||||||
|
if place.country: |
||||||
|
data['country'] = place.country.id |
||||||
|
if place.city: |
||||||
|
data['city'] = place.city.id |
||||||
|
#data from translated fields |
||||||
|
for code, name in settings.LANGUAGES: |
||||||
|
obj = PlaceConference._meta.translations_model.objects.get(language_code = code,master__id=getattr(place, 'id')) #access to translated fields |
||||||
|
data['name_%s'%code] = obj.name |
||||||
|
data['description_%s'%code] = obj.description |
||||||
|
data['adress_%s'%code] = obj.adress |
||||||
|
data['hall_capacity_%s'%code] = obj.hall_capacity |
||||||
|
data['title_%s'%code] = obj.title |
||||||
|
data['keywords_%s'%code] = obj.keywords |
||||||
|
data['descriptions_%s'%code] = obj.descriptions |
||||||
|
|
||||||
|
form = ConferenceForm(initial=data) |
||||||
|
#set choices filled by ajax |
||||||
|
form.fields['city'].choices = [(item.id, item.name) for item in City.objects.filter(country=data['country'])] |
||||||
|
#get existing halls |
||||||
|
halls = Hall.objects.filter(place_conference=getattr(place, 'id')) |
||||||
|
#fill HallFormSet |
||||||
|
formset = HallFormSet(queryset=halls) |
||||||
|
|
||||||
|
args = {} |
||||||
|
args.update(csrf(request)) |
||||||
|
args['languages'] = settings.LANGUAGES |
||||||
|
args['form'] = form |
||||||
|
args['formset'] = formset |
||||||
|
args['file_form'] = file_form |
||||||
|
|
||||||
|
#get list of files which connected with specific model object |
||||||
|
args['files'] = FileModel.objects.filter(content_type=ContentType.objects.get_for_model(place), |
||||||
|
object_id=getattr(place, 'id')) |
||||||
|
args['obj_id'] = getattr(place, 'id') |
||||||
|
|
||||||
|
|
||||||
|
return render_to_response('place_conference_add.html', args) |
||||||
@ -0,0 +1,10 @@ |
|||||||
|
# -*- coding: utf-8 -*- |
||||||
|
from django.contrib import admin |
||||||
|
from hvad.admin import TranslatableAdmin |
||||||
|
from models import PlaceConference |
||||||
|
|
||||||
|
class PlaceConferenceAdmin(TranslatableAdmin): |
||||||
|
pass |
||||||
|
|
||||||
|
admin.site.register(PlaceConference, PlaceConferenceAdmin) |
||||||
|
|
||||||
@ -1,9 +1,9 @@ |
|||||||
# -*- coding: utf-8 -*- |
# -*- coding: utf-8 -*- |
||||||
from django.conf.urls import patterns, include, url |
from django.conf.urls import patterns, include, url |
||||||
|
|
||||||
urlpatterns = patterns('place_conference.views', |
urlpatterns = patterns('place_conference.admin', |
||||||
url(r'^add.*/$', 'conference_add'), |
url(r'^add.*/$', 'conference_add'), |
||||||
url(r'^delete/(?P<url>.*)/$', 'conference_delete'), |
url(r'^delete/(?P<url>.*)/$', 'conference_delete'), |
||||||
url(r'^change/(?P<url>.*)/$', 'conference_change'), |
url(r'^change/(?P<url>.*)/$', 'conference_change'), |
||||||
url(r'^all/$', 'conference_all'), |
url(r'^all/$', 'conference_all'), |
||||||
) |
) |
||||||
|
|||||||
@ -1,169 +0,0 @@ |
|||||||
# -*- coding: utf-8 -*- |
|
||||||
from django.shortcuts import render_to_response |
|
||||||
from django.http import HttpResponseRedirect |
|
||||||
from django.core.context_processors import csrf |
|
||||||
from django.conf import settings |
|
||||||
from django.forms.formsets import formset_factory |
|
||||||
from django.forms.models import modelformset_factory |
|
||||||
|
|
||||||
from django.contrib.auth.decorators import login_required |
|
||||||
from django.contrib.contenttypes.models import ContentType |
|
||||||
#models and forms |
|
||||||
from forms import * |
|
||||||
from models import PlaceConference, Hall |
|
||||||
from city.models import City |
|
||||||
from file.models import FileModel, TmpFile |
|
||||||
from file.forms import FileModelForm |
|
||||||
#python |
|
||||||
import random |
|
||||||
#custom views |
|
||||||
from functions.custom_views import objects_list, delete_object |
|
||||||
|
|
||||||
|
|
||||||
def conference_all(request): |
|
||||||
""" |
|
||||||
Return list of all place_conferences with pagination |
|
||||||
""" |
|
||||||
return objects_list(request, PlaceConference, 'place_conference_all.html') |
|
||||||
|
|
||||||
|
|
||||||
# http://stackoverflow.com/questions/2406537/django-formsets-make-first-required/4951032#4951032 |
|
||||||
@login_required |
|
||||||
def conference_add(request): |
|
||||||
""" |
|
||||||
Returns form of place_conference and formset of halls and post it on the server. |
|
||||||
|
|
||||||
If forms is posted redirect on the page of all place_conferences. |
|
||||||
""" |
|
||||||
|
|
||||||
#formset of HallForm |
|
||||||
HallFormSet = formset_factory(HallForm) |
|
||||||
if request.POST.get('key'): |
|
||||||
key = request.POST['key'] |
|
||||||
else: |
|
||||||
key = random.getrandbits(128) |
|
||||||
|
|
||||||
file_form = FileModelForm(initial={'key': key}) |
|
||||||
|
|
||||||
if request.POST: |
|
||||||
form = ConferenceForm(request.POST) |
|
||||||
#set choices filled by ajax |
|
||||||
form.fields['city'].choices = [(item.id, item.name) for item in City.objects.filter(country=request.POST['country'])] |
|
||||||
|
|
||||||
formset = HallFormSet(request.POST) |
|
||||||
|
|
||||||
if form.is_valid() and formset.is_valid(): |
|
||||||
place_conference = form.save() |
|
||||||
|
|
||||||
for item in formset.forms: |
|
||||||
#saves forms if its valid and not empty |
|
||||||
if item.is_valid() and item.has_changed(): |
|
||||||
hall = item.save(commit=False) |
|
||||||
hall.place_conference = place_conference |
|
||||||
hall.save() |
|
||||||
|
|
||||||
return HttpResponseRedirect ('/admin/place_conference/all') |
|
||||||
else: |
|
||||||
form = ConferenceForm(initial={'key': key}) |
|
||||||
formset = HallFormSet() |
|
||||||
|
|
||||||
args = {} |
|
||||||
args.update(csrf(request)) |
|
||||||
|
|
||||||
args['languages'] = settings.LANGUAGES |
|
||||||
args['form'] = form |
|
||||||
args['formset'] = formset |
|
||||||
args['file_form'] = file_form |
|
||||||
args['files'] = TmpFile.objects.filter(key=key) |
|
||||||
|
|
||||||
return render_to_response('place_conference_add.html', args) |
|
||||||
|
|
||||||
|
|
||||||
def conference_delete(request, url): |
|
||||||
return delete_object(request, PlaceConference, PlaceConferenceFormDelete, url, '/admin/place_conference/all') |
|
||||||
|
|
||||||
|
|
||||||
@login_required |
|
||||||
def conference_change(request, url): |
|
||||||
""" |
|
||||||
Return form of place_conference and formset of halls and fill it with existing PlaceConference and Hall object data. |
|
||||||
|
|
||||||
If form of conference is posted redirect on the page of all conferences. |
|
||||||
|
|
||||||
""" |
|
||||||
try: |
|
||||||
#check if conference_id exists else redirect to the list of place of conference |
|
||||||
place = PlaceConference.objects.get(url=url) |
|
||||||
file_form = FileModelForm(initial={'model': 'place_conference.PlaceConference'}) |
|
||||||
except: |
|
||||||
return HttpResponseRedirect('/admin/place_conference/all') |
|
||||||
|
|
||||||
if request.POST: |
|
||||||
#formset of HallForm |
|
||||||
HallFormSet = formset_factory(HallForm) |
|
||||||
form = ConferenceForm(request.POST) |
|
||||||
#set choices filled by ajax |
|
||||||
form.fields['city'].choices = [(item.id, item.name) for item in City.objects.filter(country=request.POST['country'])] |
|
||||||
formset = HallFormSet(request.POST) |
|
||||||
|
|
||||||
if form.is_valid() and formset.is_valid(): |
|
||||||
place_conference = form.save(getattr(place, 'id')) |
|
||||||
#delete old halls |
|
||||||
Hall.objects.filter(place_conference=getattr(place, 'id')).delete() |
|
||||||
for item in formset.forms: |
|
||||||
#saves new halls if its valid and not empty |
|
||||||
if item.is_valid() and item.has_changed(): |
|
||||||
hall = item.save(commit=False) |
|
||||||
hall.place_conference = place_conference |
|
||||||
hall.save() |
|
||||||
|
|
||||||
return HttpResponseRedirect('/admin/place_conference/all') |
|
||||||
else: |
|
||||||
#initial HallFormSet |
|
||||||
HallFormSet = modelformset_factory(Hall, form=HallForm, exclude=('place_conference',)) |
|
||||||
#fill form with data from database |
|
||||||
data = {'type': place.type, 'address': place.address, |
|
||||||
'phone': place.phone, 'fax': place.fax, 'web_page': place.web_page, 'email': place.email, |
|
||||||
'total_capacity': place.total_capacity, 'amount_halls': place.amount_halls, |
|
||||||
'exposition_hall': place.exposition_hall, 'exp_hall_area': place.exp_hall_area, |
|
||||||
'wifi': place.wifi, 'multimedia_equipment': place.multimedia_equipment, 'conference_call':place.conference_call, |
|
||||||
'translate_equipment': place.translate_equipment, 'banquet_hall': place.banquet_hall, |
|
||||||
'catering': place.catering, 'hotel': place.hotel, 'place_conference_id':place.id} |
|
||||||
|
|
||||||
if place.country: |
|
||||||
data['country'] = place.country.id |
|
||||||
if place.city: |
|
||||||
data['city'] = place.city.id |
|
||||||
#data from translated fields |
|
||||||
for code, name in settings.LANGUAGES: |
|
||||||
obj = PlaceConference._meta.translations_model.objects.get(language_code = code,master__id=getattr(place, 'id')) #access to translated fields |
|
||||||
data['name_%s'%code] = obj.name |
|
||||||
data['description_%s'%code] = obj.description |
|
||||||
data['adress_%s'%code] = obj.adress |
|
||||||
data['hall_capacity_%s'%code] = obj.hall_capacity |
|
||||||
data['title_%s'%code] = obj.title |
|
||||||
data['keywords_%s'%code] = obj.keywords |
|
||||||
data['descriptions_%s'%code] = obj.descriptions |
|
||||||
|
|
||||||
form = ConferenceForm(initial=data) |
|
||||||
#set choices filled by ajax |
|
||||||
form.fields['city'].choices = [(item.id, item.name) for item in City.objects.filter(country=data['country'])] |
|
||||||
#get existing halls |
|
||||||
halls = Hall.objects.filter(place_conference=getattr(place, 'id')) |
|
||||||
#fill HallFormSet |
|
||||||
formset = HallFormSet(queryset=halls) |
|
||||||
|
|
||||||
args = {} |
|
||||||
args.update(csrf(request)) |
|
||||||
args['languages'] = settings.LANGUAGES |
|
||||||
args['form'] = form |
|
||||||
args['formset'] = formset |
|
||||||
args['file_form'] = file_form |
|
||||||
|
|
||||||
#get list of files which connected with specific model object |
|
||||||
args['files'] = FileModel.objects.filter(content_type=ContentType.objects.get_for_model(place), |
|
||||||
object_id=getattr(place, 'id')) |
|
||||||
args['obj_id'] = getattr(place, 'id') |
|
||||||
|
|
||||||
|
|
||||||
return render_to_response('place_conference_add.html', args) |
|
||||||
@ -1,9 +1,176 @@ |
|||||||
# -*- coding: utf-8 -*- |
# -*- coding: utf-8 -*- |
||||||
from django.contrib import admin |
from django.shortcuts import render_to_response |
||||||
from hvad.admin import TranslatableAdmin |
from django.http import HttpResponseRedirect |
||||||
from models import PlaceExposition |
from django.core.context_processors import csrf |
||||||
|
from django.conf import settings |
||||||
|
from django.forms.formsets import formset_factory |
||||||
|
from django.forms.models import modelformset_factory |
||||||
|
from django.contrib.contenttypes.models import ContentType |
||||||
|
from django.contrib.auth.decorators import login_required |
||||||
|
from django.forms.formsets import BaseFormSet, formset_factory |
||||||
|
from django.forms.models import modelformset_factory |
||||||
|
#models and forms |
||||||
|
from forms import ExpositionForm, PlaceExpositionFormDelete, HallForm |
||||||
|
from models import PlaceExposition, Hall |
||||||
|
from city.models import City |
||||||
|
from file.models import FileModel, TmpFile |
||||||
|
from file.forms import FileModelForm |
||||||
|
#python |
||||||
|
import random |
||||||
|
#custom fields |
||||||
|
from functions.custom_views import objects_list, delete_object |
||||||
|
|
||||||
class PlaceExpositionAdmin(TranslatableAdmin): |
|
||||||
pass |
|
||||||
|
|
||||||
admin.site.register(PlaceExposition, PlaceExpositionAdmin) |
def exposition_all(request): |
||||||
|
""" |
||||||
|
Return list of all place_expositions with pagination |
||||||
|
""" |
||||||
|
return objects_list(request, PlaceExposition, 'place_exposition_all.html') |
||||||
|
|
||||||
|
|
||||||
|
@login_required |
||||||
|
def exposition_add(request): |
||||||
|
""" |
||||||
|
Returns form of place_exposition and formset of pavilions and post it on the server. |
||||||
|
|
||||||
|
If forms is posted redirect on the page of all place_expositions. |
||||||
|
""" |
||||||
|
#formset of HallForm |
||||||
|
HallFormSet = formset_factory(HallForm) |
||||||
|
if request.POST.get('key'): |
||||||
|
key = request.POST['key'] |
||||||
|
else: |
||||||
|
key = random.getrandbits(128) |
||||||
|
|
||||||
|
file_form = FileModelForm(initial={'key': key}) |
||||||
|
|
||||||
|
if request.POST: |
||||||
|
form = ExpositionForm(request.POST) |
||||||
|
#set choices filled by ajax |
||||||
|
form.fields['city'].choices = [(item.id, item.name) for item in City.objects.filter(country=request.POST['country'])] |
||||||
|
|
||||||
|
formset = HallFormSet(request.POST) |
||||||
|
|
||||||
|
if form.is_valid() and formset.is_valid(): |
||||||
|
place_exposition = form.save() |
||||||
|
|
||||||
|
for item in formset.forms: |
||||||
|
#saves forms if its valid and not empty |
||||||
|
if item.is_valid() and item.has_changed(): |
||||||
|
hall = item.save(commit=False) |
||||||
|
hall.place_exposition = place_exposition |
||||||
|
hall.save() |
||||||
|
|
||||||
|
return HttpResponseRedirect('/admin/place_exposition/all') |
||||||
|
else: |
||||||
|
form = ExpositionForm(initial={'key': key}) |
||||||
|
formset = HallFormSet() |
||||||
|
|
||||||
|
args = {} |
||||||
|
args.update(csrf(request)) |
||||||
|
|
||||||
|
args['languages'] = settings.LANGUAGES |
||||||
|
args['form'] = form |
||||||
|
args['formset'] = formset |
||||||
|
args['file_form'] = file_form |
||||||
|
args['files'] = TmpFile.objects.filter(key=key) |
||||||
|
|
||||||
|
return render_to_response('place_exposition_add.html', args) |
||||||
|
|
||||||
|
|
||||||
|
def exposition_delete(request, url): |
||||||
|
return delete_object(request, PlaceExposition, PlaceExpositionFormDelete, url, '/admin/place_exposition/all') |
||||||
|
|
||||||
|
|
||||||
|
@login_required |
||||||
|
def exposition_change(request, url): |
||||||
|
""" |
||||||
|
Return form of place_expositions and formset of pavilions |
||||||
|
and fill it with existing PlaceExposition and Pavilion object data. |
||||||
|
|
||||||
|
If form of conference is posted redirect on the page of all conferences. |
||||||
|
|
||||||
|
""" |
||||||
|
try: |
||||||
|
#check if exposition_id exists else redirect to the list of place of conference |
||||||
|
place = PlaceExposition.objects.get(url=url) |
||||||
|
exposition_id = getattr(place, 'id') |
||||||
|
file_form = FileModelForm(initial={'model': 'place_exposition.PlaceExposition'}) |
||||||
|
except: |
||||||
|
return HttpResponseRedirect('/admin/place_exposition/all') |
||||||
|
|
||||||
|
if request.POST: |
||||||
|
#formset of HallForm |
||||||
|
HallFormSet = formset_factory(HallForm) |
||||||
|
form = ExpositionForm(request.POST) |
||||||
|
#set choices filled by ajax |
||||||
|
form.fields['city'].choices = [(item.id, item.name) for item in City.objects.filter(country=request.POST['country'])] |
||||||
|
formset = HallFormSet(request.POST) |
||||||
|
|
||||||
|
if form.is_valid() and formset.is_valid(): |
||||||
|
place_exposition = form.save(exposition_id) |
||||||
|
#delete old halls |
||||||
|
Hall.objects.filter(place_exposition=getattr(place, 'id')).delete() |
||||||
|
for item in formset.forms: |
||||||
|
#saves new halls if its valid and not empty |
||||||
|
if item.is_valid() and item.has_changed(): |
||||||
|
hall = item.save(commit=False) |
||||||
|
hall.place_exposition = place_exposition |
||||||
|
hall.save() |
||||||
|
|
||||||
|
return HttpResponseRedirect('/admin/place_exposition/all') |
||||||
|
else: |
||||||
|
#initial HallFormSet |
||||||
|
HallFormSet = modelformset_factory(Hall, form=HallForm, exclude=('place_exposition',)) |
||||||
|
#fill form with data from database |
||||||
|
data= {'type': place.type, 'address': place.address, |
||||||
|
'phone': place.phone, 'fax': place.fax, 'web_page': place.web_page, 'email': place.email, |
||||||
|
'foundation_year': place.foundation_year, 'total_area': place.total_area, |
||||||
|
'closed_area': place.closed_area, 'open_area': place.open_area, |
||||||
|
'total_pavilions': place.total_pavilions, 'total_halls': place.total_halls, 'wifi':place.wifi, |
||||||
|
'bank': place.bank, 'children_room': place.children_room, |
||||||
|
'disabled_service': place.disabled_service, 'conference_centre': place.conference_centre, |
||||||
|
'business_centre': place.business_centre, 'online_registration': place.online_registration, |
||||||
|
'cafe': place.cafe, 'terminals': place.terminals, 'parking': place.parking, |
||||||
|
'press_centre': place.press_centre, 'mobile_application': place.mobile_application, |
||||||
|
'place_exposition_id':place.id} |
||||||
|
|
||||||
|
if place.country: |
||||||
|
data['country'] = place.country.id |
||||||
|
if place.city: |
||||||
|
data['city'] = place.city.id |
||||||
|
#data from translated fields |
||||||
|
for code, name in settings.LANGUAGES: |
||||||
|
obj = PlaceExposition._meta.translations_model.objects.get(language_code = code,master__id=exposition_id) #access to translated fields |
||||||
|
data['name_%s'%code] = obj.name |
||||||
|
data['description_%s'%code] = obj.description |
||||||
|
data['adress_%s'%code] = obj.adress |
||||||
|
data['total_year_action_%s'%code] = obj.total_year_action |
||||||
|
data['title_%s'%code] = obj.title |
||||||
|
data['keywords_%s'%code] = obj.keywords |
||||||
|
data['descriptions_%s'%code] = obj.descriptions |
||||||
|
|
||||||
|
form = ExpositionForm(initial=data) |
||||||
|
#set choices filled by ajax |
||||||
|
form.fields['city'].choices = [(item.id, item.name) for item in City.objects.filter(country=data['country'])] |
||||||
|
#get existing halls |
||||||
|
halls = Hall.objects.filter(place_exposition=getattr(place, 'id')) |
||||||
|
#fill HallFormSet |
||||||
|
formset = HallFormSet(queryset=halls) |
||||||
|
|
||||||
|
|
||||||
|
args = {} |
||||||
|
args.update(csrf(request)) |
||||||
|
|
||||||
|
args['languages'] = settings.LANGUAGES |
||||||
|
args['form'] = form |
||||||
|
args['formset'] = formset |
||||||
|
args['file_form'] = file_form |
||||||
|
|
||||||
|
#get list of files which connected with specific model object |
||||||
|
args['files'] = FileModel.objects.filter(content_type=ContentType.objects.get_for_model(place), |
||||||
|
object_id=getattr(place, 'id')) |
||||||
|
args['obj_id'] = exposition_id |
||||||
|
|
||||||
|
|
||||||
|
return render_to_response('place_exposition_add.html', args) |
||||||
@ -0,0 +1,9 @@ |
|||||||
|
# -*- coding: utf-8 -*- |
||||||
|
from django.contrib import admin |
||||||
|
from hvad.admin import TranslatableAdmin |
||||||
|
from models import PlaceExposition |
||||||
|
|
||||||
|
class PlaceExpositionAdmin(TranslatableAdmin): |
||||||
|
pass |
||||||
|
|
||||||
|
admin.site.register(PlaceExposition, PlaceExpositionAdmin) |
||||||
@ -1,9 +1,9 @@ |
|||||||
# -*- coding: utf-8 -*- |
# -*- coding: utf-8 -*- |
||||||
from django.conf.urls import patterns, include, url |
from django.conf.urls import patterns, include, url |
||||||
|
|
||||||
urlpatterns = patterns('place_exposition.views', |
urlpatterns = patterns('place_exposition.admin', |
||||||
url(r'^add.*/$', 'exposition_add'), |
url(r'^add.*/$', 'exposition_add'), |
||||||
url(r'^delete/(?P<url>.*)/$', 'exposition_delete'), |
url(r'^delete/(?P<url>.*)/$', 'exposition_delete'), |
||||||
url(r'^change/(?P<url>.*)/$', 'exposition_change'), |
url(r'^change/(?P<url>.*)/$', 'exposition_change'), |
||||||
url(r'^all/$', 'exposition_all'), |
url(r'^all/$', 'exposition_all'), |
||||||
) |
) |
||||||
|
|||||||
@ -1,176 +0,0 @@ |
|||||||
# -*- coding: utf-8 -*- |
|
||||||
from django.shortcuts import render_to_response |
|
||||||
from django.http import HttpResponseRedirect |
|
||||||
from django.core.context_processors import csrf |
|
||||||
from django.conf import settings |
|
||||||
from django.forms.formsets import formset_factory |
|
||||||
from django.forms.models import modelformset_factory |
|
||||||
from django.contrib.contenttypes.models import ContentType |
|
||||||
from django.contrib.auth.decorators import login_required |
|
||||||
from django.forms.formsets import BaseFormSet, formset_factory |
|
||||||
from django.forms.models import modelformset_factory |
|
||||||
#models and forms |
|
||||||
from forms import ExpositionForm, PlaceExpositionFormDelete, HallForm |
|
||||||
from models import PlaceExposition, Hall |
|
||||||
from city.models import City |
|
||||||
from file.models import FileModel, TmpFile |
|
||||||
from file.forms import FileModelForm |
|
||||||
#python |
|
||||||
import random |
|
||||||
#custom fields |
|
||||||
from functions.custom_views import objects_list, delete_object |
|
||||||
|
|
||||||
|
|
||||||
def exposition_all(request): |
|
||||||
""" |
|
||||||
Return list of all place_expositions with pagination |
|
||||||
""" |
|
||||||
return objects_list(request, PlaceExposition, 'place_exposition_all.html') |
|
||||||
|
|
||||||
|
|
||||||
@login_required |
|
||||||
def exposition_add(request): |
|
||||||
""" |
|
||||||
Returns form of place_exposition and formset of pavilions and post it on the server. |
|
||||||
|
|
||||||
If forms is posted redirect on the page of all place_expositions. |
|
||||||
""" |
|
||||||
#formset of HallForm |
|
||||||
HallFormSet = formset_factory(HallForm) |
|
||||||
if request.POST.get('key'): |
|
||||||
key = request.POST['key'] |
|
||||||
else: |
|
||||||
key = random.getrandbits(128) |
|
||||||
|
|
||||||
file_form = FileModelForm(initial={'key': key}) |
|
||||||
|
|
||||||
if request.POST: |
|
||||||
form = ExpositionForm(request.POST) |
|
||||||
#set choices filled by ajax |
|
||||||
form.fields['city'].choices = [(item.id, item.name) for item in City.objects.filter(country=request.POST['country'])] |
|
||||||
|
|
||||||
formset = HallFormSet(request.POST) |
|
||||||
|
|
||||||
if form.is_valid() and formset.is_valid(): |
|
||||||
place_exposition = form.save() |
|
||||||
|
|
||||||
for item in formset.forms: |
|
||||||
#saves forms if its valid and not empty |
|
||||||
if item.is_valid() and item.has_changed(): |
|
||||||
hall = item.save(commit=False) |
|
||||||
hall.place_exposition = place_exposition |
|
||||||
hall.save() |
|
||||||
|
|
||||||
return HttpResponseRedirect('/admin/place_exposition/all') |
|
||||||
else: |
|
||||||
form = ExpositionForm(initial={'key': key}) |
|
||||||
formset = HallFormSet() |
|
||||||
|
|
||||||
args = {} |
|
||||||
args.update(csrf(request)) |
|
||||||
|
|
||||||
args['languages'] = settings.LANGUAGES |
|
||||||
args['form'] = form |
|
||||||
args['formset'] = formset |
|
||||||
args['file_form'] = file_form |
|
||||||
args['files'] = TmpFile.objects.filter(key=key) |
|
||||||
|
|
||||||
return render_to_response('place_exposition_add.html', args) |
|
||||||
|
|
||||||
|
|
||||||
def exposition_delete(request, url): |
|
||||||
return delete_object(request, PlaceExposition, PlaceExpositionFormDelete, url, '/admin/place_exposition/all') |
|
||||||
|
|
||||||
|
|
||||||
@login_required |
|
||||||
def exposition_change(request, url): |
|
||||||
""" |
|
||||||
Return form of place_expositions and formset of pavilions |
|
||||||
and fill it with existing PlaceExposition and Pavilion object data. |
|
||||||
|
|
||||||
If form of conference is posted redirect on the page of all conferences. |
|
||||||
|
|
||||||
""" |
|
||||||
try: |
|
||||||
#check if exposition_id exists else redirect to the list of place of conference |
|
||||||
place = PlaceExposition.objects.get(url=url) |
|
||||||
exposition_id = getattr(place, 'id') |
|
||||||
file_form = FileModelForm(initial={'model': 'place_exposition.PlaceExposition'}) |
|
||||||
except: |
|
||||||
return HttpResponseRedirect('/admin/place_exposition/all') |
|
||||||
|
|
||||||
if request.POST: |
|
||||||
#formset of HallForm |
|
||||||
HallFormSet = formset_factory(HallForm) |
|
||||||
form = ExpositionForm(request.POST) |
|
||||||
#set choices filled by ajax |
|
||||||
form.fields['city'].choices = [(item.id, item.name) for item in City.objects.filter(country=request.POST['country'])] |
|
||||||
formset = HallFormSet(request.POST) |
|
||||||
|
|
||||||
if form.is_valid() and formset.is_valid(): |
|
||||||
place_exposition = form.save(exposition_id) |
|
||||||
#delete old halls |
|
||||||
Hall.objects.filter(place_exposition=getattr(place, 'id')).delete() |
|
||||||
for item in formset.forms: |
|
||||||
#saves new halls if its valid and not empty |
|
||||||
if item.is_valid() and item.has_changed(): |
|
||||||
hall = item.save(commit=False) |
|
||||||
hall.place_exposition = place_exposition |
|
||||||
hall.save() |
|
||||||
|
|
||||||
return HttpResponseRedirect('/admin/place_exposition/all') |
|
||||||
else: |
|
||||||
#initial HallFormSet |
|
||||||
HallFormSet = modelformset_factory(Hall, form=HallForm, exclude=('place_exposition',)) |
|
||||||
#fill form with data from database |
|
||||||
data= {'type': place.type, 'address': place.address, |
|
||||||
'phone': place.phone, 'fax': place.fax, 'web_page': place.web_page, 'email': place.email, |
|
||||||
'foundation_year': place.foundation_year, 'total_area': place.total_area, |
|
||||||
'closed_area': place.closed_area, 'open_area': place.open_area, |
|
||||||
'total_pavilions': place.total_pavilions, 'total_halls': place.total_halls, 'wifi':place.wifi, |
|
||||||
'bank': place.bank, 'children_room': place.children_room, |
|
||||||
'disabled_service': place.disabled_service, 'conference_centre': place.conference_centre, |
|
||||||
'business_centre': place.business_centre, 'online_registration': place.online_registration, |
|
||||||
'cafe': place.cafe, 'terminals': place.terminals, 'parking': place.parking, |
|
||||||
'press_centre': place.press_centre, 'mobile_application': place.mobile_application, |
|
||||||
'place_exposition_id':place.id} |
|
||||||
|
|
||||||
if place.country: |
|
||||||
data['country'] = place.country.id |
|
||||||
if place.city: |
|
||||||
data['city'] = place.city.id |
|
||||||
#data from translated fields |
|
||||||
for code, name in settings.LANGUAGES: |
|
||||||
obj = PlaceExposition._meta.translations_model.objects.get(language_code = code,master__id=exposition_id) #access to translated fields |
|
||||||
data['name_%s'%code] = obj.name |
|
||||||
data['description_%s'%code] = obj.description |
|
||||||
data['adress_%s'%code] = obj.adress |
|
||||||
data['total_year_action_%s'%code] = obj.total_year_action |
|
||||||
data['title_%s'%code] = obj.title |
|
||||||
data['keywords_%s'%code] = obj.keywords |
|
||||||
data['descriptions_%s'%code] = obj.descriptions |
|
||||||
|
|
||||||
form = ExpositionForm(initial=data) |
|
||||||
#set choices filled by ajax |
|
||||||
form.fields['city'].choices = [(item.id, item.name) for item in City.objects.filter(country=data['country'])] |
|
||||||
#get existing halls |
|
||||||
halls = Hall.objects.filter(place_exposition=getattr(place, 'id')) |
|
||||||
#fill HallFormSet |
|
||||||
formset = HallFormSet(queryset=halls) |
|
||||||
|
|
||||||
|
|
||||||
args = {} |
|
||||||
args.update(csrf(request)) |
|
||||||
|
|
||||||
args['languages'] = settings.LANGUAGES |
|
||||||
args['form'] = form |
|
||||||
args['formset'] = formset |
|
||||||
args['file_form'] = file_form |
|
||||||
|
|
||||||
#get list of files which connected with specific model object |
|
||||||
args['files'] = FileModel.objects.filter(content_type=ContentType.objects.get_for_model(place), |
|
||||||
object_id=getattr(place, 'id')) |
|
||||||
args['obj_id'] = exposition_id |
|
||||||
|
|
||||||
|
|
||||||
return render_to_response('place_exposition_add.html', args) |
|
||||||
@ -0,0 +1,138 @@ |
|||||||
|
# -*- coding: utf-8 -*- |
||||||
|
from django.shortcuts import render_to_response |
||||||
|
from django.http import HttpResponseRedirect, HttpResponse |
||||||
|
from django.core.context_processors import csrf |
||||||
|
from django.conf import settings |
||||||
|
from django.contrib.contenttypes.models import ContentType |
||||||
|
from django.contrib.auth.decorators import login_required |
||||||
|
# |
||||||
|
from models import Seminar |
||||||
|
from forms import SeminarCreateForm, SeminarChangeForm, SeminarDeleteForm |
||||||
|
from theme.models import Tag |
||||||
|
from city.models import City |
||||||
|
from file.models import FileModel, TmpFile |
||||||
|
from file.forms import FileModelForm |
||||||
|
#python |
||||||
|
import random |
||||||
|
#custom views |
||||||
|
from functions.custom_views import objects_list, delete_object |
||||||
|
|
||||||
|
|
||||||
|
def seminar_all(request): |
||||||
|
""" |
||||||
|
Return list of all seminars with pagination |
||||||
|
""" |
||||||
|
return objects_list(request, Seminar, 'seminar_all.html') |
||||||
|
|
||||||
|
|
||||||
|
@login_required |
||||||
|
def seminar_add(request): |
||||||
|
""" |
||||||
|
Returns form of seminar and post it on the server. |
||||||
|
|
||||||
|
If form is posted redirect on the page of all seminars. |
||||||
|
""" |
||||||
|
#if form would be not valid key must be same |
||||||
|
if request.POST.get('key'): |
||||||
|
key = request.POST['key'] |
||||||
|
else: |
||||||
|
key = random.getrandbits(128) |
||||||
|
|
||||||
|
file_form = FileModelForm(initial={'key': key}) |
||||||
|
|
||||||
|
if request.POST: |
||||||
|
form = SeminarCreateForm(request.POST) |
||||||
|
#set choices filled by ajax |
||||||
|
form.fields['tag'].choices = [(item.id, item.name) for item in Tag.objects.all()] |
||||||
|
form.fields['city'].choices = [(item.id, item.name) for item in City.objects.filter(country=request.POST['country'])] |
||||||
|
|
||||||
|
if form.is_valid(): |
||||||
|
form.save() |
||||||
|
return HttpResponseRedirect('/admin/seminar/all') |
||||||
|
else: |
||||||
|
form = SeminarCreateForm(initial={'key': key}) |
||||||
|
|
||||||
|
args = {} |
||||||
|
args.update(csrf(request)) |
||||||
|
|
||||||
|
args['form'] = form |
||||||
|
args['languages'] = settings.LANGUAGES |
||||||
|
args['file_form'] = file_form |
||||||
|
args['files'] = TmpFile.objects.filter(key=key) |
||||||
|
|
||||||
|
return render_to_response('seminar_add.html', args) |
||||||
|
|
||||||
|
|
||||||
|
def seminar_delete(request, url): |
||||||
|
return delete_object(request, Seminar, SeminarDeleteForm, url, '/admin/seminar/all') |
||||||
|
|
||||||
|
|
||||||
|
@login_required |
||||||
|
def seminar_change(request, url): |
||||||
|
""" |
||||||
|
Return form of seminar and fill it with existing Seminar object data. |
||||||
|
|
||||||
|
If form of seminar is posted redirect on the page of all seminars. |
||||||
|
|
||||||
|
""" |
||||||
|
try: |
||||||
|
#check if seminar_id exists else redirect to the list of seminars |
||||||
|
seminar = Seminar.objects.get(url=url) |
||||||
|
file_form = FileModelForm(initial={'model': 'seminar.Seminar'}) |
||||||
|
except: |
||||||
|
return HttpResponseRedirect('/admin/seminar/all') |
||||||
|
|
||||||
|
if request.POST: |
||||||
|
form = SeminarChangeForm(request.POST) |
||||||
|
#set choices filled by ajax |
||||||
|
form.fields['tag'].choices = [(item.id, item.name) for item in Tag.objects.all()] |
||||||
|
form.fields['city'].choices = [(item.id, item.name) for item in City.objects.filter(country=request.POST['country'])] |
||||||
|
#set choices filled by ajax |
||||||
|
form.fields['tag'].choices = [(item.id, item.name) for item in Tag.objects.all()] |
||||||
|
form.fields['city'].choices = [(item.id, item.name) for item in City.objects.filter(country=request.POST['country'])] |
||||||
|
if form.is_valid(): |
||||||
|
form.save(getattr(seminar, 'id')) |
||||||
|
return HttpResponseRedirect('/admin/seminar/all') |
||||||
|
else: |
||||||
|
#fill form with data from database |
||||||
|
data = {'web_page':seminar.web_page, 'foundation_year': seminar.foundation_year, |
||||||
|
'data_begin':seminar.data_begin, 'data_end':seminar.data_end, 'currency':seminar.currency, |
||||||
|
'tax':seminar.tax, 'min_price':seminar.min_price, 'link':seminar.link, |
||||||
|
'max_price':seminar.max_price, 'address':seminar.address, 'seminar_id':seminar.id} |
||||||
|
|
||||||
|
if seminar.country: |
||||||
|
data['country'] = seminar.country.id |
||||||
|
|
||||||
|
if seminar.city: |
||||||
|
data['city'] = seminar.city.id |
||||||
|
|
||||||
|
data['theme'] = [item.id for item in seminar.theme.all()] |
||||||
|
data['tag'] = [item.id for item in seminar.tag.all()] |
||||||
|
#data from translated fields |
||||||
|
for code, name in settings.LANGUAGES: |
||||||
|
obj = Seminar._meta.translations_model.objects.get(language_code = code,master__id=getattr(seminar, 'id')) #access to translated fields |
||||||
|
data['name_%s' % code] = obj.name |
||||||
|
data['programm_%s' % code] = obj.programm |
||||||
|
data['main_title_%s' % code] = obj.main_title |
||||||
|
data['discount_%s' % code] = obj.discount |
||||||
|
data['title_%s' % code] = obj.title |
||||||
|
data['keywords_%s' % code] = obj.keywords |
||||||
|
data['descriptions_%s' % code] = obj.descriptions |
||||||
|
#initial form |
||||||
|
form = SeminarChangeForm(initial=data) |
||||||
|
#set choices filled by ajax |
||||||
|
form.fields['city'].choices = [(item.id, item.name) for item in City.objects.filter(country=data['country'])] |
||||||
|
form.fields['tag'].choices = [(item.id, item.name) for item in Tag.objects.filter(theme__in=data['theme'])] |
||||||
|
|
||||||
|
args = {} |
||||||
|
args.update(csrf(request)) |
||||||
|
|
||||||
|
args['form'] = form |
||||||
|
args['languages'] = settings.LANGUAGES |
||||||
|
args['file_form'] = file_form |
||||||
|
#get list of files which connected with specific model object |
||||||
|
args['files'] = FileModel.objects.filter(content_type=ContentType.objects.get_for_model(seminar), |
||||||
|
object_id=getattr(seminar, 'id')) |
||||||
|
args['obj_id'] = getattr(seminar, 'id') |
||||||
|
|
||||||
|
return render_to_response('seminar_add.html', args) |
||||||
@ -1,9 +1,9 @@ |
|||||||
# -*- coding: utf-8 -*- |
# -*- coding: utf-8 -*- |
||||||
from django.conf.urls import patterns, include, url |
from django.conf.urls import patterns, include, url |
||||||
|
|
||||||
urlpatterns = patterns('seminar.views', |
urlpatterns = patterns('seminar.admin', |
||||||
url(r'^add.*/$', 'seminar_add'), |
url(r'^add.*/$', 'seminar_add'), |
||||||
url(r'^delete/(?P<url>.*)/$', 'seminar_delete'), |
url(r'^delete/(?P<url>.*)/$', 'seminar_delete'), |
||||||
url(r'^change/(?P<url>.*)/$', 'seminar_change'), |
url(r'^change/(?P<url>.*)/$', 'seminar_change'), |
||||||
url(r'^all/$', 'seminar_all'), |
url(r'^all/$', 'seminar_all'), |
||||||
) |
) |
||||||
|
|||||||
@ -1,138 +0,0 @@ |
|||||||
# -*- coding: utf-8 -*- |
|
||||||
from django.shortcuts import render_to_response |
|
||||||
from django.http import HttpResponseRedirect, HttpResponse |
|
||||||
from django.core.context_processors import csrf |
|
||||||
from django.conf import settings |
|
||||||
from django.contrib.contenttypes.models import ContentType |
|
||||||
from django.contrib.auth.decorators import login_required |
|
||||||
# |
|
||||||
from models import Seminar |
|
||||||
from forms import SeminarCreateForm, SeminarChangeForm, SeminarDeleteForm |
|
||||||
from theme.models import Tag |
|
||||||
from city.models import City |
|
||||||
from file.models import FileModel, TmpFile |
|
||||||
from file.forms import FileModelForm |
|
||||||
#python |
|
||||||
import random |
|
||||||
#custom views |
|
||||||
from functions.custom_views import objects_list, delete_object |
|
||||||
|
|
||||||
|
|
||||||
def seminar_all(request): |
|
||||||
""" |
|
||||||
Return list of all seminars with pagination |
|
||||||
""" |
|
||||||
return objects_list(request, Seminar, 'seminar_all.html') |
|
||||||
|
|
||||||
|
|
||||||
@login_required |
|
||||||
def seminar_add(request): |
|
||||||
""" |
|
||||||
Returns form of seminar and post it on the server. |
|
||||||
|
|
||||||
If form is posted redirect on the page of all seminars. |
|
||||||
""" |
|
||||||
#if form would be not valid key must be same |
|
||||||
if request.POST.get('key'): |
|
||||||
key = request.POST['key'] |
|
||||||
else: |
|
||||||
key = random.getrandbits(128) |
|
||||||
|
|
||||||
file_form = FileModelForm(initial={'key': key}) |
|
||||||
|
|
||||||
if request.POST: |
|
||||||
form = SeminarCreateForm(request.POST) |
|
||||||
#set choices filled by ajax |
|
||||||
form.fields['tag'].choices = [(item.id, item.name) for item in Tag.objects.all()] |
|
||||||
form.fields['city'].choices = [(item.id, item.name) for item in City.objects.filter(country=request.POST['country'])] |
|
||||||
|
|
||||||
if form.is_valid(): |
|
||||||
form.save() |
|
||||||
return HttpResponseRedirect('/admin/seminar/all') |
|
||||||
else: |
|
||||||
form = SeminarCreateForm(initial={'key': key}) |
|
||||||
|
|
||||||
args = {} |
|
||||||
args.update(csrf(request)) |
|
||||||
|
|
||||||
args['form'] = form |
|
||||||
args['languages'] = settings.LANGUAGES |
|
||||||
args['file_form'] = file_form |
|
||||||
args['files'] = TmpFile.objects.filter(key=key) |
|
||||||
|
|
||||||
return render_to_response('seminar_add.html', args) |
|
||||||
|
|
||||||
|
|
||||||
def seminar_delete(request, url): |
|
||||||
return delete_object(request, Seminar, SeminarDeleteForm, url, '/admin/seminar/all') |
|
||||||
|
|
||||||
|
|
||||||
@login_required |
|
||||||
def seminar_change(request, url): |
|
||||||
""" |
|
||||||
Return form of seminar and fill it with existing Seminar object data. |
|
||||||
|
|
||||||
If form of seminar is posted redirect on the page of all seminars. |
|
||||||
|
|
||||||
""" |
|
||||||
try: |
|
||||||
#check if seminar_id exists else redirect to the list of seminars |
|
||||||
seminar = Seminar.objects.get(url=url) |
|
||||||
file_form = FileModelForm(initial={'model': 'seminar.Seminar'}) |
|
||||||
except: |
|
||||||
return HttpResponseRedirect('/admin/seminar/all') |
|
||||||
|
|
||||||
if request.POST: |
|
||||||
form = SeminarChangeForm(request.POST) |
|
||||||
#set choices filled by ajax |
|
||||||
form.fields['tag'].choices = [(item.id, item.name) for item in Tag.objects.all()] |
|
||||||
form.fields['city'].choices = [(item.id, item.name) for item in City.objects.filter(country=request.POST['country'])] |
|
||||||
#set choices filled by ajax |
|
||||||
form.fields['tag'].choices = [(item.id, item.name) for item in Tag.objects.all()] |
|
||||||
form.fields['city'].choices = [(item.id, item.name) for item in City.objects.filter(country=request.POST['country'])] |
|
||||||
if form.is_valid(): |
|
||||||
form.save(getattr(seminar, 'id')) |
|
||||||
return HttpResponseRedirect('/admin/seminar/all') |
|
||||||
else: |
|
||||||
#fill form with data from database |
|
||||||
data = {'web_page':seminar.web_page, 'foundation_year': seminar.foundation_year, |
|
||||||
'data_begin':seminar.data_begin, 'data_end':seminar.data_end, 'currency':seminar.currency, |
|
||||||
'tax':seminar.tax, 'min_price':seminar.min_price, 'link':seminar.link, |
|
||||||
'max_price':seminar.max_price, 'address':seminar.address, 'seminar_id':seminar.id} |
|
||||||
|
|
||||||
if seminar.country: |
|
||||||
data['country'] = seminar.country.id |
|
||||||
|
|
||||||
if seminar.city: |
|
||||||
data['city'] = seminar.city.id |
|
||||||
|
|
||||||
data['theme'] = [item.id for item in seminar.theme.all()] |
|
||||||
data['tag'] = [item.id for item in seminar.tag.all()] |
|
||||||
#data from translated fields |
|
||||||
for code, name in settings.LANGUAGES: |
|
||||||
obj = Seminar._meta.translations_model.objects.get(language_code = code,master__id=getattr(seminar, 'id')) #access to translated fields |
|
||||||
data['name_%s' % code] = obj.name |
|
||||||
data['programm_%s' % code] = obj.programm |
|
||||||
data['main_title_%s' % code] = obj.main_title |
|
||||||
data['discount_%s' % code] = obj.discount |
|
||||||
data['title_%s' % code] = obj.title |
|
||||||
data['keywords_%s' % code] = obj.keywords |
|
||||||
data['descriptions_%s' % code] = obj.descriptions |
|
||||||
#initial form |
|
||||||
form = SeminarChangeForm(initial=data) |
|
||||||
#set choices filled by ajax |
|
||||||
form.fields['city'].choices = [(item.id, item.name) for item in City.objects.filter(country=data['country'])] |
|
||||||
form.fields['tag'].choices = [(item.id, item.name) for item in Tag.objects.filter(theme__in=data['theme'])] |
|
||||||
|
|
||||||
args = {} |
|
||||||
args.update(csrf(request)) |
|
||||||
|
|
||||||
args['form'] = form |
|
||||||
args['languages'] = settings.LANGUAGES |
|
||||||
args['file_form'] = file_form |
|
||||||
#get list of files which connected with specific model object |
|
||||||
args['files'] = FileModel.objects.filter(content_type=ContentType.objects.get_for_model(seminar), |
|
||||||
object_id=getattr(seminar, 'id')) |
|
||||||
args['obj_id'] = getattr(seminar, 'id') |
|
||||||
|
|
||||||
return render_to_response('seminar_add.html', args) |
|
||||||
@ -1,9 +1,114 @@ |
|||||||
# -*- coding: utf-8 -*- |
# -*- coding: utf-8 -*- |
||||||
from django.contrib import admin |
from django.shortcuts import render_to_response |
||||||
from hvad.admin import TranslatableAdmin |
from django.http import HttpResponseRedirect, HttpResponse |
||||||
|
from django.core.context_processors import csrf |
||||||
|
from django.conf import settings |
||||||
|
from django.contrib.auth.decorators import login_required |
||||||
|
#models and forms |
||||||
from models import Service |
from models import Service |
||||||
|
from forms import ServiceForm, ServiceDeleteForm |
||||||
|
from country.models import Country |
||||||
|
from city.models import City |
||||||
|
#custom views |
||||||
|
from functions.custom_views import objects_list, delete_object |
||||||
|
|
||||||
class ServiceAdmin(TranslatableAdmin): |
|
||||||
pass |
|
||||||
|
|
||||||
admin.site.register(Service, ServiceAdmin) |
def service_all(request): |
||||||
|
""" |
||||||
|
return list of all services with pagination |
||||||
|
""" |
||||||
|
return objects_list(request, Service, 'service_all.html') |
||||||
|
|
||||||
|
def service_delete(request, url): |
||||||
|
return delete_object(request, Service, ServiceDeleteForm, url, '/admin/service/all') |
||||||
|
|
||||||
|
|
||||||
|
@login_required |
||||||
|
def service_change(request, url): |
||||||
|
try: |
||||||
|
service = Service.objects.get(url=url) |
||||||
|
service_id = getattr(service, 'id') |
||||||
|
except: |
||||||
|
return HttpResponseRedirect('/admin/service/all') |
||||||
|
if request.POST: |
||||||
|
form = ServiceForm(request.POST) |
||||||
|
form.fields['city'].choices = [(item.id, item.name) for item in City.objects.all()] |
||||||
|
|
||||||
|
if form.is_valid(): |
||||||
|
form.save(service_id) |
||||||
|
|
||||||
|
return HttpResponseRedirect('/admin/service/all') |
||||||
|
else: |
||||||
|
data = {} |
||||||
|
try: |
||||||
|
data['price'] = service.price.split(' ')[0] |
||||||
|
data['currency'] = service.price.split(' ')[1] |
||||||
|
except:pass |
||||||
|
#countries sorted by this service |
||||||
|
services_in_countries = Country.objects.filter(services=getattr(Country.services, str(service_id))) |
||||||
|
|
||||||
|
data['europa'] = services_in_countries |
||||||
|
data['asia'] = services_in_countries |
||||||
|
data['africa'] = services_in_countries |
||||||
|
data['america'] = services_in_countries |
||||||
|
#hidden field |
||||||
|
data['service_id'] = service_id |
||||||
|
|
||||||
|
data['url'] = service.url |
||||||
|
|
||||||
|
#data from translated fields |
||||||
|
for code, name in settings.LANGUAGES: |
||||||
|
obj = Service._meta.translations_model.objects.get(language_code = code,master__id=service_id) #access to translated fields |
||||||
|
data['name_%s'%code] = obj.name |
||||||
|
data['description_%s'%code] = obj.description |
||||||
|
data['main_title_%s'%code] = obj.main_title |
||||||
|
data['advantage_%s'%code] = obj.advantage |
||||||
|
data['title_%s'%code] = obj.title |
||||||
|
data['keywords_%s'%code] = obj.keywords |
||||||
|
data['descriptions_%s'%code] = obj.descriptions |
||||||
|
|
||||||
|
|
||||||
|
form = ServiceForm(initial=data) |
||||||
|
|
||||||
|
args = {} |
||||||
|
args.update(csrf(request)) |
||||||
|
|
||||||
|
args['form'] = form |
||||||
|
args['languages'] = settings.LANGUAGES |
||||||
|
args['service_id'] = service_id |
||||||
|
return render_to_response('service_add.html', args) |
||||||
|
|
||||||
|
|
||||||
|
@login_required |
||||||
|
def service_add(request): |
||||||
|
if request.POST: |
||||||
|
form = ServiceForm(request.POST) |
||||||
|
if form.is_valid(): |
||||||
|
form.save() |
||||||
|
return HttpResponseRedirect('/admin/service/all') |
||||||
|
else: |
||||||
|
form = ServiceForm() |
||||||
|
|
||||||
|
args = {} |
||||||
|
args.update(csrf(request)) |
||||||
|
|
||||||
|
args['form'] = form |
||||||
|
args['languages'] = settings.LANGUAGES |
||||||
|
|
||||||
|
return render_to_response('service_add.html', args) |
||||||
|
|
||||||
|
def get_country(request): |
||||||
|
if request.GET: |
||||||
|
country_region = request.GET['region'] |
||||||
|
countries = Country.objects.filter(region=country_region) |
||||||
|
return render_to_response('checkbox_option.html', {'options': countries}) |
||||||
|
else: |
||||||
|
return HttpResponse('error') |
||||||
|
|
||||||
|
def get_city(request): |
||||||
|
if request.GET: |
||||||
|
country_id = request.GET['id'] |
||||||
|
cities = City.objects.filter(country=country_id) |
||||||
|
return render_to_response('checkbox_option.html', {'options': cities}) |
||||||
|
else: |
||||||
|
return HttpResponse('error') |
||||||
|
|||||||
@ -0,0 +1,9 @@ |
|||||||
|
# -*- coding: utf-8 -*- |
||||||
|
from django.contrib import admin |
||||||
|
from hvad.admin import TranslatableAdmin |
||||||
|
from models import Service |
||||||
|
|
||||||
|
class ServiceAdmin(TranslatableAdmin): |
||||||
|
pass |
||||||
|
|
||||||
|
admin.site.register(Service, ServiceAdmin) |
||||||
@ -1,114 +0,0 @@ |
|||||||
# -*- coding: utf-8 -*- |
|
||||||
from django.shortcuts import render_to_response |
|
||||||
from django.http import HttpResponseRedirect, HttpResponse |
|
||||||
from django.core.context_processors import csrf |
|
||||||
from django.conf import settings |
|
||||||
from django.contrib.auth.decorators import login_required |
|
||||||
#models and forms |
|
||||||
from models import Service |
|
||||||
from forms import ServiceForm, ServiceDeleteForm |
|
||||||
from country.models import Country |
|
||||||
from city.models import City |
|
||||||
#custom views |
|
||||||
from functions.custom_views import objects_list, delete_object |
|
||||||
|
|
||||||
|
|
||||||
def service_all(request): |
|
||||||
""" |
|
||||||
return list of all services with pagination |
|
||||||
""" |
|
||||||
return objects_list(request, Service, 'service_all.html') |
|
||||||
|
|
||||||
def service_delete(request, url): |
|
||||||
return delete_object(request, Service, ServiceDeleteForm, url, '/admin/service/all') |
|
||||||
|
|
||||||
|
|
||||||
@login_required |
|
||||||
def service_change(request, url): |
|
||||||
try: |
|
||||||
service = Service.objects.get(url=url) |
|
||||||
service_id = getattr(service, 'id') |
|
||||||
except: |
|
||||||
return HttpResponseRedirect('/admin/service/all') |
|
||||||
if request.POST: |
|
||||||
form = ServiceForm(request.POST) |
|
||||||
form.fields['city'].choices = [(item.id, item.name) for item in City.objects.all()] |
|
||||||
|
|
||||||
if form.is_valid(): |
|
||||||
form.save(service_id) |
|
||||||
|
|
||||||
return HttpResponseRedirect('/admin/service/all') |
|
||||||
else: |
|
||||||
data = {} |
|
||||||
try: |
|
||||||
data['price'] = service.price.split(' ')[0] |
|
||||||
data['currency'] = service.price.split(' ')[1] |
|
||||||
except:pass |
|
||||||
#countries sorted by this service |
|
||||||
services_in_countries = Country.objects.filter(services=getattr(Country.services, str(service_id))) |
|
||||||
|
|
||||||
data['europa'] = services_in_countries |
|
||||||
data['asia'] = services_in_countries |
|
||||||
data['africa'] = services_in_countries |
|
||||||
data['america'] = services_in_countries |
|
||||||
#hidden field |
|
||||||
data['service_id'] = service_id |
|
||||||
|
|
||||||
data['url'] = service.url |
|
||||||
|
|
||||||
#data from translated fields |
|
||||||
for code, name in settings.LANGUAGES: |
|
||||||
obj = Service._meta.translations_model.objects.get(language_code = code,master__id=service_id) #access to translated fields |
|
||||||
data['name_%s'%code] = obj.name |
|
||||||
data['description_%s'%code] = obj.description |
|
||||||
data['main_title_%s'%code] = obj.main_title |
|
||||||
data['advantage_%s'%code] = obj.advantage |
|
||||||
data['title_%s'%code] = obj.title |
|
||||||
data['keywords_%s'%code] = obj.keywords |
|
||||||
data['descriptions_%s'%code] = obj.descriptions |
|
||||||
|
|
||||||
|
|
||||||
form = ServiceForm(initial=data) |
|
||||||
|
|
||||||
args = {} |
|
||||||
args.update(csrf(request)) |
|
||||||
|
|
||||||
args['form'] = form |
|
||||||
args['languages'] = settings.LANGUAGES |
|
||||||
args['service_id'] = service_id |
|
||||||
return render_to_response('service_add.html', args) |
|
||||||
|
|
||||||
|
|
||||||
@login_required |
|
||||||
def service_add(request): |
|
||||||
if request.POST: |
|
||||||
form = ServiceForm(request.POST) |
|
||||||
if form.is_valid(): |
|
||||||
form.save() |
|
||||||
return HttpResponseRedirect('/admin/service/all') |
|
||||||
else: |
|
||||||
form = ServiceForm() |
|
||||||
|
|
||||||
args = {} |
|
||||||
args.update(csrf(request)) |
|
||||||
|
|
||||||
args['form'] = form |
|
||||||
args['languages'] = settings.LANGUAGES |
|
||||||
|
|
||||||
return render_to_response('service_add.html', args) |
|
||||||
|
|
||||||
def get_country(request): |
|
||||||
if request.GET: |
|
||||||
country_region = request.GET['region'] |
|
||||||
countries = Country.objects.filter(region=country_region) |
|
||||||
return render_to_response('checkbox_option.html', {'options': countries}) |
|
||||||
else: |
|
||||||
return HttpResponse('error') |
|
||||||
|
|
||||||
def get_city(request): |
|
||||||
if request.GET: |
|
||||||
country_id = request.GET['id'] |
|
||||||
cities = City.objects.filter(country=country_id) |
|
||||||
return render_to_response('checkbox_option.html', {'options': cities}) |
|
||||||
else: |
|
||||||
return HttpResponse('error') |
|
||||||
@ -1,11 +0,0 @@ |
|||||||
$(document).ready(function(){ |
|
||||||
$('.delete_file').click(function(){ |
|
||||||
var url = '/admin/ajax_delete_file/'; |
|
||||||
$.get( |
|
||||||
url, {'id': $(this).attr("value")}, function(j){ |
|
||||||
$('#file_list').html(j); |
|
||||||
});//end get
|
|
||||||
return false; |
|
||||||
});//end delete
|
|
||||||
});//end ready
|
|
||||||
|
|
||||||
@ -1,19 +1,113 @@ |
|||||||
# -*- coding: utf-8 -*- |
# -*- coding: utf-8 -*- |
||||||
from hvad.admin import TranslatableAdmin |
from django.shortcuts import render_to_response |
||||||
from django.contrib import admin |
from django.http import HttpResponseRedirect, HttpResponse |
||||||
from models import Tag, Theme |
from django.core.context_processors import csrf |
||||||
from bitfield import BitField |
from django.conf import settings |
||||||
from bitfield.forms import BitFieldCheckboxSelectMultiple |
from django.forms.formsets import BaseFormSet, formset_factory |
||||||
|
from django.forms.models import modelformset_factory |
||||||
|
from django.contrib.contenttypes.models import ContentType |
||||||
|
from django.contrib.auth.decorators import login_required |
||||||
|
#forms and models |
||||||
|
from forms import ThemeForm, TagForm, ThemeDeleteForm, TagDeleteForm |
||||||
|
from models import Theme, Tag |
||||||
|
#custom views |
||||||
|
from functions.custom_views import objects_list, add_object, delete_object |
||||||
|
|
||||||
|
|
||||||
class TagAdmin(TranslatableAdmin): |
def theme_all(request): |
||||||
pass |
return objects_list(request, Theme, 'theme_all.html') |
||||||
|
|
||||||
class ThemeAdmin(TranslatableAdmin): |
|
||||||
formfield_overrides = { |
|
||||||
BitField: {'widget': BitFieldCheckboxSelectMultiple}, |
|
||||||
} |
|
||||||
|
|
||||||
|
def tag_all(request): |
||||||
|
return objects_list(request, Tag, 'tag_all.html') |
||||||
|
|
||||||
admin.site.register(Tag, TagAdmin) |
|
||||||
admin.site.register(Theme, ThemeAdmin) |
def theme_add(request): |
||||||
|
return add_object(request, ThemeForm, 'theme_add.html', '/admin/theme/theme/all') |
||||||
|
|
||||||
|
def tag_add(request): |
||||||
|
return add_object(request, TagForm, 'tag_add.html', '/admin/theme/tag/all') |
||||||
|
|
||||||
|
def theme_delete(request, theme_id): |
||||||
|
return delete_object(request, Theme, ThemeDeleteForm, theme_id, '/admin/theme/theme/all') |
||||||
|
|
||||||
|
def tag_delete(request, tag_id): |
||||||
|
return delete_object(request, Tag, TagDeleteForm, tag_id, '/admin/theme/tag/all') |
||||||
|
|
||||||
|
|
||||||
|
@login_required |
||||||
|
def theme_change(request, theme_id=None): |
||||||
|
try: |
||||||
|
theme = Theme.objects.get(id=theme_id) |
||||||
|
except: |
||||||
|
return HttpResponseRedirect('/admin/theme/theme/all') |
||||||
|
if request.POST: |
||||||
|
form = ThemeForm(request.POST) |
||||||
|
if form.is_valid(): |
||||||
|
form.save(theme_id) |
||||||
|
return HttpResponseRedirect('/admin/theme/theme/all') |
||||||
|
else: |
||||||
|
data = {} |
||||||
|
#bitfeild |
||||||
|
data['types'] = [item for item, bool in theme.types if bool==True] |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#data from translated fields |
||||||
|
for code, name in settings.LANGUAGES: |
||||||
|
obj = Theme._meta.translations_model.objects.get(language_code = code,master__id=theme_id) #access to translated fields |
||||||
|
data['name_%s'%code] = obj.name |
||||||
|
data['description_%s'%code] = obj.description |
||||||
|
data['main_title_%s'%code] = obj.main_title |
||||||
|
data['title_%s'%code] = obj.title |
||||||
|
data['keywords_%s'%code] = obj.keywords |
||||||
|
data['descriptions_%s'%code] = obj.descriptions |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
form = ThemeForm(data) |
||||||
|
|
||||||
|
args = {} |
||||||
|
args.update(csrf(request)) |
||||||
|
|
||||||
|
args['form'] = form |
||||||
|
args['languages'] = settings.LANGUAGES |
||||||
|
args['theme_id'] = theme_id |
||||||
|
|
||||||
|
return render_to_response('theme_add.html', args) |
||||||
|
|
||||||
|
@login_required |
||||||
|
def tag_change(request, tag_id=None): |
||||||
|
try: |
||||||
|
tag = Tag.objects.get(id=tag_id) |
||||||
|
except: |
||||||
|
return HttpResponseRedirect('/admin/theme/tag/all') |
||||||
|
if request.POST: |
||||||
|
form = TagForm(request.POST) |
||||||
|
if form.is_valid(): |
||||||
|
form.save(tag_id) |
||||||
|
return HttpResponseRedirect('/admin/theme/tag/all') |
||||||
|
else: |
||||||
|
data = {} |
||||||
|
if tag.theme: |
||||||
|
data['theme'] = tag.theme.id |
||||||
|
#data from translated fields |
||||||
|
for code, name in settings.LANGUAGES: |
||||||
|
obj = Tag._meta.translations_model.objects.get(language_code = code,master__id=tag_id) #access to translated fields |
||||||
|
data['name_%s'%code] = obj.name |
||||||
|
data['description_%s'%code] = obj.description |
||||||
|
data['main_title_%s'%code] = obj.main_title |
||||||
|
data['title_%s'%code] = obj.title |
||||||
|
data['keywords_%s'%code] = obj.keywords |
||||||
|
data['descriptions_%s'%code] = obj.descriptions |
||||||
|
|
||||||
|
form = TagForm(data) |
||||||
|
|
||||||
|
args = {} |
||||||
|
args.update(csrf(request)) |
||||||
|
|
||||||
|
args['form'] = form |
||||||
|
args['languages'] = settings.LANGUAGES |
||||||
|
args['tag_id'] = tag_id |
||||||
|
|
||||||
|
return render_to_response('tag_add.html', args) |
||||||
@ -0,0 +1,19 @@ |
|||||||
|
# -*- coding: utf-8 -*- |
||||||
|
from hvad.admin import TranslatableAdmin |
||||||
|
from django.contrib import admin |
||||||
|
from models import Tag, Theme |
||||||
|
from bitfield import BitField |
||||||
|
from bitfield.forms import BitFieldCheckboxSelectMultiple |
||||||
|
|
||||||
|
|
||||||
|
class TagAdmin(TranslatableAdmin): |
||||||
|
pass |
||||||
|
|
||||||
|
class ThemeAdmin(TranslatableAdmin): |
||||||
|
formfield_overrides = { |
||||||
|
BitField: {'widget': BitFieldCheckboxSelectMultiple}, |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
admin.site.register(Tag, TagAdmin) |
||||||
|
admin.site.register(Theme, ThemeAdmin) |
||||||
@ -1,113 +0,0 @@ |
|||||||
# -*- coding: utf-8 -*- |
|
||||||
from django.shortcuts import render_to_response |
|
||||||
from django.http import HttpResponseRedirect, HttpResponse |
|
||||||
from django.core.context_processors import csrf |
|
||||||
from django.conf import settings |
|
||||||
from django.forms.formsets import BaseFormSet, formset_factory |
|
||||||
from django.forms.models import modelformset_factory |
|
||||||
from django.contrib.contenttypes.models import ContentType |
|
||||||
from django.contrib.auth.decorators import login_required |
|
||||||
#forms and models |
|
||||||
from forms import ThemeForm, TagForm, ThemeDeleteForm, TagDeleteForm |
|
||||||
from models import Theme, Tag |
|
||||||
#custom views |
|
||||||
from functions.custom_views import objects_list, add_object, delete_object |
|
||||||
|
|
||||||
|
|
||||||
def theme_all(request): |
|
||||||
return objects_list(request, Theme, 'theme_all.html') |
|
||||||
|
|
||||||
|
|
||||||
def tag_all(request): |
|
||||||
return objects_list(request, Tag, 'tag_all.html') |
|
||||||
|
|
||||||
|
|
||||||
def theme_add(request): |
|
||||||
return add_object(request, ThemeForm, 'theme_add.html', '/admin/theme/theme/all') |
|
||||||
|
|
||||||
def tag_add(request): |
|
||||||
return add_object(request, TagForm, 'tag_add.html', '/admin/theme/tag/all') |
|
||||||
|
|
||||||
def theme_delete(request, theme_id): |
|
||||||
return delete_object(request, Theme, ThemeDeleteForm, theme_id, '/admin/theme/theme/all') |
|
||||||
|
|
||||||
def tag_delete(request, tag_id): |
|
||||||
return delete_object(request, Tag, TagDeleteForm, tag_id, '/admin/theme/tag/all') |
|
||||||
|
|
||||||
|
|
||||||
@login_required |
|
||||||
def theme_change(request, theme_id=None): |
|
||||||
try: |
|
||||||
theme = Theme.objects.get(id=theme_id) |
|
||||||
except: |
|
||||||
return HttpResponseRedirect('/admin/theme/theme/all') |
|
||||||
if request.POST: |
|
||||||
form = ThemeForm(request.POST) |
|
||||||
if form.is_valid(): |
|
||||||
form.save(theme_id) |
|
||||||
return HttpResponseRedirect('/admin/theme/theme/all') |
|
||||||
else: |
|
||||||
data = {} |
|
||||||
#bitfeild |
|
||||||
data['types'] = [item for item, bool in theme.types if bool==True] |
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#data from translated fields |
|
||||||
for code, name in settings.LANGUAGES: |
|
||||||
obj = Theme._meta.translations_model.objects.get(language_code = code,master__id=theme_id) #access to translated fields |
|
||||||
data['name_%s'%code] = obj.name |
|
||||||
data['description_%s'%code] = obj.description |
|
||||||
data['main_title_%s'%code] = obj.main_title |
|
||||||
data['title_%s'%code] = obj.title |
|
||||||
data['keywords_%s'%code] = obj.keywords |
|
||||||
data['descriptions_%s'%code] = obj.descriptions |
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
form = ThemeForm(data) |
|
||||||
|
|
||||||
args = {} |
|
||||||
args.update(csrf(request)) |
|
||||||
|
|
||||||
args['form'] = form |
|
||||||
args['languages'] = settings.LANGUAGES |
|
||||||
args['theme_id'] = theme_id |
|
||||||
|
|
||||||
return render_to_response('theme_add.html', args) |
|
||||||
|
|
||||||
@login_required |
|
||||||
def tag_change(request, tag_id=None): |
|
||||||
try: |
|
||||||
tag = Tag.objects.get(id=tag_id) |
|
||||||
except: |
|
||||||
return HttpResponseRedirect('/admin/theme/tag/all') |
|
||||||
if request.POST: |
|
||||||
form = TagForm(request.POST) |
|
||||||
if form.is_valid(): |
|
||||||
form.save(tag_id) |
|
||||||
return HttpResponseRedirect('/admin/theme/tag/all') |
|
||||||
else: |
|
||||||
data = {} |
|
||||||
if tag.theme: |
|
||||||
data['theme'] = tag.theme.id |
|
||||||
#data from translated fields |
|
||||||
for code, name in settings.LANGUAGES: |
|
||||||
obj = Tag._meta.translations_model.objects.get(language_code = code,master__id=tag_id) #access to translated fields |
|
||||||
data['name_%s'%code] = obj.name |
|
||||||
data['description_%s'%code] = obj.description |
|
||||||
data['main_title_%s'%code] = obj.main_title |
|
||||||
data['title_%s'%code] = obj.title |
|
||||||
data['keywords_%s'%code] = obj.keywords |
|
||||||
data['descriptions_%s'%code] = obj.descriptions |
|
||||||
|
|
||||||
form = TagForm(data) |
|
||||||
|
|
||||||
args = {} |
|
||||||
args.update(csrf(request)) |
|
||||||
|
|
||||||
args['form'] = form |
|
||||||
args['languages'] = settings.LANGUAGES |
|
||||||
args['tag_id'] = tag_id |
|
||||||
|
|
||||||
return render_to_response('tag_add.html', args) |
|
||||||
@ -1,9 +1,120 @@ |
|||||||
# -*- coding: utf-8 -*- |
# -*- coding: utf-8 -*- |
||||||
from django.contrib import admin |
from django.shortcuts import render_to_response |
||||||
from hvad.admin import TranslatableAdmin |
from django.http import HttpResponseRedirect, HttpResponse |
||||||
|
from django.core.context_processors import csrf |
||||||
|
from django.conf import settings |
||||||
|
from django.contrib.contenttypes.models import ContentType |
||||||
|
from django.contrib.auth.decorators import login_required |
||||||
|
# |
||||||
|
from theme.models import Tag |
||||||
from models import Webinar |
from models import Webinar |
||||||
|
from forms import WebinarChangeForm, WebinarCreateForm, WebinarDeleteForm |
||||||
|
from file.models import FileModel, TmpFile |
||||||
|
from file.forms import FileModelForm |
||||||
|
#python |
||||||
|
import random |
||||||
|
#custom views |
||||||
|
from functions.custom_views import objects_list, delete_object |
||||||
|
|
||||||
class WebinarAdmin(TranslatableAdmin): |
|
||||||
pass |
|
||||||
|
|
||||||
admin.site.register(Webinar, WebinarAdmin) |
def webinar_all(request): |
||||||
|
""" |
||||||
|
Return list of all webinars with pagination |
||||||
|
""" |
||||||
|
return objects_list(request, Webinar, 'webinar_all.html') |
||||||
|
|
||||||
|
|
||||||
|
@login_required |
||||||
|
def webinar_add(request): |
||||||
|
""" |
||||||
|
Returns form of webinar and post it on the server. |
||||||
|
|
||||||
|
If form is posted redirect on the page of all webinars. |
||||||
|
""" |
||||||
|
#if form would be not valid key must be same |
||||||
|
if request.POST.get('key'): |
||||||
|
key = request.POST['key'] |
||||||
|
else: |
||||||
|
key = random.getrandbits(128) |
||||||
|
|
||||||
|
file_form = FileModelForm(initial={'key': key}) |
||||||
|
|
||||||
|
if request.POST: |
||||||
|
form = WebinarCreateForm(request.POST) |
||||||
|
form.fields['tag'].choices = [(item.id, item.name) for item in Tag.objects.all()] |
||||||
|
if form.is_valid(): |
||||||
|
form.save() |
||||||
|
return HttpResponseRedirect('/admin/webinar/all/') |
||||||
|
else: |
||||||
|
form = WebinarCreateForm(initial={'key': key}) |
||||||
|
|
||||||
|
args = {} |
||||||
|
args.update(csrf(request)) |
||||||
|
|
||||||
|
args['form'] = form |
||||||
|
args['languages'] = settings.LANGUAGES |
||||||
|
args['file_form'] = file_form |
||||||
|
args['files'] = TmpFile.objects.filter(key=key) |
||||||
|
|
||||||
|
return render_to_response('webinar_add.html', args) |
||||||
|
|
||||||
|
|
||||||
|
def webinar_delete(request, url): |
||||||
|
return delete_object(request, Webinar, WebinarDeleteForm, url, '/admin/webinar/delete') |
||||||
|
|
||||||
|
|
||||||
|
@login_required |
||||||
|
def webinar_change(request, url): |
||||||
|
""" |
||||||
|
Return form of Webinar and fill it with existing Webinar object data. |
||||||
|
|
||||||
|
If form of webinar is posted redirect on the page of all webinars. |
||||||
|
|
||||||
|
""" |
||||||
|
try: |
||||||
|
#check if webinar_id exists else redirect to the list of webinars |
||||||
|
webinar = Webinar.objects.get(url=url) |
||||||
|
file_form = FileModelForm(initial={'model': 'webinar.Webinar'}) |
||||||
|
except: |
||||||
|
return HttpResponseRedirect('/admin/webinar/all/') |
||||||
|
if request.POST: |
||||||
|
form = WebinarChangeForm(request.POST) |
||||||
|
form.fields['tag'].choices = [(item.id, item.name) for item in Tag.objects.all()] |
||||||
|
if form.is_valid(): |
||||||
|
form.save(getattr(webinar, 'id')) |
||||||
|
return HttpResponseRedirect('/admin/webinar/all/') |
||||||
|
else: |
||||||
|
#fill form with data from database |
||||||
|
data = {'web_page':webinar.web_page, 'data_begin':webinar.data_begin, 'currency':webinar.currency, |
||||||
|
'tax':webinar.tax, 'min_price':webinar.min_price, 'link':webinar.link, |
||||||
|
'max_price':webinar.max_price, 'webinar_id':webinar.id} |
||||||
|
|
||||||
|
data['theme'] = [item.id for item in webinar.theme.all()] |
||||||
|
data['tag'] = [item.id for item in webinar.tag.all()] |
||||||
|
#data from translated fields |
||||||
|
for code, name in settings.LANGUAGES: |
||||||
|
obj = Webinar._meta.translations_model.objects.get(language_code = code,master__id=getattr(webinar, 'id')) #access to translated fields |
||||||
|
data['name_%s' % code] = obj.name |
||||||
|
data['programm_%s' % code] = obj.programm |
||||||
|
data['main_title_%s' % code] = obj.main_title |
||||||
|
data['discount_%s' % code] = obj.discount |
||||||
|
data['title_%s' % code] = obj.title |
||||||
|
data['keywords_%s' % code] = obj.keywords |
||||||
|
data['descriptions_%s' % code] = obj.descriptions |
||||||
|
#initial form |
||||||
|
form = WebinarChangeForm(initial=data) |
||||||
|
form.fields['tag'].choices = [(item.id, item.name) for item in Tag.objects.filter(theme__in=data['theme'])] |
||||||
|
|
||||||
|
args = {} |
||||||
|
args.update(csrf(request)) |
||||||
|
|
||||||
|
args['form'] = form |
||||||
|
args['languages'] = settings.LANGUAGES |
||||||
|
args['file_form'] = file_form |
||||||
|
|
||||||
|
#get list of files which connected with specific model object |
||||||
|
args['files'] = FileModel.objects.filter(content_type=ContentType.objects.get_for_model(webinar), |
||||||
|
object_id=getattr(webinar, 'id')) |
||||||
|
args['obj_id'] = getattr(webinar, 'id') |
||||||
|
|
||||||
|
return render_to_response('webinar_add.html', args) |
||||||
@ -0,0 +1,9 @@ |
|||||||
|
# -*- coding: utf-8 -*- |
||||||
|
from django.contrib import admin |
||||||
|
from hvad.admin import TranslatableAdmin |
||||||
|
from models import Webinar |
||||||
|
|
||||||
|
class WebinarAdmin(TranslatableAdmin): |
||||||
|
pass |
||||||
|
|
||||||
|
admin.site.register(Webinar, WebinarAdmin) |
||||||
@ -1,120 +0,0 @@ |
|||||||
# -*- coding: utf-8 -*- |
|
||||||
from django.shortcuts import render_to_response |
|
||||||
from django.http import HttpResponseRedirect, HttpResponse |
|
||||||
from django.core.context_processors import csrf |
|
||||||
from django.conf import settings |
|
||||||
from django.contrib.contenttypes.models import ContentType |
|
||||||
from django.contrib.auth.decorators import login_required |
|
||||||
# |
|
||||||
from theme.models import Tag |
|
||||||
from models import Webinar |
|
||||||
from forms import WebinarChangeForm, WebinarCreateForm, WebinarDeleteForm |
|
||||||
from file.models import FileModel, TmpFile |
|
||||||
from file.forms import FileModelForm |
|
||||||
#python |
|
||||||
import random |
|
||||||
#custom views |
|
||||||
from functions.custom_views import objects_list, delete_object |
|
||||||
|
|
||||||
|
|
||||||
def webinar_all(request): |
|
||||||
""" |
|
||||||
Return list of all webinars with pagination |
|
||||||
""" |
|
||||||
return objects_list(request, Webinar, 'webinar_all.html') |
|
||||||
|
|
||||||
|
|
||||||
@login_required |
|
||||||
def webinar_add(request): |
|
||||||
""" |
|
||||||
Returns form of webinar and post it on the server. |
|
||||||
|
|
||||||
If form is posted redirect on the page of all webinars. |
|
||||||
""" |
|
||||||
#if form would be not valid key must be same |
|
||||||
if request.POST.get('key'): |
|
||||||
key = request.POST['key'] |
|
||||||
else: |
|
||||||
key = random.getrandbits(128) |
|
||||||
|
|
||||||
file_form = FileModelForm(initial={'key': key}) |
|
||||||
|
|
||||||
if request.POST: |
|
||||||
form = WebinarCreateForm(request.POST) |
|
||||||
form.fields['tag'].choices = [(item.id, item.name) for item in Tag.objects.all()] |
|
||||||
if form.is_valid(): |
|
||||||
form.save() |
|
||||||
return HttpResponseRedirect('/admin/webinar/all/') |
|
||||||
else: |
|
||||||
form = WebinarCreateForm(initial={'key': key}) |
|
||||||
|
|
||||||
args = {} |
|
||||||
args.update(csrf(request)) |
|
||||||
|
|
||||||
args['form'] = form |
|
||||||
args['languages'] = settings.LANGUAGES |
|
||||||
args['file_form'] = file_form |
|
||||||
args['files'] = TmpFile.objects.filter(key=key) |
|
||||||
|
|
||||||
return render_to_response('webinar_add.html', args) |
|
||||||
|
|
||||||
|
|
||||||
def webinar_delete(request, url): |
|
||||||
return delete_object(request, Webinar, WebinarDeleteForm, url, '/admin/webinar/delete') |
|
||||||
|
|
||||||
|
|
||||||
@login_required |
|
||||||
def webinar_change(request, url): |
|
||||||
""" |
|
||||||
Return form of Webinar and fill it with existing Webinar object data. |
|
||||||
|
|
||||||
If form of webinar is posted redirect on the page of all webinars. |
|
||||||
|
|
||||||
""" |
|
||||||
try: |
|
||||||
#check if webinar_id exists else redirect to the list of webinars |
|
||||||
webinar = Webinar.objects.get(url=url) |
|
||||||
file_form = FileModelForm(initial={'model': 'webinar.Webinar'}) |
|
||||||
except: |
|
||||||
return HttpResponseRedirect('/admin/webinar/all/') |
|
||||||
if request.POST: |
|
||||||
form = WebinarChangeForm(request.POST) |
|
||||||
form.fields['tag'].choices = [(item.id, item.name) for item in Tag.objects.all()] |
|
||||||
if form.is_valid(): |
|
||||||
form.save(getattr(webinar, 'id')) |
|
||||||
return HttpResponseRedirect('/admin/webinar/all/') |
|
||||||
else: |
|
||||||
#fill form with data from database |
|
||||||
data = {'web_page':webinar.web_page, 'data_begin':webinar.data_begin, 'currency':webinar.currency, |
|
||||||
'tax':webinar.tax, 'min_price':webinar.min_price, 'link':webinar.link, |
|
||||||
'max_price':webinar.max_price, 'webinar_id':webinar.id} |
|
||||||
|
|
||||||
data['theme'] = [item.id for item in webinar.theme.all()] |
|
||||||
data['tag'] = [item.id for item in webinar.tag.all()] |
|
||||||
#data from translated fields |
|
||||||
for code, name in settings.LANGUAGES: |
|
||||||
obj = Webinar._meta.translations_model.objects.get(language_code = code,master__id=getattr(webinar, 'id')) #access to translated fields |
|
||||||
data['name_%s' % code] = obj.name |
|
||||||
data['programm_%s' % code] = obj.programm |
|
||||||
data['main_title_%s' % code] = obj.main_title |
|
||||||
data['discount_%s' % code] = obj.discount |
|
||||||
data['title_%s' % code] = obj.title |
|
||||||
data['keywords_%s' % code] = obj.keywords |
|
||||||
data['descriptions_%s' % code] = obj.descriptions |
|
||||||
#initial form |
|
||||||
form = WebinarChangeForm(initial=data) |
|
||||||
form.fields['tag'].choices = [(item.id, item.name) for item in Tag.objects.filter(theme__in=data['theme'])] |
|
||||||
|
|
||||||
args = {} |
|
||||||
args.update(csrf(request)) |
|
||||||
|
|
||||||
args['form'] = form |
|
||||||
args['languages'] = settings.LANGUAGES |
|
||||||
args['file_form'] = file_form |
|
||||||
|
|
||||||
#get list of files which connected with specific model object |
|
||||||
args['files'] = FileModel.objects.filter(content_type=ContentType.objects.get_for_model(webinar), |
|
||||||
object_id=getattr(webinar, 'id')) |
|
||||||
args['obj_id'] = getattr(webinar, 'id') |
|
||||||
|
|
||||||
return render_to_response('webinar_add.html', args) |
|
||||||
Loading…
Reference in new issue