Example #1
0
    def getSavedItems(self, request):
        """
        Returns a user's saved items for this plugin 
        """
        from terapix.youpi.views import get_entity_permissions

        # Full cart items count to be stored in the cache
        full_count = CartItem.objects.filter(kind__name__exact=self.id).count()
        saved = cache.get(self.id + "_saved_items")
        if saved:
            if cache.get(self.id + "_saved_items_num") == full_count:
                return saved

        items, filtered = read_proxy(request, CartItem.objects.filter(kind__name__exact=self.id).order_by("-date"))
        res = []
        for it in items:
            data = marshal.loads(base64.decodestring(str(it.data)))
            res.append(
                {
                    "date": "%s %s" % (it.date.date(), it.date.time()),
                    "username": str(it.user.username),
                    "descr": str(data["Descr"]),
                    "itemId": str(it.id),
                    "resultsOutputDir": str(self.getUserResultsOutputDir(request)),
                    "perms": json.encode(get_entity_permissions(request, "cartitem", it.id)),
                    "name": str(it.name),
                }
            )

        cache.set(self.id + "_saved_items_num", full_count)
        cache.set(self.id + "_saved_items", res)
        return res
Example #2
0
    def getSavedItems(self, request):
        """
        Returns a user's saved items. 
        """
        from terapix.youpi.views import get_entity_permissions
        # Full cart items count to be stored in the cache
        full_count = CartItem.objects.filter(kind__name__exact = self.id).count()
        saved = cache.get(self.id + '_saved_items')
        if saved:
            if cache.get(self.id + '_saved_items_num') == full_count:
                return saved

        # per-user items
        items, filtered = read_proxy(request, CartItem.objects.filter(kind__name__exact = self.id).order_by('-date'))
        res = []
        for it in items:
            data = marshal.loads(base64.decodestring(str(it.data)))
            res.append({'date'              : "%s %s" % (it.date.date(), it.date.time()), 
                        'username'          : str(it.user.username),
                        'idList'            : str(data['idList']), 
                        'resultsOutputDir'  : str(self.getUserResultsOutputDir(request, data['resultsOutputDir'], it.user.username)),
                        'aheadPath'         : str(data['aheadPath']),
                        'name'              : str(it.name),
                        'taskId'            : str(data['taskId']), 
                        'itemId'            : str(it.id), 
                        'perms'             : json.encode(get_entity_permissions(request, 'cartitem', it.id)),
                        'config'            : str(data['config'])})

        cache.set(self.id + '_saved_items_num', full_count)
        cache.set(self.id + '_saved_items', res)
        return res
Example #3
0
def cart_saved_items_stats(request):
	"""
    Return some statistic on per-plugin saved items. Uses :func:`~terapix.youpi.auth.read_proxy` 
    to filter saved items.
	"""
	stats = {}
	for plugin in manager.plugins:
		items, filtered = read_proxy(request, CartItem.objects.filter(kind__name__exact = plugin.id).order_by('-date'))
		stats[plugin.id] = len(items)
	return HttpResponse(json.encode({'stats' : stats}), mimetype = 'text/plain')
