class CommissionMembership(models.Model, Jsonify): current = models.BooleanField(default=True) creation_datetime = models.DateTimeField(default=datetime.now) role = models.CharField(max_length=1337) role_en = models.CharField(max_length=1337) commission = models.ForeignKey("Commission") deputy = models.ForeignKey("Deputy") with_history = models.Manager() objects = HistoryManager()
class Deputy(models.Model, Jsonify): current = models.BooleanField(default=True) creation_datetime = models.DateTimeField(default=datetime.now) full_name = models.CharField(max_length=1337) first_name = models.CharField(max_length=1337) last_name = models.CharField(max_length=1337) sex = models.CharField(max_length=1337, null=True) emails = ListField() party = models.ForeignKey('Party') url = models.CharField(max_length=1337) websites = ListField() lachambre_id = models.CharField(max_length=1337) language = models.CharField(max_length=1337, null=True) cv = DictField() with_history = models.Manager() objects = HistoryManager() #commissions = ListField(EmbeddedModelField('CommissionMembership')) #documents_principal_author_url = models.URLField() #documents_principal_author_list = ListField(EmbeddedModelField('Document')) #documents_principal_signator_url = models.URLField() #documents_principal_signator_list = ListField(EmbeddedModelField('Document')) #documents_next_author_url = models.URLField() #documents_next_author_list = ListField(EmbeddedModelField('Document')) #documents_next_signator_url = models.URLField() #documents_next_signator_list = ListField(EmbeddedModelField('Document')) #documents_rapporter_url = models.URLField() #documents_rapporter_list = ListField(EmbeddedModelField('Document')) #questions_written_url = models.URLField() #questions_written_list = ListField(EmbeddedModelField('WrittenQuestion')) #questions_oral_plenary_url = models.URLField() #questions_oral_plenary_list = ListField(EmbeddedModelField('Question')) #questions_oral_commission_url = models.URLField() #questions_oral_commission_list = ListField(EmbeddedModelField('Question')) def __unicode__(self): return '%s - %s' % (self.full_name, self.party) class Meta: ordering = ["lachambre_id"] class MongoMeta: indexes = [[("lachambre_id", 1)]] def get_url(self): return LACHAMBRE_PREFIX + self.url if not self.url.startswith( "http") else self.url
class AnnualReport(models.Model, Jsonify): current = models.BooleanField(default=True) creation_datetime = models.DateTimeField(default=datetime.now) title = DictField() date = models.CharField(max_length=1337) law_and_article = DictField() periodicity = models.CharField(max_length=1337) pdf_url = models.URLField() with_history = models.Manager() objects = HistoryManager()
class Party(models.Model, Jsonify): current = models.BooleanField(default=True) creation_datetime = models.DateTimeField(default=datetime.now) name = models.CharField(max_length=1337) url = models.URLField() with_history = models.Manager() objects = HistoryManager() def __unicode__(self): return self.name def get_url(self): return LACHAMBRE_PREFIX + self.url if not self.url.startswith( "http") else self.url
class Document(models.Model, Jsonify): current = models.BooleanField(default=True) creation_datetime = models.DateTimeField(default=datetime.now) title = DictField() url = models.CharField(max_length=1337) full_details_url = models.CharField(max_length=1337) status_chambre = DictField() status_senat = DictField() deposition_date = models.CharField(max_length=1337, null=True) constitution_article = DictField() in_charge_commissions = ListField( EmbeddedModelField('InChargeCommissions')) plenaries = ListField(EmbeddedModelField('DocumentPlenary')) senat_plenaries = ListField(EmbeddedModelField('DocumentSenatPlenary')) timeline = ListField(EmbeddedModelField('DocumentTimeLine')) eurovoc_main_descriptor = DictField() eurovoc_descriptors = DictField() eurovoc_candidats_descriptors = DictField() keywords = DictField() lachambre_id = models.IntegerField() analysis = EmbeddedModelField('Analysis', null=True) document_chambre = EmbeddedModelField('DocumentChambre', null=True) document_senat = EmbeddedModelField('DocumentSenat', null=True) vote_date = models.CharField(max_length=1337) vote_senat_date = models.CharField(max_length=1337) law_date = models.CharField(max_length=1337) moniteur_number = models.CharField(max_length=1337) moniteur_date = models.CharField(max_length=1337) main_docs = DictField() candidature_vote_date = models.CharField(max_length=1337) done = models.BooleanField(default=False) with_history = models.Manager() objects = HistoryManager() def __unicode__(self): return "%s - %s" % (self.lachambre_id, self.title["fr"]) def get_url(self): return LACHAMBRE_PREFIX + self.url if not self.url.startswith( "http") else self.url class Meta: ordering = ["-lachambre_id"] class MongoMeta: indexes = [[("lachambre_id", -1)]]
class Commission(models.Model, Jsonify): current = models.BooleanField(default=True) creation_datetime = models.DateTimeField(default=datetime.now) lachambre_id = models.IntegerField() name = DictField() full_name = DictField() url = models.URLField() type = DictField() deputies = ListField(models.ForeignKey(CommissionMembership)) seats = DictField() with_history = models.Manager() objects = HistoryManager() def get_url(self): return LACHAMBRE_PREFIX + self.url if not self.url.startswith( "http") else self.url class Meta: ordering = ["lachambre_id"] class MongoMeta: indexes = [[("lachambre_id", 1)]]
class WrittenQuestion(models.Model, Jsonify): current = models.BooleanField(default=True) creation_datetime = models.DateTimeField(default=datetime.now) title = DictField() departement = DictField() sub_departement = DictField() author = models.CharField(max_length=1337) deposition_date = models.CharField(max_length=1337) delay_date = models.CharField(max_length=1337, null=True) eurovoc_descriptors = DictField() eurovoc_candidats_descriptors = DictField() keywords = DictField() url = models.URLField() lachambre_id = models.CharField(max_length=1337) language = models.CharField(max_length=1337) status = DictField() question_status = DictField() publication_date = models.CharField(max_length=1337) question = DictField() answer = DictField() publication_reponse_pdf_url = models.CharField(max_length=1337) publication_question_pdf_url = models.CharField(max_length=1337) publication_reponse = models.CharField(max_length=1337, null=True) publication_question = models.CharField(max_length=1337, null=True) with_history = models.Manager() objects = HistoryManager() def get_url(self): return LACHAMBRE_PREFIX + self.url if not self.url.startswith( "http") else self.url class Meta: ordering = ["lachambre_id"] class MongoMeta: indexes = [[("lachambre_id", 1)]]
UploadTooManyFilesException, handle_exception import utils UPLOAD_FOLDER = '/tmp/filebin/usercontent' app = Flask(__name__) app.secret_key = 'i should probably change this' app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER app.config['MAX_FILES_PER_UPLOAD'] = 10 app.config['MAX_CONTENT_LENGTH'] = 64 * 1024 * 1024 app.config['FILESTORE_EXPIRATION_TIME_SECONDS'] = 10 * 60 # ten minutes filestore = FileStore(app) history = HistoryManager(filestore) @app.template_filter('formatsize') def size_filter(size): return utils.sizeof_fmt(size) @app.template_filter('formatseconds') def timestamp_filter(seconds): if seconds < 10: return '0{}'.format(seconds) return seconds