From 1a7cab1757e093ee5bb7c5f15644e89f95602ea2 Mon Sep 17 00:00:00 2001 From: ArturBaybulatov Date: Wed, 31 Aug 2016 17:36:58 +0300 Subject: [PATCH] Fixes --- .../commands/generate_portfolios.py | 4 +- .../management/commands/generate_projects.py | 4 +- .../commands/generate_work_sells.py | 4 +- archilance/management/commands/tmp.py | 2 +- common/templatetags/common_tags.py | 6 ++ projects/models.py | 30 ++++--- projects/templates/comparison.html | 10 ++- projects/templates/project_detail.html | 24 +++++- projects/views.py | 27 ++++++- templates/partials/header.html | 78 ++++++++++--------- users/models.py | 11 ++- work_sell/models.py | 4 +- 12 files changed, 128 insertions(+), 76 deletions(-) diff --git a/archilance/management/commands/generate_portfolios.py b/archilance/management/commands/generate_portfolios.py index abd307c..2945567 100644 --- a/archilance/management/commands/generate_portfolios.py +++ b/archilance/management/commands/generate_portfolios.py @@ -7,7 +7,7 @@ import random from archilance import util from common.models import Location -from projects.models import Portfolio, PortfolioPhoto, CURRENCIES, TERMS, BuildingClassfication , ConstructionType +from projects.models import Portfolio, PortfolioPhoto, CURRENCIES, TERM_TYPES, BuildingClassfication , ConstructionType from specializations.models import Specialization from users.models import User, Team, GENDERS @@ -42,7 +42,7 @@ class Command(BaseCommand): budget=util.random_amount(), currency=_.sample(CURRENCIES)[0], term=_.random(0, 20), - term_type=_.sample(TERMS)[0], + term_type=_.sample(TERM_TYPES)[0], worksell=_.sample((True, False)), ) diff --git a/archilance/management/commands/generate_projects.py b/archilance/management/commands/generate_projects.py index 49daa9b..18ad4b2 100644 --- a/archilance/management/commands/generate_projects.py +++ b/archilance/management/commands/generate_projects.py @@ -6,7 +6,7 @@ import pydash as _; _.map = _.map_; _.filter = _.filter_ import random from archilance import util -from projects.models import Project, Order, CURRENCIES, TERMS, Specialization, Realty +from projects.models import Project, Order, CURRENCIES, TERM_TYPES, Specialization, Realty from users.models import User @@ -62,7 +62,7 @@ class Command(BaseCommand): price_and_term_required=_.sample((True, False)), deal_type=_.sample(Project.DEAL_TYPES)[0], term=_.random(0, 20), - term_type=_.sample(TERMS)[0], + term_type=_.sample(TERM_TYPES)[0], text=util.lorem(_.random(5, 30)), work_type=_.sample(Project.WORK_TYPES)[0], state='active', diff --git a/archilance/management/commands/generate_work_sells.py b/archilance/management/commands/generate_work_sells.py index daef0ec..9992356 100644 --- a/archilance/management/commands/generate_work_sells.py +++ b/archilance/management/commands/generate_work_sells.py @@ -7,7 +7,7 @@ import random from archilance import util from common.models import Location -from projects.models import TERMS, CURRENCIES, BuildingClassfication, ConstructionType +from projects.models import TERM_TYPES, CURRENCIES, BuildingClassfication, ConstructionType from specializations.models import Specialization from users.models import User from work_sell.models import WorkSell, WorkSellPhoto @@ -27,7 +27,7 @@ class Command(BaseCommand): description=util.lorem(), name=util.lorem(words=_.random(2, 20), sentences=1), term=_.random(0, 20), - term_type=_.sample(TERMS)[0], + term_type=_.sample(TERM_TYPES)[0], ) ws.save() diff --git a/archilance/management/commands/tmp.py b/archilance/management/commands/tmp.py index 751c975..8583603 100644 --- a/archilance/management/commands/tmp.py +++ b/archilance/management/commands/tmp.py @@ -7,7 +7,7 @@ import random from archilance import util from common.models import Location -from projects.models import Project, Order, CURRENCIES, TERMS, Specialization, Realty +from projects.models import Project, Order, CURRENCIES, TERM_TYPES, Specialization, Realty from users.models import User, Team diff --git a/common/templatetags/common_tags.py b/common/templatetags/common_tags.py index 77c0a5c..1f03ba0 100644 --- a/common/templatetags/common_tags.py +++ b/common/templatetags/common_tags.py @@ -124,4 +124,10 @@ def fa_currency_classes(currency): return 'fa fa-%s' % currency_class +@register.filter +def get(dic, key): + if isinstance(dic, dict): + return dic.get(key) + + # import code; code.interact(local=dict(globals(), **locals())) diff --git a/projects/models.py b/projects/models.py index 29e96a7..5136c1e 100644 --- a/projects/models.py +++ b/projects/models.py @@ -17,13 +17,20 @@ CURRENCIES = ( ('eur', 'EUR'), ) -TERMS = ( - ('project', 'За проект'), - ('hour', 'За час'), +TERM_TYPES = ( ('day', 'За день'), + ('hour', 'За час'), ('month', 'За месяц'), + ('project', 'За проект'), ) +TERM_TYPE_MORPHS = { + 'day': 'день,дня,дней', + 'hour': 'час,часа,часов', + 'month': 'месяц,месяца,месяцев', + 'project': 'проект,проекта,проектов' +} + class BuildingClassfication(models.Model): name = models.CharField(max_length=255) @@ -92,7 +99,7 @@ class Project(models.Model, HitCountMixin): specialization = TreeForeignKey(Specialization, related_name='projects') state = models.CharField(default='active', max_length=20, choices=STATES) term = models.IntegerField(default=0) - term_type = models.CharField(max_length=20, choices=TERMS, default='hour') + term_type = models.CharField(max_length=20, choices=TERM_TYPES, default='hour') text = models.TextField(blank=True) work_type = models.IntegerField(default=1, choices=WORK_TYPES) @@ -131,7 +138,7 @@ class Answer(models.Model): project = models.ForeignKey(Project, related_name='answers') secure_deal_only = models.BooleanField(default=False) term = models.IntegerField(blank=True, null=True) - term_type = models.CharField(max_length=10, choices=TERMS, blank=True, null=True) + term_type = models.CharField(max_length=10, choices=TERM_TYPES, blank=True, null=True) is_archive = models.BooleanField(default=False) rejected = models.BooleanField(default=False) @@ -141,15 +148,6 @@ class Answer(models.Model): def get_first_message(self): return self.messages.first().text - - def get_term_type_labels(self): - term_type_labels = { - 'hour': 'час,часа,часов', - 'day': 'день,дня,дней', - 'month': 'месяц,месяца,месяцев', - 'project': 'проект,проект,проект' - } - return term_type_labels.get(self.term_type) def __str__(self): return "{author}'s answer ({id})".format(author=type(self.author).__name__, id=self.pk) @@ -252,7 +250,7 @@ class Stage(models.Model): order = models.ForeignKey(Order, related_name='stages') result = models.CharField(max_length=255) term = models.DateField() - term_type = models.CharField(max_length=10, choices=TERMS, default='hour') + term_type = models.CharField(max_length=10, choices=TERM_TYPES, default='hour') status = models.CharField(choices=STATUSES, max_length=30, default='not_agreed') created = models.DateTimeField(default=timezone.now) pos = models.IntegerField(default=0, null=True, blank=True) @@ -295,7 +293,7 @@ class Portfolio(models.Model): name = models.CharField(max_length=255) specialization = TreeForeignKey(Specialization, related_name='portfolios', null=True, blank=True) term = models.IntegerField(default=0, null=True, blank=True) - term_type = models.CharField(max_length=20, choices=TERMS, default='hour', null=True, blank=True) + term_type = models.CharField(max_length=20, choices=TERM_TYPES, default='hour', null=True, blank=True) user = models.ForeignKey(User, related_name='portfolios', null=True, blank=True) worksell = models.BooleanField(default=False) diff --git a/projects/templates/comparison.html b/projects/templates/comparison.html index a73f3c2..eef4d49 100644 --- a/projects/templates/comparison.html +++ b/projects/templates/comparison.html @@ -45,13 +45,15 @@ {{ cand.answer.budget }} - {{ cand.answer.term }}
- {% morph_words cand.answer.term cand.answer.get_term_type_labels %} - + {% if cand.answer.term_type == 'project' %} + За проект + {% else %} + {% morph cand.answer.term TERM_TYPE_MORPHS|get:cand.answer.term_type %} + {% endif %} - + diff --git a/projects/templates/project_detail.html b/projects/templates/project_detail.html index c13322c..8015dfe 100644 --- a/projects/templates/project_detail.html +++ b/projects/templates/project_detail.html @@ -240,7 +240,11 @@

