Skip to content
This repository has been archived by the owner on Sep 3, 2021. It is now read-only.

Commit

Permalink
Merge pull request #31 from SemmLille/dev
Browse files Browse the repository at this point in the history
Dev 1.2
  • Loading branch information
ptitloup committed Jun 24, 2015
2 parents fcf4363 + a8685a7 commit b80efaf
Show file tree
Hide file tree
Showing 165 changed files with 6,070 additions and 15,500 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ media/
*pods/fixtures/
pod_project/urls.py
## Lang files
*.po
locale/
*.mo
## Others
jwplayer/
Expand Down
Empty file.
Empty file.
81 changes: 81 additions & 0 deletions pod_project/core/management/commands/add_user.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# -*- coding: utf-8 -*-

import commands
import csv
import os

from django.core.management.base import NoArgsCommand

import random
import string

from django.contrib.auth.models import User
from django.core.validators import validate_email
from django.core.exceptions import ValidationError



from django.db import IntegrityError
from django.core.mail import send_mail
from random import choice
from string import digits, letters
from core.models import UserProfile

def _pw(length=6):
s = ''
for i in range(length):
s += random.choice(digits + letters)
return s

class Command(NoArgsCommand):


def handle_noargs(self, **options):
""" Encode all pending streams """
members = open('import_user.csv', "rU")
data = csv.reader(members, delimiter=';', quotechar='"')
#data = csv.DictReader(members)

for row in data:
#print u'%s' %row
nom = row[0]
prenom = row[1]
email = row[2]
is_staff = True if row[3]=="1" else False
detail=""
try:
detail = u'%s' %unicode(row[4], errors='ignore')
except Exception as e:
print u'\nError in adding info video ***** Unexpected error :%r' % e

print nom, prenom, email, is_staff, detail
try:
validate_email(email)
tokens = email.split('@')
username = tokens[0]
#print "email valide : %s" %username
add_user(nom, prenom, username, email, is_staff, detail)
except ValidationError:
print "email is not valid"



def add_user(nom, prenom, username, email, is_staff, detail):
pwd = ''.join([random.choice(string.digits + string.letters) for i in range(0, 10)])
message = u'Bonjour,\nUn compte a été créé pour vous sur PodMoot. Voici les informations de connexion : \n - Identifiant : %(id)s\n - Mot de passe : %(mdp)s\n A bientôt sur http://podmoot.univ-lille1.fr.\nCordialement, \n L\'équipe de Pod.' %{"id":username, "mdp":pwd}
try:
user = User.objects.create_user(username, email, pwd)
user.is_staff = is_staff
user.first_name = prenom
user.last_name = nom
user.save()
profile, created = UserProfile.objects.get_or_create(user=user)
profile.commentaire = u'%s \n- %s' %(detail,message)
profile.save()
#send email
send_mail('Votre compte sur PodMoot', message, 'nicolas.can@univ-lille1.fr',[email], fail_silently=False)
print "%s - %s => ok" %(username,pwd)
except IntegrityError:
print "IntegrityError %s" %username


4 changes: 2 additions & 2 deletions pod_project/core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,9 @@ class Video(models.Model):
editable=False)
owner = models.ForeignKey(User, verbose_name=_('Owner'))

date_added = models.DateField(_('Creation date'), default=datetime.now)
date_added = models.DateField(_('Date added'), default=datetime.now)
date_evt = models.DateField(
_(u'Date of the event'), default=datetime.now, blank=True, null=True)
_(u'Date of event'), default=datetime.now, blank=True, null=True)
description = RichTextField(
_('Description'), config_name='complete', blank=True)

Expand Down
Loading

0 comments on commit b80efaf

Please sign in to comment.