From af66e4959f7322c8452c9b02bf80afa2c77e584c Mon Sep 17 00:00:00 2001 From: Alexander Burdeiny Date: Mon, 30 May 2016 09:52:10 +0300 Subject: [PATCH] feedback fixes Makefile added fabfile.py added --- Makefile | 71 +++++++++++++ expobanner/admin.py | 2 +- fabfile.py | 118 +++++++++++++++++++++ stats_collector/admin.py | 13 ++- stats_collector/forms.py | 4 +- templates/admin/stats/event_stat.html | 2 +- templates/client/includes/side_places.html | 6 +- 7 files changed, 205 insertions(+), 11 deletions(-) create mode 100644 Makefile create mode 100644 fabfile.py diff --git a/Makefile b/Makefile new file mode 100644 index 00000000..772dc2a0 --- /dev/null +++ b/Makefile @@ -0,0 +1,71 @@ +.PHONY: requirements requirements-upgrade freeze syncdb run run-public makemessages compilemessages collectstatic cloc clean user south + +project_name=proj + +requirements: + -@echo "### Installing requirements" + -@pip install -r requirements.txt + +requirements-upgrade: + -@echo "### Upgrading requirements" + -@pip freeze | cut -d = -f 1 | xargs pip install -U + +freeze: + -@echo "### Freezing python packages to requirements.txt" + -@pip freeze > requirements.txt + +syncdb: + -@echo "### Creating database tables and loading fixtures" + @PYTHONPATH=$(PYTHONPATH):. DJANGO_SETTINGS_MODULE=$(project_name).settings ipython manage.py syncdb --noinput + @PYTHONPATH=$(PYTHONPATH):. DJANGO_SETTINGS_MODULE=$(project_name).settings ipython manage.py migrate + +run: + @PYTHONPATH=$(PYTHONPATH):. DJANGO_SETTINGS_MODULE=$(project_name).settings ipython manage.py runserver + +run-public: + @PYTHONPATH=$(PYTHONPATH):. DJANGO_SETTINGS_MODULE=$(project_name).settings ipython manage.py runserver 0.0.0.0:8000 + +shell: + @PYTHONPATH=$(PYTHONPATH):. DJANGO_SETTINGS_MODULE=$(project_name).settings python manage.py shell + +solrrun: + /opt/solr/bin/solr start -p 8983 + +solrstop: + /opt/solr/bin/solr stop -all + +makemessages: + -@ipython manage.py makemessages --all + +compilemessages: + -@ipython manage.py compilemessages + +collectstatic: + @ipython manage.py collectstatic + +user: + -@ipython manage.py createsuperuser + +# If the first argument is "south"... +ifeq (south,$(firstword $(MAKECMDGOALS))) + # use the rest as arguments for "south" + RUN_ARGS := $(wordlist 2,$(words $(MAKECMDGOALS)),$(MAKECMDGOALS)) + # ...and turn them into do-nothing targets + $(eval $(RUN_ARGS):;@:) +endif +south: + -@python manage.py schemamigration $(RUN_ARGS) --auto + -@python manage.py migrate $(RUN_ARGS) + +cloc: + -@echo "### Counting lines of code within the project" + -@echo "# Total:" ; find . -iregex '.*\.py\|.*\.js\|.*\.html\|.*\.css' -type f -exec cat {} + | wc -l + -@echo "# Python:" ; find . -name '*.py' -type f -exec cat {} + | wc -l + -@echo "# JavaScript:" ; find . -name '*.js' -type f -exec cat {} + | wc -l + -@echo "# HTML:" ; find . -name '*.html' -type f -exec cat {} + | wc -l + -@echo "# CSS:" ; find . -name '*.css' -type f -exec cat {} + | wc -l + +clean: + -@echo "### Cleaning *.pyc and .DS_Store files " + -@find . -name '*.pyc' -exec rm -f {} \; + -@find . -name '.DS_Store' -exec rm -f {} \; diff --git a/expobanner/admin.py b/expobanner/admin.py index e49ba53f..2d90b84d 100644 --- a/expobanner/admin.py +++ b/expobanner/admin.py @@ -272,7 +272,7 @@ class PaidCreate(CreateView): class PaidConfCreate(PaidCreate): form_class = PaidConfCreateForm - success_url = '/admin/expobanners/paid/list/' + success_url = '/admin/expobanners/paid_conf/list/' class PaidUpdate(UpdateView): diff --git a/fabfile.py b/fabfile.py new file mode 100644 index 00000000..2c65cd11 --- /dev/null +++ b/fabfile.py @@ -0,0 +1,118 @@ +# -*- coding: utf-8 -*- +from os.path import join, basename +from collections import namedtuple + +from fabric.api import * + +env.roledefs = { + 'dev': ['root@176.121.11.165'], + 'prod': ['root@176.121.11.162'], +} +env.passwords = { + 'root@176.121.11.165:22': 'ue6R287QZfMc', + 'root@176.121.11.162:22': 'XcS2jx5e8k6n', +} + +REMOTE_HOME_DIR = '/home/www/expomap/' +LOCAL_HOME_DIR = '/home/alexander/projects/expomap/' + +nginx_conf = '/etc/nginx/sites-available/hit.expomap.ru' +apache2_conf = '/etc/apache2/sites-available/proj.com' +settings_conf = join(REMOTE_HOME_DIR, 'proj/settings.py') +services = ['nginx', 'apache2'] + + +def set_host(host): + env.hosts = env.roledefs.get(host) + env.role = host + + +def dev(): + set_host('dev') + + +def prod(): + set_host('prod') + + +def get_configs(): + localdir = join(LOCAL_HOME_DIR, 'support/', env.role) + get(nginx_conf, localdir) + get(apache2_conf, localdir) + get(join(REMOTE_HOME_DIR, 'schema.xml'), localdir) + get(settings_conf, localdir) + + +def put_configs(): + localdir = join(LOCAL_HOME_DIR, 'support/', env.role) + # nginx + put(join(localdir, basename(nginx_conf)), + nginx_conf) + # apache2 + put(join(localdir, basename(apache2_conf)), + apache2_conf) + # settings + put(join(localdir, basename(settings_conf)), + settings_conf) + + +def call_state(state, only=None): + if only is not None and only in services: + run('service {only} {state}'.format(only=only, state=state)) + return + for service in services: + run('service {service} {state}'.format(service=service, state=state)) + +def put_1345(): + call_state('stop', only='nginx') + with cd(REMOTE_HOME_DIR): + run('git pull') + # put_configs() + call_state('start', only='nginx') + + +def chown(): + with cd(REMOTE_HOME_DIR): + run('chown -Rv www-data:www-data .') + + +def pull(): + with cd(REMOTE_HOME_DIR): + call_state('stop', only='apache2') + run('git pull') + call_state('start', only='apache2') + + +def stage3_pre_final(): + with cd(REMOTE_HOME_DIR): + run('pip install pandas') + run('pip install django-rosetta==0.7.6') + run('git checkout master') + run('git pull') + call_state('stop') + put_configs() + run('python manage.py migrate conference 0001 --fake') + run('python manage.py migrate conference') + run('python manage.py migrate expobanner') + run('python manage.py migrate theme 0001 --fake') + run('python manage.py migrate theme 0002') + run('python manage.py migrate article 0001 --fake') + run('python manage.py migrate article 0002') + run('python manage.py migrate stats_collector') + run('python manage.py crontab remove') + run('python manage.py crontab add') + chown() + call_state('start') + + +def stage3_release(): + call_state('stop') + with cd(REMOTE_HOME_DIR): + # run('python manage.py themeblog_to_blog') + run('git checkout stage3_release') + run('git pull') + run('python manage.py migrate settings 0002 --fake') + run('python manage.py migrate settings') + run('python manage.py migrate article 0003') + chown() + call_state('start') diff --git a/stats_collector/admin.py b/stats_collector/admin.py index 743269d2..7cb263f6 100644 --- a/stats_collector/admin.py +++ b/stats_collector/admin.py @@ -67,10 +67,15 @@ class StatBaseView(FormView): return super(StatBaseView, self).get(request, *args, **kwargs) def form_valid(self, form): - if form.cleaned_data['date_begin']: - self.qs = self.qs.filter(created_at__gte=form.cleaned_data['date_begin']) - if form.cleaned_data['date_end']: - self.qs = self.qs.filter(created_at__lte=form.cleaned_data['date_end']) + begin = form.cleaned_data['date_begin'] + end = form.cleaned_data['date_end'] + if (begin and end) and begin == end: + self.qs = self.qs.filter(created_at=begin) + else: + if begin: + self.qs = self.qs.filter(created_at__gte=begin) + if end: + self.qs = self.qs.filter(created_at__lte=end) def make_json_response(self, data): return HttpResponse(json.dumps(data), content_type='application/json') diff --git a/stats_collector/forms.py b/stats_collector/forms.py index 11240a14..6f45d0e1 100644 --- a/stats_collector/forms.py +++ b/stats_collector/forms.py @@ -31,9 +31,9 @@ class BaseDateFilter(forms.Form): date_end = self.cleaned_data['date_end'] if not date_begin and date_end: self.cleaned_data['date_begin'] = date_end - timedelta(days=14) - elif date_begin and date_end and date_begin >= date_end: + elif date_begin and date_end and date_begin > date_end: raise forms.ValidationError( - _(u'Дата начала должна быть меньше даты окончания.'), + _(u'Дата начала должна быть меньше либо соответствовать дате окончания.'), code='invalid') return self.cleaned_data diff --git a/templates/admin/stats/event_stat.html b/templates/admin/stats/event_stat.html index df201c78..0dff2f9d 100644 --- a/templates/admin/stats/event_stat.html +++ b/templates/admin/stats/event_stat.html @@ -23,7 +23,7 @@ {% endautoescape %} ]); var options = { - title: '{% trans "Статистика разделов" %}', + title: '{% trans "Статистика событий" %}', legend: { position: 'bottom' }, vAxis: { title: '{% trans "Просмотры" %}' diff --git a/templates/client/includes/side_places.html b/templates/client/includes/side_places.html index 68166361..b3dc0c0a 100644 --- a/templates/client/includes/side_places.html +++ b/templates/client/includes/side_places.html @@ -5,9 +5,9 @@