- Срок: {{ answer.term }} {{ answer.get_currency_display }} {{ answer.get_term_type_display|decap }} + {% if answer.term_type == 'project' %} + Срок: За проект + {% else %} + Срок: {% morph answer.term TERM_TYPE_MORPHS|get:answer.term_type %} + {% endif %}

Опубликован: {{ answer.created|date:'M d, Y' }}

@@ -566,7 +570,11 @@

- Срок: {{ answer.term }} {{ answer.get_currency_display }} {{ answer.get_term_type_display|decap }} + {% if answer.term_type == 'project' %} + Срок: За проект + {% else %} + Срок: {% morph answer.term TERM_TYPE_MORPHS|get:answer.term_type %} + {% endif %}

Опубликован: {{ answer.created|date:'M d, Y' }}

@@ -722,7 +730,11 @@

- Срок: {{ answer.term }} {{ answer.get_currency_display }} {{ answer.get_term_type_display|decap }} + {% if answer.term_type == 'project' %} + Срок: За проект + {% else %} + Срок: {% morph answer.term TERM_TYPE_MORPHS|get:answer.term_type %} + {% endif %}

Опубликован: {{ answer.created|date:'M d, Y' }}

@@ -876,7 +888,11 @@

- Срок: {{ answer.term }} {{ answer.get_currency_display }} {{ answer.get_term_type_display|decap }} + {% if answer.term_type == 'project' %} + Срок: За проект + {% else %} + Срок: {% morph answer.term TERM_TYPE_MORPHS|get:answer.term_type %} + {% endif %}

