コード例 #1
0
def remove_tags_from(request):
    data = retrieve_param(request)
    t = RemoveTagsThread()
    t.set_data(data)
    t.set_tag_app('user:'******'{"result": "Remove tags processing"}', mimetype="application/json")
コード例 #2
0
 def authenticate(self, request):
     data = retrieve_param(request)
     if ("password" in data) and ("username" in data):
         user = authenticate(username=data["username"], password=data["password"])
         if user is not None:
             return user
     return None
コード例 #3
0
ファイル: views.py プロジェクト: weijia/django-sheet
def update_cell(request):
    data = retrieve_param(request)
    json_str = ""
    if "json_obj" in data:
        json_str = data["json_obj"]
    else:
        for item in data:
            json_str = item
            break
    json_obj = json.loads(json_str)
    s = StringCellValue(value=json_obj["value"])
    s.save()
    sheet_name = json_obj["sheet"]
    sheet_file, is_file_created = SheetFile.objects.get_or_create(filename="TestFile")
    sheet, is_sheet_created = Sheet.objects.get_or_create(sheet_name=sheet_name, sheet_file=sheet_file)
    existing_cell = Cell.objects.filter(cell_row=json_obj["cell_row"], cell_column=json_obj["cell_column"],
                                        sheet=sheet)
    if existing_cell.exists():
        existing_cell[0].cell_value = s
        existing_cell[0].save()
    else:
        c = Cell(cell_row=json_obj["cell_row"], cell_column=json_obj["cell_column"],
                 sheet=sheet, cell_value=s)
        c.save()
    return HttpResponse("OK")
コード例 #4
0
    def get_context_data(self, **kwargs):
        default_context = super(ResourceScheduleTemplateView, self).get_context_data(**kwargs)
        resource_list_query = self.bookable_resource_class.objects.all()
        resource_list = []
        for resource in resource_list_query:
            resource_list.append({"id": str(resource.pk), "title": resource.get_title()})
        default_context["resource_list"] = json.dumps(resource_list)
        default_context["resource_type"] = self.resource_title
        default_context["get_schedule"] = reverse(self.get_schedule_url_name)

        # default_context["new_resource_form"] = self.resource_create_view_class().get_form_class()
        form_factory = ModelFormFactory(self.bookable_resource_class)
        form_factory.set_exclude("approver")
        default_context["new_resource_form"] = form_factory.get_form_class()()

        default_context["booking_req_form"] = self.request_create_view().get_form_class()
        default_context["resource_detail"] = self.resource_detail
        # default_context["color_for_need_approval_from_others"] = self.WAITING_FOR_APPROVAL_FROM_OTHERS_COLOR
        # default_context["color_for_approved"] = self.APPROVED_COLOR
        # default_context["color_for_ongoing"] = self.ONGOING_COLOR
        # default_context["color_for_need_your_approval"] = self.WAITING_FOR_YOUR_APPROVAL_COLOR
        default_context["event_colors"] = json.dumps(self.get_colors())
        data = retrieve_param(self.request)
        if "start" in data:
            default_context["year"] = int(data["start"])
        else:
            default_context["year"] = 2015

        default_context["is_admin"] = "false"
        default_context["page_title"] = self.page_title
        if self.request.user.has_perm(self.resource_permission_id):
            default_context["is_admin"] = "true"
        return default_context
コード例 #5
0
ファイル: views.py プロジェクト: weijia/mptt-node-creator
    def get_context_data(self, **kwargs):
        ctx = super(TreeNodeCreator, self).get_context_data(**kwargs)

        param = retrieve_param(self.request)
        level = 0
        parent = None
        level_parameter_name = "level%d[]" % level
        while level_parameter_name in param:
            level_node_name = param[level_parameter_name]
            parent = self.create_node_creation_request(level_node_name, parent)
            level += 1
            level_parameter_name = "level%d[]" % level

        all_leaf_new_items = self.get_all_new_leaf_nodes()

        ctx["items"] = all_leaf_new_items

        ctx["tree_table"] = TreeTableGenerator(
            self.display_field, self.level_names).get_tree_table(all_leaf_new_items)

        javascript_vars = {
            "base_tree_url": get_tastypie_api_url(self.base_tree_model),
            "root_parent": self.root_parent,
            "parent_name": self.parent_name,
            "display_field": self.display_field,
            "query_param": self.query_param,
            "results_field": self.results_field,
            "max_level_of_input": self.max_level_of_input,
        }

        ctx["javascript_vars"] = javascript_vars
        return ctx
