@ -0,0 +1,20 @@ |
|||||||
|
from hvad.models import TranslationManager |
||||||
|
|
||||||
|
|
||||||
|
class ClientManager(TranslationManager): |
||||||
|
def get_query_set(self): |
||||||
|
return super(ClientManager, self).get_query_set().filter(is_published=True) |
||||||
|
|
||||||
|
|
||||||
|
""" |
||||||
|
|
||||||
|
from exposition.models import Exposition |
||||||
|
from django.db import connection |
||||||
|
from django.utils import translation |
||||||
|
translation.activate('en') |
||||||
|
len(connection.queries) |
||||||
|
e = list(Exposition.enable.list()) |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
""" |
||||||
@ -0,0 +1,16 @@ |
|||||||
|
from django import forms |
||||||
|
from django.conf import settings |
||||||
|
|
||||||
|
|
||||||
|
class AdminForm(forms.Form): |
||||||
|
model = None |
||||||
|
|
||||||
|
def __init__(self, *args, **kwargs): |
||||||
|
""" |
||||||
|
create dynamical translated fields fields |
||||||
|
""" |
||||||
|
if len(settings.LANGUAGES) in range(10): |
||||||
|
for lid, (code, name) in enumerate(settings.LANGUAGES): |
||||||
|
# uses enumerate for detect iteration number |
||||||
|
# first iteration is a default lang so it required fields |
||||||
|
required = True if lid == 0 else False |
||||||
@ -0,0 +1,62 @@ |
|||||||
|
from django.views.generic import FormView |
||||||
|
from django.shortcuts import render_to_response, get_object_or_404 |
||||||
|
from django.http import HttpResponseRedirect |
||||||
|
from django.conf import settings |
||||||
|
|
||||||
|
class AdminView(FormView): |
||||||
|
obj = None |
||||||
|
|
||||||
|
def set_obj(self): |
||||||
|
url = self.kwargs.get('url') |
||||||
|
if url: |
||||||
|
obj = get_object_or_404(self.model, url=url) |
||||||
|
self.obj = obj |
||||||
|
return obj |
||||||
|
slug = self.kwargs.get('slug') |
||||||
|
if slug: |
||||||
|
obj = get_object_or_404(self.model, slug=slug) |
||||||
|
self.obj = obj |
||||||
|
return obj |
||||||
|
self.obj = None |
||||||
|
return None |
||||||
|
|
||||||
|
def get_context_data(self, **kwargs): |
||||||
|
context = super(AdminView, self).get_context_data(**kwargs) |
||||||
|
self.set_obj() |
||||||
|
context['object'] = self.obj |
||||||
|
context['languages'] = settings.LANGUAGES |
||||||
|
return context |
||||||
|
|
||||||
|
def form_valid(self, form): |
||||||
|
self.set_obj() |
||||||
|
form.save(obj=self.obj) |
||||||
|
return HttpResponseRedirect(self.success_url) |
||||||
|
# example get_form |
||||||
|
""" |
||||||
|
def get_form(self, form_class): |
||||||
|
if self.request.POST: |
||||||
|
return super(AdminView, self).get_form(form_class) |
||||||
|
self.set_obj() |
||||||
|
if self.obj: |
||||||
|
obj = self.obj |
||||||
|
data = {} |
||||||
|
data['theme'] = [item.id for item in article.theme.all()] |
||||||
|
data['exposition'] = article.exposition |
||||||
|
data['conference'] = article.conference |
||||||
|
a = ','.join(['%s:%s'%(item.id, item.name) for item in article.tag.all()]) |
||||||
|
|
||||||
|
data['tag'] = ','.join(['%s:%s'%(item.id, item.name) for item in article.tag.all()]) |
||||||
|
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 |
||||||
|
form = form_class(data) |
||||||
|
#form.fields['tag'].widget.attrs['data-init-text'] = [item.name for item in article.tag.all()] |
||||||
|
return form_class(data) |
||||||
|
else: |
||||||
|
return form_class() |
||||||
|
""" |
||||||
@ -0,0 +1,26 @@ |
|||||||
|
from django.core.management.base import BaseCommand |
||||||
|
from photologue.models import PhotoSize |
||||||
|
|
||||||
|
|
||||||
|
class Command(BaseCommand): |
||||||
|
def handle(self, *args, **options): |
||||||
|
|
||||||
|
PhotoSize.objects.create(name='admin_thumbnail', |
||||||
|
width=100, |
||||||
|
height=75, |
||||||
|
crop=True, |
||||||
|
pre_cache=True, |
||||||
|
increment_count=False) |
||||||
|
PhotoSize.objects.create(name='client_thumbnail', |
||||||
|
width=256, |
||||||
|
height=140, |
||||||
|
crop=True, |
||||||
|
pre_cache=True, |
||||||
|
increment_count=False) |
||||||
|
|
||||||
|
PhotoSize.objects.create(name='display', |
||||||
|
width=730, |
||||||
|
height=533, |
||||||
|
crop=True, |
||||||
|
pre_cache=True, |
||||||
|
increment_count=True) |
||||||
@ -1,10 +1,15 @@ |
|||||||
# -*- coding: utf-8 -*- |
# -*- coding: utf-8 -*- |
||||||
from django.conf.urls import patterns, include, url |
from django.conf.urls import patterns, include, url |
||||||
|
from admin import PlaceExpositionView |
||||||
|
|
||||||
urlpatterns = patterns('place_exposition.admin', |
urlpatterns = patterns('place_exposition.admin', |
||||||
|
url(r'^all/$', 'exposition_all'), |
||||||
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'^copy/(?P<url>.*)/$', 'place_exposition_copy'), |
url(r'^copy/(?P<url>.*)/$', 'place_exposition_copy'), |
||||||
url(r'^all/$', 'exposition_all'), |
url(r'^$', PlaceExpositionView.as_view()), |
||||||
|
url(r'^(?P<url>.*)/$', PlaceExpositionView.as_view()), |
||||||
|
|
||||||
|
|
||||||
) |
) |
||||||
|
|||||||
@ -0,0 +1,61 @@ |
|||||||
|
from django.core.management.base import BaseCommand, CommandError |
||||||
|
from place_exposition.models import PlaceExposition |
||||||
|
from django.contrib.sites.models import Site |
||||||
|
from photologue.models import Gallery, Photo |
||||||
|
from file.models import FileModel |
||||||
|
from django.core.files import File |
||||||
|
from django.core.files.temp import NamedTemporaryFile |
||||||
|
import urllib2 |
||||||
|
from django.conf import settings |
||||||
|
|
||||||
|
|
||||||
|
#img_temp = NamedTemporaryFile(delete=True) |
||||||
|
#img_temp.write(urllib2.urlopen(url).read()) |
||||||
|
#img_temp.flush() |
||||||
|
|
||||||
|
#im.file.save(img_filename, File(img_temp)) |
||||||
|
|
||||||
|
|
||||||
|
def convert_photo(photo): |
||||||
|
domain = 'http://hit.expomap.ru' |
||||||
|
url = domain+photo.file_path.url |
||||||
|
file_name = url.split('/')[-1] |
||||||
|
download_to = settings.MEDIA_ROOT+'photologue/'+file_name |
||||||
|
try: |
||||||
|
response = urllib2.urlopen(url, timeout=5) |
||||||
|
except: |
||||||
|
print('download error') |
||||||
|
return None |
||||||
|
|
||||||
|
with open(download_to,'wb') as f: |
||||||
|
f.write(response.read()) |
||||||
|
f.close() |
||||||
|
file_name = 'photologue/'+file_name |
||||||
|
new_photo = Photo(image=file_name) |
||||||
|
new_photo.translate('en') |
||||||
|
new_photo.title = file_name.replace('photologue/', '') |
||||||
|
new_photo.save() |
||||||
|
return new_photo |
||||||
|
|
||||||
|
def handle_place(place): |
||||||
|
|
||||||
|
domain = 'http://hit.expomap.ru' |
||||||
|
for photo in list(place.photos.all()): |
||||||
|
new_photo = convert_photo(photo) |
||||||
|
place.upload_photo(new_photo) |
||||||
|
print(place) |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class Command(BaseCommand): |
||||||
|
def handle(self, *args, **options): |
||||||
|
for place in PlaceExposition.objects.all('en'): |
||||||
|
if place.photos.all().exists(): |
||||||
|
handle_place(place) |
||||||
|
|
||||||
|
""" |
||||||
|
url = 'adnec-abu-dhabi-national-exhibitions-center' |
||||||
|
p = PlaceExposition.objects.get(url=url) |
||||||
|
handle_place(p) |
||||||
|
""" |
||||||
|
|
||||||
@ -0,0 +1 @@ |
|||||||
|
/home/www/proj/templates/client/static_client |
||||||
|
Before Width: | Height: | Size: 70 KiB After Width: | Height: | Size: 70 KiB |
|
Before Width: | Height: | Size: 80 KiB After Width: | Height: | Size: 80 KiB |
|
Before Width: | Height: | Size: 74 KiB After Width: | Height: | Size: 74 KiB |
|
Before Width: | Height: | Size: 71 KiB After Width: | Height: | Size: 71 KiB |
|
Before Width: | Height: | Size: 71 KiB After Width: | Height: | Size: 71 KiB |
|
Before Width: | Height: | Size: 72 KiB After Width: | Height: | Size: 72 KiB |
|
Before Width: | Height: | Size: 1.4 KiB After Width: | Height: | Size: 1.4 KiB |
|
Before Width: | Height: | Size: 1.4 KiB After Width: | Height: | Size: 1.4 KiB |
|
Before Width: | Height: | Size: 5.1 KiB After Width: | Height: | Size: 5.1 KiB |
|
Before Width: | Height: | Size: 4.5 KiB After Width: | Height: | Size: 4.5 KiB |
|
Before Width: | Height: | Size: 10 KiB After Width: | Height: | Size: 10 KiB |
|
Before Width: | Height: | Size: 4.1 KiB After Width: | Height: | Size: 4.1 KiB |
|
Before Width: | Height: | Size: 4.5 KiB After Width: | Height: | Size: 4.5 KiB |
|
Before Width: | Height: | Size: 8.2 KiB After Width: | Height: | Size: 8.2 KiB |
|
Before Width: | Height: | Size: 10 KiB After Width: | Height: | Size: 10 KiB |
|
Before Width: | Height: | Size: 250 B After Width: | Height: | Size: 250 B |
|
Before Width: | Height: | Size: 1.6 KiB After Width: | Height: | Size: 1.6 KiB |
|
Before Width: | Height: | Size: 1.5 KiB After Width: | Height: | Size: 1.5 KiB |
|
Before Width: | Height: | Size: 5.4 KiB After Width: | Height: | Size: 5.4 KiB |
|
Before Width: | Height: | Size: 120 KiB After Width: | Height: | Size: 120 KiB |
|
Before Width: | Height: | Size: 19 KiB After Width: | Height: | Size: 19 KiB |
|
Before Width: | Height: | Size: 4.4 KiB After Width: | Height: | Size: 4.4 KiB |
|
Before Width: | Height: | Size: 128 KiB After Width: | Height: | Size: 128 KiB |
|
Before Width: | Height: | Size: 6.1 KiB After Width: | Height: | Size: 6.1 KiB |
|
Before Width: | Height: | Size: 1.6 KiB After Width: | Height: | Size: 1.6 KiB |
|
Before Width: | Height: | Size: 62 KiB After Width: | Height: | Size: 62 KiB |
|
Before Width: | Height: | Size: 448 KiB After Width: | Height: | Size: 448 KiB |
|
Before Width: | Height: | Size: 4.8 KiB After Width: | Height: | Size: 4.8 KiB |
|
Before Width: | Height: | Size: 6.1 KiB After Width: | Height: | Size: 6.1 KiB |
|
Before Width: | Height: | Size: 9.7 KiB After Width: | Height: | Size: 9.7 KiB |
|
Before Width: | Height: | Size: 2.8 KiB After Width: | Height: | Size: 2.8 KiB |
|
Before Width: | Height: | Size: 6.0 KiB After Width: | Height: | Size: 6.0 KiB |
|
Before Width: | Height: | Size: 126 KiB After Width: | Height: | Size: 126 KiB |
|
Before Width: | Height: | Size: 28 KiB After Width: | Height: | Size: 28 KiB |
|
Before Width: | Height: | Size: 25 KiB After Width: | Height: | Size: 25 KiB |
|
Before Width: | Height: | Size: 25 KiB After Width: | Height: | Size: 25 KiB |
|
Before Width: | Height: | Size: 12 KiB After Width: | Height: | Size: 12 KiB |