def save_model(self, request, obj, form, change): new_obj = False if obj.pk: obj._review_date = timezone.now() query = ''' UPDATE tblmosavabat SET tblmosavabat.natije = ? ''' params = [obj.result] if request.user.is_superuser or request.user.is_secretary: query += ", tblmosavabat.sharh=?, tblmosavabat.peygiri1=?, tblmosavabat.peygiri2=?" \ ", tblmosavabat.tarikh=?, tblmosavabat.jalaseh=?, tblmosavabat.muzoo=?" \ ", tblmosavabat.gooyandeh=?, tblmosavabat.vahed=?, tblmosavabat.vahed2=?" \ ", tblmosavabat.mosavabatcode=?, tblmosavabat.TarikhBaznegari=?, tblmosavabat.[date]=?" \ ", tblmosavabat.review_date=?" params.extend( (obj.description, obj.first_actor.lname if obj.first_actor else '-', obj.second_actor.lname if obj.second_actor else '-', int(to_jalali(obj._date, no_time=True).replace('/', '')) - 13000000, obj.session.name, obj.subject.name, obj.assigner.name, obj.first_actor.supervisor.name if obj.first_actor and obj.first_actor.supervisor else '-', obj.second_actor.supervisor.name if obj.second_actor and obj.second_actor.supervisor else '-', obj.code, obj.review_date(), obj._date, obj._review_date)) query += ''' WHERE ID = ? ''' params.append(obj.row) execute_query(query, params, update=True) else: query = ''' INSERT INTO tblmosavabat (sharh, peygiri1, peygiri2, tarikh, lozoomepeygiri, natije, jalaseh, muzoo, gooyandeh, vahed, vahed2, mosavabatcode, TarikhBaznegari, [date], review_date) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) ''' obj.follow_grade = 1 params = (obj.description, obj.first_actor.lname if obj.first_actor else '-', obj.second_actor.lname if obj.second_actor else '-', int(to_jalali(obj._date, True).replace('/', '')) - 13000000, obj.follow_grade, obj.result, obj.session.name, obj.subject.name, obj.assigner.name, obj.first_actor.supervisor.name if obj.first_actor and obj.first_actor.supervisor else '-', obj.second_actor.supervisor.name if obj.second_actor and obj.second_actor.supervisor else '-', obj.code, obj.review_date(), obj._date, obj._review_date) obj.row = execute_query(query, params, insert=True) new_obj = True super(EnactmentAdmin, self).save_model(request, obj, form, change) if new_obj: queryset_name = '%s_query_set' % self.model._meta.model_name enactment_query_set = request.session[queryset_name] enactment_query_set.append({'pk': obj.pk}) request.session[queryset_name] = list(enactment_query_set)
def date_joined_jalali(self): return to_jalali(self.date_joined)
def review_date(self): return to_jalali(self._review_date) if translation.get_language( ) == 'fa' else format_date(self._review_date)
def last_login_jalali(self): return to_jalali(self.last_login)