Опубликован: {{ answer.created|date:'M d, Y' }}

diff --git a/projects/views.py b/projects/views.py index fabf8cc..d2daa8e 100644 --- a/projects/views.py +++ b/projects/views.py @@ -18,12 +18,26 @@ import pydash as _; _.map = _.map_; _.filter = _.filter_ import re from .mixins import LastAccessMixin -from .models import Arbitration, Project, ProjectFile, Portfolio, PortfolioPhoto, Candidate, Answer, AnswerFile, AnswerMessage, Realty, Order from archilance import util from archilance.mixins import BaseMixin from users.models import User, Team from work_sell.models import Picture, WorkSell, WorkSellPhoto +from .models import ( + Answer, + AnswerFile, + AnswerMessage, + Arbitration, + Candidate, + Order, + Portfolio, + PortfolioPhoto, + Project, + ProjectFile, + Realty, + TERM_TYPE_MORPHS, +) + from .forms import ( ContractorPortfolioTrashForm, CustomerProjectDeleteForm, @@ -45,7 +59,9 @@ class ProjectDetailWithAnswerView(BaseMixin, View): def get(self, request, *args, **kwargs): context = self.get_context_data(**_.merge({}, request.GET, kwargs)) - + + context.update({'TERM_TYPE_MORPHS': TERM_TYPE_MORPHS}) + project = get_object_or_404(Project, pk=kwargs.get('pk')) context.update({'project': project}) @@ -594,6 +610,13 @@ class CustomerProjectDeleteView(View): class ProjectComparisonView(DetailView): model = Project template_name = 'comparison.html' + + def get_context_data(self, **kwargs): + c = super().get_context_data(**kwargs) + + c['TERM_TYPE_MORPHS'] = TERM_TYPE_MORPHS + + return c def add_candidate(request, answer_id, project_id): diff --git a/templates/partials/header.html b/templates/partials/header.html index 99be311..becf5b6 100644 --- a/templates/partials/header.html +++ b/templates/partials/header.html @@ -7,25 +7,44 @@
- +
-{% activeurl %} - {% if request.user.is_authenticated %} -
- +
+ {% endif %} + {% endactiveurl %} + {% if request.user.is_authenticated %}
diff --git a/users/models.py b/users/models.py index bc73a6a..d693aa0 100644 --- a/users/models.py +++ b/users/models.py @@ -174,12 +174,17 @@ class User(AbstractBaseUser, PermissionsMixin): return self.avatar def summary(self): - age = relativedelta(timezone.now(), util.to_local_datetime(self.date_of_birth)).years + if self.date_of_birth: + years = relativedelta(timezone.now(), util.to_local_datetime(self.date_of_birth)).years + age = '%s %s' % (years, util.morph(years, ('год', 'года', 'лет'))) + dob = formats.date_format(self.date_of_birth, 'DATE_FORMAT') + else: + age = dob = None return _.join(_.filter(( self.get_gender_display(), - '%s %s' % (age, util.morph(age, ('год', 'года', 'лет'))), - formats.date_format(self.date_of_birth, 'DATE_FORMAT'), + age, + dob, ), _.identity), ', ') USERNAME_FIELD = 'username' diff --git a/work_sell/models.py b/work_sell/models.py index d1ed8bd..2d3b75f 100644 --- a/work_sell/models.py +++ b/work_sell/models.py @@ -4,7 +4,7 @@ from mptt.models import TreeForeignKey from sorl.thumbnail import ImageField from users.models import User, Team -from projects.models import BuildingClassfication, ConstructionType, TERMS, CURRENCIES +from projects.models import BuildingClassfication, ConstructionType, TERM_TYPES, CURRENCIES from specializations.models import Specialization @@ -22,7 +22,7 @@ class WorkSell(models.Model): name = models.CharField(max_length=255) specialization = TreeForeignKey(Specialization, related_name='worksells', null=True, blank=True) term = models.IntegerField(default=0, null=True, blank=True) - term_type = models.CharField(max_length=20, choices=TERMS, default='hour', null=True, blank=True) + term_type = models.CharField(max_length=20, choices=TERM_TYPES, default='hour', null=True, blank=True) def __str__(self): return self.name