Example #4
0
    def getSavedItems(self, request):
        """
        Returns a user's saved items for this plugin 
        """
        from terapix.youpi.views import get_entity_permissions
        # Full cart items count to be stored in the cache
        full_count = CartItem.objects.filter(kind__name__exact = self.id).count()
        saved = cache.get(self.id + '_saved_items')
        if saved:
            if cache.get(self.id + '_saved_items_num') == full_count:
                return saved

        # per-user items
        items, filtered = read_proxy(request, CartItem.objects.filter(kind__name__exact = self.id).order_by('-date'))
        res = []
        for it in items:
            data = marshal.loads(base64.decodestring(str(it.data)))
            # Set default values for items without this information
            if not data.has_key('headPath'):
                data['headPath'] = 'AUTO'
            if not data.has_key('useAutoScampHeads'):
                data['useAutoScampHeads'] = 1
            if not data.has_key('useAutoQFITSWeights'):
                data['useAutoQFITSWeights'] = 1
            res.append({'date'              : "%s %s" % (it.date.date(), it.date.time()), 
                        'username'          : str(it.user.username),
                        'idList'            : str(data['idList']), 
                        'taskId'            : str(data['taskId']), 
                        'itemId'            : str(it.id), 
                        'weightPath'        : str(data['weightPath']), 
                        'headPath'          : str(data['headPath']), 
                        'resultsOutputDir'  : str(self.getUserResultsOutputDir(request, data['resultsOutputDir'], it.user.username)),
                        'useAutoQFITSWeights'   : str(data['useAutoQFITSWeights']),
                        'useAutoScampHeads'     : str(data['useAutoScampHeads']),
                        'name'              : str(it.name),
                        'headDataPaths'     : string.join([str(p) for p in data['headDataPaths']], ','),
                        'perms'             : json.encode(get_entity_permissions(request, 'cartitem', it.id)),
                        'config'            : str(data['config'])})

        cache.set(self.id + '_saved_items_num', full_count)
        cache.set(self.id + '_saved_items', res)
        return res
Example #5
0
        missing = []
        imgList = Image.objects.filter(id__in = idList).order_by('name')
        curTask = None

        for img in imgList:
            ldacMissing = aheadMissing = False
            rels = Rel_it.objects.filter(image = img)
            if not rels:
                #missing.extend([str(img.name)])
                ldacMissing = True

            relTaskIds = [rel.task.id for rel in rels]

            tasks, filtered = read_proxy(request, Processing_task.objects.filter(
                id__in = relTaskIds, 
                kind__name__exact = 'fitsin',
                success = True).order_by('-end_date'),
            )

            if not tasks:
                #missing.append(str(img.name))
                ldacMissing = True

            if not os.path.exists(os.path.join(aheadPath, img.filename + '.ahead')):
                aheadMissing = True

            if ldacMissing or aheadMissing:
                #info variable keeps name in database(not the real filename on disks)
                info = [str(img.name)]
                miss = []
                if ldacMissing: miss.append(str(img.filename) + '.ldac')
Example #6
0
    except ValueError, e:
        # Unlimitted
        limit = 0

    # First check for permission
    if not request.user.has_perm('youpi.can_view_ing_logs'):
        return HttpResponse(str({
            'Error': "Sorry, you don't have permission to view ingestion logs",
        }), mimetype = 'text/plain')

    if limit > 0:
        rset = Ingestion.objects.all().order_by('-start_ingestion_date')[:limit]
    else:
        rset = Ingestion.objects.all().order_by('-start_ingestion_date')

    res, filtered = read_proxy(request, rset)

    #
    # We build a standard header that can be used for table's header.
    # header var must be a list not a tuple since it get passed 'as is' to the json 
    # dictionary
    #
    header = ['start', 'duration', 'ID', 'user', 'fitsverified', 'validated', 'multiple', 'exit', 'log']

    data = []
    for ing in res:
        # Current user permissions
        isOwner = ing.user == request.user
        groups = [g.name for g in request.user.groups.all()]
        cuser_write = False
        perms = Permissions(ing.mode)
Example #7
0
            "dualFlagPath": dualFlagPath,
        }
        return res

    def getTaskInfo(self, request):
        """
        Returns information about a finished processing task. Used on the results page.
        """

        post = request.POST
        try:
            taskid = post["TaskId"]
        except Exception, e:
            raise PluginError, "POST argument error. Unable to process data."

        task, filtered = read_proxy(request, Processing_task.objects.filter(id=taskid))
        if not task:
            return {"Error": str("Sorry, you don't have permission to see this result entry.")}
        task = task[0]
        data = Plugin_sex.objects.filter(task__id=taskid)[0]

        # Error log content
        if task.error_log:
            err_log = str(zlib.decompress(base64.decodestring(task.error_log)))
        else:
            err_log = ""

        if data.log:
            sexlog = str(zlib.decompress(base64.decodestring(data.log)))
        else:
            sexlog = ""