コード例 #6
0
ファイル: obj_tagging.py プロジェクト: weijia/obj_sys
def add_tag(request):
    data = retrieve_param(request)
    if ('ufs_url' in data) and ('tag' in data):
        obj = get_ufs_obj_from_ufs_url(data['ufs_url'])
        Tag.objects.add_tag(obj, data["tag"], tag_app='user:'******'{"result": "added tag: %s to %s done"}' % (data["tag"], data["ufs_url"]),
                            mimetype="application/json")
    return JsonResponse({"result": "not enough params"})
コード例 #7
0
 def get_level(self):
     data = retrieve_param(self.request)
     if "level" in data:
         try:
             return int(data["level"])
         except:
             pass
     return self.default_level
コード例 #8
0
 def init_tree_items(self):
     data = retrieve_param(self.request)
     if "root" in data:
         self.root_pk = data["root"]
         self.tree_items = self.get_children(self.root_pk)
     else:
         self.tree_items = self.item_class.objects.filter(
             level__lt=self.get_level())
コード例 #9
0
ファイル: obj_operator.py プロジェクト: weijia/obj_sys
def rm_obj_from_db(request):
    data = retrieve_param(request)
    json_result_str = '{"result": "not enough params"}'
    if "ufs_url" in data:
        for obj in UfsObj.objects.filter(ufs_url=data["ufs_url"]):
            invalid_obj_and_rm_tags(obj)
        json_result_str = '{"result": "removed: %s"}' % (data["ufs_url"])
    return HttpResponse(json_result_str, mimetype="application/json")
コード例 #10
0
ファイル: views.py プロジェクト: weijia/webmanager
def handle_debug_param_request(request):
    data = retrieve_param(request)
    param_dict = {}
    for field in data:
        param_dict[field] = data[field]

    param = json.dumps(param_dict)
    v = DebugRequestParam(request_json=param)
    v.save()
    return HttpResponse("Good")
コード例 #11
0
ファイル: views.py プロジェクト: weijia/django-sheet
 def get_context_data(self, **kwargs):
     data = retrieve_param(self.request)
     sheet_name = "First sheet"
     if "sheet_name" in data:
         sheet_name = data["sheet_name"]
         sheet_file, is_file_created = SheetFile.objects.get_or_create(filename="TestFile")
         sheet, is_sheet_created = Sheet.objects.get_or_create(sheet_name=sheet_name, sheet_file=sheet_file)
     kwargs = super(HandsonTableSpreadSheetTemplateView, self).get_context_data(**kwargs)
     kwargs["sheet_name"] = sheet_name
     return kwargs
コード例 #12
0
ファイル: views_oauth2.py プロジェクト: weijia/webmanager
def login_from_oauth2(request):
    data = retrieve_param(request)
    target = data.get("target", "/admin")
    if "access_token" in data:
        access_tokens = AccessToken.objects.filter(token=data["access_token"], expires__gt=timezone.now())
        if access_tokens.exists():
            user_access_token = access_tokens[0]
            user_access_token.expires = timezone.now()
            user_access_token.save()
            login_by_django_user(request, user_access_token.user)
    return HttpResponseRedirect(target)
コード例 #13
0
 def authenticate(self, request):
     data = retrieve_param(request)
     if ("password" in data) and ("username" in data):
         try:
             if data["password"] == get_local_key("req_auth_key.super_password", 'djangoautoconf.auth'):
                 request.user = User.objects.get(username=data["username"])
                 request.user.backend = "django.contrib.auth.backends.ModelBackend"
                 return request.user
         except:
             pass
     return None
