Example #1
0
        
    def get_embed_url(self):
        return "http://" + self.padserver + '/p/' + pad_slugify(self.padname)
    
    def get_api_url(self):
        return "http://" + self.padserver + '/api/'
    
    def save(self,*args,**kwargs):
        if not self.pk:
            self.slug = self.padserver + '/p/' + pad_slugify(self.padname)  
    
    def preview(self):
        try:
            c = EtherpadLiteClient(base_url=self.get_api_url())
            data = c.getHTML(padID=self.padname)
            return data
        except (HTTPError, URLError):
            return super(Etherpad,self).preview()
        
    @staticmethod
    def make_from_slug(parent,slug):
        tokens = slug.split('/p/')
        if(len(tokens) != 2):
            print "bouh"
            print slug
            raise ValidationError(_("Impossible de reconstruire l'adresse du PAD correspondant à " + slug ))
        padname = pad_deslugify(tokens[1])
        return Etherpad(parent=parent,name=padname,slug=slug,padserver="http://" + tokens[0],padname=padname)

register_resource(Etherpad)
Example #2
0
    def save(self, *args, **kwargs):
        if not self.pk:
            u = urlparse(self.url)
            self.slug = u.netloc + self.link
        self.set_defaults()
        super(FeedEntry, self).save(*args, **kwargs)

    def data(self):
        return {'html': self.entry.content[0].value}

    def preview(self):
        if not self.description:
            if 'description' in self.entry:
                return self.entry['description']
        return self.description

    @staticmethod
    def make_from_slug(parent, slug):
        'Construct feed entry from its slug'
        feed_path = FeedBase.make_feed_path(slug)
        u = urlparse("http://" + slug)
        ret = FeedEntry(parent=parent,
                        site_url="http://" + u.netloc,
                        feed_path=feed_path,
                        link=u.path + u.params + u.query + u.fragment)
        ret.set_defaults()
        return ret


register_resource(Feed)
register_resource(FeedEntry)
Example #3
0
        SUBSCRIBE_DATA['pw-conf'] = password
        SUBSCRIBE_DATA['fullname'] = name
        SUBSCRIBE_DATA['language'] = language
        opener = urllib2.build_opener(MultipartPostHandler(self.encoding, True))
        request = opener.open(url, SUBSCRIBE_DATA)
        content = request.read()
        for status in SUBSCRIBE_MSG:
            if len(re.findall(status, content)) > 0:
                return True
        raise Exception(content)

    def user_unsubscribe(self, email, language='fr'):

        url = '%s/options/%s/%s' % (self.main_url, self.listname, email)

        email = check_encoding(email, self.encoding)

        UNSUBSCRIBE_DATA['email'] = email
        UNSUBSCRIBE_DATA['language'] = language
        UNSUBSCRIBE_DATA['login-unsub'] = UNSUBSCRIBE_BUTTON[language]
        
        opener = urllib2.build_opener(MultipartPostHandler(self.encoding, True))
        request = opener.open(url, UNSUBSCRIBE_DATA)
        content = request.read()
        for status in UNSUBSCRIBE_MSG:
            if len(re.findall(status, content)) > 0:
                return True
        raise Exception(content)
            
register_resource(MailmanList)
Example #4
0
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from catalog.models.base import Resource,GeoLocation,register_resource
from django.db import models
from django.utils.translation import ugettext_lazy as __

class Human(Resource):
    """Une personne susceptible de contribuer à un apprentissage."""
    geo = models.ForeignKey(GeoLocation,default=None,null=True,blank=True,verbose_name=__(u'Localisation'), help_text=__(u'Le lieu où se trouve la personne'))
    email = models.EmailField(blank=True,verbose_name=__(u'Adresse électronique'), help_text=__(u"Une adresse où joindre cette personne"))
    user = models.ForeignKey('auth.User',default=None,null=True,blank=True,verbose_name=__(u'Identifiant'),help_text=__(u"L'identifiant du compte associé à cette personne si elle en possède un"))
    class Meta:
        verbose_name =  __('Humain-e')
        verbose_name_plural =  __('Humain-e-s')
        
    def save(self,*args,**kwargs):
        if not self.pk and not self.name and self.user:
            self.name = self.user.username
        super(Human, self).save(*args,**kwargs) 

