staff.py 文件源码

python
阅读 17 收藏 0 点赞 0 评论 0

项目:CommunityCellularManager 作者: facebookincubator 项目源码 文件源码
def post(self, request):
        """Handles POST requests.

        The forms on the analysis page POST here to set URL params.  This page
        then redirects to GET with those params set and the values are read out
        of the URL to determine how to run the actual computations.
        """
        user_profile = models.UserProfile.objects.get(user=request.user)
        if not user_profile.user.is_staff:
            return response.Response('', status=status.HTTP_404_NOT_FOUND)
        network = user_profile.network
        url_params = {}
        if request.POST.get('network', None):
            url_params['network'] = request.POST.get('network')
        # Encode the proposed prices from the table into the URL.  The 'name'
        # of each input is pretty convoluted and there are lots of inputs.
        # Each name and corresponding url param is a combo of the params below.
        traffic_types = ('call', 'sms')
        entities = ('sub', 'op', 'e')
        tiers = self.get_ordered_tiers(network)
        for entity in entities:
            for traffic_type in traffic_types:
                for tier in tiers:
                    key = '%s_%s_proposed_%s_cost' % (
                        traffic_type, slugify(tier.name), entity)
                    if request.POST.get(key, None):
                        # Only encode values in the URL when the proposed cost
                        # is different than the actual cost.
                        proposed = int(request.POST.get(key))
                        actual = self.get_cost(tier, traffic_type, entity)
                        if proposed != actual:
                            url_params[key] = proposed
        base_url = urlresolvers.reverse('margin-analysis')
        url = '%s?%s' % (base_url, urllib.urlencode(url_params))
        return redirect(url)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号