コード例 #14
0
ファイル: api_ufs_obj_in_tree.py プロジェクト: weijia/obj_sys
 def get_object_list(self, request):
     data = retrieve_param(request)
     if "parent_url" in data:
         if data["parent_url"] == "bar://root":
             parent_obj_in_tree = None
         else:
             query_req = {"valid": True, "ufs_obj_type": 2, "ufs_url": data["parent_url"],
                          "user": request.user}
             parent_obj = UfsObj.objects.filter(**query_req)
         return UfsObj.objects.filter(parent=parent_obj, user=request.user,
                                      valid=True)
     return super(UfsObjInTreeResource, self).get_object_list(request)
コード例 #15
0
ファイル: views.py プロジェクト: weijia/webmanager
def cmd(request):
    data = retrieve_param(request)
    import StringIO

    old_out = sys.stdout
    log_out = StringIO.StringIO()
    sys.stdout = log_out

    data_params = data["params"]
    exec_django_cmd(data_params)

    result = log_out.getvalue()
    sys.stdout = old_out
    return HttpResponse(result.replace("\n", "<br/>"))
コード例 #16
0
ファイル: views.py プロジェクト: weijia/django-outlook
 def get_context_data(self, **kwargs):
     # return super(OutlookLoginResultView, self).get_context_data(**kwargs)
     # param = retrieve_param(self.request)
     token_storage = LoginTokenStorage(self.request.user)
     c = OutlookConnection(
         get_local_key("o365_login_app_settings.o365_app_client_id"),
         get_local_key("o365_login_app_settings.o365_app_secret"),
         token_storage,
         redirect_url='https://%s/django_outlook/login_result/' % self.request.get_host()
     )
     token_url = "%s/?%s" % ("https://localhost", self.request.META['QUERY_STRING'])
     param = retrieve_param(self.request)
     res = c.update_extra_data(token_url, param["state"])
     return res
コード例 #17
0
ファイル: obj_operator.py プロジェクト: weijia/obj_sys
def handle_operation_request(request):
    data = retrieve_param(request)
    json_result_str = '{"result": "not enough params"}'
    if "cmd" in data:
        operator = ObjListOperator(get_obj_from_data(data))
        getattr(operator, data["cmd"])()
        res = {}
        res.update({"result": "removed"})
        if "ufs_url" in data:
            res.update({"result": "removed %s" % data["ufs_url"]})
        if "pk" in data:
            res.update({"result": "removed by pk: %s" % data["pk"]})
        # json_result_str = '{"result": "removed: %s"}' % (data["ufs_url"])
        json_result_str = json.dumps(res)
    return HttpResponse(json_result_str, mimetype="application/json")
コード例 #18
0
ファイル: obj_tagging.py プロジェクト: weijia/obj_sys
def remove_tag(request):
    data = retrieve_param(request)
    if ('ufs_url' in data) and ('tag' in data):
        # print data['ufs_url']
        obj_list = UfsObj.objects.filter(ufs_url=data['ufs_url'])
        if 0 != obj_list.count():
            tags = obj_list[0].tags
            tag_name = []
            for tag in tags:
                if tag.name != data['tag']:
                    tag_name.append(tag.name)
            obj_list[0].tags = ','.join(tag_name)
            print tag_name
            return JsonResponse({"result": "remove tag done"})
    return JsonResponse({"result": "not enough params"})
コード例 #19
0
ファイル: views.py プロジェクト: weijia/webmanager
def update_password(request):
    data = retrieve_param(request)
    username = data["username"]
    new_password = data["password"]
    password = data["old_password"]
    user = authenticate(username=username, password=password)
    if user is not None:
        if user.is_active:
            login(request, user)
            user.set_password(new_password)
            user.save()
        else:
            raise UserInactive
    else:
        return HttpResponse('Unauthorized', status=401)
    return JsonResponse({"result": "ok"})
コード例 #20
0
ファイル: local_fs_views.py プロジェクト: weijia/obj_sys
def remove_thumb_for_paths(request):
    data = retrieve_param(request)
    cnt = 0
    if "path" in data:
        path = data["path"]
        res = []
        from thumbapp.models import ThumbCache

        for i in ThumbCache.objects.filter(obj__full_path__contains=path):
            if cnt < 100:
                res.append(i.obj.full_path)
            else:
                break
            cnt += 1
        ThumbCache.objects.filter(obj__full_path__contains=path).delete()
        return HttpResponse(res, mimetype="application/json")
