Copy. Alternative place

remotes/origin/1203
Kotiuk Nazarii 11 years ago
parent f9dc583cb4
commit a69201edcd
  1. 11
      conference/admin.py
  2. 1
      conference/admin_urls.py
  3. 9
      exposition/admin.py
  4. 1
      exposition/admin_urls.py
  5. 43
      functions/model_mixin.py
  6. 8
      service/forms.py
  7. 59
      service/models.py
  8. 43
      templates/admin/conference/conference_list.html
  9. 41
      templates/admin/exposition/exposition_list.html
  10. 8
      templates/admin/service/control.html
  11. 15
      templates/client/includes/conference/conference_object.html
  12. 15
      templates/client/includes/exposition/exposition_object.html

@ -313,3 +313,14 @@ def search_conf(request):
result = [{'id': item.pk, 'label': get_by_lang(item, 'name', lang)} for item in qs]
return HttpResponse(json.dumps(result), content_type='application/json')
def conf_copy(request):
response = {'redirect': ''}
conf = Conference.objects.get(id=request.GET['id'])
duplicate = conf.copy(request.GET['url'])
if isinstance(duplicate, Conference):
response['redirect'] = '/admin/conference/%s/'%duplicate.url
else:
response['msg'] = duplicate
return HttpResponse(json.dumps(response), content_type='application/json')