register_resource(Human)
Example #5
0
    def save(self, *args, **kwargs):
        if not self.pk:
            self.slug = self.padserver + '/p/' + pad_slugify(self.padname)

    def preview(self):
        try:
            c = EtherpadLiteClient(base_url=self.get_api_url())
            data = c.getHTML(padID=self.padname)
            return data
        except (HTTPError, URLError):
            return super(Etherpad, self).preview()

    @staticmethod
    def make_from_slug(parent, slug):
        tokens = slug.split('/p/')
        if (len(tokens) != 2):
            print "bouh"
            print slug
            raise ValidationError(
                _("Impossible de reconstruire l'adresse du PAD correspondant à "
                  + slug))
        padname = pad_deslugify(tokens[1])
        return Etherpad(parent=parent,
                        name=padname,
                        slug=slug,
                        padserver="http://" + tokens[0],
                        padname=padname)


register_resource(Etherpad)
Example #6
0
        return self.entry.title
    def set_defaults(self):
        if not self.name:
            self.name = self.entry.title
        if not self.description:
            if 'description' in self.entry:
                self.description = self.entry['description']            
    def save(self,*args,**kwargs):
        if not self.pk:
            u = urlparse(self.url)
            self.slug = u.netloc + self.link 
        self.set_defaults()
        super(FeedEntry, self).save(*args,**kwargs)  
    def data(self):
        return {'html': self.entry.content[0].value }
    def preview(self):
        if not self.description:
            if 'description' in self.entry:
                return self.entry['description']
        return self.description
    @staticmethod
    def make_from_slug(parent,slug):
        'Construct feed entry from its slug'
        feed_path = FeedBase.make_feed_path(slug)
        u = urlparse("http://" + slug)
        ret = FeedEntry(parent=parent,site_url="http://" + u.netloc,feed_path=feed_path,link=u.path+u.params+u.query+u.fragment)
        ret.set_defaults()
        return ret
    
