diff --git a/accounts/admin.py b/accounts/admin.py index 3dd04327..b0a394ee 100644 --- a/accounts/admin.py +++ b/accounts/admin.py @@ -1,34 +1,182 @@ # -*- coding: utf-8 -*- -from django.contrib import admin -from django.contrib.auth.models import Group -from django.contrib.auth.admin import UserAdmin - +from django.shortcuts import render_to_response +from django.http import HttpResponseRedirect, HttpResponse +from django.template import RequestContext +from django.core.context_processors import csrf +from django.contrib.auth.decorators import login_required +import random +from django.utils.translation import ugettext as _ +#models and forms from models import User -from forms import UserCreationForm, UserChangeForm +from forms import UserForm, UserCreationForm, ChangePasswordForm, EmailAnnouncementForm +#custom views +from functions.custom_views import objects_list + +from hashlib import md5 +import json + + +@login_required +def profile(request): + args = {'change_password_form': ChangePasswordForm(), + 'email_announcement_form': EmailAnnouncementForm()} + args.update(csrf(request)) + return render_to_response('profile.html', args, context_instance=RequestContext(request)) + + + +def user_all(request): + """ + Return list of all users with pagination + """ + return objects_list(request, User, 'user_all.html') + +def user_change(request, url): + """ + Return form of user and post it on the server. + If form is posted redirect on the page of all users. + """ + user = User.objects.safe_get(id=url) + # try get user by url if doesnt work by id + if user is None: + user = User.objects.safe_get(url=url) + #redirect to list of all users if cannot find user + if user is None: + return HttpResponseRedirect('/admin/accounts/all') + + if request.POST: + form = UserForm(request.POST, instance=user) + if form.is_valid(): + form.save() + return HttpResponseRedirect('/admin/accounts/all') + else: + form = UserForm(instance=user) + + args = {} + args.update(csrf(request)) + + args['form'] = form + + return render_to_response('user_change.html', args) + +def create_admin(request): + if request.POST: + form = UserCreationForm(request.POST) + if form.is_valid(): + user = form.save(commit=False) + user.is_admin = False + user.save() + return HttpResponseRedirect('/admin/accounts/all') + + else: + form = UserCreationForm() + + args = {} + args.update(csrf(request)) + args['form'] = form + + return render_to_response('create_admin.html', args) + +def create_md5(request): + if request.POST: + form = UserCreationForm(request.POST) + if form.is_valid(): + user = User() + user.email = request.POST['email'] + user.first_name = request.POST['first_name'] + user.last_name = request.POST['last_name'] + user.password = md5(request.POST['password2']).hexdigest() + user.is_admin = True + user.save() + + return HttpResponseRedirect('/admin/accounts/all') + + else: + form = UserCreationForm() + + args = {} + args.update(csrf(request)) + args['form'] = form + + return render_to_response('create_admin.html', args) + +from django.core.mail import EmailMessage + + +def registration(request): + if request.POST: + form = UserCreationForm(request.POST) + if form.is_valid(): + user = form.save() + email = EmailMessage('Subject', 'Body', to=['%s'%user.email]) + email.send() + return HttpResponseRedirect('/admin/accounts/registration') + else: + form = UserCreationForm() + args = {} + args.update(csrf(request)) + args['form'] = form -class UserAdmin(UserAdmin): + return render_to_response('registration.html', args) - form = UserChangeForm - add_form = UserCreationForm +def generatePassword(): + """ + generate random password from 8 symbols + """ + SYMBOLS = [',', '.', '?', '!', '-', '+', '1', '2', '3', '4', '5', '6', '7', '8', + '9', '0', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', + 'm', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', + 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', + 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '#'] + PASSWORD_LENGTH = 8 + newPassword = [] + for i in range(PASSWORD_LENGTH): + newPassword.append(SYMBOLS[random.randrange(0, len(SYMBOLS))]) + return ''.join(newPassword) - list_display = ('email', 'first_name', 'last_name', 'is_admin',) - list_filter = ('is_admin',) +from django.conf import settings - fieldsets = ( - (None, {'fields': ('email', 'first_name', 'last_name', 'password')}), - (None, {'fields': ('url', 'country', 'city', 'position', - 'about', 'phone', 'avatar', 'web_page', - 'social', 'title', 'descriptions', 'keywords', - 'is_admin', 'is_active')}), +def reset_password_email(request): + """ + generate random password + set this password to user and send on email + """ + if request.GET: + user = User.objects.get(email=request.GET['email']) + new_pass = generatePassword() + user.email_user('Reset password', 'Your new password: "%s" '%new_pass, settings.DEFAULT_FROM_EMAIL, ) + user.set_password(u'%s'%new_pass) + user.save() + return HttpResponse('success') - ) - add_fieldsets = ( - (None, {'classes': ('wide',), 'fields': ('email','first_name', 'last_name', 'password1', 'password2')}), - ) - ordering = ('email',) - filter_horizontal = () + return HttpResponse('error') -admin.site.register(User, UserAdmin) -admin.site.unregister(Group) \ No newline at end of file +@login_required +def change_password(request): + """ + Change current user password if new password is valid + """ + success = {'success': False} + if request.POST: + form = ChangePasswordForm(request.POST) + if form.is_valid(): + user = request.user + if(user.check_password(form.cleaned_data.get('old_password'))): + #user.set_password(form.cleaned_data.get('new_password')) + #user.save() + success['success'] = True + success['message'] = _(u'Пароль именен') + return HttpResponse(json.dumps(success), content_type='application/json') + else: + errors = {'errors': [_(u'Не правильный пароль')]} + success.update(errors) + return HttpResponse(json.dumps(success), content_type='application/json') + else: + errors = [err[0] for err in form.errors.values()] + errors = {'errors': errors} + success.update(errors) + return HttpResponse(json.dumps(success), content_type='application/json') + else: + return HttpResponse(json.dumps(success), content_type='application/json') diff --git a/accounts/admin_urls.py b/accounts/admin_urls.py new file mode 100644 index 00000000..138639fb --- /dev/null +++ b/accounts/admin_urls.py @@ -0,0 +1,12 @@ +# -*- coding: utf-8 -*- +from django.conf.urls import patterns, url + +urlpatterns = patterns('', + url(r'^registration/$', 'accounts.admin.registration'), + url(r'^create_admin/$', 'accounts.admin.create_admin'), + url(r'^create_md5user/$', 'accounts.admin.create_md5'), + url(r'^change/(.*)/$', 'accounts.admin.user_change'), +# url(r'^change/(?P\d+).*/$', 'accounts.views.user_change'), + url(r'^all/$', 'accounts.admin.user_all'), + url(r'^reset_password_email/$', 'accounts.admin.reset_password_email'), +) \ No newline at end of file diff --git a/accounts/signals.py b/accounts/signals.py new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/accounts/signals.py @@ -0,0 +1 @@ + diff --git a/accounts/urls.py b/accounts/urls.py deleted file mode 100644 index 3e670b7a..00000000 --- a/accounts/urls.py +++ /dev/null @@ -1,15 +0,0 @@ -# -*- coding: utf-8 -*- -from django.conf.urls import patterns, include, url -from django.contrib.auth.views import login, logout - -urlpatterns = patterns('', - url(r'^login_admin/', login, {'template_name': 'admin/login.html' }), - url(r'^logout_admin', logout, {'next_page': '/admin/accounts/login_admin/'}), - url(r'^registration/$', 'accounts.views.registration'), - url(r'^create_admin/$', 'accounts.views.create_admin'), - url(r'^create_md5user/$', 'accounts.views.create_md5'), - url(r'^change/(.*)/$', 'accounts.views.user_change'), -# url(r'^change/(?P\d+).*/$', 'accounts.views.user_change'), - url(r'^all/$', 'accounts.views.user_all'), - url(r'^reset_password_email/$', 'accounts.views.reset_password_email'), -) \ No newline at end of file diff --git a/accounts/views.py b/accounts/views.py index b0a394ee..52648bfa 100644 --- a/accounts/views.py +++ b/accounts/views.py @@ -4,15 +4,10 @@ from django.http import HttpResponseRedirect, HttpResponse from django.template import RequestContext from django.core.context_processors import csrf from django.contrib.auth.decorators import login_required -import random from django.utils.translation import ugettext as _ -#models and forms -from models import User -from forms import UserForm, UserCreationForm, ChangePasswordForm, EmailAnnouncementForm -#custom views -from functions.custom_views import objects_list - -from hashlib import md5 +# forms +from forms import ChangePasswordForm, EmailAnnouncementForm +# python import json @@ -23,136 +18,6 @@ def profile(request): args.update(csrf(request)) return render_to_response('profile.html', args, context_instance=RequestContext(request)) - - -def user_all(request): - """ - Return list of all users with pagination - """ - return objects_list(request, User, 'user_all.html') - -def user_change(request, url): - """ - Return form of user and post it on the server. - If form is posted redirect on the page of all users. - """ - user = User.objects.safe_get(id=url) - # try get user by url if doesnt work by id - if user is None: - user = User.objects.safe_get(url=url) - #redirect to list of all users if cannot find user - if user is None: - return HttpResponseRedirect('/admin/accounts/all') - - if request.POST: - form = UserForm(request.POST, instance=user) - if form.is_valid(): - form.save() - return HttpResponseRedirect('/admin/accounts/all') - else: - form = UserForm(instance=user) - - args = {} - args.update(csrf(request)) - - args['form'] = form - - return render_to_response('user_change.html', args) - -def create_admin(request): - if request.POST: - form = UserCreationForm(request.POST) - if form.is_valid(): - user = form.save(commit=False) - user.is_admin = False - user.save() - return HttpResponseRedirect('/admin/accounts/all') - - else: - form = UserCreationForm() - - args = {} - args.update(csrf(request)) - args['form'] = form - - return render_to_response('create_admin.html', args) - -def create_md5(request): - if request.POST: - form = UserCreationForm(request.POST) - if form.is_valid(): - user = User() - user.email = request.POST['email'] - user.first_name = request.POST['first_name'] - user.last_name = request.POST['last_name'] - user.password = md5(request.POST['password2']).hexdigest() - user.is_admin = True - user.save() - - return HttpResponseRedirect('/admin/accounts/all') - - else: - form = UserCreationForm() - - args = {} - args.update(csrf(request)) - args['form'] = form - - return render_to_response('create_admin.html', args) - -from django.core.mail import EmailMessage - - -def registration(request): - if request.POST: - form = UserCreationForm(request.POST) - if form.is_valid(): - user = form.save() - email = EmailMessage('Subject', 'Body', to=['%s'%user.email]) - email.send() - return HttpResponseRedirect('/admin/accounts/registration') - else: - form = UserCreationForm() - - args = {} - args.update(csrf(request)) - - args['form'] = form - - return render_to_response('registration.html', args) - -def generatePassword(): - """ - generate random password from 8 symbols - """ - SYMBOLS = [',', '.', '?', '!', '-', '+', '1', '2', '3', '4', '5', '6', '7', '8', - '9', '0', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', - 'm', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', - 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', - 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '#'] - PASSWORD_LENGTH = 8 - newPassword = [] - for i in range(PASSWORD_LENGTH): - newPassword.append(SYMBOLS[random.randrange(0, len(SYMBOLS))]) - return ''.join(newPassword) - -from django.conf import settings - -def reset_password_email(request): - """ - generate random password - set this password to user and send on email - """ - if request.GET: - user = User.objects.get(email=request.GET['email']) - new_pass = generatePassword() - user.email_user('Reset password', 'Your new password: "%s" '%new_pass, settings.DEFAULT_FROM_EMAIL, ) - user.set_password(u'%s'%new_pass) - user.save() - return HttpResponse('success') - - return HttpResponse('error') - @login_required def change_password(request): """ @@ -179,4 +44,4 @@ def change_password(request): success.update(errors) return HttpResponse(json.dumps(success), content_type='application/json') else: - return HttpResponse(json.dumps(success), content_type='application/json') + return HttpResponse(json.dumps(success), content_type='application/json') \ No newline at end of file diff --git a/article/admin2.py b/article/admin2.py deleted file mode 100644 index 7bd07ef3..00000000 --- a/article/admin2.py +++ /dev/null @@ -1,9 +0,0 @@ -# -*- 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) \ No newline at end of file diff --git a/article/urls.py b/article/admin_urls.py similarity index 100% rename from article/urls.py rename to article/admin_urls.py diff --git a/article/forms.py b/article/forms.py index 443b5afa..1045ebf1 100644 --- a/article/forms.py +++ b/article/forms.py @@ -5,7 +5,7 @@ from ckeditor.widgets import CKEditorWidget from django.core.exceptions import ValidationError from django.forms.util import ErrorList #functions -from functions.translate import populate_all, fill_trans_fields_all +from functions.translate import fill_with_signal from functions.files import check_tmp_files from functions.form_check import translit_with_separator #models @@ -77,27 +77,19 @@ class ArticleForm(forms.Form): article.user = User.objects.get(id=data['author'].id)#.id cause select uses queryset #create slug field from russian language - article.url = translit_with_separator(data['main_title_ru']).lower() - - # uses because in the next loop data will be overwritten - article.save() + article.url = translit_with_separator(data['main_title_ru'].strip()).lower() + # fill translated fields and save object + fill_with_signal(Article, article, data) + # fill manytomany fields for item in data['theme']: article.theme.add(item.id)#.id cause select uses queryset for item in data['tag']: article.tag.add(item) - # uses because in the next loop data will be overwritten - article.save() - #populate fields with zero language - zero_fields = {} - fill_trans_fields_all(Article, article, data, id, zero_fields) + article.save() - #autopopulate - #populate empty fields and fields which was already populated - article_id = getattr(article, 'id') - populate_all(Article, data, article_id, zero_fields) #save files check_tmp_files(article, data['key']) diff --git a/article/signals.py b/article/signals.py new file mode 100644 index 00000000..bfabd4de --- /dev/null +++ b/article/signals.py @@ -0,0 +1,6 @@ +# -*- coding: utf-8 -*- +from django.db.models.signals import post_save +from models import Article +from functions.signal_handlers import post_save_handler + +post_save.connect(post_save_handler, sender=Article) diff --git a/city/admin2.py b/city/admin2.py deleted file mode 100644 index b7a71a76..00000000 --- a/city/admin2.py +++ /dev/null @@ -1,9 +0,0 @@ -# -*- 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) \ No newline at end of file diff --git a/city/urls.py b/city/admin_urls.py similarity index 100% rename from city/urls.py rename to city/admin_urls.py diff --git a/city/forms.py b/city/forms.py index 451ea820..43922b1d 100644 --- a/city/forms.py +++ b/city/forms.py @@ -9,7 +9,7 @@ from models import City from country.models import Country from directories.models import Iata #functions -from functions.translate import fill_trans_fields_all, populate_all, fill_with_signal +from functions.translate import fill_with_signal from functions.form_check import is_positive_integer, translit_with_separator from functions.files import check_tmp_files @@ -56,17 +56,13 @@ class CityForm(forms.Form): self.fields['shoping_%s' % code] = forms.CharField(label='Шопинг', required=False, widget=CKEditorWidget()) self.fields['transport_%s' % code] = forms.CharField(label='Транспорт', required=False, widget=CKEditorWidget()) #meta data - self.fields['title_%s' % code] = forms.CharField(label='Тайтл', required=required, max_length=255, + self.fields['title_%s' % code] = forms.CharField(label='Тайтл', required=False, max_length=255, widget=forms.TextInput(attrs={'style':'width: 550px'})) self.fields['keywords_%s' % code] = forms.CharField(label='Дескрипшен', required=False, max_length=255, widget=forms.TextInput(attrs={'style':'width: 550px'})) - self.fields['descriptions_%s' % code] = forms.CharField(label='Кейвордс', required=required, max_length=255, + self.fields['descriptions_%s' % code] = forms.CharField(label='Кейвордс', required=False, max_length=255, widget=forms.TextInput(attrs={'style':'width: 550px'})) - #creates select inputs ind fill it - #countries = ((item.id, item.name) for item in Country.objects.all()) - #self.fields['country'] = forms.ChoiceField(label='Страна', choices=countries, required=False) - def save(self, id=None): """ @@ -77,24 +73,27 @@ class CityForm(forms.Form): """ data = self.cleaned_data #create new City object or get exists - if not id: - city = City() - else: + if id: city = City.objects.get(id=id) - city.phone_code = data['phone_code'] - city.population = data['population'] + else: + city = City() + + city.phone_code = data.get('phone_code') + city.population = data.get('population') if data.get('code_IATA'): - city.code_IATA = Iata.objects.get(id=data['code_IATA'].id)#.id cause select uses queryset + city.code_IATA = Iata.objects.get(id=data['code_IATA'].id)# .id cause select uses queryset if data.get('country'): - city.country = Country.objects.get(id=data['country'].id)#.id cause select uses queryset + city.country = Country.objects.get(id=data['country'].id)# .id cause select uses queryset + # url generate for city: "country_name-city_name" city.url = '%s-'%translit_with_separator(city.country.name) + translit_with_separator(data['name_ru']).lower() + # fill translated fields and save object fill_with_signal(City, city, data) - #save files + # save files check_tmp_files(city, data['key']) diff --git a/city/signals.py b/city/signals.py new file mode 100644 index 00000000..9982362b --- /dev/null +++ b/city/signals.py @@ -0,0 +1,8 @@ +# -*- coding: utf-8 -*- +from django.db.models.signals import post_save +from models import City +from functions.signal_handlers import post_save_handler + +post_save.connect(post_save_handler, sender=City) + + diff --git a/company/admin2.py b/company/admin2.py deleted file mode 100644 index f9d75d09..00000000 --- a/company/admin2.py +++ /dev/null @@ -1,9 +0,0 @@ -# -*- 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) diff --git a/company/urls.py b/company/admin_urls.py similarity index 100% rename from company/urls.py rename to company/admin_urls.py diff --git a/company/forms.py b/company/forms.py index e84d80b8..d73abb5d 100644 --- a/company/forms.py +++ b/company/forms.py @@ -10,7 +10,7 @@ from country.models import Country from theme.models import Theme from city.models import City #functions -from functions.translate import populate_all, fill_trans_fields_all +from functions.translate import fill_with_signal from functions.form_check import is_positive_integer, translit_with_separator from functions.files import check_tmp_files from functions.custom_fields import LocationWidget @@ -98,7 +98,7 @@ class CompanyForm(forms.Form): company.tag.clear() #simple fields - company.url = translit_with_separator(data['url']).lower() + company.url = translit_with_separator(data['url'].strip()).lower() company.staff_number = data['staff_number'] company.address = data['address'] company.phone = data['phone'] @@ -114,8 +114,8 @@ class CompanyForm(forms.Form): if data.get('city'): company.city = City.objects.get(id=data['city']) - # uses because in the next loop data will be overwritten - company.save() + # fill translated fields and save object + fill_with_signal(Company, company, data) #fill manytomany fields for item in data['theme']: @@ -127,15 +127,6 @@ class CompanyForm(forms.Form): # uses because in the next loop data will be overwritten company.save() - #will be saved populated fields - zero_fields = {} - #fills all translated fields with data - #if saves new object, will fill city object. otherwise existing object of City model - fill_trans_fields_all(Company, company, data, id, zero_fields) - #autopopulate - #populate empty fields and fields which was already populated - company_id = getattr(company, 'id') - populate_all(Company, data, company_id, zero_fields) #save files check_tmp_files(company, data['key']) diff --git a/company/signals.py b/company/signals.py new file mode 100644 index 00000000..56ff1a16 --- /dev/null +++ b/company/signals.py @@ -0,0 +1,6 @@ +# -*- coding: utf-8 -*- +from django.db.models.signals import post_save +from models import Company +from functions.signal_handlers import post_save_handler + +post_save.connect(post_save_handler, sender=Company) diff --git a/conference/admin2.py b/conference/admin2.py deleted file mode 100644 index e69de29b..00000000 diff --git a/conference/urls.py b/conference/admin_urls.py similarity index 100% rename from conference/urls.py rename to conference/admin_urls.py diff --git a/conference/forms.py b/conference/forms.py index 6e8ddb18..18eff36a 100644 --- a/conference/forms.py +++ b/conference/forms.py @@ -112,7 +112,7 @@ class ConferenceCreateForm(forms.Form): conference.tag.clear() #simple fields - conference.url = translit_with_separator(data['name_ru']).lower() + conference.url = translit_with_separator(data['name_ru'].strip()).lower() conference.data_begin = data['data_begin'] conference.data_end = data['data_end'] conference.link = data['link'] @@ -133,7 +133,9 @@ class ConferenceCreateForm(forms.Form): if data.get('place'): conference.place = PlaceConference.objects.get(id=data['place'].id)#.id cause select uses queryset + # fill translated fields and save object fill_with_signal(Conference, conference, data) + #fill manytomany fields for item in data['theme']: conference.theme.add(item.id)#.id cause select uses queryset diff --git a/conference/models.py b/conference/models.py index 7e17f7ab..8d026e74 100644 --- a/conference/models.py +++ b/conference/models.py @@ -158,46 +158,4 @@ class TimeTable(TranslatableModel): #translated fields translations = TranslatedFields( name = models.CharField(verbose_name='Название', max_length=255) - ) - -from django.db.models.signals import post_save -from django.dispatch import receiver -from django.conf import settings -from functions.form_check import translit_with_separator -from functions.translate import get_translated_fields - -@receiver(post_save) -def conference_post_save_handler(sender, **kwargs): - """ - objects saves two times: - - first time Conference object - - second time ConferenceTranslation object - object must have at least one Translation - """ - - obj = kwargs['instance'] - if isinstance(obj, Conference): - # object is Exposition - if kwargs['created'] and obj.url == '': - # if url doesn't set in new object set it - obj.url = translit_with_separator(obj.name) - - # what languages must be - all_langs = [code for code, lang in settings.LANGUAGES] - # what languages are - obj_langs = obj.get_available_languages() - # - missing_languages = list(set(all_langs) - set(obj_langs)) - # get first Translation object - translation = obj.translations.all()[0] - # translated fields - fields = get_translated_fields(obj) - - for code in missing_languages: - # translate - obj.translate(code) - # go through all fields and set value - for field in fields: - setattr(obj, field, getattr(translation, field)) - - obj.save() \ No newline at end of file + ) \ No newline at end of file diff --git a/conference/signals.py b/conference/signals.py new file mode 100644 index 00000000..376c2d92 --- /dev/null +++ b/conference/signals.py @@ -0,0 +1,6 @@ +# -*- coding: utf-8 -*- +from django.db.models.signals import post_save +from models import Conference +from functions.signal_handlers import post_save_handler + +post_save.connect(post_save_handler, sender=Conference) diff --git a/country/urls.py b/country/admin_urls.py similarity index 100% rename from country/urls.py rename to country/admin_urls.py diff --git a/country/forms.py b/country/forms.py index 0c0f5ffa..14d68558 100644 --- a/country/forms.py +++ b/country/forms.py @@ -12,10 +12,6 @@ from functions.translate import fill_with_signal from functions.files import check_tmp_files from functions.form_check import is_positive_integer, translit_with_separator - -from functions.translate import get_translated_fields - - tz = [ (99, ''), (-12.0, '(GMT -12:00) Eniwetok, Kwajalein'), (-11.0,'(GMT -11:00) Midway Island, Samoa'), @@ -131,7 +127,7 @@ class CountryForm(forms.Form): country.currency.clear() - country.url = translit_with_separator(data['name_ru']).lower() + country.url = translit_with_separator(data['name_ru'].strip()).lower() country.population = data['population'] country.teritory = data['teritory'] country.timezone = data['timezone'] @@ -141,10 +137,12 @@ class CountryForm(forms.Form): if data.get('capital'): country.capital = City.objects.get(id=data['capital']) + # fill translated fields and save object fill_with_signal(Country, country, data) - #fill manytomany fields + + # fill manytomany fields for item in data['language']: country.language.add(item.id)#.id cause select uses queryset @@ -155,21 +153,22 @@ class CountryForm(forms.Form): country.currency.add(item.id)#.id cause select uses queryset country.save() - #save files + # save files check_tmp_files(country, data['key']) def clean(self): - id = self.cleaned_data.get('country_id') - name_ru = self.cleaned_data.get('name_ru') + data = self.cleaned_data + id = data.get('country_id') + name_ru = data.get('name_ru') country = Country.objects.filter(url=translit_with_separator(name_ru)) if country and str(country[0].id) != id: msg = 'Страна с таким названием уже существует' self._errors['name_ru'] = ErrorList([msg]) - del self.cleaned_data['name_ru'] + del data['name_ru'] - return self.cleaned_data + return data def clean_phone_code(self): """ diff --git a/country/models.py b/country/models.py index 08ca9757..485211b5 100644 --- a/country/models.py +++ b/country/models.py @@ -2,18 +2,16 @@ from django.db import models from hvad.models import TranslatableModel, TranslatedFields from django.contrib.contenttypes import generic -#models +# models from directories.models import Language, Currency from city.models import City from service.models import Service -#func +# func from functions.custom_fields import EnumField from bitfield import BitField from functions.db import db_table_exists -from django.conf import settings - -#check if table exist and create flags if true +# check if table exist and create flags if true flags = [str(item.id) for item in Service.objects.all()] if db_table_exists('service_service') else [] @@ -31,7 +29,7 @@ class Country(TranslatableModel): REGIONS =('europa', 'asia', 'america', 'africa') url = models.SlugField(unique=True) - #relations + # relations big_cities = models.ManyToManyField(City, blank=True, null=True, related_name='cities') capital = models.ForeignKey(City,blank=True, null=True, on_delete=models.PROTECT, related_name='capital') language = models.ManyToManyField(Language, blank=True, null=True) @@ -45,10 +43,10 @@ class Country(TranslatableModel): time_delivery = models.PositiveSmallIntegerField(blank=True, null=True) # region = EnumField(values=REGIONS) - #fields saves information about creating and changing model + # fields saves information about creating and changing model created = models.DateTimeField(auto_now_add=True) modified = models.DateTimeField(auto_now=True) - #connection with FileModel by ContentType + # connection with FileModel by ContentType files = generic.GenericRelation('file.FileModel',content_type_field='content_type', object_id_field='object_id') #translated fields translations = TranslatedFields( @@ -67,55 +65,4 @@ class Country(TranslatableModel): ) def __unicode__(self): - return self.lazy_translation_getter('name', unicode(self.pk)) - -from django.db.models.signals import post_save -from models import Country -from django.dispatch import receiver -from django.conf import settings -from functions.form_check import translit_with_separator -from functions.translate import get_translated_fields - -from functions.signal_handlers import post_save_handler, post_save_translation_handler - -post_save.connect(post_save_handler, sender=Country) -post_save.connect(post_save_translation_handler, sender=CountryTranslation) -''' -@receiver(post_save, sender=Country) -def country_post_save_handler(sender, **kwargs): - """ - objects saves two times: - - first time Country object - - second time CountryTranslation object - object must have at least one Translation - """ - - obj = kwargs['instance'] - if isinstance(obj, Country): - # object is Country - # what languages must be - all_langs = [code for code, lang in settings.LANGUAGES] - # what languages are - obj_langs = obj.get_available_languages() - # - missing_languages = list(set(all_langs) - set(obj_langs)) - # get first Translation object - translation = obj.translations.all()[0] - # - fields = get_translated_fields(obj) - for code in missing_languages: - # translate - obj.translate(code) - # set values equal to first translation - for field in fields: - setattr(obj, field, getattr(translation, field)) - - obj.save() - if isinstance(obj, CountryTranslation): - # object is Translation - if obj.language_code == 'ru': - country = Country.objects.get(id=obj.master_id) - - country.url = translit_with_separator(obj.name) - country.save() -''' \ No newline at end of file + return self.lazy_translation_getter('name', unicode(self.pk)) \ No newline at end of file diff --git a/country/signals.py b/country/signals.py index 40a96afc..7213a6bf 100644 --- a/country/signals.py +++ b/country/signals.py @@ -1 +1,9 @@ # -*- coding: utf-8 -*- +from django.db.models.signals import post_save +from functions.signal_handlers import post_save_handler +from models import Country + +post_save.connect(post_save_handler, sender=Country) + + + diff --git a/directories/admin2.py b/directories/admin2.py deleted file mode 100644 index a44ddf95..00000000 --- a/directories/admin2.py +++ /dev/null @@ -1,7 +0,0 @@ -# -*- 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) diff --git a/exposition/admin2.py b/exposition/admin2.py deleted file mode 100644 index 2ab2f297..00000000 --- a/exposition/admin2.py +++ /dev/null @@ -1,9 +0,0 @@ -# -*- 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) diff --git a/exposition/urls.py b/exposition/admin_urls.py similarity index 100% rename from exposition/urls.py rename to exposition/admin_urls.py diff --git a/exposition/forms.py b/exposition/forms.py index 6473bec8..f51296a4 100644 --- a/exposition/forms.py +++ b/exposition/forms.py @@ -118,7 +118,7 @@ class ExpositionCreateForm(forms.Form): exposition.tag.clear() #simple fields - exposition.url = translit_with_separator(data['name_ru']).lower() + exposition.url = translit_with_separator(data['name_ru'].strip()).lower() exposition.data_begin = data['data_begin'] exposition.data_end = data['data_end'] exposition.periodic = data['periodic'] @@ -146,6 +146,7 @@ class ExpositionCreateForm(forms.Form): if data.get('place'): exposition.place = PlaceExposition.objects.get(id=data['place'].id)#.id cause select uses queryset + # fill translated fields and save object fill_with_signal(Exposition, exposition, data) #fill manytomany fields diff --git a/exposition/models.py b/exposition/models.py index 03b2ddac..9b0f9a49 100644 --- a/exposition/models.py +++ b/exposition/models.py @@ -171,49 +171,4 @@ class TimeTable(TranslatableModel): #translated fields translations = TranslatedFields( name = models.CharField(verbose_name='Название', max_length=255) - ) - - -from django.db.models.signals import post_save - -from django.dispatch import receiver -from django.conf import settings -from functions.form_check import translit_with_separator - -from functions.translate import get_translated_fields - -@receiver(post_save) -def exposition_post_save_handler(sender, **kwargs): - """ - objects saves two times: - - first time Exposition object - - second time ExpositionTranslation object - object must have at least one Translation - """ - - obj = kwargs['instance'] - if isinstance(obj, Exposition): - # object is Exposition - if kwargs['created'] and obj.url == '': - # if url doesn't set in new object set it - obj.url = translit_with_separator(obj.name) - - # what languages must be - all_langs = [code for code, lang in settings.LANGUAGES] - # what languages are - obj_langs = obj.get_available_languages() - # - missing_languages = list(set(all_langs) - set(obj_langs)) - # get first Translation object - translation = obj.translations.all()[0] - # translated fields - fields = get_translated_fields(obj) - - for code in missing_languages: - # translate - obj.translate(code) - # go through all fields and set value - for field in fields: - setattr(obj, field, getattr(translation, field)) - - obj.save() + ) \ No newline at end of file diff --git a/exposition/signals.py b/exposition/signals.py new file mode 100644 index 00000000..e56b6536 --- /dev/null +++ b/exposition/signals.py @@ -0,0 +1,6 @@ +# -*- coding: utf-8 -*- +from django.db.models.signals import post_save +from models import Exposition +from functions.signal_handlers import post_save_handler + +post_save.connect(post_save_handler, sender=Exposition) diff --git a/file/urls.py b/file/urls.py deleted file mode 100644 index 32ef57a3..00000000 --- a/file/urls.py +++ /dev/null @@ -1,6 +0,0 @@ -# -*- coding: utf-8 -*- -from django.conf.urls import patterns, url - -urlpatterns = patterns('', - - ) \ No newline at end of file diff --git a/functions/form_check.py b/functions/form_check.py index 5bdea5d5..a8c916e0 100644 --- a/functions/form_check.py +++ b/functions/form_check.py @@ -30,7 +30,4 @@ def translit_with_separator(string, separator='-'): #delete dublicating separators st = re.sub('%s+'%separator, separator, st) - return st - -#def check_url(url, id, Model, field='url', msg='Такой урл уже занят'): -# try: + return st \ No newline at end of file diff --git a/functions/signal_additional_func.py b/functions/signal_additional_func.py index 5cff9251..b8008f8b 100644 --- a/functions/signal_additional_func.py +++ b/functions/signal_additional_func.py @@ -39,22 +39,23 @@ def fill_meta_information(obj): """ # return list of settings for this object s_list = settings_dict.get(obj.__class__.__name__) - - for s in s_list: - # get Setting model object - setting = Setting.objects.get(key=s.get('key')) - field = s.get('field_name') - if setting.type != 'transl': - # simple field - if getattr(obj, field)=="": - setattr(obj, field, setting.get_value()) - obj.save() - else: - # translated field - for code, lang in settings.LANGUAGES: - # get translation object - tr = obj._meta.translations_model.objects.get(language_code=code, master__id=getattr(obj, 'id')) - - if getattr(tr, field)=="": - setattr(tr, field, setting.get_value(code)) - tr.save() \ No newline at end of file + if s_list: + + for s in s_list: + # get Setting model object + setting = Setting.objects.get(key=s.get('key')) + field = s.get('field_name') + if setting.type != 'transl': + # simple field + if getattr(obj, field)=="": + setattr(obj, field, setting.get_value()) + obj.save() + else: + # translated field + for code, lang in settings.LANGUAGES: + # get translation object + tr = obj._meta.translations_model.objects.get(language_code=code, master__id=getattr(obj, 'id')) + + if getattr(tr, field)=="": + setattr(tr, field, setting.get_value(code)) + tr.save() \ No newline at end of file diff --git a/functions/signal_handlers.py b/functions/signal_handlers.py index 316a5946..bf12869d 100644 --- a/functions/signal_handlers.py +++ b/functions/signal_handlers.py @@ -14,7 +14,7 @@ def post_save_handler(sender, **kwargs): fill_missing_languages(obj) fill_meta_information(obj) - +from country.models import Country def post_save_translation_handler(sender, **kwargs): """ receiver function @@ -22,5 +22,8 @@ def post_save_translation_handler(sender, **kwargs): """ obj = kwargs['instance'] if obj.language_code == 'ru': - obj.master.url = translit_with_separator(obj.name) - obj.master.save() \ No newline at end of file + c = Country.objects.all()[0] + c.url = 'tttt' + c.save() + #obj.master.url = translit_with_separator(obj.name) + #obj.master.save() \ No newline at end of file diff --git a/functions/translate.py b/functions/translate.py index 96ac6fd2..c1a154a2 100644 --- a/functions/translate.py +++ b/functions/translate.py @@ -92,6 +92,9 @@ def populate_all(Model, data={}, id=None, zero_fields={}): def fill_with_signal(model, obj, data): + """ + function useful when post_save signal what filling languages exist for this model + """ all_langs = [code for code, lang in settings.LANGUAGES] # fields in translations model that doesn't need bad_fields = ['id', 'language_code', 'master_id'] @@ -105,13 +108,13 @@ def fill_with_signal(model, obj, data): obj.translate(all_langs[0]) # go through all fields and set value for field in fields: - setattr(obj, field, data.get('%s_%s'%(field, all_langs[0]))) + setattr(obj, field, data.get('%s_%s'%(field, all_langs[0])).strip()) obj.save() else: trans_obj = model._meta.translations_model.objects.get(language_code = all_langs[0], master__id=getattr(obj, 'id')) for field in fields: - setattr(trans_obj, field, data.get('%s_%s'%(field, all_langs[0]))) + setattr(trans_obj, field, data.get('%s_%s'%(field, all_langs[0])).strip()) trans_obj.save() @@ -123,7 +126,7 @@ def fill_with_signal(model, obj, data): # start from second language trans_obj = model._meta.translations_model.objects.get(language_code = code,master__id=getattr(obj, 'id')) for field in fields: - val = data.get('%s_%s'%(field, code)) + val = data.get('%s_%s'%(field, code)).strip() if val == '': # get value from require translation setattr(trans_obj, field, getattr(require_transl, field)) @@ -132,8 +135,6 @@ def fill_with_signal(model, obj, data): trans_obj.save() - - def get_translated_fields(obj, exclude_fields=[]): """ get translated fields diff --git a/news/admin2.py b/news/admin2.py deleted file mode 100644 index 3095456d..00000000 --- a/news/admin2.py +++ /dev/null @@ -1,9 +0,0 @@ -# -*- 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) diff --git a/news/urls.py b/news/admin_urls.py similarity index 100% rename from news/urls.py rename to news/admin_urls.py diff --git a/news/forms.py b/news/forms.py index 628fb7d7..b447a004 100644 --- a/news/forms.py +++ b/news/forms.py @@ -10,8 +10,7 @@ from theme.models import Theme from accounts.models import User from django.db.models.loading import get_model #functions -from functions.translate import populate_all, fill_trans_fields_all -from functions.form_check import is_positive_integer +from functions.translate import fill_with_signal from functions.files import check_tmp_files from functions.form_check import translit_with_separator @@ -41,7 +40,6 @@ class NewsForm(forms.Form): #field for comparing tmp files key = forms.CharField(required=False, widget=forms.HiddenInput()) - def __init__(self, *args, **kwargs): """ create dynamical translated fields fields @@ -88,7 +86,7 @@ class NewsForm(forms.Form): news.content_type = ContentType.objects.get_for_model(obj)# news.object_id = data['event_id'] #simple fields - news.url = translit_with_separator(data['main_title_ru']) + news.url = translit_with_separator(data['main_title_ru'].strip()) news.date = data['date'] news.type = data['type'] news.paid = data['paid'] @@ -96,8 +94,9 @@ class NewsForm(forms.Form): if data.get('user'): news.user = data['user'] - # uses because in the next loop data will be overwritten - news.save() + # fill translated fields and save object + fill_with_signal(News, news, data) + #fill manytomany fields for item in data['theme']: news.theme.add(item.id)#.id cause select uses queryset @@ -108,15 +107,6 @@ class NewsForm(forms.Form): # uses because in the next loop data will be overwritten news.save() - #will be saved populated fields - zero_fields = {} - #fills all translated fields with data - #if saves new object, will fill city object. otherwise existing object of City model - fill_trans_fields_all(News, news, data, id, zero_fields) - #autopopulate - #populate empty fields and fields which was already populated - news_id = getattr(news, 'id') - populate_all(News, data, news_id, zero_fields) #save files check_tmp_files(news, data['key']) diff --git a/news/signals.py b/news/signals.py new file mode 100644 index 00000000..d6eb8412 --- /dev/null +++ b/news/signals.py @@ -0,0 +1,6 @@ +# -*- coding: utf-8 -*- +from django.db.models.signals import post_save +from models import News +from functions.signal_handlers import post_save_handler + +post_save.connect(post_save_handler, sender=News) \ No newline at end of file diff --git a/organiser/admin2.py b/organiser/admin2.py deleted file mode 100644 index a56fe3ab..00000000 --- a/organiser/admin2.py +++ /dev/null @@ -1,9 +0,0 @@ -# -*- 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) diff --git a/organiser/urls.py b/organiser/admin_urls.py similarity index 100% rename from organiser/urls.py rename to organiser/admin_urls.py diff --git a/organiser/forms.py b/organiser/forms.py index f1dbf360..5405027b 100644 --- a/organiser/forms.py +++ b/organiser/forms.py @@ -12,7 +12,7 @@ from accounts.models import User from place_exposition.models import PlaceExposition from place_conference.models import PlaceConference #functions -from functions.translate import populate_all, fill_trans_fields_all +from functions.translate import fill_with_signal from functions.form_check import is_positive_integer, translit_with_separator from functions.files import check_tmp_files from functions.custom_fields import LocationWidget @@ -124,8 +124,7 @@ class OrganiserForm(forms.Form): if data.get('city'): organiser.city = City.objects.get(id=data['city']) - # uses because in the next loop data will be overwritten - organiser.save() + fill_with_signal(Organiser, organiser, data) #fill manytomany fields @@ -144,15 +143,6 @@ class OrganiserForm(forms.Form): # uses because in the next loop data will be overwritten organiser.save() - #will be saved populated fields - zero_fields = {} - #fills all translated fields with data - #if saves new object, will fill city object. otherwise existing object of City model - fill_trans_fields_all(Organiser, organiser, data, id, zero_fields) - #autopopulate - #populate empty fields and fields which was already populated - organiser_id = getattr(organiser, 'id') - populate_all(Organiser, data, organiser_id, zero_fields) #save files check_tmp_files(organiser, data['key']) diff --git a/organiser/signals.py b/organiser/signals.py new file mode 100644 index 00000000..b0cf86c3 --- /dev/null +++ b/organiser/signals.py @@ -0,0 +1,6 @@ +# -*- coding: utf-8 -*- +from django.db.models.signals import post_save +from models import Organiser +from functions.signal_handlers import post_save_handler + +post_save.connect(post_save_handler, sender=Organiser) \ No newline at end of file diff --git a/place_conference/admin2.py b/place_conference/admin2.py deleted file mode 100644 index cc28aeaa..00000000 --- a/place_conference/admin2.py +++ /dev/null @@ -1,10 +0,0 @@ -# -*- 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) - diff --git a/place_conference/urls.py b/place_conference/admin_urls.py similarity index 100% rename from place_conference/urls.py rename to place_conference/admin_urls.py diff --git a/place_conference/forms.py b/place_conference/forms.py index 98596f52..7da1e56a 100644 --- a/place_conference/forms.py +++ b/place_conference/forms.py @@ -10,7 +10,7 @@ from models import PlaceConference, Hall, CONFERENCE_TYPE from country.models import Country from city.models import City #functions -from functions.translate import populate_all, fill_trans_fields_all +from functions.translate import fill_with_signal from functions.files import check_tmp_files from functions.form_check import is_positive_integer, translit_with_separator from functions.custom_fields import LocationWidget @@ -114,7 +114,7 @@ class ConferenceForm(forms.Form): place_conference = PlaceConference.objects.get(id=id) #simple fields - place_conference.url = translit_with_separator(data['name_ru']).lower() + place_conference.url = translit_with_separator(data['name_ru'].strip()).lower() place_conference.type = data['type'] place_conference.address = data['address'] place_conference.phone = data['phone'] @@ -132,27 +132,18 @@ class ConferenceForm(forms.Form): place_conference.banquet_hall = data['banquet_hall'] place_conference.catering = data['catering'] place_conference.hotel = data['hotel'] + if data.get('country'): place_conference.country = Country.objects.get(id=data['country'].id)#.id cause select uses queryset if data.get('city'): place_conference.city = City.objects.get(id=data['city']) - # uses because in the next loop data will be overwritten - place_conference.save() - #will be saved populated fields - zero_fields = {} - #fills all translated fields with data - #if saves new object, will fill city object. otherwise existing object of City model - fill_trans_fields_all(PlaceConference, place_conference, data, id, zero_fields) - #autopopulate - #populate empty fields and fields which was already populated - place_conference_id = getattr(place_conference, 'id') - populate_all(PlaceConference, data, place_conference_id, zero_fields) + fill_with_signal(PlaceConference, place_conference, data) + #save files check_tmp_files(place_conference, data['key']) - - return PlaceConference.objects.get(id=place_conference_id) + return PlaceConference.objects.get(id=place_conference.id) def clean(self): id = self.cleaned_data.get('place_conference_id') diff --git a/place_conference/signals.py b/place_conference/signals.py new file mode 100644 index 00000000..ce0b3db3 --- /dev/null +++ b/place_conference/signals.py @@ -0,0 +1,6 @@ +# -*- coding: utf-8 -*- +from django.db.models.signals import post_save +from models import PlaceConference +from functions.signal_handlers import post_save_handler + +post_save.connect(post_save_handler, sender=PlaceConference) diff --git a/place_exposition/admin2.py b/place_exposition/admin2.py deleted file mode 100644 index e5de8cfd..00000000 --- a/place_exposition/admin2.py +++ /dev/null @@ -1,9 +0,0 @@ -# -*- 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) diff --git a/place_exposition/urls.py b/place_exposition/admin_urls.py similarity index 100% rename from place_exposition/urls.py rename to place_exposition/admin_urls.py diff --git a/place_exposition/forms.py b/place_exposition/forms.py index 0d778750..07cdeca6 100644 --- a/place_exposition/forms.py +++ b/place_exposition/forms.py @@ -10,7 +10,7 @@ from models import PlaceExposition, EXPOSITION_TYPE, Hall from country.models import Country from city.models import City #functions -from functions.translate import populate_all, fill_trans_fields_all +from functions.translate import fill_with_signal from functions.files import check_tmp_files from functions.form_check import is_positive_integer, translit_with_separator from functions.custom_fields import LocationWidget @@ -145,21 +145,12 @@ class ExpositionForm(forms.Form): if data.get('city'): place_exposition.city = City.objects.get(id=data['city']) - # uses because in the next loop data will be overwritten - place_exposition.save() - #will be saved populated fields - zero_fields = {} - #fills all translated fields with data - #if saves new object, will fill city object. otherwise existing object of City model - fill_trans_fields_all(PlaceExposition, place_exposition, data, id, zero_fields) - #autopopulate - #populate empty fields and fields which was already populated - place_exposition_id = getattr(place_exposition, 'id') - populate_all(PlaceExposition, data, place_exposition_id, zero_fields) + fill_with_signal(PlaceExposition, place_exposition, data) + #save files check_tmp_files(place_exposition, data['key']) - return PlaceExposition.objects.get(id=place_exposition_id) + return PlaceExposition.objects.get(id=place_exposition.id) def clean(self): id = self.cleaned_data.get('place_exposition_id') diff --git a/place_exposition/signals.py b/place_exposition/signals.py new file mode 100644 index 00000000..2be2af68 --- /dev/null +++ b/place_exposition/signals.py @@ -0,0 +1,6 @@ +# -*- coding: utf-8 -*- +from django.db.models.signals import post_save +from models import PlaceExposition +from functions.signal_handlers import post_save_handler + +post_save.connect(post_save_handler, sender=PlaceExposition) diff --git a/proj/admin_urls.py b/proj/admin_urls.py index ba65faf3..5fdc43da 100644 --- a/proj/admin_urls.py +++ b/proj/admin_urls.py @@ -9,23 +9,22 @@ urlpatterns = required( url(r'^$', 'proj.admin.admin_home'), url(r'^import-event/$', 'import_xls.views.import_event'), url(r'^export-event/$', 'import_xls.views.export_event'), - 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'^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/$', include('settings.urls')), + url(r'^article/', include('article.admin_urls')), + url(r'^city/', include('city.admin_urls')), + url(r'^company/', include('company.admin_urls')), + url(r'^conference/', include('conference.admin_urls')), + url(r'^country/', include('country.admin_urls')), + url(r'^exposition/', include('exposition.admin_urls')), + url(r'^news/', include('news.admin_urls')), + url(r'^organiser/', include('organiser.admin_urls')), + url(r'^place_conference/', include('place_conference.admin_urls')), + url(r'^place_exposition/', include('place_exposition.admin_urls')), + url(r'^seminar/', include('seminar.admin_urls')), + url(r'^service/', include('service.admin_urls')), + url(r'^theme/', include('theme.admin_urls')), + url(r'^translator/', include('translator.admin_urls')), + url(r'^webinar/', include('webinar.admin_urls')), + url(r'^settings/$', include('settings.admin_urls')), url(r'^language/add/', 'directories.admin.language_add'), url(r'^currency/add/', 'directories.admin.currency_add'), # ajax requests diff --git a/proj/settings.py b/proj/settings.py index 9971133c..f9e883f1 100644 --- a/proj/settings.py +++ b/proj/settings.py @@ -240,7 +240,7 @@ INSTALLED_APPS = ( 'ckeditor', 'bitfield', 'social_auth', - #'south', + 'south', #'debug_toolbar', ) diff --git a/proj/urls.py b/proj/urls.py index f3b8ec2c..739b1ca0 100644 --- a/proj/urls.py +++ b/proj/urls.py @@ -7,6 +7,7 @@ urlpatterns = patterns('', url(r'^login/', 'registration.backends.default.views.LoginView'), url(r'^logout/', 'registration.backends.default.views.LogoutView'), url(r'^profile/$', 'accounts.views.profile'), + url(r'^accounts/', include('registration.backends.default.urls')), # admin part url(r'^admin/', include('proj.admin_urls')), ) diff --git a/proj/views.py b/proj/views.py index 7c5381fe..5fd8223c 100644 --- a/proj/views.py +++ b/proj/views.py @@ -1,22 +1,9 @@ # -*- coding: utf-8 -*- from django.core.context_processors import csrf from django.shortcuts import render_to_response -from django.http import HttpResponseRedirect, HttpResponse -from django.contrib.contenttypes.models import ContentType -#from forms import SettingsForm -#from models import Settings -from django.contrib.auth.decorators import login_required from django.template import RequestContext - - -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 home(request): #reg_form = RegistrationFormUniqueEmail() #login_form = LoginForm() @@ -24,84 +11,4 @@ def home(request): args = {} args.update(csrf(request)) - return render_to_response('index.html', args, context_instance=RequestContext(request)) - -def admin_home(request): - return render_to_response('base.html') - - -@login_required -def ajax_city(request): - """ - returns html