示例#1
0
 def dispatch(self, request, *args, **kwargs):
     """
     Overridde `dispatch` method to provide extra variables.
     """
     # @desc: extra view instance variable using request.
     self.user = get_user(request, self.kwargs)
     if not self.user == request.user:
         user_profile = Profile.objects.get(user=request.user)
         if not user_profile.friends.filter(user=self.user).exists():
             raise PermissionDenied
     return super(CommonInfoMixin, self).dispatch(request, *args, **kwargs)
示例#2
0
 def dispatch_request(self):
     """
     Return stickers for logged in user.
     """
     profile = get_user(request.args)
     stickers = {
         sticker.sequence: {
             'status': sticker.label.status.value,
             'caption': sticker.caption,
             'description': sticker.description,
         }
         for sticker in profile.sticker_set
     }
     return json.dumps(stickers)
示例#3
0
 def dispatch_request(self):
     """
     Return stickers for logged in user.
     """
     profile = get_user(request.args)
     stickers = {
         sticker.sequence: {
             'status': sticker.label.status.value,
             'caption': sticker.caption,
             'description': sticker.description,
         }
         for sticker in profile.sticker_set
     }
     return json.dumps(stickers)
示例#4
0
 def get_context_data(self, **kwargs):
     """
     Update context data on request keyword arguments to have a simple
     access to view data, for instace url parameters.
     Add `short_urls_allowed` variable indicating if a displayed element
     (e.g. profile, board, sticker) is owned by logged user so username
     can be omitted.
     Also append action to context data to know action of page.
     """
     context = super(ContextMixin, self).get_context_data(**kwargs)
     context['action'] = self.action
     context['short_urls_allowed'] = self._get_short_urls_allowed()
     context['username'] = get_user(self.request, self.kwargs).username
     kwargs = {
         key: value for key, value in self.kwargs.iteritems()
         if key not in context
     }
     context.update(**kwargs)
     return context
示例#5
0
 def __init__(self):
     self.user = get_user(request.view_args)