parent
615a5c22ce
commit
bda826a60c
25 changed files with 371 additions and 401 deletions
@ -1,16 +0,0 @@ |
|||||||
# -*- 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) |
|
||||||
@ -0,0 +1,53 @@ |
|||||||
|
#https://djangosnippets.org/snippets/2607/ |
||||||
|
def required(wrapping_functions,patterns_rslt): |
||||||
|
''' |
||||||
|
Used to require 1..n decorators in any view returned by a url tree |
||||||
|
|
||||||
|
Usage: |
||||||
|
urlpatterns = required(func,patterns(...)) |
||||||
|
urlpatterns = required((func,func,func),patterns(...)) |
||||||
|
|
||||||
|
Note: |
||||||
|
Use functools.partial to pass keyword params to the required |
||||||
|
decorators. If you need to pass args you will have to write a |
||||||
|
wrapper function. |
||||||
|
|
||||||
|
Example: |
||||||
|
from functools import partial |
||||||
|
|
||||||
|
urlpatterns = required( |
||||||
|
partial(login_required,login_url='/accounts/login/'), |
||||||
|
patterns(...) |
||||||
|
) |
||||||
|
''' |
||||||
|
if not hasattr(wrapping_functions,'__iter__'): |
||||||
|
wrapping_functions = (wrapping_functions,) |
||||||
|
|
||||||
|
return [ |
||||||
|
_wrap_instance__resolve(wrapping_functions,instance) |
||||||
|
for instance in patterns_rslt |
||||||
|
] |
||||||
|
|
||||||
|
def _wrap_instance__resolve(wrapping_functions,instance): |
||||||
|
if not hasattr(instance,'resolve'): return instance |
||||||
|
resolve = getattr(instance,'resolve') |
||||||
|
|
||||||
|
def _wrap_func_in_returned_resolver_match(*args,**kwargs): |
||||||
|
rslt = resolve(*args,**kwargs) |
||||||
|
|
||||||
|
if not hasattr(rslt,'func'):return rslt |
||||||
|
f = getattr(rslt,'func') |
||||||
|
|
||||||
|
for _f in reversed(wrapping_functions): |
||||||
|
# @decorate the function from inner to outter |
||||||
|
f = _f(f) |
||||||
|
|
||||||
|
setattr(rslt,'func',f) |
||||||
|
|
||||||
|
return rslt |
||||||
|
|
||||||
|
setattr(instance,'resolve',_wrap_func_in_returned_resolver_match) |
||||||
|
|
||||||
|
return instance |
||||||
|
|
||||||
|
#----------------------------- |
||||||
@ -0,0 +1,26 @@ |
|||||||
|
from form_check import translit_with_separator |
||||||
|
from signal_additional_func import fill_missing_languages, fill_meta_information |
||||||
|
|
||||||
|
|
||||||
|
def post_save_handler(sender, **kwargs): |
||||||
|
""" |
||||||
|
receiver function |
||||||
|
take object |
||||||
|
fill missing languages |
||||||
|
fill settings if its exist for this object |
||||||
|
|
||||||
|
""" |
||||||
|
obj = kwargs['instance'] |
||||||
|
fill_missing_languages(obj) |
||||||
|
fill_meta_information(obj) |
||||||
|
|
||||||
|
|
||||||
|
def post_save_translation_handler(sender, **kwargs): |
||||||
|
""" |
||||||
|
receiver function |
||||||
|
take object and change url |
||||||
|
""" |
||||||
|
obj = kwargs['instance'] |
||||||
|
if obj.language_code == 'ru': |
||||||
|
obj.master.url = translit_with_separator(obj.name) |
||||||
|
obj.master.save() |
||||||
@ -0,0 +1,84 @@ |
|||||||
|
# -*- coding: utf-8 -*- |
||||||
|
from django.shortcuts import render_to_response |
||||||
|
from django.http import HttpResponseRedirect, HttpResponse |
||||||
|
from django.contrib.contenttypes.models import ContentType |
||||||
|
from django.contrib.auth.decorators import login_required |
||||||
|
from django.contrib.admin.views.decorators import staff_member_required |
||||||
|
from file.models import TmpFile, FileModel |
||||||
|
from file.forms import FileModelForm |
||||||
|
from city.models import City |
||||||
|
from theme.models import Tag |
||||||
|
from django.db.models.loading import get_model |
||||||
|
|
||||||
|
|
||||||
|
def admin_home(request): |
||||||
|
return render_to_response('base.html') |
||||||
|
|
||||||
|
def ajax_city(request): |
||||||
|
""" |
||||||
|
returns html <option> tags filled with cities filtered by country value from request |
||||||
|
""" |
||||||
|
objects = City.objects.filter(country=request.GET['id']) |
||||||
|
return render_to_response('select.html', {'objects': objects}) |
||||||
|
|
||||||
|
def ajax_tag(request): |
||||||
|
""" |
||||||
|
|
||||||
|
return array of tags (id, name) filtered by theme values from request |
||||||
|
|
||||||
|
""" |
||||||
|
if request.GET: |
||||||
|
ids = request.GET.get('id') |
||||||
|
if ids: |
||||||
|
#get id values in list |
||||||
|
data = ids.replace('theme=', '').split('&') |
||||||
|
#generate list of tags |
||||||
|
tags = ['[%d, "%s"]'%(int(item.id), item.name) for item in Tag.objects.filter(theme__in=data)] |
||||||
|
return HttpResponse('[%s]'%', '.join(tags), content_type='application/json') |
||||||
|
else: |
||||||
|
#request empty - send empty array |
||||||
|
return HttpResponse('[]', content_type='application/json') |
||||||
|
|
||||||
|
def ajax_post_file(request, obj_id=None): |
||||||
|
""" |
||||||
|
Takes file and file data and save it |
||||||
|
If obj_id = None creates TmpFile |
||||||
|
|
||||||
|
Returns 'file_list.html' template with existing files if id != None. |
||||||
|
N/A file_list.html' template with Tmp files filtered by key |
||||||
|
""" |
||||||
|
if request.POST: |
||||||
|
file_form = FileModelForm(request.POST, request.FILES) |
||||||
|
if file_form.is_valid(): |
||||||
|
#if obj_id is not exist create TMPfile objects else FileModel objects |
||||||
|
if obj_id != None: |
||||||
|
#takes data from hidden input "model" and initial Model |
||||||
|
Model = get_model(request.POST['model'].split('.')[0], request.POST['model'].split('.')[1]) |
||||||
|
#initial model object |
||||||
|
obj = Model.objects.get(id=obj_id) |
||||||
|
file = file_form.save(request.FILES, obj) |
||||||
|
#data = serializers.serialize('json', [file]) |
||||||
|
#return HttpResponse(data) |
||||||
|
files = FileModel.objects.filter(content_type=ContentType.objects.get_for_model(obj),object_id=getattr(obj, 'id')) |
||||||
|
else: |
||||||
|
file_form.save(request.FILES) |
||||||
|
files = TmpFile.objects.filter(key=request.POST['key']) |
||||||
|
|
||||||
|
return render_to_response('file_list.html', {'files' : files}) |
||||||
|
|
||||||
|
args = {} |
||||||
|
|
||||||
|
args['languages'] = settings.LANGUAGES |
||||||
|
args['file_form'] = file_form |
||||||
|
return render_to_response('ajax_error_form.html', args) |
||||||
|
|
||||||
|
def ajax_delete_file(request): |
||||||
|
""" |
||||||
|
delete file |
||||||
|
""" |
||||||
|
if request.GET: |
||||||
|
file = FileModel.objects.get(id = request.GET['id']) |
||||||
|
file.delete() |
||||||
|
return HttpResponse('success') |
||||||
|
else: |
||||||
|
return HttpResponse('error') |
||||||
@ -1,9 +0,0 @@ |
|||||||
# -*- coding: utf-8 -*- |
|
||||||
from hvad.admin import TranslatableAdmin |
|
||||||
from django.contrib import admin |
|
||||||
from models import Settings |
|
||||||
|
|
||||||
class SettingsAdmin(TranslatableAdmin): |
|
||||||
pass |
|
||||||
|
|
||||||
admin.site.register(Settings, SettingsAdmin) |
|
||||||
@ -1,40 +1,40 @@ |
|||||||
# -*- coding: utf-8 -*- |
# -*- coding: utf-8 -*- |
||||||
from django.conf.urls import patterns, include, url |
from django.conf.urls import patterns, include, url |
||||||
|
from functions import required |
||||||
|
from django.contrib.admin.views.decorators import staff_member_required |
||||||
|
|
||||||
|
urlpatterns = required( |
||||||
urlpatterns = patterns('', |
staff_member_required, |
||||||
url(r'^$', 'proj.views.home', name='home'), |
patterns('', |
||||||
url(r'^import-event/$', 'import_xls.views.import_event'), |
url(r'^$', 'proj.admin.admin_home'), |
||||||
url(r'^export-event/$', 'import_xls.views.export_event'), |
url(r'^import-event/$', 'import_xls.views.import_event'), |
||||||
url(r'^accounts/', include('registration.backends.default.urls')), |
url(r'^export-event/$', 'import_xls.views.export_event'), |
||||||
url(r'^accounts/', include('accounts.urls')), |
url(r'^accounts/', include('accounts.urls')), |
||||||
url(r'^article/', include('article.urls')), |
url(r'^article/', include('article.urls')), |
||||||
url(r'^city/', include('city.urls')), |
url(r'^city/', include('city.urls')), |
||||||
url(r'^company/', include('company.urls')), |
url(r'^company/', include('company.urls')), |
||||||
url(r'^conference/', include('conference.urls')), |
url(r'^conference/', include('conference.urls')), |
||||||
url(r'^country/', include('country.urls')), |
url(r'^country/', include('country.urls')), |
||||||
url(r'^exposition/', include('exposition.urls')), |
url(r'^exposition/', include('exposition.urls')), |
||||||
url(r'^news/', include('news.urls')), |
url(r'^news/', include('news.urls')), |
||||||
url(r'^organiser/', include('organiser.urls')), |
url(r'^organiser/', include('organiser.urls')), |
||||||
url(r'^place_conference/', include('place_conference.urls')), |
url(r'^place_conference/', include('place_conference.urls')), |
||||||
url(r'^place_exposition/', include('place_exposition.urls')), |
url(r'^place_exposition/', include('place_exposition.urls')), |
||||||
url(r'^seminar/', include('seminar.urls')), |
url(r'^seminar/', include('seminar.urls')), |
||||||
url(r'^service/', include('service.urls')), |
url(r'^service/', include('service.urls')), |
||||||
url(r'^theme/', include('theme.urls')), |
url(r'^theme/', include('theme.urls')), |
||||||
url(r'^translator/', include('translator.urls')), |
url(r'^translator/', include('translator.urls')), |
||||||
url(r'^webinar/', include('webinar.urls')), |
url(r'^webinar/', include('webinar.urls')), |
||||||
#url(r'^settings/$', 'proj.views.settings'), |
url(r'^settings/$', include('settings.urls')), |
||||||
url(r'^settings/$', include('settings.urls')), |
url(r'^language/add/', 'directories.admin.language_add'), |
||||||
url(r'^language/add/', 'directories.admin.language_add'), |
url(r'^currency/add/', 'directories.admin.currency_add'), |
||||||
url(r'^currency/add/', 'directories.admin.currency_add'), |
# ajax requests |
||||||
# |
url(r'^ajax_post_file/(?P<obj_id>\d+)/$', 'proj.admin.ajax_post_file'),#must be before /ajax_post_file/ |
||||||
url(r'^test/', 'proj.views.test'), |
url(r'^ajax_post_file/', 'proj.admin.ajax_post_file'), |
||||||
#ajax requests |
url(r'^ajax_delete_file/', 'proj.admin.ajax_delete_file'), |
||||||
url(r'^ajax_post_file/(?P<obj_id>\d+)/$', 'proj.views.ajax_post_file'),#must be before /ajax_post_file/ |
url(r'^ajax_city/', 'proj.admin.ajax_city'), |
||||||
url(r'^ajax_post_file/', 'proj.views.ajax_post_file'), |
url(r'^ajax_tag/', 'proj.admin.ajax_tag'), |
||||||
url(r'^ajax_delete_file/', 'proj.views.ajax_delete_file'), |
# |
||||||
url(r'^ajax_city/', 'proj.views.ajax_city'), |
url(r'^ckeditor/', include('ckeditor.urls')), |
||||||
url(r'^ajax_tag/', 'proj.views.ajax_tag'), |
) |
||||||
# |
|
||||||
url(r'^ckeditor/', include('ckeditor.urls')), |
|
||||||
) |
) |
||||||
|
|||||||
@ -1,36 +0,0 @@ |
|||||||
# -*- coding: utf-8 -*- |
|
||||||
from django import forms |
|
||||||
from models import Settings |
|
||||||
from settings import LANGUAGES |
|
||||||
from functions.translate import fill_trans_fields, populate, ZERO_LANGUAGE, populate_all, fill_trans_fields_all |
|
||||||
|
|
||||||
|
|
||||||
class SettingsForm(forms.Form): |
|
||||||
""" |
|
||||||
Create Settings form for creating settings |
|
||||||
|
|
||||||
__init__ uses for dynamic creates fields |
|
||||||
|
|
||||||
save function saves data in Settings object. If it doesnt exist create new object |
|
||||||
""" |
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs): |
|
||||||
super(SettingsForm, self).__init__(*args, **kwargs) |
|
||||||
# creates translated form fields, example: name_ru, name_en |
|
||||||
# len(10) is a hack for detect if settings.LANGUAGES is not configured it return all langs |
|
||||||
obj = Settings.objects.get(key='hall_template') |
|
||||||
if len(LANGUAGES) in range(10): |
|
||||||
for lid, (code, name) in enumerate(LANGUAGES): |
|
||||||
# using enumerate for detect iteration number |
|
||||||
# first iteration is a default lang so it required fields |
|
||||||
required = True if lid == 0 else False |
|
||||||
self.fields['hall_capacity_tmpl_%s' % code] = forms.CharField(label=getattr(obj, 'name'), initial=obj.get_value(code), |
|
||||||
required=required,widget=forms.TextInput(attrs={'style':'width: 550px'})) |
|
||||||
def save(self): |
|
||||||
""" |
|
||||||
changes Settings model |
|
||||||
""" |
|
||||||
data = self.cleaned_data |
|
||||||
capacity_tmpl = Settings.objects.get(key='hall_template') |
|
||||||
for code, name in LANGUAGES: |
|
||||||
capacity_tmpl.set_value(data['hall_capacity_tmpl_%s'%code], code) |
|
||||||
@ -1,52 +0,0 @@ |
|||||||
# -*- coding: utf-8 -*- |
|
||||||
from django.db import models |
|
||||||
from hvad.models import TranslatableModel, TranslatedFields |
|
||||||
from settings import LANGUAGES |
|
||||||
# |
|
||||||
from functions.custom_fields import EnumField |
|
||||||
|
|
||||||
VALUES = ('int', 'text', 'transl', 'date') |
|
||||||
|
|
||||||
|
|
||||||
class Settings(TranslatableModel): |
|
||||||
""" |
|
||||||
Create Settings model, which stores different settings of project |
|
||||||
|
|
||||||
Uses hvad.TranslatableModel which is child of django.db.models class |
|
||||||
""" |
|
||||||
key = models.CharField(max_length=50) |
|
||||||
type = EnumField(values=VALUES) |
|
||||||
int = models.IntegerField(blank=True, null=True) |
|
||||||
text = models.CharField(max_length=255, blank=True) |
|
||||||
date = models.DateTimeField(blank=True, null=True) |
|
||||||
|
|
||||||
translations = TranslatedFields( |
|
||||||
transl = models.CharField(max_length=255, blank=True), |
|
||||||
name = models.CharField(max_length=50), |
|
||||||
) |
|
||||||
|
|
||||||
def __unicode__(self): |
|
||||||
return self.key |
|
||||||
|
|
||||||
def get_value(self, code=None): |
|
||||||
""" |
|
||||||
returns value of setting |
|
||||||
value can be - int, text, date or translated field |
|
||||||
|
|
||||||
""" |
|
||||||
if self.type == 'transl': |
|
||||||
obj = Settings._meta.translations_model.objects.get(language_code = code,master__id=getattr(self, 'id')) |
|
||||||
return getattr(obj, self.type) |
|
||||||
else: |
|
||||||
return getattr(self,self.type) |
|
||||||
|
|
||||||
def set_value(self, value, code=None): |
|
||||||
""" |
|
||||||
sets value of setting |
|
||||||
""" |
|
||||||
if self.type == 'transl': |
|
||||||
obj = Settings._meta.translations_model.objects.get(language_code = code,master__id=getattr(self, 'id')) |
|
||||||
setattr(obj, self.type, value) |
|
||||||
obj.save() |
|
||||||
else: |
|
||||||
setattr(self, self.type, value) |
|
||||||
@ -1,62 +1,18 @@ |
|||||||
# -*- coding: utf-8 -*- |
# -*- coding: utf-8 -*- |
||||||
from django.conf.urls import patterns, include, url |
from django.conf.urls import patterns, include, url |
||||||
|
|
||||||
# Uncomment the next two lines to enable the admin: |
|
||||||
from django.contrib import admin |
|
||||||
admin.autodiscover() |
|
||||||
|
|
||||||
from django.contrib.auth.views import login, logout |
|
||||||
|
|
||||||
urlpatterns = patterns('', |
urlpatterns = patterns('', |
||||||
url(r'^$', 'proj.views.home', name='home'), |
url(r'^$', 'proj.views.home', name='home'), |
||||||
url(r'^login/', 'registration.backends.default.views.LoginView'), |
url(r'^login/', 'registration.backends.default.views.LoginView'), |
||||||
url(r'^logout/', 'registration.backends.default.views.LogoutView'), |
url(r'^logout/', 'registration.backends.default.views.LogoutView'), |
||||||
url(r'^profile/', 'accounts.views.profile'), |
url(r'^profile/$', 'accounts.views.profile'), |
||||||
|
# admin part |
||||||
|
|
||||||
url(r'^admin/', include('proj.admin_urls')), |
url(r'^admin/', include('proj.admin_urls')), |
||||||
url(r'^accounts/', include('registration.backends.default.urls')), |
|
||||||
) |
) |
||||||
|
|
||||||
# ajax urls |
# ajax urls |
||||||
urlpatterns += patterns('', |
urlpatterns += patterns('', |
||||||
url(r'^register/', 'registration.backends.default.views.RegisterAjaxView'), |
url(r'^register/', 'registration.backends.default.views.RegisterAjaxView'), |
||||||
|
url(r'^profile/change-password/', 'accounts.views.change_password'), |
||||||
) |
) |
||||||
''' |
|
||||||
urlpatterns = patterns('', |
|
||||||
url(r'^$', 'proj.views.home', name='home'), |
|
||||||
url(r'^accounts/', include('registration.backends.default.urls')), |
|
||||||
url(r'^accounts/', include('accounts.urls')), |
|
||||||
url(r'^article/', include('article.urls')), |
|
||||||
url(r'^city/', include('city.urls')), |
|
||||||
url(r'^company/', include('company.urls')), |
|
||||||
url(r'^conference/', include('conference.urls')), |
|
||||||
url(r'^country/', include('country.urls')), |
|
||||||
url(r'^exposition/', include('exposition.urls')), |
|
||||||
url(r'^file/', include('file.urls')), |
|
||||||
url(r'^news/', include('news.urls')), |
|
||||||
url(r'^organiser/', include('organiser.urls')), |
|
||||||
url(r'^place_conference/', include('place_conference.urls')), |
|
||||||
url(r'^place_exposition/', include('place_exposition.urls')), |
|
||||||
url(r'^seminar/', include('seminar.urls')), |
|
||||||
url(r'^service/', include('service.urls')), |
|
||||||
url(r'^theme/', include('theme.urls')), |
|
||||||
url(r'^translator/', include('translator.urls')), |
|
||||||
url(r'^webinar/', include('webinar.urls')), |
|
||||||
url(r'^settings/$', 'proj.views.settings'), |
|
||||||
url(r'^language/add/', 'directories.views.language_add'), |
|
||||||
url(r'^currency/add/', 'directories.views.currency_add'), |
|
||||||
# |
|
||||||
url(r'^test/', 'proj.views.test'), |
|
||||||
#ajax requests |
|
||||||
url(r'^ajax_post_file/(?P<obj_id>\d+)/$', 'proj.views.ajax_post_file'),#must be before /ajax_post_file/ |
|
||||||
url(r'^ajax_post_file/', 'proj.views.ajax_post_file'), |
|
||||||
url(r'^ajax_delete_file/', 'proj.views.ajax_delete_file'), |
|
||||||
url(r'^ajax_city/', 'proj.views.ajax_city'), |
|
||||||
url(r'^ajax_tag/', 'proj.views.ajax_tag'), |
|
||||||
# |
|
||||||
url(r'^ckeditor/', include('ckeditor.urls')), |
|
||||||
#-------------------------- |
|
||||||
url(r'^admin/', include(admin.site.urls)), |
|
||||||
) |
|
||||||
''' |
|
||||||
Loading…
Reference in new issue