@ -5,6 +5,7 @@ from admin import ConferenceListView, ConferenceView
urlpatterns = patterns('conference.admin',
url(r'^upload-photo/(?P<conf_id>.*)/$', 'upload_conference_photo'),
url(r'^delete/(?P<url>.*)$', 'conference_delete'),
url(r'^copy/$', 'conf_copy'),
url(r'^all/$', ConferenceListView.as_view()),
#url(r'^change/(?P<url>.*)/$', 'conference_change'),

@ -404,3 +404,12 @@ class PaidView(FormView):
def expo_copy(request):
response = {'redirect': ''}
expo = Exposition.objects.get(id=request.GET['id'])
duplicate = expo.copy(request.GET['url'])
if isinstance(duplicate, Exposition):
response['redirect'] = '/admin/exposition/%s/'%duplicate.url
else:
response['msg'] = duplicate
return HttpResponse(json.dumps(response), content_type='application/json')

@ -4,6 +4,7 @@ from admin import ExpositionListView, ExpositionView, PaidView
urlpatterns = patterns('exposition.admin',
url(r'^upload-photo/(?P<expo_id>.*)/$', 'upload_exposition_photo'),
url(r'^copy/$', 'expo_copy'),
url(r'^(?P<url>.*)/paid/$', PaidView.as_view()),
#url(r'^add.*/$', 'exposition_add'),

@ -1,3 +1,5 @@
# -*- coding: utf-8 -*-
import copy
import calendar as python_calendar
from service.models import Service
@ -101,4 +103,43 @@ class EventMixin(object):
if self.data_end.month == month:
return self.data_end.day
return 0
return 0
def copy(self, url):
"""
Copy event with new url
:param url: new url for event
:return: event object
"""
# check url
Model = type(self)
try:
Model.objects.get(url=url)
return u'Событие с таким урлом уже существует'
except Model.DoesNotExist:
pass
duplicate = copy.copy(self)
duplicate.url = url
# Setting pk to None. for Django its a new object.
duplicate.pk = None
# copy translations
ignore_fields = ['id', 'master', 'language_code']
duplicate.translate('ru')
tr = self._meta.translations_model.objects.get(language_code='ru', master__id=self.pk)
for field in duplicate._translated_field_names:
if field in ignore_fields:
continue
setattr(duplicate, field, getattr(tr, field))
duplicate.is_published = False
duplicate.save() # save but lost all ManyToMany relations
# copy relations
for field in self._meta.many_to_many:
source = getattr(self, field.attname)
destination = getattr(duplicate, field.attname)
for item in source.all():
destination.add(item)
return duplicate

@ -129,15 +129,15 @@ from exposition.models import Exposition
from conference.models import Conference
class ServiceControlForm(forms.Form):
event = [{'verbose': 'Выставки', 'model': Exposition, 'id': 1},
{'verbose': 'Конференции', 'model': Conference, 'id': 2}]
event = [{'verbose': 'Выставки', 'model': Exposition, 'id': 1, 'service_bit': 'expo'},
{'verbose': 'Конференции', 'model': Conference, 'id': 2, 'service_bit': 'conference'}]
region = forms.ChoiceField(required=False, label='Регион',
choices=[('', '')]+[(item.id, item.name)
for item in list(Area.objects.all())])
country = forms.MultipleChoiceField(required=False, label='Страны',
choices=[('', '')]+[(item.id, item.name)
for item in list(Country.objects.all())])
country_all = forms.BooleanField()
country_all = forms.BooleanField(required=False)
expositions = forms.CharField(label=u'Выставки', widget=forms.HiddenInput(), required=False)
conferences = forms.CharField(label=u'Конференции', widget=forms.HiddenInput(), required=False)
@ -145,5 +145,5 @@ class ServiceControlForm(forms.Form):
super(ServiceControlForm, self).__init__(*args, **kwargs)
self.fields['event_type'] = forms.MultipleChoiceField(required=False, label = 'Тип события',
widget=forms.CheckboxSelectMultiple(),
choices=[(item['id'], item['verbose'])
choices=[(item['service_bit'], item['verbose'])
for item in self.event])

@ -52,18 +52,56 @@ class Service(TranslatableModel):
uses for control form
:return:
"""
state = {'event_type':[1, 2],
'region': [],
'country':[],
'country_all': True,
'expositions': [],
'conferences': []}
from country.models import Country
country_all = False
country = []
region = []
expositions = []
conferences = []
service = self.url
event_type = [key for key, value in self.type.iteritems() if value]
if not event_type:
return {'event_type': event_type,
'region': region,
'country': country,
'country_all': country_all,
'expositions': expositions,
'conferences': conferences}
count1 = Country.objects.filter().count()
count2 = Country.objects.filter(services=getattr(Country.services, service)).count()
country_all = count1 == count2
if not country_all:
from exposition.models import Exposition
from conference.models import Conference
from country.models import Area
from django.utils.translation import get_language
lang = get_language()
countries = list(Country.objects.language(lang).filter(services=getattr(Country.services, service)))
expositions = [(item.id, item.name) for item in Exposition.enable.upcoming().exclude(country__in=countries, services=getattr(Exposition.services, service))]
conferences = [(item.id, item.name) for item in Conference.enable.upcoming().exclude(country__in=countries, services=getattr(Conference.services, service))]
region = []
countries = set(countries)
for item in list(Area.objects.language(lang).all()):
print(item)
area_countries = item.countries()
if set(area_countries).issubset(countries):
region.append((item.id, item.name))
countries = countries - set(area_countries)
country = [(item.id, item.name) for item in list(countries)]
state = {'event_type': event_type,
'region': region,
'country': country,
'country_all': country_all,
'expositions': expositions,
'conferences': conferences}
return state
from django.db.models.signals import post_save
from functions.signal_handlers import post_save_handler
@ -118,6 +156,7 @@ class Translation(AbstractOrder):
languages = models.TextField(blank=True)
themes = models.TextField(blank=True)
class Visit(AbstractOrder):
fr = models.DateField()
to = models.DateField()

@ -1,11 +1,7 @@
{% extends 'admin_list.html' %}
{% load static %}
{% block scripts %}
<script src="{% static 'custom_js/event_switcher.js' %}"></script>
{% endblock %}
{% block styles %}
@ -41,21 +37,25 @@ td a{
<div class="box-content">
<table class="table table-hover">
<col width="25%">
<col width="15%">
<col width="35%">
<col width="25%">
<thead>
<tr>
<th>id</th>
<th>Название</th>
<th>Дата начала</th>
<th>&nbsp;</th>
<th>&nbsp;</th>
</tr>
</thead>
<tbody>
{% for item in object_list %}
<tr>
<td>{{ item.id }}</td>
<td>{{ item.name }}</td>
<td>{{ item.data_begin }}</td>
<td>{{ item.data_begin|date:"Y-m-d" }}</td>
<td><a class="btn-small btn-inverse copy" data-id="{{ item.id }}" href="#">Копировать</a><input id="copy_url_{{ item.id }}" type="text" placeholder="новый урл"></td>
<td style="width: 200px; height:100px;">
<a class="btn-small btn-warning off" style="{% if item.is_published %}{% else %}display: none;{% endif %}"
href="/admin/conference/switch/{{ item.url }}/off">
@ -87,4 +87,33 @@ td a{
{# pagination #}
{% include 'admin/includes/admin_pagination.html' with page_obj=object_list %}
</div>
<script>
$(function(){
$('.copy').on('click', function(e){
e.preventDefault();
var id = $(this).attr('data-id');
var copy_url = '#copy_url_'+id
var input_url = $(copy_url).val();
if(input_url == ''){
alert('Урл не должен быть пустым')
}
else{
url = '/admin/conference/copy/';
formData = {'id': id, url: input_url};
$.get(url, formData, function(data){
if(data['redirect']==''){
alert(data['msg'])
}
else{
window.location = data['redirect'];
}
})
}
});
})
</script>
{% endblock %}

@ -34,21 +34,25 @@ td a{
<div class="box-content">
<table class="table table-hover">
<col width="25%">
<col width="15%">
<col width="35%">
<col width="25%">
<thead>
<tr>
<th>id</th>
<th>Название</th>
<th>Дата начала</th>
<th>&nbsp;</th>
<th>&nbsp;</th>
</tr>
</thead>
<tbody>
{% for item in object_list %}
<tr>
<td>{{ item.id }}</td>
<td>{{ item.name }}</td>
<td>{{ item.data_begin }}</td>
<td>{{ item.data_begin|date:"Y-m-d" }}</td>
<td><a class="btn-small btn-inverse copy" data-id="{{ item.id }}" href="#">Копировать</a><input id="copy_url_{{ item.id }}" type="text" placeholder="новый урл"></td>
<td style="width: 200px; height:100px;">
<a class="btn-small btn-warning off" style="{% if item.is_published %}{% else %}display: none;{% endif %}"
href="/admin/exposition/switch/{{ item.url }}/off">
@ -80,4 +84,33 @@ td a{
{# pagination #}
{% include 'admin/includes/admin_pagination.html' with page_obj=object_list %}
</div>
{% endblock %}
<script>
$(function(){
$('.copy').on('click', function(e){
e.preventDefault();
var id = $(this).attr('data-id');
var copy_url = '#copy_url_'+id
var input_url = $(copy_url).val();
if(input_url == ''){
alert('Урл не должен быть пустым')
}
else{
url = '/admin/exposition/copy/';
formData = {'id': id, url: input_url};
$.get(url, formData, function(data){
if(data['redirect']==''){
alert(data['msg'])
}
else{
window.location = data['redirect'];
}
})
}
});
})
</script>
{% endblock %}

@ -29,6 +29,14 @@
</div>
</div>
{# country_all #}
<div class="control-group {% if form.country_all.errors %}error{% endif %}">
<label class="control-label">{{ form.country_all.label }}:</label>
<div class="controls">{{ form.country_all }}
<span class="help-inline">{{ form.country_all.errors }}</span>
</div>
</div>
{# region #}
<div class="control-group {% if form.region.errors %}error{% endif %}">
<label class="control-label">{{ form.region.label }}:</label>

@ -58,6 +58,14 @@
<div class="map-canvas" id="map-canvas" data-coords="{{ event.place.address.lat|stringformat:'f' }},{{ event.place.address.lng|stringformat:'f' }}" ></div>
</div>
</div>
{% else %}
<div class="i-address">
<header>
<div class="address">
{{ event.country.name }}, {{ event.city.name }}{% if event.place_alt %} , {{ event.place_alt }}{% endif %}
</div>
</header>
</div>
{% endif %}
<hr />
<div class="i-buttons clearfix">
@ -165,12 +173,7 @@
{% endif %}
{% endif %}
{% if not event.place %}
<dt>{% trans 'Место проведения' %}:</dt>
<dd>
<a href="{{ event.get_catalog_url }}country/{{ event.country.url }}/">{{ event.country.name }}</a> , <a href="{{ event.get_catalog_url }}city/{{ event.city.url }}/">{{ event.city.name }}</a>{% if event.place_alt %} , {{ event.place_alt }}{% endif %}
</dd>
{% endif %}
{% if event.web_page %}
<dt>{% trans 'Веб-сайт' %}:</dt>
<dd>

@ -59,6 +59,15 @@
<div class="map-canvas" id="map-canvas" data-coords="{{ exposition.place.address.lat|stringformat:'f' }},{{ exposition.place.address.lng|stringformat:'f' }}" ></div>
</div>
</div>
{% else %}
<div class="i-address">
<header>
<div class="address">
{{ exposition.country.name }}, {{ exposition.city.name }}{% if exposition.place_alt %} , {{ exposition.place_alt }}{% endif %}
</div>
</header>
</div>
{% endif %}
<hr />
<div class="i-buttons clearfix">
@ -169,12 +178,6 @@
{% endif %}
{% endif %}
{% if not exposition.place %}
<dt>{% trans 'Место проведения' %}:</dt>
<dd>
<a href="{{ exposition.get_catalog_url }}country/{{ exposition.country.url }}/">{{ exposition.country.name }}</a> , <a href="{{ exposition.get_catalog_url }}city/{{ exposition.city.url }}/">{{ exposition.city.name }}</a>{% if exposition.place_alt %} , {{ exposition.place_alt }}{% endif %}
</dd>
{% endif %}
{% if exposition.web_page %}
<dt>{% trans 'Веб-сайт' %}:</dt>

Loading…
Cancel
Save