def _freeze_counts(request, context):
        if not (request.POST.get('sp_select') and request.POST.get('area_select')):
            raise ValidationError("Please fill all the fields carefully")

        a = Area.query(ar=request.POST.get('area_select'))
        if a is None:
            raise ValidationError("Are you tracking to hack me??!!")

        sp = SoftwareProduct.query(sp_id=request.POST.get('sp_select'))
        if sp is None:
            raise ValidationError("Invalid SP")

        sa = SubArea.query(fa_obj=a)
        if sa is None:
            raise ValidationError("No Sub Areas found under this Area")

        locs = Geo.objects.all()
        for lev in LEVELS:
            lev = str(lev.value)
            for s in sa:
                for l in locs:
                    k = s.subarea + "_" + l.geo + "_L" + str(lev)
                    if k in request.POST.keys():
                        cnt = request.POST.get(k)
                        if cnt == "":
                            cnt = 0
                        cc, created = CaseCount.get_or_create(
                            sp_obj=sp[0], sa_obj=s, lev=lev,
                            loc=l, cnt=cnt)
                        logger.info(cc)

        return ProductViewHelper._return_context(context=context,
                                                 created=created,
                                                 msgname='countsform_msg',
                                                 added_data=a.area + ' counts')
    def _get_report_bysp(context, sp, area, msg):
        sp = SoftwareProduct.query(sp_id=sp)
        if not sp is None:
            context[msg] = sp[0].sp_name

        ar = Area.query(ar=area)
        if not ar is None:
            context[msg] += ' ' + ar.area

        return context, sp[0].sp_name, ar.area
 def _add_sp(request, context):
     if not {'sp', 'chip_select', 'activepl', 'sp_soddate',
             'sp_fcdate', 'sp_csdate'}.issubset(request.POST.keys()):
         raise ValidationError("Please fill all the fields")
     # this below logic will work only for dates in YYYY-MM-DD format
     if not (request.POST.get('sp_soddate') <= request.POST.get('sp_fcdate') <= request.POST.get('sp_csdate')):
         raise ValidationError("Mile stone dates are fake SOD <= FC <= CS")
     sp, created = SoftwareProduct.get_or_create(
         spname=request.POST.get('sp'),
         chip=Chipset.objects.filter(id=request.POST.get('chip_select'))[0],
         active=request.POST.get('activepl'),
         sod_date=request.POST.get('sp_soddate'),
         fc_date=request.POST.get('sp_fcdate'),
         cs_date=request.POST.get('sp_csdate'))
     return ProductViewHelper._return_context(context=context, created=created, msgname='spform_msg',
                                              added_data=sp.sp_name)
    def _query_by_spid(sp_id):
        sp = SoftwareProduct.query(sp_id=sp_id)
        if sp is None:
            return None

        return sp[0]