def to_python(self, value): if isinstance(value, Month): month = value elif isinstance(value, datetime.date): month = Month.from_date(value) elif isinstance(value, basestring): month = Month.from_string(value) else: month = None return month
def to_python(self, value): if isinstance(value, Month): month = value elif isinstance(value, datetime.date): month = Month.from_date(value) elif isinstance(value, basestring): month = Month.from_string(value) else: month = None return month
def to_python(self, value): if isinstance(value, Month): month = value elif isinstance(value, datetime.date): month = Month.from_date(value) if len(str(month.year)) < 4: raise exceptions.ValidationError( self.error_messages['invalid_year'], code='invalid_year', params={'value': value}, ) elif isinstance(value, string_type): month = Month.from_string(value) else: month = None return month
def upload(self, request): """ Upload Invoicing Report. """ month = request.data.get('month', None) report = request.data.get('report', None) if not month or not report: return Response( { 'success': False, 'error': 'Month or report is not set.', }, 400) try: report = InvoicingReport.objects.get(month=month) report.report = request.data.get('report') except InvoicingReport.DoesNotExist: report = InvoicingReport(month=Month.from_string(month), report=request.data.get('report')) finally: report.save() return JsonResponse({'success': True})