register_resource(Feed)        
register_resource(FeedEntry)
    Model of a way which is attached to a session,
     to which resources created on-the-fly get attached by default
    """
    user = models.OneToOneField(
        User,
        related_name='way',
        help_text=__(u"L'utilisateur.rice propriétaire de la session"))

    class Meta:
        verbose_name = __('Ton Parcours')
        verbose_name_plural = __('Parcours d\'utilisat.rice.eur')

    def __init__(self, *args, **kwargs):
        if not 'name' in kwargs:
            kwargs['name'] = _('Ajouter un titre...')
        if 'parent' in kwargs:
            raise ValidationError('SessionWay cannot have a parent!')
        kwargs['public'] = False
        super(SessionWay, self).__init__(*args, **kwargs)

    def save(self, *args, **kwargs):
        if not self.pk:
            self.slug = ''
        super(SessionWay, self).save(*args, **kwargs)

    def get_absolute_url(self):
        return reverse('catalog:sessionway-view')


register_resource(Way)
#register_resource(SessionWay)
Example #8
0
        null=True,
        blank=True,
        verbose_name=__(u'Localisation'),
        help_text=__(u'La localisation géographique du lieu'))
    phone_number = PhoneNumberField(
        null=True,
        blank=True,
        verbose_name=__(u'Téléphone'),
        help_text=__(u'Un numéro de téléphone fixe'))
    opening_times = models.CharField(
        max_length=200,
        blank=True,
        default='',
        verbose_name=__(u'Horaires'),
        help_text=__(u"Les horaires d'accueil du lieu"))

    @staticmethod
    def make_from_slug(parent, slug):
        return Place(parent=parent, geo=GeoLocation.make_from_slug(slug))

    def save(self, *args, **kwargs):
        if not self.pk:
            self.slug = self.geo.slug()

    class Meta:
        verbose_name = __('Lieu')
        verbose_name_plural = __('Lieux')


register_resource(Place)
Example #9
0
    def clean(self):
        # check if an article with this title exists in the provided wiki
        new_title = self.wiki.get_redirect_title(self.title)
        if new_title is '':
            raise ValidationError(_('L\'article "' + self.title + '" n\'existe pas sur ' + self.wiki.name ))
        self.title = new_title
        super(WikimediaArticle, self).clean()
    def save(self,*args,**kwargs):
        if not self.pk:
            self.slug = self.wiki.slugify(self.title)
            self.name = self.title
        super(WikimediaArticle, self).save(*args,**kwargs)
    @staticmethod
    def make_from_slug(parent,slug):
        wiki,name,snippet = Wiki.make_from_slug(slug)
        return WikimediaArticle(name=name,wiki=wiki,title=name,parent=parent,description=snippet)    
    def data(self):
        """Returns raw HTML data of the article fetched using the Wikimedia API"""
        return {'html': self.wiki.get_page(self.title) }
    def source_url(self):
        """Returns the URL of the article on the source Wiki"""
        p = urlsplit(self.wiki.url)
        return 'http://' + p.netloc + '/wiki/' + wiki_slugify(self.title) 
    class ExternalSearch:
        "Search for articles matching a given query on available wikis"
        sources = staticmethod(Wiki.list_all_wikis)
        search = staticmethod(Wiki.search_all_wikis)
    

register_resource(WikimediaArticle)
        if not self.pk:
            self.slug = self.wiki.slugify(self.title)
            self.name = self.title
        super(WikimediaArticle, self).save(*args, **kwargs)

    @staticmethod
    def make_from_slug(parent, slug):
        wiki, name, snippet = Wiki.make_from_slug(slug)
        return WikimediaArticle(name=name,
                                wiki=wiki,
                                title=name,
                                parent=parent,
                                description=snippet)

    def data(self):
        """Returns raw HTML data of the article fetched using the Wikimedia API"""
        return {'html': self.wiki.get_page(self.title)}

    def source_url(self):
        """Returns the URL of the article on the source Wiki"""
        p = urlsplit(self.wiki.url)
        return 'http://' + p.netloc + '/wiki/' + wiki_slugify(self.title)

    class ExternalSearch:
        "Search for articles matching a given query on available wikis"
        sources = staticmethod(Wiki.list_all_wikis)
        search = staticmethod(Wiki.search_all_wikis)


register_resource(WikimediaArticle)
Example #11
0
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from catalog.models.base import Resource,GeoLocation,register_resource
from catalog.models.place import Place
from django.db import models
from schedule.models import Event
from django.utils.translation import ugettext_lazy as __
from django.contrib.auth.models import User

class Meeting(Resource,Event):
    """Un ou plusieurs évènements pendant lesquels des personnes se retrouvent pour agir, apprendre, échanger..."""
    places = models.ManyToManyField(Place,verbose_name=__(u'Où?'), help_text=__(u'Lieu(x) de rendez-vous'))
    participants = models.ManyToManyField(User)
    mixite = models.CharField(max_length=50,default=__(u'Aucune'),blank=True,verbose_name=__(u'Non-mixité'), help_text=__(u'Régle de non-mixité'))
    class Meta:
        verbose_name =  __('Rencontre')
        verbose_name_plural =  __('Rencontres')    
    def save(self,*args,**kwargs):
        self.title = self.name
        self.calendar = self.parent.calendar
        super(Meeting, self).save(*args,**kwargs)

register_resource(Meeting)
                            default=None,
                            null=True,
                            blank=True,
                            verbose_name=__(u'Localisation'),
                            help_text=__(u'Le lieu où se trouve la personne'))
    email = models.EmailField(
        blank=True,
        verbose_name=__(u'Adresse électronique'),
        help_text=__(u"Une adresse où joindre cette personne"))
    user = models.ForeignKey(
        'auth.User',
        default=None,
        null=True,
        blank=True,
        verbose_name=__(u'Identifiant'),
        help_text=__(
            u"L'identifiant du compte associé à cette personne si elle en possède un"
        ))

    class Meta:
        verbose_name = __('Humain-e')
        verbose_name_plural = __('Humain-e-s')

    def save(self, *args, **kwargs):
        if not self.pk and not self.name and self.user:
            self.name = self.user.username
        super(Human, self).save(*args, **kwargs)


register_resource(Human)
Example #13
0
        opener = urllib2.build_opener(MultipartPostHandler(
            self.encoding, True))
        request = opener.open(url, SUBSCRIBE_DATA)
        content = request.read()
        for status in SUBSCRIBE_MSG:
            if len(re.findall(status, content)) > 0:
                return True
        raise Exception(content)

    def user_unsubscribe(self, email, language='fr'):

        url = '%s/options/%s/%s' % (self.main_url, self.listname, email)

        email = check_encoding(email, self.encoding)

        UNSUBSCRIBE_DATA['email'] = email
        UNSUBSCRIBE_DATA['language'] = language
        UNSUBSCRIBE_DATA['login-unsub'] = UNSUBSCRIBE_BUTTON[language]

        opener = urllib2.build_opener(MultipartPostHandler(
            self.encoding, True))
        request = opener.open(url, UNSUBSCRIBE_DATA)
        content = request.read()
        for status in UNSUBSCRIBE_MSG:
            if len(re.findall(status, content)) > 0:
                return True
        raise Exception(content)


register_resource(MailmanList)