Beispiel #1
0
def generate_printer_dict_from_list(request, list_object):
    '''constructs an xml/plist from list_object.objects.all()
    Where the list_object is either a SubscriptionList or
    PrinterList.
    '''

    plist = []
    printers = list_object.printers.all()
    pp_site_info = site_info(request)

    if settings.SERVE_FILES and Version.objects.all():
        pp_site_info = site_info(request)
        update_server = os.path.join(pp_site_info['root'],
                                     pp_site_info['subpath'],
                                     'sparkle/client/appcast.xml',)
    else:
        update_server = settings.GITHUB_APPCAST_URL

    for printer in printers:
        printer_dict = {'name': printer.name,
                        'host': printer.host,
                        'protocol': printer.protocol,
                        'description': printer.description,
                        'location': printer.location,
                        'model': printer.model }

        if printer.ppd_file and 'root' in pp_site_info:
            ppd_url = os.path.join(pp_site_info['root'],\
                            printer.ppd_file.url.lstrip('/'))
            printer_dict["ppd_url"] = ppd_url

        option_objects = printer.options.all()
        options = []
        for opt in option_objects:
            options.append(opt.option)

        if options:
            printer_dict['options'] = options

        # If the class is a subscripton list override
        #  the location property with the subnet variable
        if isinstance(list_object, SubscriptionPrinterList):
            printer_dict['location'] = '%s_pp-printer' % (list_object.subnet)

        plist.append(printer_dict)

    xml = {'printerList': plist, 'updateServer': update_server}
    return xml
Beispiel #2
0
    def get_context_data(self, **kwargs):
        # Call the base implementation first to get a context
        context = super(IndexView, self).get_context_data(**kwargs)

        # add the static items to the context
        context['organization'] = settings.ORGANIZATION_NAME

        # Add in the querysets to
        context['printerlists'] = PrinterList.objects.filter(public=True)

        # Create a BOOL indicating whether there are any subscription lists
        context['subscriptions'] = SubscriptionPrinterList.objects.all().count() > 0

        # create the context for the verson_url
        version_url = None
        if settings.HOST_SPARKLE_UPDATES:
            version = Version.objects.filter(
                application__name=settings.APP_NAME,
                active=True).order_by('-published')
            if version:
                version_url = version[0].update.url

        # If we're not hosting updates, or it has yet to be configured
        # with any releases, use the client's GitHub release page.
        if not version_url:
            # We only need one object, so get it or create it
            version = PPClientGitHubRelease.objects.first()

            if not version:
                print 'Creating new PPClientGitHubRelease'
                version = PPClientGitHubRelease()

            # Only check-in with GitHub once a day for new releases
            # use the locally stored value every other time
            today = datetime.date.today()
            last_checked = version.last_checked
            version_url = version.url

            print "%s vs %s" % (today, last_checked)
            if not last_checked or last_checked < today:
                print "Getting latest GitHub release...."
                # version_url = github_latest_release(settings.GITHUB_LATEST_RELEASE)
                if version_url:
                    version.url = version_url

                version.last_checked = today
                print "NEW %s vs %s" % (version.last_checked, today)

                version.save()

        if version_url:
            context['version'] = version_url

        #Construct the site url used with the template tags
        #to generate the printer_portal(s) registered uri and
        #xml url for the printerlists
        context['site_info'] = site_info(self.request)

        return context
Beispiel #3
0
def appcast(request, name, testing=False):
    """Generate the appcast for the given application while recording any system profile reports"""
    application = None
    context = {}
    parameters = dict(request.GET)
    content_type = 'application/rss+xml'
    site = site_info(request)

    # Check if a parameter for testing was set (how the template specifies it)
    # the requst, or accessing the 'testing url' (how the test client would
    # specify)
    active = not parameters.get('testing', testing)
    # __default is defined in sparkle.urls context when someone access
    # the appcast by simply using "client" as the application specifier
    # e.g `http://server.com/sparkle/client/appcast.xml`
    # This is usefull when the site is only hosting a single application.
    if name == '__default':
        application = Application.objects.first()
    else:
        application = get_object_or_404(Application, name=name)

    # The template passes in the parameter "display=true" to indicate
    # the appcast should simply be displayed in the browser
    if parameters.get('display', False):
        content_type = 'application/xhtml+xml'

    # clean up the viewability parameters so we can
    # accurately determine if a report was submitted
    parameters.pop('testing', None)
    parameters.pop('display', None)

    if len(parameters):
        # create a report and records of the keys/values
        report = SystemProfileReport.objects.create(
            ip_address=request.META.get('REMOTE_ADDR'))

        for key, value in parameters.iteritems():
            record = SystemProfileReportRecord.objects.create(
                report=report,
                key=key,
                value=value)
            record.save()

    # get the latest versions
    versions = Version.objects.filter(
        application__name=application.name,
        active=active).order_by('-published')

    context = {'application': application, 'versions': versions, 'site': site}
    return render_to_response(
        'sparkle/appcast.xml', context, content_type=content_type)
Beispiel #4
0
    def get_context_data(self, **kwargs):
        context = super(ManageView, self).get_context_data(**kwargs)

        printerlists = PrinterList.objects.all()
        subscription_lists = SubscriptionPrinterList.objects.all()
        printers = Printer.objects.all()
        options = Option.objects.all()

        context['printerlists'] = printerlists
        context['subscription_lists'] = subscription_lists
        context['printers'] = printers
        context['options'] = options

        '''Construct the site url used with the template tags
        to generate the printerportal(s) registered uri and
        xml url for the printerlists'''

        context['site_info'] = site_info(self.request)

        return context