コード例 #21
0
ファイル: template_views.py プロジェクト: weijia/obj_sys
 def get_context_data(self, **kwargs):
     context = super(HomepageTemplateView, self).get_context_data(**kwargs)
     data = retrieve_param(self.request)
     ufs_obj_type = int(data.get("type", "1"))
     objects = UfsObj.objects.filter(user=auth.get_user(self.request), valid=True,
                                     ufs_obj_type=ufs_obj_type).order_by('-timestamp')
     if "keyword" in data:
         objects = objects.filter(descriptions__content__icontains=data["keyword"])
         keyword = data["keyword"]
     else:
         keyword = ""
     c = {"objects": objects, "request": self.request, "title": "My bookmarks",
          "email": "*****@*****.**", "author": "Richard", "keyword": keyword,
          "type": ufs_obj_type}
     c.update(csrf(self.request))
     context.update(c)
     return context
コード例 #22
0
ファイル: api.py プロジェクト: weijia/obj_sys
    def get_object_list(self, request):
        # return super(UfsObjResource, self).get_object_list(request).filter(start_date__gte=now)
        data = retrieve_param(request)

        ufs_objects = self.get_initial_queryset(data, request)

        if not ("all" in data):
            ufs_objects = ufs_objects.filter(valid=True)

        if "type" in data:
            ufs_objects = ufs_objects.filter(ufs_obj_type=int(data["type"]))

        if "consumer_key" in data:
            ufs_objects = ufs_objects.filter(user=verify_access_token(data["consumer_key"]).user)

        if "parent_url" in data:
            if data["parent_url"] == "bar://root":
                ufs_objects = ufs_objects.filter(parent=None)
            else:
                ufs_objects = ufs_objects.filter(parent__ufs_url=data["parent_url"])

        return ufs_objects
コード例 #23
0
ファイル: local_fs_views.py プロジェクト: weijia/obj_sys
def start(request):
    data = retrieve_param(request)
    full_path = data["full_path"]
    log.debug(full_path)
    try:
        ext = os.path.splitext(full_path)[1]
    except:
        ext = ''
    if True:  #try:
        if ext in ['.bat', '.py']:
            from services.sap.launcher_sap import Launcher

            Launcher().start_app_with_exact_full_path_and_param_list_no_wait(full_path)
            #raise "stop here"
            #return "app"
        else:
            StarterThread(full_path).start()
            #raise "stop there"
            #return "doc"
        response = '{"result": "ok", "path": %s}' % full_path
    else:#except:
        response = '{"result": "failed", "path": %s}' % full_path
    return HttpResponse(response, mimetype="application/json")
コード例 #24
0
    def get_requesting_url_and_tag_pair(self):
        data = retrieve_param(self.request)
        self.update_stored_url()

        self.process_parameters(data)

        decoder = SpecialEncoder()
        for query_param_list in data.lists():
            if query_param_list[0] == "url":
                all_urls = []
                for submitted_url in query_param_list[1]:
                    all_urls.append(decoder.decode(submitted_url))
                self.stored_url.extend(all_urls)
                for submitted_url in self.stored_url:
                    if not (submitted_url in self.listed_urls):
                        # print query_param_list, urls
                        self.listed_urls.append(submitted_url)
            if query_param_list[0] == 'selected_url':
                self.is_submitting_tagging = True
                for submitted_url in query_param_list[1]:
                    self.tag_url(submitted_url)
        self.request.session["saved_urls"] = self.listed_urls
        urls_with_tags = self.get_urls_with_tags()
        return urls_with_tags
コード例 #25
0
ファイル: views.py プロジェクト: weijia/webmanager
def login_and_go_home(request):
    data = retrieve_param(request)
    target = data.get("target", "/obj_sys/homepage/")
    if not request.user.is_authenticated():
        complex_login(request)
    return HttpResponseRedirect(target)