當前位置: 首頁>>代碼示例>>Python>>正文


Python Account.find_account_by_user方法代碼示例

本文整理匯總了Python中accounts.models.Account.find_account_by_user方法的典型用法代碼示例。如果您正苦於以下問題:Python Account.find_account_by_user方法的具體用法?Python Account.find_account_by_user怎麽用?Python Account.find_account_by_user使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在accounts.models.Account的用法示例。


在下文中一共展示了Account.find_account_by_user方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: post

# 需要導入模塊: from accounts.models import Account [as 別名]
# 或者: from accounts.models.Account import find_account_by_user [as 別名]
 def post(self, request, format=None):
     '''
     create a personal plan
     {
         "id": 18,
         "dish": [{
             "type": 0,
             "ingredient": [{
                 "id": 1,
                 "amount": 100
             }],
             "recipe": [{
                 "id": 2,
                 "amount": 200
             }]
         },{
             "type": 1,
             "ingredient": [],
             "recipe": [{
                 "id":3,
                 "amount": 300
             }]
         }],
         "joined_date": "2015-01-01"
     }
     '''
     try:
         body = json.loads(request.body)
         user = Account.find_account_by_user(request.user)
         try:
             joined_date = datetime.strptime(body['joined_date'],'%Y-%m-%d').date()
         except:
             joined_date = date.today()
         planid = body.get('id', None)
         if planid is None:
             # create
             p = Plan.objects.create(user=user)
         else :
             p = Plan.objects.get(user=user, pk=planid)
             p.delete_routines()
         r = Routine.objects.create(plan=p)
         for dish in body.get('dish', []):
             d = Dish.objects.create(type=dish['type'], routine=r)
             for si in dish.get('ingredient', []):
                 ingredient = Ingredient.objects.get(pk=si['id'])
                 SingleIngredient.objects.create(ingredient=ingredient, amount=si['amount'], dish=d)
             for sr in dish.get('recipe', []):
                 recipe = Recipe.objects.get(pk=sr['id'])
                 SingleRecipe.objects.create(recipe=recipe, amount=sr['amount'], dish=d)
         # after created it join it!
         try:
             c = Calendar.objects.get(user=user, joined_date=joined_date)
             if c.plan.id != p.id:
                 c.plan = p
                 c.save()
         except Calendar.DoesNotExist:
             Calendar.objects.create(user=user, plan=p, joined_date=joined_date)
         return self.success_response(PlanSerializer(p).data)
     except:
         return self.fail_response(400, 'fail')
開發者ID:CrowleyZYF,項目名稱:fitRecipe,代碼行數:62,代碼來源:views.py

示例2: get

# 需要導入模塊: from accounts.models import Account [as 別名]
# 或者: from accounts.models.Account import find_account_by_user [as 別名]
    def get(self, request, format=None):
        '''
        get my calendar
        '''
        user = Account.find_account_by_user(request.user)
        turn_to_date = lambda x: x and datetime.strptime(x, '%Y%m%d') or date.today()
        start_date = turn_to_date(request.GET.get('start', None))
        end_date = turn_to_date(request.GET.get('end', None))
        plans = []
        calendars = (Calendar.objects
            .select_related('plan')
            .select_related('user')
            .filter(user=user, joined_date__gte=start_date, joined_date__lte=end_date))

        try:
            last_joined = Calendar.objects.filter(user=user, joined_date__lte=start_date).order_by('-joined_date')[0]
            last = CalendarSerializer(last_joined, context={'simple': False}).data
            plans.append(last['plan'])
        except IndexError:
            last = None
        serializer = CalendarSerializer(calendars, many=True, context={'simple': False}).data
        for c in serializer:
            plans.append(c['plan'])
        punchs = Punch.objects.filter(user=user, date__lte=end_date, date__gte=start_date, state__gte=10)
        count = Punch.objects.filter(user=user, state__gte=10)
        result = {
            'lastJoined': last,
            'calendar': serializer,
            'punch': PunchSerializer(punchs, many=True).data,
            'plans': plans,
            'count': len(count)
        }
        return self.success_response(result)
開發者ID:tiant167,項目名稱:fitRecipe,代碼行數:35,代碼來源:views.py

示例3: post

# 需要導入模塊: from accounts.models import Account [as 別名]
# 或者: from accounts.models.Account import find_account_by_user [as 別名]
 def post(self, request, format=None):
     user = Account.find_account_by_user(request.user)
     body = json.loads(request.body)
     type = body.get('type', None)
     img = body.get('img', None)
     if None in (type, img):
         return self.fail_response(400, 'Wrong Data')
     p = Punch.objects.create(user=user, type=type, img=img)
     return self.success_response(PunchSerializer(p).data)
開發者ID:tiant167,項目名稱:fitRecipe,代碼行數:11,代碼來源:views.py

示例4: post

# 需要導入模塊: from accounts.models import Account [as 別名]
# 或者: from accounts.models.Account import find_account_by_user [as 別名]
 def post(self, request, format=None):
     c = Comment()
     try:
         data = json.loads(request.body)
         reply_id = data.get('reply', None)
         c.reply= reply_id and Account.objects.get(pk=reply_id)
         c.content = data['content']
         c.author = Account.find_account_by_user(request.user)
         c.recipe = Recipe.objects.get(pk=data['recipe'])
     except:
         return self.fail_response(400, 'BadArgument')
     c.save()
     return self.success_response(CommentSerializer(c).data)
開發者ID:CrowleyZYF,項目名稱:fitRecipe,代碼行數:15,代碼來源:views.py

示例5: get

# 需要導入模塊: from accounts.models import Account [as 別名]
# 或者: from accounts.models.Account import find_account_by_user [as 別名]
 def get(self, request, pk, format=None):
     '''
     return a specific recipe.
     '''
     recipe = self.get_object(Recipe, pk)
     try:
         user = Account.find_account_by_user(request.user)
         has_collected = RecipeCollection.has_collected(recipe, user)
     except Account.DoesNotExist:
         has_collected = False
     if recipe.status > 0:
         serializer = RecipeSerializer(recipe, context={'simple': False})
         result = serializer.data
         result['has_collected'] = has_collected
         result['comment_count'] = recipe.comment_set.count()
         return self.success_response(result)
     else:
         return self.fail_response(400, 'DoesNotExist')
開發者ID:CrowleyZYF,項目名稱:fitRecipe,代碼行數:20,代碼來源:views.py

示例6: get

# 需要導入模塊: from accounts.models import Account [as 別名]
# 或者: from accounts.models.Account import find_account_by_user [as 別名]
 def get(self, request, collection_type, format=None):
     lastid = request.GET.get('lastid', None)
     if collection_type == 'theme':
         model = ThemeCollection
         serializer = ThemeCollectionSerializer
     elif collection_type == 'series':
         model = SeriesCollection
         serializer = SeriesCollectionSerializer
     elif collection_type == 'recipe':
         model = RecipeCollection
         serializer = RecipeCollectionSerializer
     else:
         return self.fail_response(400, 'BadArgument')
     owner = Account.find_account_by_user(request.user)
     if lastid:
         result = model.objects.filter(owner=owner, id__lt=lastid, status__gt=0).order_by('-created_time')[0:20]
     else:
         result = model.objects.filter(owner=owner, status__gt=0).order_by('-created_time')[0:20]
     return self.success_response(serializer(result, many=True).data)
開發者ID:CrowleyZYF,項目名稱:fitRecipe,代碼行數:21,代碼來源:views.py


注:本文中的accounts.models.Account.find_account_by_user方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。